Search in sources :

Example 1 with CohortService

use of org.openmrs.api.CohortService in project openmrs-core by openmrs.

the class PatientDataUnvoidHandler method handle.

@Override
public void handle(Patient patient, User originalVoidingUser, Date origParentVoidedDate, String unused) {
    // can't be unvoiding a patient that doesn't exist in the database
    if (patient.getId() != null) {
        // unvoid all the encounter that got voided as a result of the patient getting voided
        EncounterService es = Context.getEncounterService();
        EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setPatient(patient).setIncludeVoided(true).createEncounterSearchCriteria();
        List<Encounter> encounters = es.getEncounters(encounterSearchCriteria);
        if (CollectionUtils.isNotEmpty(encounters)) {
            for (Encounter encounter : encounters) {
                if (encounter.getVoided() && encounter.getDateVoided().equals(origParentVoidedDate) && encounter.getVoidedBy().equals(originalVoidingUser)) {
                    es.unvoidEncounter(encounter);
                }
            }
        }
        // unvoid all the orders that got voided as a result of the patient getting voided
        OrderService os = Context.getOrderService();
        List<Order> orders = os.getAllOrdersByPatient(patient);
        if (CollectionUtils.isNotEmpty(orders)) {
            for (Order order : orders) {
                if (order.getVoided() && order.getDateVoided().equals(origParentVoidedDate) && order.getVoidedBy().equals(originalVoidingUser)) {
                    os.unvoidOrder(order);
                }
            }
        }
        CohortService cs = Context.getCohortService();
        cs.notifyPatientUnvoided(patient, originalVoidingUser, origParentVoidedDate);
    }
}
Also used : Order(org.openmrs.Order) CohortService(org.openmrs.api.CohortService) EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) Encounter(org.openmrs.Encounter) OrderService(org.openmrs.api.OrderService) EncounterService(org.openmrs.api.EncounterService)

Example 2 with CohortService

use of org.openmrs.api.CohortService in project openmrs-core by openmrs.

the class PatientDataUnvoidHandlerTest method handle_shouldUnvoidMembersAssociatedWithThePatient.

/**
 * @verifies unvoid the members associated with the patient
 * @see PatientDataUnvoidHandler#handle(Patient,User,Date,String)
 */
@Test
public void handle_shouldUnvoidMembersAssociatedWithThePatient() throws Exception {
    executeDataSet(COHORT_XML);
    CohortService cs = Context.getCohortService();
    Cohort cohort = cs.getCohort(2);
    CohortMembership otherMembership = cohort.getMemberships().iterator().next();
    Patient patient = Context.getPatientService().getPatient(7);
    CohortMembership membership = new CohortMembership(patient.getPatientId());
    membership.setStartDate(parseDate("2001-01-01", "yyyy-MM-dd"));
    membership.setEndDate(parseDate("2001-12-31", "yyyy-MM-dd"));
    cohort.addMembership(membership);
    cs.saveCohort(cohort);
    patient = Context.getPatientService().voidPatient(patient, "Void Reason");
    assertTrue(membership.getVoided());
    assertFalse(otherMembership.getVoided());
    Context.getPatientService().unvoidPatient(patient);
    assertFalse(membership.getVoided());
    assertNull(membership.getDateVoided());
    assertNull(membership.getVoidedBy());
    assertNull(membership.getVoidReason());
}
Also used : CohortService(org.openmrs.api.CohortService) Cohort(org.openmrs.Cohort) Patient(org.openmrs.Patient) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

CohortService (org.openmrs.api.CohortService)2 Test (org.junit.Test)1 Cohort (org.openmrs.Cohort)1 CohortMembership (org.openmrs.CohortMembership)1 Encounter (org.openmrs.Encounter)1 Order (org.openmrs.Order)1 Patient (org.openmrs.Patient)1 EncounterService (org.openmrs.api.EncounterService)1 OrderService (org.openmrs.api.OrderService)1 EncounterSearchCriteria (org.openmrs.parameter.EncounterSearchCriteria)1 EncounterSearchCriteriaBuilder (org.openmrs.parameter.EncounterSearchCriteriaBuilder)1 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)1