diff --git a/api-2.2/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesElement.java b/api-2.2/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesElement.java index 28ed8c537..99655bea6 100644 --- a/api-2.2/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesElement.java +++ b/api-2.2/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesElement.java @@ -70,6 +70,8 @@ public class EncounterDiagnosesElement implements HtmlGeneratorElement, FormSubm private String diagnosisConceptSources; private String preferredCodingSource; + + private String diagnosisConceptClasses; private EmrApiProperties emrApiProperties; @@ -144,6 +146,7 @@ public String generateHtml(FormEntryContext context) { fragmentConfig.put("diagnosisSets", validateAndFormat(diagnosisSets)); fragmentConfig.put("preferredCodingSource", preferredCodingSource); fragmentConfig.put("diagnosisConceptSources", StringUtils.deleteWhitespace(diagnosisConceptSources)); + fragmentConfig.put("diagnosisConceptClasses", StringUtils.deleteWhitespace(diagnosisConceptClasses)); // add the prior diagnoses if requested if (FormEntryContext.Mode.ENTER == context.getMode() && dispositionTypeForPriorDiagnoses != null) { @@ -430,6 +433,14 @@ public void setPreferredCodingSource(String preferredCodingSource) { public String getPreferredCodingSource() { return preferredCodingSource; } + + public void setDiagnosisConceptClasses(String diagnosisConceptClasses) { + this.diagnosisConceptClasses = diagnosisConceptClasses; + } + + public String getDiagnosisConceptClasses() { + return diagnosisConceptClasses; + } public void setUiUtils(UiUtils uiUtils) { this.uiUtils = uiUtils; diff --git a/api-pre2.2/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesElement.java b/api-pre2.2/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesElement.java index 28cb4cee9..2842008bc 100644 --- a/api-pre2.2/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesElement.java +++ b/api-pre2.2/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesElement.java @@ -75,6 +75,8 @@ public class EncounterDiagnosesElement implements HtmlGeneratorElement, FormSubm private String diagnosisSets; private String diagnosisConceptSources; + + private String diagnosisConceptClasses; private AdtService adtService; @@ -123,6 +125,7 @@ public String generateHtml(FormEntryContext context) { fragmentConfig.put("diagnosisSets", validateAndFormat(diagnosisSets)); fragmentConfig.put("preferredCodingSource", preferredCodingSource); fragmentConfig.put("diagnosisConceptSources", StringUtils.deleteWhitespace(diagnosisConceptSources)); + fragmentConfig.put("diagnosisConceptClasses", StringUtils.deleteWhitespace(diagnosisConceptClasses)); // add the prior diagnoses if requested if (FormEntryContext.Mode.ENTER == context.getMode() && dispositionTypeForPriorDiagnoses != null) { @@ -379,6 +382,14 @@ public void setPreferredCodingSource(String preferredCodingSource) { public String getPreferredCodingSource() { return preferredCodingSource; } + + public void setDiagnosisConceptClasses(String diagnosisConceptClasses) { + this.diagnosisConceptClasses = diagnosisConceptClasses; + } + + public String getDiagnosisConceptClasses() { + return diagnosisConceptClasses; + } public void setUiUtils(UiUtils uiUtils) { this.uiUtils = uiUtils; diff --git a/api/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesByObsElement.java b/api/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesByObsElement.java index 2aa122727..858a41d69 100644 --- a/api/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesByObsElement.java +++ b/api/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesByObsElement.java @@ -75,6 +75,8 @@ public class EncounterDiagnosesByObsElement implements HtmlGeneratorElement, For private String diagnosisConceptSources; private String preferredCodingSource; + + private String diagnosisConceptClasses; private AdtService adtService; @@ -123,6 +125,7 @@ public String generateHtml(FormEntryContext context) { fragmentConfig.put("diagnosisSets", validateAndFormat(diagnosisSets)); fragmentConfig.put("preferredCodingSource", preferredCodingSource); fragmentConfig.put("diagnosisConceptSources", StringUtils.deleteWhitespace(diagnosisConceptSources)); + fragmentConfig.put("diagnosisConceptClasses", StringUtils.deleteWhitespace(diagnosisConceptClasses)); // add the prior diagnoses if requested if (FormEntryContext.Mode.ENTER == context.getMode() && dispositionTypeForPriorDiagnoses != null) { @@ -379,6 +382,14 @@ public void setPreferredCodingSource(String preferredCodingSource) { public String getPreferredCodingSource() { return preferredCodingSource; } + + public void setDiagnosisConceptClasses(String diagnosisConceptClasses) { + this.diagnosisConceptClasses = diagnosisConceptClasses; + } + + public String getDiagnosisConceptClasses() { + return diagnosisConceptClasses; + } public void setUiUtils(UiUtils uiUtils) { this.uiUtils = uiUtils; diff --git a/api/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesByObsTagHandler.java b/api/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesByObsTagHandler.java index eb997419b..d6735a8d6 100644 --- a/api/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesByObsTagHandler.java +++ b/api/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesByObsTagHandler.java @@ -77,6 +77,7 @@ protected String getSubstitution(FormEntrySession session, FormSubmissionControl element.setConceptService(conceptService); element.setAdtService(adtService); element.setDiagnosisSets(attributes.get("diagnosisSets") != null ? attributes.get("diagnosisSets") : ""); + element.setDiagnosisConceptClasses(attributes.get("diagnosisConceptClasses") != null ? attributes.get("diagnosisConceptClasses") : ""); element.setDiagnosisConceptSources(attributes.get("diagnosisConceptSources") != null ? attributes.get("diagnosisConceptSources") : ""); element.setPreferredCodingSource(attributes.get("preferredCodingSource") != null ? attributes.get("preferredCodingSource"): CoreAppsConstants.DEFAULT_CODING_SOURCE); diff --git a/api/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesTagHandler.java b/api/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesTagHandler.java index 441831073..d918d622b 100644 --- a/api/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesTagHandler.java +++ b/api/src/main/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesTagHandler.java @@ -79,6 +79,7 @@ protected String getSubstitution(FormEntrySession session, FormSubmissionControl element.setConceptService(conceptService); element.setAdtService(adtService); element.setDiagnosisSets(attributes.get("diagnosisSets") != null ? attributes.get("diagnosisSets") : ""); + element.setDiagnosisConceptClasses(attributes.get("diagnosisConceptClasses") != null ? attributes.get("diagnosisConceptClasses") : ""); element.setDiagnosisConceptSources(attributes.get("diagnosisConceptSources") != null ? attributes.get("diagnosisConceptSources") : ""); element.setPreferredCodingSource(attributes.get("preferredCodingSource") != null ? attributes.get("preferredCodingSource"): CoreAppsConstants.DEFAULT_CODING_SOURCE); diff --git a/omod/src/main/java/org/openmrs/module/coreapps/fragment/controller/DiagnosesFragmentController.java b/omod/src/main/java/org/openmrs/module/coreapps/fragment/controller/DiagnosesFragmentController.java index 08c87751b..7a82aecd5 100644 --- a/omod/src/main/java/org/openmrs/module/coreapps/fragment/controller/DiagnosesFragmentController.java +++ b/omod/src/main/java/org/openmrs/module/coreapps/fragment/controller/DiagnosesFragmentController.java @@ -19,6 +19,7 @@ import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.map.ObjectMapper; import org.openmrs.Concept; +import org.openmrs.ConceptClass; import org.openmrs.ConceptName; import org.openmrs.ConceptSearchResult; import org.openmrs.ConceptSource; @@ -58,6 +59,7 @@ public List search(UiSessionContext context, @RequestParam("term") String query, @RequestParam(value = "diagnosisSets", defaultValue = "") String diagnosisSetUuids, @RequestParam(value = "diagnosisConceptSources", defaultValue = "") String diagnosisConceptSources, + @RequestParam(value = "diagnosisConceptClasses", defaultValue = "") String diagnosisConceptClasses, @RequestParam(value = "start", defaultValue = "0") Integer start, @RequestParam(value = "size", defaultValue = "50") Integer size) throws Exception { @@ -71,7 +73,7 @@ public List search(UiSessionContext context, } } } - else{ + else { diagnosisSets = emrApiProperties.getDiagnosisSets(); } @@ -86,13 +88,27 @@ public List search(UiSessionContext context, } } } - else{ + else { sources = emrApiProperties.getConceptSourcesForDiagnosisSearch(); } + + List conceptClasses = new ArrayList(); + if (StringUtils.isNotEmpty(diagnosisConceptClasses)) { + String [] conceptClassNames = diagnosisConceptClasses.split(","); + for (String className : conceptClassNames) { + ConceptClass conceptClass = conceptService.getConceptClassByName(className); + if (conceptClass != null) { + conceptClasses.add(conceptClass); + } + } + } + else { + conceptClasses = null; + } Locale locale = context.getLocale(); - List hits = emrConceptService.conceptSearch(query, locale, null, diagnosisSets, sources, null); + List hits = emrConceptService.conceptSearch(query, locale, conceptClasses, diagnosisSets, sources, null); List ret = new ArrayList(); for (ConceptSearchResult hit : hits) { ret.add(simplify(hit, ui, locale)); @@ -110,7 +126,7 @@ public List searchNonCoded(UiSessionContext context, @RequestParam(value = "start", defaultValue = "0") Integer start, @RequestParam(value = "size", defaultValue = "50") Integer size) throws Exception { - return search(context, ui, emrApiProperties, emrConceptService, conceptService, query, null, null, start, size); + return search(context, ui, emrApiProperties, emrConceptService, conceptService, query, null, null, null, start, size); } public FragmentActionResult codeDiagnosis(UiUtils ui, diff --git a/omod/src/main/webapp/fragments/diagnosis/encounterDiagnoses.gsp b/omod/src/main/webapp/fragments/diagnosis/encounterDiagnoses.gsp index f92e7cd3b..90d9acdaa 100644 --- a/omod/src/main/webapp/fragments/diagnosis/encounterDiagnoses.gsp +++ b/omod/src/main/webapp/fragments/diagnosis/encounterDiagnoses.gsp @@ -66,7 +66,7 @@
- + <% if(jsForPrior.size > 0) { %> diff --git a/omod/src/main/webapp/resources/scripts/diagnoses/diagnoses-angular.js b/omod/src/main/webapp/resources/scripts/diagnoses/diagnoses-angular.js index 86af21284..9afcb3e27 100644 --- a/omod/src/main/webapp/resources/scripts/diagnoses/diagnoses-angular.js +++ b/omod/src/main/webapp/resources/scripts/diagnoses/diagnoses-angular.js @@ -4,7 +4,7 @@ var app = angular.module('diagnoses', []) // I don't know how to use an angular template programmatically, so use an underscore template instead. :-( var itemFormatter = _.template($('#' + attrs.itemformatter).html()); element.autocomplete({ - source: emr.fragmentActionLink("coreapps", "diagnoses", "search", {diagnosisSets: attrs.diagnosissets, diagnosisConceptSources: attrs.diagnosisconceptsources}), + source: emr.fragmentActionLink("coreapps", "diagnoses", "search", {diagnosisSets: attrs.diagnosissets, diagnosisConceptSources: attrs.diagnosisconceptsources, diagnosisConceptClasses: attrs.diagnosisconceptclasses}), response: function(event, ui) { var query = event.target.value.toLowerCase(); var items = ui.content; diff --git a/omod/src/test/java/org/openmrs/module/coreapps/fragment/controller/DiagnosesFragmentControllerTest.java b/omod/src/test/java/org/openmrs/module/coreapps/fragment/controller/DiagnosesFragmentControllerTest.java index ad54a499e..5c0673f93 100644 --- a/omod/src/test/java/org/openmrs/module/coreapps/fragment/controller/DiagnosesFragmentControllerTest.java +++ b/omod/src/test/java/org/openmrs/module/coreapps/fragment/controller/DiagnosesFragmentControllerTest.java @@ -14,20 +14,28 @@ package org.openmrs.module.coreapps.fragment.controller; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.openmrs.api.ConceptService; +import org.openmrs.Concept; +import org.openmrs.ConceptClass; +import org.openmrs.ConceptSource; import org.openmrs.module.appui.UiSessionContext; import org.openmrs.module.emrapi.EmrApiProperties; import org.openmrs.module.emrapi.concept.EmrConceptService; import org.openmrs.ui.framework.UiUtils; +import java.util.List; +import java.util.ArrayList; + @RunWith(MockitoJUnitRunner.class) public class DiagnosesFragmentControllerTest { @@ -53,7 +61,7 @@ public class DiagnosesFragmentControllerTest { @Test public void search_shouldSearchForDiagnosisConceptsFromSpecifiedSets() throws Exception { // replay - controller.search(context, uiUtils, emrApiProperties, emrConceptService, conceptService, queryString, "1st_diagnosis_set_uuid,2nd_diagnosis_set_uuid", null, null, null); + controller.search(context, uiUtils, emrApiProperties, emrConceptService, conceptService, queryString, "1st_diagnosis_set_uuid,2nd_diagnosis_set_uuid", null, null, null, null); // verify verify(emrApiProperties, never()).getDiagnosisSets(); @@ -62,7 +70,7 @@ public void search_shouldSearchForDiagnosisConceptsFromSpecifiedSets() throws Ex @Test public void search_shouldSearchForDiagnosisConceptsUsingGloballyDefinedSuperSetGivenEmptyDiagnosisSets() throws Exception { // replay - controller.search(context, uiUtils, emrApiProperties, emrConceptService, conceptService, queryString, "", null, null, null); + controller.search(context, uiUtils, emrApiProperties, emrConceptService, conceptService, queryString, "", null, null, null, null); // verify verify(emrApiProperties, times(1)).getDiagnosisSets(); @@ -71,7 +79,7 @@ public void search_shouldSearchForDiagnosisConceptsUsingGloballyDefinedSuperSetG @Test public void search_shouldSearchForDiagnosisConceptsUsingGloballyDefinedSuperSetGivenNullDiagnosisSets() throws Exception { // replay - controller.search(context, uiUtils, emrApiProperties, emrConceptService, conceptService, queryString, null, null, null, null); + controller.search(context, uiUtils, emrApiProperties, emrConceptService, conceptService, queryString, null, null, null, null, null); // verify verify(emrApiProperties, times(1)).getDiagnosisSets(); @@ -81,7 +89,7 @@ public void search_shouldSearchForDiagnosisConceptsUsingGloballyDefinedSuperSetG @Test public void search_shouldSearchForDiagnosesFromSpecifiedDiagnosisConceptSources() throws Exception { // replay - controller.search(context, uiUtils, emrApiProperties, emrConceptService, conceptService, queryString, null, "CIEL,ICD-10-WHO", null, null); + controller.search(context, uiUtils, emrApiProperties, emrConceptService, conceptService, queryString, null, "CIEL,ICD-10-WHO", null, null, null); // verify verify(emrApiProperties, never()).getConceptSourcesForDiagnosisSearch(); @@ -90,7 +98,7 @@ public void search_shouldSearchForDiagnosesFromSpecifiedDiagnosisConceptSources( @Test public void search_shouldSearchForDiagnosesUsingGloballyDefinedConceptSourcesGivenEmptyDiagnosisConceptSourcesAttr() throws Exception { // replay - controller.search(context, uiUtils, emrApiProperties, emrConceptService, conceptService, queryString, null, "", null, null); + controller.search(context, uiUtils, emrApiProperties, emrConceptService, conceptService, queryString, null, "", null, null, null); // verify verify(emrApiProperties, times(1)).getConceptSourcesForDiagnosisSearch(); @@ -99,9 +107,30 @@ public void search_shouldSearchForDiagnosesUsingGloballyDefinedConceptSourcesGiv @Test public void search_shouldSearchForDiagnosesUsingGloballyDefinedConceptSourcesGivenNullDiagnosisConceptSourcesAttr() throws Exception { // replay - controller.search(context, uiUtils, emrApiProperties, emrConceptService, conceptService, queryString, null, null, null, null); + controller.search(context, uiUtils, emrApiProperties, emrConceptService, conceptService, queryString, null, null, null, null, null); // verify verify(emrApiProperties, times(1)).getConceptSourcesForDiagnosisSearch(); } + + @Test + public void search_shouldSearchForDiagnosesUsingSpecifiedDiagnosisConceptClasses() throws Exception { + // setup + ConceptClass conceptClass = new ConceptClass(); + List classList = new ArrayList (); + classList.add(conceptClass); + + ConceptSource source = new ConceptSource(); + List sourceList = new ArrayList (); + sourceList.add(source); + when(conceptService.getConceptClassByName(eq("Diagnosis"))).thenReturn(conceptClass); + when(conceptService.getConceptSourceByName(eq("ICD-10-WHO"))).thenReturn(source); + when(emrApiProperties.getDiagnosisSets()).thenReturn(null); + + // replay + controller.search(context, uiUtils, emrApiProperties, emrConceptService, conceptService, queryString, null, "ICD-10-WHO", "Diagnosis", null, null); + + // verify + verify(emrConceptService, times(1)).conceptSearch(queryString, null, classList, null, sourceList, null); + } } \ No newline at end of file diff --git a/omod/src/test/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesTagHandlerComponentTest.java b/omod/src/test/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesTagHandlerComponentTest.java index ddc8636d1..f25aa79d9 100644 --- a/omod/src/test/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesTagHandlerComponentTest.java +++ b/omod/src/test/java/org/openmrs/module/coreapps/htmlformentry/EncounterDiagnosesTagHandlerComponentTest.java @@ -506,6 +506,42 @@ public void getSubstitution_shouldAddEmptyStringToDiagnosisConceptSourcesAttribu // verify assertTrue(StringUtils.contains(generatedHtml, "diagnosisConceptSources=\"" + diagnosisConceptSources + "\"")); } + + @Test + public void getSubstitution_shouldAddDiagnosisConceptClassesAttributeOnDiagnosisSearchField() throws Exception { + // setup + String diagnosisConceptClasses = "Diagnosis,Findig"; + + Map attributes = new HashMap(); + attributes.put("required", "true"); + attributes.put(CoreAppsConstants.HTMLFORMENTRY_ENCOUNTER_DIAGNOSES_TAG_INCLUDE_PRIOR_DIAGNOSES_ATTRIBUTE_NAME, "admit"); + attributes.put("selectedDiagnosesTarget", "example-target"); + + // replay + attributes.put("diagnosisConceptClasses", "Diagnosis,Findig"); + String generatedHtml = encounterDiagnosesTagHandler.getSubstitution(formEntrySession, formSubmissionController, attributes); + + // verify + assertTrue(StringUtils.contains(generatedHtml, "diagnosisConceptClasses=\"" + diagnosisConceptClasses + "\"")); + } + + @Test + public void getSubstitution_shouldAddEmptyStringToDiagnosisConceptClassesAttributeOnDiagnosisSearchFieldGivenNullAttribute() throws Exception { + // setup + String diagnosisConceptClasses = ""; + + Map attributes = new HashMap(); + attributes.put("required", "true"); + attributes.put(CoreAppsConstants.HTMLFORMENTRY_ENCOUNTER_DIAGNOSES_TAG_INCLUDE_PRIOR_DIAGNOSES_ATTRIBUTE_NAME, "admit"); + attributes.put("selectedDiagnosesTarget", "example-target"); + + // replay + attributes.put("diagnosisConceptClasses", null); + String generatedHtml = encounterDiagnosesTagHandler.getSubstitution(formEntrySession, formSubmissionController, attributes); + + // verify + assertTrue(StringUtils.contains(generatedHtml, "diagnosisConceptClasses=\"" + diagnosisConceptClasses + "\"")); + } private String renderFragmentHtml(Map fragmentConfig) throws Exception { InputStream inputStream = getClass().getClassLoader().getResourceAsStream("web/module/fragments/diagnosis/encounterDiagnoses.gsp");