use of org.openmrs.CohortMembership in project openmrs-core by openmrs.
the class CohortServiceImpl method removePatientFromCohort.
/**
* @see org.openmrs.api.CohortService#removePatientFromCohort(org.openmrs.Cohort,
* org.openmrs.Patient)
*/
@Override
public Cohort removePatientFromCohort(Cohort cohort, Patient patient) {
List<CohortMembership> memberships = getCohortMemberships(patient.getPatientId(), null, false);
List<CohortMembership> toVoid = memberships.stream().filter(m -> m.getCohort().equals(cohort)).collect(Collectors.toList());
for (CohortMembership membership : toVoid) {
Context.getCohortService().voidCohortMembership(membership, "removePatientFromCohort");
}
return cohort;
}
use of org.openmrs.CohortMembership in project openmrs-core by openmrs.
the class CohortServiceImpl method notifyPatientUnvoided.
/**
* @see org.openmrs.api.CohortService#notifyPatientUnvoided(Patient, User, Date)
*/
@Override
public void notifyPatientUnvoided(Patient patient, User originallyVoidedBy, Date originalDateVoided) throws APIException {
List<CohortMembership> memberships = getCohortMemberships(patient.getPatientId(), null, true);
List<CohortMembership> toUnvoid = memberships.stream().filter(m -> m.getVoided() && m.getVoidedBy().equals(originallyVoidedBy) && OpenmrsUtil.compare(truncateToSeconds(m.getDateVoided()), truncateToSeconds(originalDateVoided)) == 0).collect(Collectors.toList());
for (CohortMembership member : toUnvoid) {
member.setVoided(false);
member.setDateVoided(null);
member.setVoidedBy(null);
member.setVoidReason(null);
dao.saveCohortMembership(member);
}
}
use of org.openmrs.CohortMembership in project openmrs-core by openmrs.
the class PatientDataVoidHandlerTest method handle_shouldVoidCohortMemberships.
@Test
public void handle_shouldVoidCohortMemberships() throws Exception {
// test a corner case by letting the same patient belong to the cohort for two separate periods
CohortMembership membership1 = new CohortMembership(7, parseDate("2001-01-01", "yyyy-MM-dd"));
membership1.setEndDate(parseDate("2001-12-31", "yyyy-MM-dd"));
CohortMembership membership2 = new CohortMembership(7, parseDate("2017-01-01", "yyyy-MM-dd"));
CohortMembership membership3 = new CohortMembership(8);
Cohort cohort = new Cohort();
cohort.setName("Cohort");
cohort.setDescription("Description");
cohort.setUuid(COHORT_UUID);
cohort.addMembership(membership1);
cohort.addMembership(membership2);
cohort.addMembership(membership3);
cohortService.saveCohort(cohort);
PatientService patientService = Context.getPatientService();
patientService.voidPatient(patientService.getPatient(7), "void reason");
Collection<CohortMembership> memberships = cohortService.getCohortByUuid(COHORT_UUID).getMemberships(false);
assertEquals(1, memberships.size());
// patientId 7 was voided
assertEquals(8, (int) memberships.iterator().next().getPatientId());
}
use of org.openmrs.CohortMembership in project openmrs-core by openmrs.
the class CohortValidatorTest method setUp.
@Before
public void setUp() {
validator = new CohortValidator();
executeDataSet(COHORT_XML);
cohort = Context.getCohortService().getCohort(2);
patient = Context.getPatientService().getPatient(7);
cohortMembership = new CohortMembership(patient.getPatientId());
cohort.addMembership(cohortMembership);
errors = new BindException(cohort, "cohort");
}
use of org.openmrs.CohortMembership in project openmrs-core by openmrs.
the class CohortServiceTest method patientUnvoided_shouldUnvoidMemberships.
@Test
public void patientUnvoided_shouldUnvoidMemberships() {
executeDataSet(COHORT_XML);
Cohort cohort = Context.getCohortService().getCohort(2);
Patient unvoidedPatient = new Patient(7);
User voidedBy = Context.getAuthenticatedUser();
Date dateVoided = new Date();
String voidReason = "Associated patient is voided";
CohortMembership voidedMembership = new CohortMembership(unvoidedPatient.getPatientId());
cohort.addMembership(voidedMembership);
voidedMembership.setVoided(true);
voidedMembership.setVoidedBy(voidedBy);
voidedMembership.setDateVoided(dateVoided);
voidedMembership.setVoidReason(voidReason);
service.notifyPatientUnvoided(unvoidedPatient, voidedBy, dateVoided);
assertFalse(voidedMembership.getVoided());
assertNull(voidedMembership.getVoidedBy());
assertNull(voidedMembership.getDateVoided());
assertNull(voidedMembership.getVoidReason());
}
Aggregations