Search in sources :

Example 1 with CodedOrFreeTextAnswer

use of org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer in project openmrs-module-coreapps by openmrs.

the class EncounterDiagnosesFragmentControllerTest method testController_createdProperPriorDiagnoses.

@Test
public void testController_createdProperPriorDiagnoses() throws Exception {
    EncounterDiagnosesFragmentController controller = new EncounterDiagnosesFragmentController();
    ConceptName specificName = new ConceptName("Specific Name", Context.getLocale());
    specificName.setId(1);
    specificName.setLocalePreferred(true);
    Concept conceptForSpecificName = new Concept();
    conceptForSpecificName.setId(2);
    conceptForSpecificName.addName(specificName);
    Concept nonSpecificConcept = new Concept();
    nonSpecificConcept.setId(3);
    ConceptName nonSpecificConceptName = new ConceptName("Non-specific concept", Context.getLocale());
    nonSpecificConceptName.setId(4);
    nonSpecificConceptName.setLocalePreferred(true);
    nonSpecificConcept.addName(nonSpecificConceptName);
    List<Diagnosis> diagnoses = new ArrayList<Diagnosis>();
    diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer(specificName), Diagnosis.Order.PRIMARY));
    diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer(nonSpecificConcept), Diagnosis.Order.SECONDARY));
    diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer("Unknown Disease"), Diagnosis.Order.SECONDARY));
    for (Diagnosis d : diagnoses) {
        d.setExistingObs(new Obs());
    }
    FragmentModel model = new FragmentModel();
    controller.controller(new TestUiUtils(), null, diagnoses, model);
    assertThat(((List<String>) model.getAttribute("jsForExisting")).size(), is(0));
    List<String> jsForPrior = (List<String>) model.getAttribute("jsForPrior");
    assertThat(jsForPrior.get(0), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer({\"word\":null,\"conceptName\":{\"id\":1,\"uuid\":\"" + specificName.getUuid() + "\",\"conceptNameType\":\"FULLY_SPECIFIED\",\"name\":\"Specific Name\"},\"concept\":{\"id\":2,\"uuid\":\"" + conceptForSpecificName.getUuid() + "\",\"conceptMappings\":[],\"preferredName\":\"Specific Name\"}}), confirmed: false, primary: true, existingObs: null }"));
    assertThat(jsForPrior.get(1), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer({\"word\":null,\"conceptName\":null,\"concept\":{\"id\":3,\"uuid\":\"" + nonSpecificConcept.getUuid() + "\",\"conceptMappings\":[],\"preferredName\":\"Non-specific concept\"}}), confirmed: false, primary: false, existingObs: null }"));
    assertThat(jsForPrior.get(2), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer('Unknown Disease'), confirmed: false, primary: false, existingObs: null }"));
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) TestUiUtils(org.openmrs.module.appui.TestUiUtils) ArrayList(java.util.ArrayList) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) FragmentModel(org.openmrs.ui.framework.fragment.FragmentModel) ConceptName(org.openmrs.ConceptName) ArrayList(java.util.ArrayList) List(java.util.List) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) Test(org.junit.Test)

Example 2 with CodedOrFreeTextAnswer

use of org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer in project openmrs-module-coreapps by openmrs.

the class ParserEncounterIntoSimpleObjectsTest method testParsingDiagnoses.

@Test
public void testParsingDiagnoses() throws Exception {
    encounter.addObs(diagnosisMetadata.buildDiagnosisObsGroup(new Diagnosis(new CodedOrFreeTextAnswer("Random Disease"), Diagnosis.Order.PRIMARY)));
    ParsedObs parsed = parser.parseObservations(Locale.ENGLISH);
    assertThat(parsed.getDiagnoses().size(), is(1));
    assertThat(parsed.getDispositions().size(), is(0));
    assertThat(parsed.getObs().size(), is(0));
    assertThat(path(parsed.getDiagnoses(), 0, "question"), is((Object) "coreapps.patientDashBoard.diagnosisQuestion.PRIMARY"));
    assertThat(path(parsed.getDiagnoses(), 0, "answer"), is((Object) "(coreapps.Diagnosis.Certainty.PRESUMED) \"Random Disease\""));
    assertThat(path(parsed.getDiagnoses(), 0, "order"), is((Object) 0));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) Test(org.junit.Test)

Example 3 with CodedOrFreeTextAnswer

use of org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer in project openmrs-module-coreapps by openmrs.

the class EncounterDiagnosesFragmentController method generateJsForDiagnoses.

private List<String> generateJsForDiagnoses(List<Diagnosis> diagnoses, UiUtils ui) throws Exception {
    // to ensure we have the exact same json format as search results, borrow the simplify method from here
    DiagnosesFragmentController diagnosesFragmentController = new DiagnosesFragmentController();
    List<String> jsForDiagnoses = new ArrayList<String>();
    Collections.sort(diagnoses, new Comparator<Diagnosis>() {

        @Override
        public int compare(Diagnosis left, Diagnosis right) {
            return left.getOrder().compareTo(right.getOrder());
        }
    });
    for (Diagnosis d : diagnoses) {
        CodedOrFreeTextAnswer diagnosis = d.getDiagnosis();
        String jsDiagnosis;
        if (diagnosis.getNonCodedAnswer() != null) {
            jsDiagnosis = "'" + ui.escapeJs(diagnosis.getNonCodedAnswer()) + "'";
        } else {
            ConceptSearchResult csr = new ConceptSearchResult(null, diagnosis.getCodedAnswer(), diagnosis.getSpecificCodedAnswer());
            SimpleObject simple = diagnosesFragmentController.simplify(csr, ui, Context.getLocale());
            jsDiagnosis = simple.toJson();
        }
        jsForDiagnoses.add("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer(" + jsDiagnosis + "), confirmed: " + (d.getCertainty().equals(Diagnosis.Certainty.CONFIRMED)) + ", primary: " + (d.getOrder().equals(Diagnosis.Order.PRIMARY)) + ", existingObs: " + d.getExistingObs().getId() + " }");
    }
    return jsForDiagnoses;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) ArrayList(java.util.ArrayList) DiagnosesFragmentController(org.openmrs.module.coreapps.fragment.controller.DiagnosesFragmentController) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) ConceptSearchResult(org.openmrs.ConceptSearchResult)

