/** * @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()); }
/** * @see CohortService#getCohortsContainingPatient(Patient) */ @Test public void getCohortsContainingPatient_shouldReturnCohortsThatHaveGivenPatient() { executeDataSet(COHORT_XML); Patient patientToAdd = new Patient(7); service.addPatientToCohort(service.getCohort(2), patientToAdd); assertTrue(service.getCohort(2).contains(patientToAdd.getPatientId())); List<Cohort> cohortsWithGivenPatient = service.getCohortsContainingPatientId(patientToAdd.getId()); assertTrue(cohortsWithGivenPatient.contains(service.getCohort(2))); }
@Test public void patientVoided_shouldVoidMemberships() { executeDataSet(COHORT_XML); Cohort cohort = Context.getCohortService().getCohort(2); Patient voidedPatient = new Patient(7); voidedPatient.setVoided(true); voidedPatient.setDateVoided(new Date()); voidedPatient.setVoidedBy(Context.getAuthenticatedUser()); voidedPatient.setVoidReason("Voided as a result of the associated patient getting voided"); CohortMembership newMemberContainingVoidedPatient = new CohortMembership(voidedPatient.getPatientId()); cohort.addMembership(newMemberContainingVoidedPatient); assertTrue(cohort.contains(voidedPatient.getPatientId())); assertEquals(1, service.getCohortsContainingPatientId(voidedPatient.getId()).size()); service.notifyPatientVoided(voidedPatient); assertTrue(newMemberContainingVoidedPatient.getVoided()); assertEquals(newMemberContainingVoidedPatient.getDateVoided(), voidedPatient.getDateVoided()); assertEquals(newMemberContainingVoidedPatient.getVoidedBy(), voidedPatient.getVoidedBy()); assertEquals(newMemberContainingVoidedPatient.getVoidReason(), voidedPatient.getVoidReason()); }
/** * @see CohortService#getCohortsContainingPatient(Patient) */ @Test public void getCohortsContainingPatient_shouldNotReturnVoidedCohorts() { executeDataSet(COHORT_XML); // make sure we have two cohorts, the first of which is voided assertTrue(service.getCohort(1).getVoided()); assertFalse(service.getCohort(2).getVoided()); // add a patient to both cohorts Patient patientToAdd = new Patient(7); service.addPatientToCohort(service.getCohort(1), patientToAdd); service.addPatientToCohort(service.getCohort(2), patientToAdd); assertTrue(service.getCohort(1).contains(patientToAdd.getPatientId())); assertTrue(service.getCohort(2).contains(patientToAdd.getPatientId())); // call the method and it should not return the voided cohort List<Cohort> cohortsWithPatientAdded = service.getCohortsContainingPatientId(patientToAdd.getId()); assertNotNull(cohortsWithPatientAdded); assertFalse(cohortsWithPatientAdded.contains(service.getCohort(1))); }