Search in sources :

Example 1 with DispositionDescriptor

use of org.openmrs.module.emrapi.disposition.DispositionDescriptor in project openmrs-module-coreapps by openmrs.

the class EncounterDispositionTagHandlerComponentTest method testShouldNotDisplayAdmissionLocationAfterEnteringDischargeDisposition.

@Test
public void testShouldNotDisplayAdmissionLocationAfterEnteringDischargeDisposition() throws Exception {
    final Date date = new Date();
    final DispositionDescriptor dispositionDescriptor = dispositionService.getDispositionDescriptor();
    final Concept dischargeDisposition = HtmlFormEntryUtil.getConcept("org.openmrs.module.emrapi: Discharged");
    new RegressionTestHelper() {

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

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

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

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

        @Override
        public void setupRequest(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(widgets.get("Disposition:"), dischargeDisposition.toString());
        }

        @Override
        public boolean doViewEncounter() {
            return true;
        }

        @Override
        public void testViewingEncounter(Encounter encounter, String html) {
            // make sure the admission location is not displayed (ie, has style="display:none;")
            TestUtil.assertFuzzyContains("p id=\"[^\"]+\" style=\"display:none;\"><label><uimessage code=\"Admission Location\">", html);
        }
    }.run();
}
Also used : Concept(org.openmrs.Concept) TestUiUtils(org.openmrs.module.appui.TestUiUtils) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) DispositionDescriptor(org.openmrs.module.emrapi.disposition.DispositionDescriptor) Date(java.util.Date) Encounter(org.openmrs.Encounter) HashMap(java.util.HashMap) Map(java.util.Map) RegressionTestHelper(org.openmrs.module.htmlformentry.RegressionTestHelper) Test(org.junit.Test) BaseModuleWebContextSensitiveTest(org.openmrs.web.test.BaseModuleWebContextSensitiveTest)

Example 2 with DispositionDescriptor

use of org.openmrs.module.emrapi.disposition.DispositionDescriptor in project openmrs-module-coreapps by openmrs.

the class ParserEncounterIntoSimpleObjects method parseObservations.

public ParsedObs parseObservations(Locale locale) {
    DiagnosisMetadata diagnosisMetadata = emrApiProperties.getDiagnosisMetadata();
    DispositionDescriptor dispositionDescriptor = null;
    try {
        dispositionDescriptor = dispositionService.getDispositionDescriptor();
    } catch (IllegalStateException ex) {
    // No problem. We do not require dispositions to be configured here
    }
    ParsedObs parsedObs = new ParsedObs();
    for (Obs obs : encounter.getObsAtTopLevel(false)) {
        if (diagnosisMetadata.isDiagnosis(obs)) {
            parsedObs.getDiagnoses().add(parseDiagnosis(diagnosisMetadata, obs));
        } else if (dispositionDescriptor != null && dispositionDescriptor.isDisposition(obs)) {
            parsedObs.getDispositions().add(parseDisposition(dispositionDescriptor, obs, locale));
        } else {
            parsedObs.getObs().add(parseObs(obs, locale));
        }
    }
    // just sort the obs by obsId--not perfect, but a decent "natural" object
    Collections.sort(parsedObs.getObs(), new Comparator<SimpleObject>() {

        @Override
        public int compare(SimpleObject o1, SimpleObject o2) {
            return (Integer) o1.get("obsId") < (Integer) o2.get("obsId") ? -1 : 1;
        }
    });
    Collections.sort(parsedObs.getDiagnoses(), new Comparator<SimpleObject>() {

        @Override
        public int compare(SimpleObject o1, SimpleObject o2) {
            Integer order1 = (Integer) o1.get("order");
            Integer order2 = (Integer) o2.get("order");
            return order1 - order2;
        }
    });
    return parsedObs;
}
Also used : Obs(org.openmrs.Obs) SimpleObject(org.openmrs.ui.framework.SimpleObject) DiagnosisMetadata(org.openmrs.module.emrapi.diagnosis.DiagnosisMetadata) DispositionDescriptor(org.openmrs.module.emrapi.disposition.DispositionDescriptor)

Example 3 with DispositionDescriptor

