Search in sources :

Example 6 with DispositionDescriptor

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

the class ApplyDispositionAction method applyDispositionActions.

void applyDispositionActions(FormEntrySession session, DispositionService dispositionService) {
    DispositionDescriptor dispositionDescriptor = dispositionService.getDispositionDescriptor();
    Encounter encounter = session.getEncounter();
    Disposition disposition = null;
    Obs dispositionObsGroup = null;
    for (Obs candidate : encounter.getObsAtTopLevel(false)) {
        if (dispositionDescriptor.isDisposition(candidate)) {
            dispositionObsGroup = candidate;
            disposition = dispositionService.getDispositionFromObsGroup(dispositionObsGroup);
        }
    }
    if (disposition != null && disposition.getActions() != null) {
        for (String actionBeanName : disposition.getActions()) {
            DispositionAction action = getBean(actionBeanName, DispositionAction.class);
            action.action(new EncounterDomainWrapper(encounter), dispositionObsGroup, null);
        }
    }
}
Also used : Obs(org.openmrs.Obs) EncounterDomainWrapper(org.openmrs.module.emrapi.encounter.EncounterDomainWrapper) Disposition(org.openmrs.module.emrapi.disposition.Disposition) Encounter(org.openmrs.Encounter) DispositionDescriptor(org.openmrs.module.emrapi.disposition.DispositionDescriptor) DispositionAction(org.openmrs.module.emrapi.disposition.actions.DispositionAction)

Example 7 with DispositionDescriptor

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

the class ApplyDispositionActionsTest method setUp.

@Before
public void setUp() throws Exception {
    encounter = new Encounter(1);
    encounter.setDateCreated(new Date());
    encounter.setPatient(patient);
    encounter.setVisit(visit);
    deathDispositionObsGroup.setConcept(dispositionObsGroupConcept);
    deathDispositionObs.setConcept(dispositionObsConcept);
    deathDispositionObs.setValueCoded(death);
    deathDispositionObsGroup.addGroupMember(deathDispositionObs);
    nonDispositionObsGroup.setConcept(nonDispositionObsGroupConcept);
    nonDispositionObs.setConcept(nonDispositionObsConcept);
    nonDispositionObsGroup.addGroupMember(nonDispositionObs);
    deathDisposition.setActions(Arrays.asList("dischargeIfAdmittedDispositionAction", "markPatientDeadDispositionAction"));
    dispositionService = mock(DispositionService.class);
    dischargeIfAdmittedDispositionAction = mock(DispositionAction.class);
    markPatientDeadDispositionAction = mock(DispositionAction.class);
    ServiceContext.getInstance().setPersonService(mock(PersonService.class));
    ServiceContext.getInstance().setApplicationContext(mock(ApplicationContext.class));
    HtmlForm htmlForm = new HtmlForm();
    htmlForm.setXmlData("<htmlform></htmlform>");
    session = new FormEntrySession(patient, encounter, FormEntryContext.Mode.ENTER, htmlForm, null);
    DispositionDescriptor dispositionDescriptor = new DispositionDescriptor();
    dispositionDescriptor.setDispositionConcept(dispositionObsConcept);
    dispositionDescriptor.setDispositionSetConcept(dispositionObsGroupConcept);
    when(dispositionService.getDispositionDescriptor()).thenReturn(dispositionDescriptor);
    when(dispositionService.getDispositionFromObsGroup(deathDispositionObsGroup)).thenReturn(deathDisposition);
    applyDispositionActions = new ApplyDispositionAction() {

        @Override
        <T> T getBean(String beanId, Class<T> clazz) {
            if (beanId.equals("dischargeIfAdmittedDispositionAction")) {
                return (T) dischargeIfAdmittedDispositionAction;
            } else if (beanId.equals("markPatientDeadDispositionAction")) {
                return (T) markPatientDeadDispositionAction;
            } else {
                return null;
            }
        }
    };
}
Also used : DispositionService(org.openmrs.module.emrapi.disposition.DispositionService) PersonService(org.openmrs.api.PersonService) DispositionDescriptor(org.openmrs.module.emrapi.disposition.DispositionDescriptor) Date(java.util.Date) ApplicationContext(org.springframework.context.ApplicationContext) HtmlForm(org.openmrs.module.htmlformentry.HtmlForm) Encounter(org.openmrs.Encounter) FormEntrySession(org.openmrs.module.htmlformentry.FormEntrySession) DispositionAction(org.openmrs.module.emrapi.disposition.actions.DispositionAction) Before(org.junit.Before)

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