Skip to content

Commit

Permalink
RA-1611: <encounterDiagnoses*/> to support a 'diagnosisConceptClasses…
Browse files Browse the repository at this point in the history
…' attribute.
  • Loading branch information
Ruhanga authored and mks-d committed Jul 16, 2019
1 parent 73c4468 commit 90cc618
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class EncounterDiagnosesElement implements HtmlGeneratorElement, FormSubm
private String diagnosisConceptSources;

private String preferredCodingSource;

private String diagnosisConceptClasses;

private EmrApiProperties emrApiProperties;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class EncounterDiagnosesElement implements HtmlGeneratorElement, FormSubm
private String diagnosisSets;

private String diagnosisConceptSources;

private String diagnosisConceptClasses;

private AdtService adtService;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class EncounterDiagnosesByObsElement implements HtmlGeneratorElement, For
private String diagnosisConceptSources;

private String preferredCodingSource;

private String diagnosisConceptClasses;

private AdtService adtService;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,6 +59,7 @@ public List<SimpleObject> 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 {

Expand All @@ -71,7 +73,7 @@ public List<SimpleObject> search(UiSessionContext context,
}
}
}
else{
else {
diagnosisSets = emrApiProperties.getDiagnosisSets();
}

Expand All @@ -86,13 +88,27 @@ public List<SimpleObject> search(UiSessionContext context,
}
}
}
else{
else {
sources = emrApiProperties.getConceptSourcesForDiagnosisSearch();
}

List<ConceptClass> conceptClasses = new ArrayList<ConceptClass>();
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<ConceptSearchResult> hits = emrConceptService.conceptSearch(query, locale, null, diagnosisSets, sources, null);
List<ConceptSearchResult> hits = emrConceptService.conceptSearch(query, locale, conceptClasses, diagnosisSets, sources, null);
List<SimpleObject> ret = new ArrayList<SimpleObject>();
for (ConceptSearchResult hit : hits) {
ret.add(simplify(hit, ui, locale));
Expand All @@ -110,7 +126,7 @@ public List<SimpleObject> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

<div id="diagnosis-search-container">
<label for="diagnosis-search">${ ui.message("coreapps.consult.addDiagnosis") }</label>
<input id="diagnosis-search" type="text" placeholder="${ ui.message("coreapps.consult.addDiagnosis.placeholder") }" autocomplete itemFormatter="autocomplete-render-item" diagnosisSets="${ config.diagnosisSets }" diagnosisConceptSources="${ config.diagnosisConceptSources }" preferredCodingSource="${ config.preferredCodingSource }"/>
<input id="diagnosis-search" type="text" placeholder="${ ui.message("coreapps.consult.addDiagnosis.placeholder") }" autocomplete itemFormatter="autocomplete-render-item" diagnosisSets="${ config.diagnosisSets }" diagnosisConceptSources="${ config.diagnosisConceptSources }" preferredCodingSource="${ config.preferredCodingSource }" diagnosisConceptClasses="${ config.diagnosisConceptClasses }"/>

<% if(jsForPrior.size > 0) { %>
<button type="button" ng-click="addPriorDiagnoses()">${ ui.message("coreapps.consult.priorDiagnoses.add") }</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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<ConceptClass> classList = new ArrayList<ConceptClass> ();
classList.add(conceptClass);

ConceptSource source = new ConceptSource();
List<ConceptSource> sourceList = new ArrayList<ConceptSource> ();
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String,String> attributes = new HashMap<String, String>();
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<String,String> attributes = new HashMap<String, String>();
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<String, Object> fragmentConfig) throws Exception {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("web/module/fragments/diagnosis/encounterDiagnoses.gsp");
Expand Down

0 comments on commit 90cc618

Please sign in to comment.