use of org.openmrs.module.emrapi.disposition.DispositionDescriptor in project openmrs-module-coreapps by openmrs.

the class EncounterDispositionTagHandlerComponentTest method testEnteringForm.

@Test
public void testEnteringForm() throws Exception {
    final Date date = new Date();
    final DispositionDescriptor dispositionDescriptor = dispositionService.getDispositionDescriptor();
    final Concept admissionDisposition = HtmlFormEntryUtil.getConcept("org.openmrs.module.emrapi: Admit to hospital");
    new RegressionTestHelper() {

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

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

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

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

        @Override
        public void setupRequest(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(widgets.get("Disposition:"), admissionDisposition.toString());
            // hack, manually reference the widget the location
            request.setParameter("w10", "1");
        }

        @Override
        public void testResults(SubmissionResults results) {
            results.assertNoErrors();
            results.assertEncounterCreated();
            results.assertProvider(1);
            results.assertLocation(2);
            results.assertEncounterType(1);
            results.assertObsGroupCreatedCount(1);
            results.assertObsGroupCreated(dispositionDescriptor.getDispositionSetConcept().getConceptId(), dispositionDescriptor.getDispositionConcept().getId(), admissionDisposition, dispositionDescriptor.getAdmissionLocationConcept().getId(), "1");
        }
    }.run();
}
Also used : Concept(org.openmrs.Concept) TestUiUtils(org.openmrs.module.appui.TestUiUtils) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) DispositionDescriptor(org.openmrs.module.emrapi.disposition.DispositionDescriptor) Date(java.util.Date) HashMap(java.util.HashMap) Map(java.util.Map) RegressionTestHelper(org.openmrs.module.htmlformentry.RegressionTestHelper) Test(org.junit.Test) BaseModuleWebContextSensitiveTest(org.openmrs.web.test.BaseModuleWebContextSensitiveTest)

Example 4 with DispositionDescriptor

use of org.openmrs.module.emrapi.disposition.DispositionDescriptor in project openmrs-module-coreapps by openmrs.

the class EncounterDispositionTagHandlerComponentTest method testShouldDisplayAdmissionLocationAfterEnteringAdmissionDisposition.

@Test
public void testShouldDisplayAdmissionLocationAfterEnteringAdmissionDisposition() throws Exception {
    final Date date = new Date();
    final DispositionDescriptor dispositionDescriptor = dispositionService.getDispositionDescriptor();
    final Concept admissionDisposition = HtmlFormEntryUtil.getConcept("org.openmrs.module.emrapi: Admit to hospital");
    new RegressionTestHelper() {

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

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

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

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

        @Override
        public void setupRequest(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(widgets.get("Disposition:"), admissionDisposition.toString());
            // hack, manually reference the widget the location
            request.setParameter("w10", "1");
        }

        @Override
        public boolean doViewEncounter() {
            return true;
        }

        @Override
        public void testViewingEncounter(Encounter encounter, String html) {
            // make sure the admission location is displayed (ie, does not have style="display:none;")
            TestUtil.assertFuzzyContains("p id=\"[^\"]+\"><label><uimessage code=\"Admission Location\">", html);
        }
    }.run();
}
Also used : Concept(org.openmrs.Concept) TestUiUtils(org.openmrs.module.appui.TestUiUtils) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) DispositionDescriptor(org.openmrs.module.emrapi.disposition.DispositionDescriptor) Date(java.util.Date) Encounter(org.openmrs.Encounter) HashMap(java.util.HashMap) Map(java.util.Map) RegressionTestHelper(org.openmrs.module.htmlformentry.RegressionTestHelper) Test(org.junit.Test) BaseModuleWebContextSensitiveTest(org.openmrs.web.test.BaseModuleWebContextSensitiveTest)

Example 5 with DispositionDescriptor

use of org.openmrs.module.emrapi.disposition.DispositionDescriptor in project openmrs-module-pihcore by PIH.

the class ExitPatientFromCovidProgramAction method closeCovidProgram.

