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);
}
}
}
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;
}
}
};
}
Aggregations