Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ concurrency:
jobs:
build:
uses: openmrs/openmrs-contrib-gha-workflows/.github/workflows/build-backend-module.yml@main
with:
java_versions: '[8]'
secrets:
MAVEN_REPO_USERNAME: ${{ secrets.MAVEN_REPO_USERNAME }}
MAVEN_REPO_API_KEY: ${{ secrets.MAVEN_REPO_API_KEY }}
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>xforms</artifactId>
<version>4.3.19-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<artifactId>xforms-api</artifactId>
Expand Down
128 changes: 78 additions & 50 deletions api/src/main/java/org/openmrs/module/xforms/BasicFormBuilder.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
Expand Down Expand Up @@ -30,53 +30,69 @@
import org.openmrs.module.xforms.util.XformsUtil;
import org.openmrs.util.OpenmrsConstants;


/**
* Builds the basic form.
*/
public class BasicFormBuilder {

private static final int FIELD_TYPE_CONCEPT = 1;

private static final int FIELD_TYPE_SECTION = 5;

private static final int FIELD_TYPE_DATABASE_ELEMENT = 2;

private static final String SECTION_NAME_PATIENT = "PATIENT";

private static final String SECTION_NAME_ENCOUNTER = "ENCOUNTER";

private static final String SECTION_NAME_OBS = "OBS";

private static final String TABLE_NAME_PATIENT_NAME = "patient_name";

private static final String TABLE_NAME_PATIENT = "patient";

private static final String TABLE_NAME_PATIENT_IDENTIFIER = "patient_identifier";

private static final String TABLE_NAME_ENCOUNTER = "encounter";

private static final String FIELD_FAMILY_NAME = "PATIENT.FAMILY_NAME";

private static final String FIELD_GIVEN_NAME = "PATIENT.GIVEN_NAME";

private static final String FIELD_MIDDLE_NAME = "PATIENT.MIDDLE_NAME";

private static final String FIELD_MEDICAL_RECORD_NUMBER = "PATIENT.MEDICAL_RECORD_NUMBER";

private static final String FIELD_PATIENT_ID = "PATIENT.PATIENT_ID";

private static final String FIELD_SEX = "PATIENT.SEX";

private static final String FIELD_BIRTHDATE = "PATIENT.BIRTHDATE";

private static final String FIELD_ENCOUNTER_DATETIME = "ENCOUNTER.ENCOUNTER_DATETIME";

private static final String FIELD_LOCATION_ID = "ENCOUNTER.LOCATION_ID";

private static final String FIELD_PROVIDER_ID = "ENCOUNTER.PROVIDER_ID";

private static final int CONCEPT_CLASS_MISC = 11;

private static final int CONCEPT_DATATYPE_NA = 4;

private static final String CONCEPT_NAME_MEDICAL_RECORD_OBSERVATIONS = "MEDICAL RECORD OBSERVATIONS";


public static void addDefaultFields(Form form){
public static void addDefaultFields(Form form) {

FormService formService = Context.getFormService();

//Add patient section.
Field patientSection = getPatientSection(formService);
FormField patientFormField = getNewFormField(); patientSection.toString();
FormField patientFormField = getNewFormField();
patientSection.toString();
patientFormField.setField(patientSection);
patientFormField.setFieldNumber(1);
form.addFormField(patientFormField);

//Add encounter section.
Field encounterSection = getEncounterSection(formService);
FormField encounterFormField = getNewFormField();
Expand All @@ -92,27 +108,36 @@ public static void addDefaultFields(Form form){
form.addFormField(obsFormField);

//Add patient section fields.
addDatabaseElementField(formService, form, FIELD_FAMILY_NAME, TABLE_NAME_PATIENT_NAME, "family_name", "$!{patient.getFamilyName()}", patientFormField);
addDatabaseElementField(formService, form, FIELD_GIVEN_NAME, TABLE_NAME_PATIENT_NAME, "given_name", "$!{patient.getGivenName()}", patientFormField);
addDatabaseElementField(formService, form, FIELD_MIDDLE_NAME, TABLE_NAME_PATIENT_NAME, "middle_name", "$!{patient.getMiddleName()}", patientFormField);
addDatabaseElementField(formService, form, FIELD_BIRTHDATE, TABLE_NAME_PATIENT, "birthdate", "$!{date.format($patient.getBirthdate())}", patientFormField);
addDatabaseElementField(formService, form, FIELD_SEX, TABLE_NAME_PATIENT, "gender", "$!{patient.getGender()}", patientFormField);
addDatabaseElementField(formService, form, FIELD_PATIENT_ID, TABLE_NAME_PATIENT, "patient_id", "$!{patient.getPatientId()}", patientFormField);
addDatabaseElementField(formService, form, FIELD_MEDICAL_RECORD_NUMBER, TABLE_NAME_PATIENT_IDENTIFIER, "identifier", "$!{patient.getPatientIdentifier(1).getIdentifier()}", patientFormField);
addDatabaseElementField(formService, form, FIELD_FAMILY_NAME, TABLE_NAME_PATIENT_NAME, "family_name",
"$!{patient.getFamilyName()}", patientFormField);
addDatabaseElementField(formService, form, FIELD_GIVEN_NAME, TABLE_NAME_PATIENT_NAME, "given_name",
"$!{patient.getGivenName()}", patientFormField);
addDatabaseElementField(formService, form, FIELD_MIDDLE_NAME, TABLE_NAME_PATIENT_NAME, "middle_name",
"$!{patient.getMiddleName()}", patientFormField);
addDatabaseElementField(formService, form, FIELD_BIRTHDATE, TABLE_NAME_PATIENT, "birthdate",
"$!{date.format($patient.getBirthdate())}", patientFormField);
addDatabaseElementField(formService, form, FIELD_SEX, TABLE_NAME_PATIENT, "gender", "$!{patient.getGender()}",
patientFormField);
addDatabaseElementField(formService, form, FIELD_PATIENT_ID, TABLE_NAME_PATIENT, "patient_id",
"$!{patient.getPatientId()}", patientFormField);
addDatabaseElementField(formService, form, FIELD_MEDICAL_RECORD_NUMBER, TABLE_NAME_PATIENT_IDENTIFIER, "identifier",
"$!{patient.getPatientIdentifier(1).getIdentifier()}", patientFormField);

//Add encounter section fields.
addDatabaseElementField(formService, form, FIELD_ENCOUNTER_DATETIME, TABLE_NAME_ENCOUNTER, "encounter_datetime", null, encounterFormField);
addDatabaseElementField(formService, form, FIELD_LOCATION_ID, TABLE_NAME_ENCOUNTER, "location_id", null, encounterFormField);
addDatabaseElementField(formService, form, FIELD_PROVIDER_ID, TABLE_NAME_ENCOUNTER, "provider_id", null, encounterFormField);

addDatabaseElementField(formService, form, FIELD_ENCOUNTER_DATETIME, TABLE_NAME_ENCOUNTER, "encounter_datetime",
null, encounterFormField);
addDatabaseElementField(formService, form, FIELD_LOCATION_ID, TABLE_NAME_ENCOUNTER, "location_id", null,
encounterFormField);
addDatabaseElementField(formService, form, FIELD_PROVIDER_ID, TABLE_NAME_ENCOUNTER, "provider_id", null,
encounterFormField);

//Finally save everything.
formService.saveForm(form);
}

private static Field getPatientSection(FormService formService){
private static Field getPatientSection(FormService formService) {
Field field = getField(formService, SECTION_NAME_PATIENT, FIELD_TYPE_SECTION);
if(field == null){
if (field == null) {
field = getNewField();
field.setName(SECTION_NAME_PATIENT);
field.setFieldType(formService.getFieldType(FIELD_TYPE_SECTION));
Expand All @@ -122,9 +147,9 @@ private static Field getPatientSection(FormService formService){
return field;
}

private static Field getEncounterSection(FormService formService){
private static Field getEncounterSection(FormService formService) {
Field field = getField(formService, SECTION_NAME_ENCOUNTER, FIELD_TYPE_SECTION);
if(field == null){
if (field == null) {
field = getNewField();
field.setName(SECTION_NAME_ENCOUNTER);
field.setFieldType(formService.getFieldType(FIELD_TYPE_SECTION));
Expand All @@ -134,20 +159,19 @@ private static Field getEncounterSection(FormService formService){
return field;
}

private static Field getObsSection(FormService formService){
private static Field getObsSection(FormService formService) {
Field field = getField(formService, SECTION_NAME_OBS, FIELD_TYPE_CONCEPT);
if(field == null) {
if (field == null) {
field = getField(formService, SECTION_NAME_OBS, FIELD_TYPE_CONCEPT);
}

if(field == null){
if (field == null) {
field = getNewField();
field.setName(SECTION_NAME_OBS);
field.setFieldType(formService.getFieldType(FIELD_TYPE_CONCEPT));
field.setConcept(getObsSectionConcept());
field.setDescription("Obs section of form");
}
else if (field.getConcept() == null) {
} else if (field.getConcept() == null) {
field.setConcept(getObsSectionConcept());
}

Expand All @@ -160,8 +184,9 @@ private static Concept getObsSectionConcept() {
return concept;
}

String conceptId = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS);
if(conceptId != null && StringUtils.isNumeric(conceptId)) {
String conceptId = Context.getAdministrationService()
.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS);
if (conceptId != null && StringUtils.isNumeric(conceptId)) {
concept = Context.getConceptService().getConcept(Integer.parseInt(conceptId));
if (concept != null) {
return concept;
Expand All @@ -170,20 +195,22 @@ private static Concept getObsSectionConcept() {

concept = new Concept();
concept.addName(new ConceptName(CONCEPT_NAME_MEDICAL_RECORD_OBSERVATIONS, Context.getLocale()));
concept.addDescription(new ConceptDescription("General description for clinical observations entered into the system.", Context.getLocale()));
concept.addDescription(new ConceptDescription(
"General description for clinical observations entered into the system.", Context.getLocale()));
concept.setConceptClass(new ConceptClass(CONCEPT_CLASS_MISC));
concept.setDatatype(new ConceptDatatype(CONCEPT_DATATYPE_NA));
concept = Context.getConceptService().saveConcept(concept);

GlobalProperty globalProperty = Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS);
GlobalProperty globalProperty = Context.getAdministrationService()
.getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS);

if (globalProperty == null) {
globalProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS,
concept.getConceptId().toString(), "The concept id of the MEDICAL_RECORD_OBSERVATIONS concept. " +
"This concept_id is presumed to be the generic grouping (obr) concept in hl7 messages. " +
"An obs_group row is not created for this concept.");
}
else {
globalProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS,
concept.getConceptId().toString(),
"The concept id of the MEDICAL_RECORD_OBSERVATIONS concept. "
+ "This concept_id is presumed to be the generic grouping (obr) concept in hl7 messages. "
+ "An obs_group row is not created for this concept.");
} else {
globalProperty.setPropertyValue(concept.getConceptId().toString());
}

Expand All @@ -192,13 +219,12 @@ private static Concept getObsSectionConcept() {
return concept;
}

private static Field getField(FormService formService, String name, int type){
private static Field getField(FormService formService, String name, int type) {
List<Field> fields = formService.getFields(name);
if(fields != null){
for(Field field : fields){
if(field.getFieldType() != null &&
field.getFieldType().getFieldTypeId() == type &&
field.getName().equalsIgnoreCase(name)){
if (fields != null) {
for (Field field : fields) {
if (field.getFieldType() != null && field.getFieldType().getFieldTypeId() == type
&& field.getName().equalsIgnoreCase(name)) {
return field;
}
}
Expand All @@ -207,9 +233,10 @@ private static Field getField(FormService formService, String name, int type){
return null;
}

private static void addDatabaseElementField(FormService formService, Form form, String name, String tableName, String attributeName, String defaultValue, FormField parentFormField){
private static void addDatabaseElementField(FormService formService, Form form, String name, String tableName,
String attributeName, String defaultValue, FormField parentFormField) {
Field field = getField(formService, name, FIELD_TYPE_DATABASE_ELEMENT);
if(field == null){
if (field == null) {
field = getNewField();
field.setName(name);
field.setFieldType(formService.getFieldType(FIELD_TYPE_DATABASE_ELEMENT));
Expand All @@ -224,7 +251,7 @@ private static void addDatabaseElementField(FormService formService, Form form,
form.addFormField(formField);
}

private static Field getNewField(){
private static Field getNewField() {
Field field = new Field();
field.setUuid(UUID.randomUUID().toString());
field.setCreator(Context.getAuthenticatedUser());
Expand All @@ -233,7 +260,7 @@ private static Field getNewField(){
return field;
}

private static FormField getNewFormField(){
private static FormField getNewFormField() {
FormField formField = new FormField();
formField.setUuid(UUID.randomUUID().toString());
formField.setCreator(Context.getAuthenticatedUser());
Expand All @@ -243,12 +270,13 @@ private static FormField getNewFormField(){
return formField;
}

public static String getFormXslt(){
public static String getFormXslt() {

try{
try {
String fileName = XformsUtil.isOnePointNineAndAbove() ? "form_xslt.xml" : "form_xslt_pre19.xml";
StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(new InputStreamReader(BasicFormBuilder.class.getResourceAsStream(fileName), XformConstants.DEFAULT_CHARACTER_ENCODING));
BufferedReader reader = new BufferedReader(new InputStreamReader(
BasicFormBuilder.class.getResourceAsStream(fileName), XformConstants.DEFAULT_CHARACTER_ENCODING));

char[] buf = new char[1024];
int numRead = 0;
Expand All @@ -260,7 +288,7 @@ public static String getFormXslt(){
reader.close();
return fileData.toString();
}
catch(Exception ex){
catch (Exception ex) {
ex.printStackTrace();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
Expand All @@ -12,7 +12,7 @@
import org.openmrs.patient.impl.LuhnIdentifierValidator;

public class DanielLuhnIdentifierValidator extends LuhnIdentifierValidator {

/**
* @see org.openmrs.patient.IdentifierValidator#getName()
*/
Expand Down
22 changes: 12 additions & 10 deletions api/src/main/java/org/openmrs/module/xforms/FormModuleHandler.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
Expand All @@ -12,22 +12,24 @@
import org.openmrs.Form;

public class FormModuleHandler extends Form {

private static final long serialVersionUID = 1L;

private Form form;

private String moduleId;

private boolean appendModuleId;

public FormModuleHandler(Form form, String moduleId) {
this.form = form;
this.moduleId = moduleId;
}

public String getName() {
return form.getName() + (appendModuleId ? " - (" + moduleId + ")" : "");
}

public Integer getFormId() {
return form.getFormId();
}
Expand All @@ -39,19 +41,19 @@ public Boolean getPublished() {
public Boolean getRetired() {
return form.getRetired();
}

public boolean isAppendModuleId() {
return appendModuleId;
}

public void setAppendModuleId(boolean appendModuleId) {
this.appendModuleId = appendModuleId;
}

public Form getForm() {
return form;
}

public void setForm(Form form) {
this.form = form;
}
Expand Down
Loading