use of org.openmrs.PatientProgram in project openmrs-core by openmrs.
the class ProgramWorkflowServiceUnitTest method savePatientProgram_shouldFailForNullProgram.
@Test
public void savePatientProgram_shouldFailForNullProgram() {
exception.expect(APIException.class);
exception.expectMessage("PatientProgram requires a Patient and a Program");
PatientProgram patientProgram = new PatientProgram(1);
patientProgram.setPatient(new Patient(1));
pws.savePatientProgram(patientProgram);
}
use of org.openmrs.PatientProgram 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