/** * @see CohortService#addPatientToCohort(Cohort,Patient) */ @Test public void addPatientToCohort_shouldNotFailIfCohortAlreadyContainsPatient() { executeDataSet(COHORT_XML); // make a patient, add it using the method Patient patientToAdd = Context.getPatientService().getPatient(3); service.addPatientToCohort(service.getCohort(2), patientToAdd); assertTrue(service.getCohort(2).contains(3)); // do it again to see if it fails try { service.addPatientToCohort(service.getCohort(2), patientToAdd); } catch (Exception e) { Assert.fail("addPatientToCohort(Cohort,Patient) fails when cohort already contains patient."); } }
/** * @see CohortService#addPatientToCohort(Cohort,Patient) */ @Test public void addPatientToCohort_shouldAddAPatientAndSaveTheCohort() { executeDataSet(COHORT_XML); // make a patient, add it using the method Patient patientToAdd = Context.getPatientService().getPatient(3); service.addPatientToCohort(service.getCohort(2), patientToAdd); // proof of "save the cohort": see if the patient is in the cohort assertTrue(service.getCohort(2).contains(3)); }
/** * @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))); }
/** * @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))); }