use of org.openmrs.CohortMembership in project openmrs-core by openmrs.
the class CohortServiceTest method getCohortsContainingPatient_shouldNotReturnEndedMemberships.
/**
* @verifies not return ended memberships
* @see CohortService#getCohortsContainingPatient(org.openmrs.Patient)
*/
@Test
public void getCohortsContainingPatient_shouldNotReturnEndedMemberships() throws Exception {
executeDataSet(COHORT_XML);
Cohort cohort = service.getCohort(2);
Patient patient = new Patient(7);
CohortMembership membership = new CohortMembership(patient.getPatientId());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startDate = dateFormat.parse("2017-01-01 00:00:00");
membership.setStartDate(startDate);
cohort.addMembership(membership);
assertTrue(cohort.contains(patient.getPatientId()));
Date endDate = dateFormat.parse("2017-01-31 00:00:00");
membership.setEndDate(endDate);
List<Cohort> cohortsWithPatientAdded = service.getCohortsContainingPatientId(patient.getId());
assertEquals(0, cohortsWithPatientAdded.size());
}
Aggregations