Example 4 with CodedOrFreeTextAnswer

use of org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer in project openmrs-module-coreapps by openmrs.

the class CodedOrFreeTextAnswerListWidgetTest method testViewNonEmptyList.

@Test
public void testViewNonEmptyList() throws Exception {
    setUpView();
    ConceptName conceptName = new ConceptName();
    conceptName.setLocale(Context.getLocale());
    conceptName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
    conceptName.setLocalePreferred(true);
    conceptName.setName("Coded");
    Concept concept = new Concept();
    concept.addName(conceptName);
    List<CodedOrFreeTextAnswer> list = new ArrayList<CodedOrFreeTextAnswer>();
    list.add(new CodedOrFreeTextAnswer("Free text"));
    list.add(new CodedOrFreeTextAnswer(concept));
    widget.setInitialValue(list);
    String html = widget.generateHtml(context);
    assertThat(html, matches("<div class=\"coded-or-free-text-list-widget\">\\s*" + "<span class=\"coded-or-free-text-title\">\\s*" + "Title\\s*" + "</span>\\s*" + "<br/>\\s*" + "<span class=\"value\">\\s*" + "\"Free text\"\\s*" + "</span>\\s*" + "<br/>\\s*" + "<span class=\"coded-or-free-text-between\">\\s*" + "\\(between\\)\\s*" + "</span>\\s*" + "<br/>\\s*" + "<span class=\"value\">\\s*" + "Coded\\s*" + "</span>\\s*" + "</div>"));
}
Also used : Concept(org.openmrs.Concept) ArrayList(java.util.ArrayList) ConceptName(org.openmrs.ConceptName) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) Test(org.junit.Test)

Example 5 with CodedOrFreeTextAnswer

use of org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer in project openmrs-module-coreapps by openmrs.

the class CodedOrFreeTextAnswerListWidget method initialValueAsJson.

private String initialValueAsJson(List<CodedOrFreeTextAnswer> initialValue) {
    if (initialValue == null || initialValue.size() == 0) {
        return null;
    }
    // TODO large scale refactoring to have a proper REST-compatible representation of CodedOrFreeTextAnswer, and have diagnosis search use this
    try {
        // the controller is in the web layer, so we handle it in a very hacky way here.
        Object controller = Context.loadClass("org.openmrs.module.coreapps.fragment.controller.DiagnosesFragmentController").newInstance();
        Method simplify = controller.getClass().getMethod("simplify", ConceptSearchResult.class, UiUtils.class, Locale.class);
        List<Object> simplified = new ArrayList<Object>();
        for (CodedOrFreeTextAnswer answer : initialValue) {
            if (answer.getNonCodedAnswer() != null) {
                simplified.add(SimpleObject.create("matchedName", answer.getNonCodedAnswer(), "nonCodedValue", answer.getNonCodedAnswer()));
            } else {
                ConceptSearchResult result = new ConceptSearchResult(null, answer.getCodedAnswer(), answer.getSpecificCodedAnswer());
                simplified.add(simplify.invoke(controller, result, uiUtils, Context.getLocale()));
            }
        }
        return uiUtils.toJson(simplified);
    } catch (Exception ex) {
        // In an API-layer unit test this will fail due to not being able to load the class
        return null;
    }
}
Also used : ArrayList(java.util.ArrayList) SimpleObject(org.openmrs.ui.framework.SimpleObject) Method(java.lang.reflect.Method) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) ConceptSearchResult(org.openmrs.ConceptSearchResult) IOException(java.io.IOException)

Aggregations

CodedOrFreeTextAnswer (org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer)14 ArrayList (java.util.ArrayList)9 Diagnosis (org.openmrs.module.emrapi.diagnosis.Diagnosis)8 Test (org.junit.Test)6 Concept (org.openmrs.Concept)5 Obs (org.openmrs.Obs)5 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 SimpleObject (org.openmrs.ui.framework.SimpleObject)4 List (java.util.List)3 JsonNode (org.codehaus.jackson.JsonNode)3 ConceptName (org.openmrs.ConceptName)3 TestUiUtils (org.openmrs.module.appui.TestUiUtils)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ArrayNode (org.codehaus.jackson.node.ArrayNode)2 ConceptSearchResult (org.openmrs.ConceptSearchResult)2 DiagnosisMetadata (org.openmrs.module.emrapi.diagnosis.DiagnosisMetadata)2 FragmentModel (org.openmrs.ui.framework.fragment.FragmentModel)2 Method (java.lang.reflect.Method)1 Date (java.util.Date)1