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