private void closeCovidProgram(FormEntrySession formEntrySession, ProgramWorkflowService programWorkflowService, DispositionService dispositionService, ConceptService conceptService) {
    Patient patient = formEntrySession.getPatient();
    Program covid = programWorkflowService.getProgramByUuid(COVID_PROGRAM_UUID);
    Encounter encounter = formEntrySession.getEncounter();
    // use the encounter date *without* the time component
    Date encounterDate = (new DateTime(encounter.getEncounterDatetime())).withTimeAtStartOfDay().toDate();
    // we will update any COVID program started on or before the encounter date AND EITHER closed on or after encounter date OR not closed at all
    // note that this should handle moving a completion date *earlier* but *not later*:
    // ie if a patient is enrolled on Jan 11 and program is completed on Jan 14 and discharge form is entered on Jan 12, we assume
    // Jan 12 is the correct completion date and update
    // however, if a discharge form is entered on Jan 16, the program from Jan 11 to Jan 14 is *not* updated
    List<PatientProgram> candidates = programWorkflowService.getPatientPrograms(patient, covid, null, encounterDate, encounterDate, null, false);
    if (candidates != null) {
        if (candidates.size() > 1) {
            log.warn("More than one COVID program enrollment for patient " + patient.getId() + " on date " + encounterDate + ". Now unenrolling from all of them.");
        }
        for (PatientProgram patientProgram : candidates) {
            // set the date completed to the encounter date
            patientProgram.setDateCompleted(encounterDate);
            // find the disposition
            DispositionDescriptor dispositionDescriptor = dispositionService.getDispositionDescriptor();
            Disposition disposition = null;
            for (Obs candidate : encounter.getObsAtTopLevel(false)) {
                if (dispositionDescriptor.isDisposition(candidate)) {
                    disposition = dispositionService.getDispositionFromObsGroup(candidate);
                    break;
                }
            }
            // set program outcome based on dispositoion
            if (disposition != null) {
                // with the name "uuid": https://github.com/PIH/openmrs-config-zl/blob/master/configuration/pih/pih-dispositions-haiti.json#L50
                if (disposition.getUuid().equals(DISPOSITION_DEATH)) {
                    patientProgram.setOutcome(conceptService.getConceptByMapping(CONCEPT_DIED, "PIH"));
                } else if (disposition.getUuid().equals(DISPOSITION_TRANSFER_OUT)) {
                    patientProgram.setOutcome(conceptService.getConceptByMapping(CONCEPT_TRANSFER_OUT, "PIH"));
                } else if (disposition.getUuid().equals(DISPOSITION_DISCHARGE)) {
                    patientProgram.setOutcome(conceptService.getConceptByMapping(CONCEPT_DISCHARGE, "PIH"));
                } else {
                    log.warn("When closing COVID program no concept mapping rule found for disposition " + disposition.getUuid());
                }
            } else {
                log.warn("No disposition found on COVID discharge note for patient " + patient.getId());
            }
            programWorkflowService.savePatientProgram(patientProgram);
        }
    }
}
Also used : Obs(org.openmrs.Obs) PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) Disposition(org.openmrs.module.emrapi.disposition.Disposition) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) DispositionDescriptor(org.openmrs.module.emrapi.disposition.DispositionDescriptor) PatientProgram(org.openmrs.PatientProgram) Date(java.util.Date) DateTime(org.joda.time.DateTime)

Aggregations

DispositionDescriptor (org.openmrs.module.emrapi.disposition.DispositionDescriptor)7 Date (java.util.Date)5 Encounter (org.openmrs.Encounter)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Test (org.junit.Test)3 Concept (org.openmrs.Concept)3 Obs (org.openmrs.Obs)3 TestUiUtils (org.openmrs.module.appui.TestUiUtils)3 RegressionTestHelper (org.openmrs.module.htmlformentry.RegressionTestHelper)3 BaseModuleWebContextSensitiveTest (org.openmrs.web.test.BaseModuleWebContextSensitiveTest)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 Disposition (org.openmrs.module.emrapi.disposition.Disposition)2 DispositionAction (org.openmrs.module.emrapi.disposition.actions.DispositionAction)2 DateTime (org.joda.time.DateTime)1 Before (org.junit.Before)1 Patient (org.openmrs.Patient)1 PatientProgram (org.openmrs.PatientProgram)1 Program (org.openmrs.Program)1