diff --git a/api-tests/src/test/java/org/openmrs/module/htmlformentry/HtmlFormEntryUtilTest.java b/api-tests/src/test/java/org/openmrs/module/htmlformentry/HtmlFormEntryUtilTest.java index b2f504b83..d1bdb6e27 100644 --- a/api-tests/src/test/java/org/openmrs/module/htmlformentry/HtmlFormEntryUtilTest.java +++ b/api-tests/src/test/java/org/openmrs/module/htmlformentry/HtmlFormEntryUtilTest.java @@ -1114,6 +1114,21 @@ public void stringToDocument_shouldNotAccessFilesystemResources() throws java.io } + @Test + @Verifies(value = "shouldSetValueTextToProviderIdGivenAProvider", method = "createObs(Concept concept, Object value, Date datetime, String accessionNumber)") + public void createObs_shouldSetValueTextToProviderIdGivenAProvider() { + Provider provider = new Provider(); + provider.setId(42); + + Concept c = new Concept(); + ConceptDatatype cd = new ConceptDatatype(); + cd.setUuid("8d4a4ab4-c2cc-11de-8d13-0010c6dffd0f"); + c.setDatatype(cd); + + Obs o = HtmlFormEntryUtil.createObs(c, provider, null, null); + Assert.assertEquals("42", o.getValueText()); + } + @Test @Verifies(value = "shouldSetTheValueComplexOfObsIfConceptIsComplex", method = "createObs(Concept concept, Object value, Date datetime, String accessionNumber)") public void createObs_shouldSetTheValueComplexOfObsIfConceptIsComplex() { diff --git a/api-tests/src/test/java/org/openmrs/module/htmlformentry/element/ObsSubmissionElementTest.java b/api-tests/src/test/java/org/openmrs/module/htmlformentry/element/ObsSubmissionElementTest.java index 3484fc10b..9983e06fd 100644 --- a/api-tests/src/test/java/org/openmrs/module/htmlformentry/element/ObsSubmissionElementTest.java +++ b/api-tests/src/test/java/org/openmrs/module/htmlformentry/element/ObsSubmissionElementTest.java @@ -37,6 +37,7 @@ import org.openmrs.ConceptNumeric; import org.openmrs.api.ConceptNameType; import org.openmrs.api.context.Context; +import org.openmrs.module.htmlformentry.BadFormDesignException; import org.openmrs.module.htmlformentry.FormEntryContext; import org.openmrs.module.htmlformentry.HtmlFormEntryUtil; import org.openmrs.module.htmlformentry.TestUtil; @@ -84,7 +85,7 @@ public void tearDown() { } @Test - public void testShowUnitsUsingTrue() { + public void testShowUnitsUsingTrue() throws Exception { ConceptDatatype numeric = new ConceptDatatype(); numeric.setUuid(ConceptDatatype.NUMERIC_UUID); @@ -106,7 +107,7 @@ public void testShowUnitsUsingTrue() { @Test @Ignore - public void testShowUnitsUsingCode() { + public void testShowUnitsUsingCode() throws Exception { ConceptDatatype numeric = new ConceptDatatype(); numeric.setUuid(ConceptDatatype.NUMERIC_UUID); @@ -211,31 +212,31 @@ public void testForcingLocaleOnRadioLabels() throws Exception { } @Test(expected = RuntimeException.class) - public void testNoConceptId_shouldThrowException() { + public void testNoConceptId_shouldThrowException() throws Exception { new ObsSubmissionElement(context, params); } @Test(expected = RuntimeException.class) - public void testDuplicateConceptIds_shouldThrowException() { + public void testDuplicateConceptIds_shouldThrowException() throws Exception { params.put("conceptId", "1"); params.put("conceptIds", "2"); new ObsSubmissionElement(context, params); } @Test(expected = RuntimeException.class) - public void testInvalidConceptIds_shouldThrowException() { + public void testInvalidConceptIds_shouldThrowException() throws Exception{ params.put("conceptIds", "adas,asda"); new ObsSubmissionElement(context, params); } @Test(expected = RuntimeException.class) - public void testEmptyConceptIds_shouldThrowException() { + public void testEmptyConceptIds_shouldThrowException() throws Exception { params.put("conceptIds", ""); new ObsSubmissionElement(context, params); } @Test(expected = RuntimeException.class) - public void testInvalidAnswerConceptIds_shouldThrowException() { + public void testInvalidAnswerConceptIds_shouldThrowException() throws Exception { params.put("answerConceptIds", "adas,asda"); new ObsSubmissionElement(context, params); } diff --git a/api/src/main/java/org/openmrs/module/htmlformentry/HtmlFormEntryUtil.java b/api/src/main/java/org/openmrs/module/htmlformentry/HtmlFormEntryUtil.java index 8a6a8d94e..043a29b18 100644 --- a/api/src/main/java/org/openmrs/module/htmlformentry/HtmlFormEntryUtil.java +++ b/api/src/main/java/org/openmrs/module/htmlformentry/HtmlFormEntryUtil.java @@ -282,6 +282,8 @@ public static Obs createObs(Concept concept, Object value, Date datetime, String } else if (value instanceof Person) { Person person = (Person) value; obs.setValueText(person.getId().toString() + " - " + person.getPersonName().toString()); + } else if (value instanceof Provider) { + obs.setValueText(((Provider) value).getId().toString()); } else { obs.setValueText(value.toString()); } diff --git a/api/src/main/java/org/openmrs/module/htmlformentry/element/ObsReferenceSubmissionElement.java b/api/src/main/java/org/openmrs/module/htmlformentry/element/ObsReferenceSubmissionElement.java index 73496270a..ef700316c 100644 --- a/api/src/main/java/org/openmrs/module/htmlformentry/element/ObsReferenceSubmissionElement.java +++ b/api/src/main/java/org/openmrs/module/htmlformentry/element/ObsReferenceSubmissionElement.java @@ -12,6 +12,7 @@ import org.openmrs.Obs; import org.openmrs.Person; import org.openmrs.api.context.Context; +import org.openmrs.module.htmlformentry.BadFormDesignException; import org.openmrs.module.htmlformentry.FormEntryContext; import org.openmrs.module.htmlformentry.HtmlFormEntryConstants; import org.openmrs.module.htmlformentry.HtmlFormEntryUtil; @@ -37,7 +38,7 @@ public class ObsReferenceSubmissionElement extends ObsSubmissionElement parameters) { + public ObsReferenceSubmissionElement(FormEntryContext context, Map parameters) throws BadFormDesignException { super(context, parameters); diff --git a/api/src/main/java/org/openmrs/module/htmlformentry/element/ObsSubmissionElement.java b/api/src/main/java/org/openmrs/module/htmlformentry/element/ObsSubmissionElement.java index a17264de4..bfc99bcd9 100644 --- a/api/src/main/java/org/openmrs/module/htmlformentry/element/ObsSubmissionElement.java +++ b/api/src/main/java/org/openmrs/module/htmlformentry/element/ObsSubmissionElement.java @@ -15,6 +15,7 @@ import org.openmrs.Role; import org.openmrs.Visit; import org.openmrs.api.context.Context; +import org.openmrs.module.htmlformentry.BadFormDesignException; import org.openmrs.module.htmlformentry.FormEntryContext; import org.openmrs.module.htmlformentry.FormEntryContext.Mode; import org.openmrs.module.htmlformentry.FormEntrySession; @@ -30,8 +31,10 @@ import org.openmrs.module.htmlformentry.widget.ConceptSearchAutocompleteWidget; import org.openmrs.module.htmlformentry.widget.DateTimeWidget; import org.openmrs.module.htmlformentry.widget.DateWidget; +import org.openmrs.module.htmlformentry.util.MatchMode; import org.openmrs.module.htmlformentry.widget.DropdownWidget; import org.openmrs.module.htmlformentry.widget.DynamicAutocompleteWidget; +import org.openmrs.module.htmlformentry.widget.ProviderAjaxAutoCompleteWidget; import org.openmrs.module.htmlformentry.widget.ErrorWidget; import org.openmrs.module.htmlformentry.widget.NumberFieldWidget; import org.openmrs.module.htmlformentry.widget.Option; @@ -163,7 +166,7 @@ public class ObsSubmissionElement implements HtmlGen private String tagControlId; - public ObsSubmissionElement(T context, Map parameters) { + public ObsSubmissionElement(T context, Map parameters) throws BadFormDesignException { if (parameters.get("locale") != null) { this.locale = LocaleUtility.fromSpecification(parameters.get("locale")); } @@ -241,7 +244,7 @@ else if (conceptId == null && conceptIds == null) isLocationObs = "location".equals(parameters.get("style")) || "location_radio".equals(parameters.get("style")) || "location_dropdown".equals(parameters.get("style")); isProviderObs = "provider".equals(parameters.get("style")) || "provider_radio".equals(parameters.get("style")) - || "provider_dropdown".equals(parameters.get("style")); + || "provider_dropdown".equals(parameters.get("style")) || "provider_autocomplete".equals(parameters.get("style")); isRadioSet = "radio".equals(parameters.get("style")) || "location_radio".equals(parameters.get("style")) || "provider_radio".equals(parameters.get("style")); @@ -273,7 +276,7 @@ private Widget buildDropdownWidget(Integer size) { return dropdownWidget; } - private void prepareWidgets(T context, Map parameters) { + private void prepareWidgets(T context, Map parameters) throws BadFormDesignException { String userLocaleStr = locale.toString(); try { if (answerConcept == null) @@ -565,19 +568,6 @@ private void prepareWidgets(T context, Map parameters) { } // configure the special obs type that allows selection of a provider (the provider_id PK is stored as the valueText) else if (isProviderObs) { - if (isRadioSet) { - valueWidget = new RadioButtonsWidget(); - if (answerSeparator != null) { - ((RadioButtonsWidget) valueWidget).setAnswerSeparator(answerSeparator); - } - } else { // dropdown - valueWidget = new DropdownWidget(); - // if initialValueIsSet=false, no initial/default location, hence this shows the 'select input' field as first option - boolean initialValueIsSet = !(initialValue == null); - ((SingleOptionWidget) valueWidget).addOption( - new Option(Context.getMessageSourceService().getMessage("htmlformentry.chooseAProvider"), "", - !initialValueIsSet)); - } List roleIds = new ArrayList<>(); String roleParam = parameters.get("providerRoles"); if (StringUtils.isNotBlank(roleParam)) { @@ -585,20 +575,48 @@ else if (isProviderObs) { roleIds.add(roleId.trim()); } } - List providers = HtmlFormEntryUtil.getProviders(roleIds, true); - - List