Search in sources :

Example 41 with Program

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

Example 42 with 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);
}
Also used : Program(org.openmrs.Program) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 43 with Program

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

Program (org.openmrs.Program)43 Test (org.junit.Test)35 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)26 PatientProgram (org.openmrs.PatientProgram)22 ProgramWorkflow (org.openmrs.ProgramWorkflow)8 BindException (org.springframework.validation.BindException)8 Errors (org.springframework.validation.Errors)8 Concept (org.openmrs.Concept)7 ArrayList (java.util.ArrayList)6 ProgramWorkflowState (org.openmrs.ProgramWorkflowState)6 Date (java.util.Date)4 Patient (org.openmrs.Patient)4 ProgramWorkflowDAO (org.openmrs.api.db.ProgramWorkflowDAO)2 MissingPropertyException (groovy.lang.MissingPropertyException)1 HashMap (java.util.HashMap)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1 Criteria (org.hibernate.Criteria)1 DateTime (org.joda.time.DateTime)1 Ignore (org.junit.Ignore)1