Search in sources :

Example 11 with Diagnosis

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

the class DiagnosesFragmentController method parseDiagnosisJson.

/**
 * @param diagnosisJson  like {"certainty":"PRESUMED","diagnosisOrder":"PRIMARY","diagnosis":"ConceptName:840"}
 * @param conceptService
 * @return
 * @throws Exception
 */
private Diagnosis parseDiagnosisJson(String diagnosisJson, ConceptService conceptService) throws Exception {
    JsonNode node = new ObjectMapper().readTree(diagnosisJson);
    CodedOrFreeTextAnswer answer = new CodedOrFreeTextAnswer(node.get("diagnosis").getTextValue(), conceptService);
    Diagnosis.Order diagnosisOrder = Diagnosis.Order.valueOf(node.get("diagnosisOrder").getTextValue());
    Diagnosis.Certainty certainty = Diagnosis.Certainty.valueOf(node.get("certainty").getTextValue());
    Diagnosis diagnosis = new Diagnosis(answer, diagnosisOrder);
    diagnosis.setCertainty(certainty);
    return diagnosis;
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 12 with Diagnosis

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

the class EncounterDiagnosesFragmentControllerTest method testController_createdProperExistingDiagnoses.

@Test
public void testController_createdProperExistingDiagnoses() 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(), diagnoses, null, model);
    assertThat(((List<String>) model.getAttribute("jsForPrior")).size(), is(0));
    List<String> jsForExisting = (List<String>) model.getAttribute("jsForExisting");
    assertThat(jsForExisting.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(jsForExisting.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(jsForExisting.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 13 with Diagnosis

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

the class EncounterDiagnosesTagHandlerComponentTest method testHandleSubmissionHandlesValidSubmissionEditingForm.

@Test
public void testHandleSubmissionHandlesValidSubmissionEditingForm() throws Exception {
    final DiagnosisMetadata dmd = emrApiProperties.getDiagnosisMetadata();
    final Date date = new Date();
    // first, create an encounter
    final Concept malaria = conceptService.getConcept(11);
    final Patient patient = patientService.getPatient(8);
    final Encounter existingEncounter = new Encounter();
    existingEncounter.setEncounterType(new EncounterType(1));
    existingEncounter.setPatient(patient);
    existingEncounter.setEncounterDatetime(date);
    existingEncounter.setLocation(locationService.getLocation(2));
    Obs primaryDiagnosis = dmd.buildDiagnosisObsGroup(new Diagnosis(new CodedOrFreeTextAnswer(malaria), Diagnosis.Order.PRIMARY));
    Obs secondaryDiagnosis = dmd.buildDiagnosisObsGroup(new Diagnosis(new CodedOrFreeTextAnswer("Unknown disease"), Diagnosis.Order.SECONDARY));
    existingEncounter.addObs(primaryDiagnosis);
    existingEncounter.addObs(secondaryDiagnosis);
    encounterService.saveEncounter(existingEncounter);
    ObjectMapper jackson = new ObjectMapper();
    ArrayNode json = jackson.createArrayNode();
    {
        // change the existing primary diagnosis from PRESUMED to CONFIRMED
        ObjectNode diagnosisNode = json.addObject();
        diagnosisNode.put("certainty", "CONFIRMED");
        diagnosisNode.put("order", "PRIMARY");
        diagnosisNode.put("diagnosis", CodedOrFreeTextAnswer.CONCEPT_PREFIX + "11");
        diagnosisNode.put("existingObs", primaryDiagnosis.getObsId());
    }
    {
        // this is a new diagnosis
        ObjectNode diagnosisNode = json.addObject();
        diagnosisNode.put("certainty", "PRESUMED");
        diagnosisNode.put("order", "SECONDARY");
        diagnosisNode.put("diagnosis", CodedOrFreeTextAnswer.NON_CODED_PREFIX + "I had spelled it wrong before");
    }
    final String jsonToSubmit = jackson.writeValueAsString(json);
    new RegressionTestHelper() {

        @Override
        public String getXmlDatasetPath() {
            return "";
        }

        @Override
        public String getFormName() {
            return "encounterDiagnosesSimpleForm";
        }

        @Override
        public Map<String, Object> getFormEntrySessionAttributes() {
            Map<String, Object> attributes = new HashMap<String, Object>();
            attributes.put("uiUtils", new TestUiUtils() {

                @Override
                public String includeFragment(String providerName, String fragmentId, Map<String, Object> config) throws PageAction {
                    return "[[ included fragment " + providerName + "." + fragmentId + " here ]]";
                }
            });
            return attributes;
        }

        @Override
        public Patient getPatientToView() throws Exception {
            return patient;
        }

        @Override
        public Encounter getEncounterToEdit() {
            return existingEncounter;
        }

        @Override
        public String[] widgetLabelsForEdit() {
            return new String[] { "Date:", "Location:", "Provider:", "Encounter Type:" };
        }

        @Override
        public void setupEditRequest(MockHttpServletRequest request, Map<String, String> widgets) {
            request.setParameter(widgets.get("Date:"), dateAsString(date));
            request.setParameter(widgets.get("Location:"), "2");
            request.setParameter(widgets.get("Provider:"), "1");
            request.setParameter(widgets.get("Encounter Type:"), "1");
            request.setParameter("encounterDiagnoses", jsonToSubmit);
        }

        @Override
        public void testEditFormHtml(String html) {
            System.out.println(html);
        }

        @Override
        public void testEditedResults(SubmissionResults results) {
            results.assertNoErrors();
            results.assertEncounterEdited();
            List<Obs> diagnoses = new ArrayList<Obs>();
            for (Obs obs : results.getEncounterCreated().getObsAtTopLevel(true)) {
                if (dmd.isDiagnosis(obs)) {
                    diagnoses.add(obs);
                }
            }
            Matcher<Obs> newPrimary = new ObsGroupMatcher().withGroupingConcept(dmd.getDiagnosisSetConcept()).withNonVoidedObs(dmd.getDiagnosisCertaintyConcept(), dmd.getConceptFor(Diagnosis.Certainty.CONFIRMED)).withVoidedObs(dmd.getDiagnosisCertaintyConcept(), dmd.getConceptFor(Diagnosis.Certainty.PRESUMED)).withNonVoidedObs(dmd.getDiagnosisOrderConcept(), dmd.getConceptFor(Diagnosis.Order.PRIMARY)).withNonVoidedObs(dmd.getCodedDiagnosisConcept(), malaria);
            Matcher<Obs> newSecondary = new ObsGroupMatcher().withGroupingConcept(dmd.getDiagnosisSetConcept()).withNonVoidedObs(dmd.getDiagnosisCertaintyConcept(), dmd.getConceptFor(Diagnosis.Certainty.PRESUMED)).withNonVoidedObs(dmd.getDiagnosisOrderConcept(), dmd.getConceptFor(Diagnosis.Order.SECONDARY)).withNonVoidedObs(dmd.getNonCodedDiagnosisConcept(), "I had spelled it wrong before");
            Matcher<Obs> oldSecondary = new ObsGroupMatcher().withGroupingConcept(dmd.getDiagnosisSetConcept()).withVoidedObs(dmd.getDiagnosisCertaintyConcept(), dmd.getConceptFor(Diagnosis.Certainty.PRESUMED)).withVoidedObs(dmd.getDiagnosisOrderConcept(), dmd.getConceptFor(Diagnosis.Order.SECONDARY)).withVoidedObs(dmd.getNonCodedDiagnosisConcept(), "Unknown disease").thatIsVoided();
            assertThat(diagnoses.size(), is(3));
            assertThat(diagnoses, containsInAnyOrder(newPrimary, newSecondary, oldSecondary));
        }
    }.run();
}
Also used : ObsGroupMatcher(org.openmrs.module.emrapi.matcher.ObsGroupMatcher) Matcher(org.hamcrest.Matcher) Encounter(org.openmrs.Encounter) ArrayList(java.util.ArrayList) List(java.util.List) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) ArrayNode(org.codehaus.jackson.node.ArrayNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) ObjectNode(org.codehaus.jackson.node.ObjectNode) TestUiUtils(org.openmrs.module.appui.TestUiUtils) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DiagnosisMetadata(org.openmrs.module.emrapi.diagnosis.DiagnosisMetadata) Patient(org.openmrs.Patient) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) Date(java.util.Date) EncounterType(org.openmrs.EncounterType) HashMap(java.util.HashMap) Map(java.util.Map) ObsGroupMatcher(org.openmrs.module.emrapi.matcher.ObsGroupMatcher) RegressionTestHelper(org.openmrs.module.htmlformentry.RegressionTestHelper) Test(org.junit.Test) BaseModuleWebContextSensitiveTest(org.openmrs.web.test.BaseModuleWebContextSensitiveTest)

Example 14 with Diagnosis

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

the class ParserEncounterIntoSimpleObjects method parseDiagnosis.

private SimpleObject parseDiagnosis(DiagnosisMetadata diagnosisMetadata, Obs obs) {
    Diagnosis diagnosis = diagnosisMetadata.toDiagnosis(obs);
    String answer = "(" + uiUtils.message("coreapps.Diagnosis.Certainty." + diagnosis.getCertainty()) + ") ";
    answer += diagnosis.getDiagnosis().formatWithCode(uiUtils.getLocale(), emrApiProperties.getConceptSourcesForDiagnosisSearch());
    SimpleObject simpleObject = SimpleObject.fromObject(obs, uiUtils, "obsId");
    simpleObject.put("question", formatDiagnosisQuestion(diagnosis.getOrder()));
    simpleObject.put("answer", answer);
    simpleObject.put("order", diagnosis.getOrder().ordinal());
    return simpleObject;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis)

Example 15 with Diagnosis

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

the class AwaitingAdmissionDiagnosisFormatter method convert.

@Override
public Object convert(Object o) {
    List<Diagnosis> diagnoses = (List<Diagnosis>) o;
    StringBuffer output = new StringBuffer();
    String prefix = "";
    for (Diagnosis diagnosis : diagnoses) {
        if (diagnosis.getDiagnosis() != null) {
            output.append(prefix);
            prefix = ", ";
            output.append(diagnosis.getDiagnosis().formatWithoutSpecificAnswer(Context.getLocale()));
        }
    }
    return output.toString();
}
Also used : List(java.util.List) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis)

Aggregations

Diagnosis (org.openmrs.module.emrapi.diagnosis.Diagnosis)16 ArrayList (java.util.ArrayList)8 CodedOrFreeTextAnswer (org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer)8 Obs (org.openmrs.Obs)7 Test (org.junit.Test)5 List (java.util.List)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 JsonNode (org.codehaus.jackson.JsonNode)3 Concept (org.openmrs.Concept)3 TestUiUtils (org.openmrs.module.appui.TestUiUtils)3 DiagnosisMetadata (org.openmrs.module.emrapi.diagnosis.DiagnosisMetadata)3 SimpleObject (org.openmrs.ui.framework.SimpleObject)3 HashMap (java.util.HashMap)2 ConceptName (org.openmrs.ConceptName)2 Patient (org.openmrs.Patient)2 FragmentModel (org.openmrs.ui.framework.fragment.FragmentModel)2 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1