Search in sources :

Example 21 with CohortMembership

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());
}
Also used : Cohort(org.openmrs.Cohort) Patient(org.openmrs.Patient) SimpleDateFormat(java.text.SimpleDateFormat) CohortMembership(org.openmrs.CohortMembership) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

CohortMembership (org.openmrs.CohortMembership)21 Test (org.junit.Test)16 Cohort (org.openmrs.Cohort)16 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)16 Date (java.util.Date)13 Patient (org.openmrs.Patient)9 User (org.openmrs.User)5 SimpleDateFormat (java.text.SimpleDateFormat)4 List (java.util.List)4 Context (org.openmrs.api.context.Context)4 Before (org.junit.Before)3 CohortService (org.openmrs.api.CohortService)3 ParseException (java.text.ParseException)2 Collection (java.util.Collection)2 Collectors (java.util.stream.Collectors)2 DateUtils (org.apache.commons.lang3.time.DateUtils)2 Is.is (org.hamcrest.core.Is.is)2 Assert (org.junit.Assert)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2