use of org.openmrs.Program in project openmrs-core by openmrs.
the class ProgramWorkflowServiceUnitTest method saveProgram_shouldFailIfProgramWorkFlowStateInitialIsNull.
@Test
public void saveProgram_shouldFailIfProgramWorkFlowStateInitialIsNull() {
exception.expect(APIException.class);
exception.expectMessage("ProgramWorkflowState concept, initial, terminal are required");
Program program = new Program();
program.setName("TEST PROGRAM");
program.setDescription("TEST PROGRAM DESCRIPTION");
program.setConcept(new Concept(1));
ProgramWorkflow workflow = new ProgramWorkflow();
workflow.setConcept(new Concept(2));
ProgramWorkflowState state1 = new ProgramWorkflowState();
state1.setConcept(new Concept(3));
state1.setTerminal(false);
workflow.addState(state1);
program.addWorkflow(workflow);
pws.saveProgram(program);
}
use of org.openmrs.Program in project openmrs-core by openmrs.
the class SerializedObjectDAOTest method saveObject_shouldThrowAnExceptionIfObjectNotSupported.
@Test(expected = DAOException.class)
public void saveObject_shouldThrowAnExceptionIfObjectNotSupported() {
dao.unregisterSupportedType(Program.class);
Program data = new Program();
data.setName("NewProgram");
data.setDescription("This is to test saving a Program");
dao.saveObject(data);
}
use of org.openmrs.Program 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);
}
}
}
Aggregations