Search in sources :

Example 36 with PatientProgram

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);
}
Also used : Patient(org.openmrs.Patient) PatientProgram(org.openmrs.PatientProgram) Test(org.junit.Test)

Example 37 with 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);
        }
    }
}
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

PatientProgram (org.openmrs.PatientProgram)37 Test (org.junit.Test)30 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)27 BindException (org.springframework.validation.BindException)18 PatientState (org.openmrs.PatientState)17 Date (java.util.Date)14 Patient (org.openmrs.Patient)11 ProgramWorkflowService (org.openmrs.api.ProgramWorkflowService)7 Program (org.openmrs.Program)6 ProgramWorkflow (org.openmrs.ProgramWorkflow)5 ArrayList (java.util.ArrayList)3 ProgramWorkflowState (org.openmrs.ProgramWorkflowState)3 MissingPropertyException (groovy.lang.MissingPropertyException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1 DateTime (org.joda.time.DateTime)1