Search in sources :

Example 1 with CohortMembership

use of org.openmrs.CohortMembership in project openmrs-core by openmrs.

the class CohortServiceTest method getMemberships_shouldNotGetMatchingMembershipsAsOfADate.

/**
 * @verifies not get matching memberships of a cohort as of a date
 * @see Cohort#getActiveMemberships(Date)
 */
@Test
public void getMemberships_shouldNotGetMatchingMembershipsAsOfADate() throws Exception {
    executeDataSet(COHORT_XML);
    Cohort cohort = Context.getCohortService().getCohort(1);
    CohortMembership newMember = new CohortMembership(4);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date startDate = dateFormat.parse("2017-11-01 00:00:00");
    newMember.setStartDate(startDate);
    cohort.addMembership(newMember);
    service.saveCohort(cohort);
    Date dateToTest = dateFormat.parse("2016-11-01 00:00:00");
    Collection<CohortMembership> membersAsOfDate = cohort.getActiveMemberships(dateToTest);
    assertFalse(membersAsOfDate.stream().anyMatch(m -> m.getStartDate().equals(dateToTest)));
}
Also used : Assert.assertNotNull(org.junit.Assert.assertNotNull) Date(java.util.Date) Collection(java.util.Collection) Cohort(org.openmrs.Cohort) Assert.assertTrue(org.junit.Assert.assertTrue) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) CohortMembership(org.openmrs.CohortMembership) DateUtils(org.apache.commons.lang3.time.DateUtils) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) Is.is(org.hamcrest.core.Is.is) User(org.openmrs.User) ParseException(java.text.ParseException) Assert(org.junit.Assert) Patient(org.openmrs.Patient) Context(org.openmrs.api.context.Context) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Cohort(org.openmrs.Cohort) SimpleDateFormat(java.text.SimpleDateFormat) CohortMembership(org.openmrs.CohortMembership) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 2 with CohortMembership

use of org.openmrs.CohortMembership in project openmrs-core by openmrs.

the class CohortServiceTest method getCohortMembershipByUuid_shouldFindObjectGivenValidUuid.

/**
 * @see CohortService#getCohortMembershipByUuid(String)
 */
@Test
public void getCohortMembershipByUuid_shouldFindObjectGivenValidUuid() {
    executeDataSet(COHORT_XML);
    String uuid = "v9a9m5i6-17e6-407c-9d4v-hbi8teu9lf0f";
    CohortMembership byUuid = Context.getCohortService().getCohortMembershipByUuid(uuid);
    Assert.assertEquals(1, (int) byUuid.getId());
}
Also used : CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with CohortMembership

use of org.openmrs.CohortMembership in project openmrs-core by openmrs.

the class CohortServiceTest method getMemberships_shouldReturnVoidedMemberships.

/**
 * @verifies return voided memberships
 * @see Cohort#getMemberships(boolean)
 */
@Test
public void getMemberships_shouldReturnVoidedMemberships() throws Exception {
    executeDataSet(COHORT_XML);
    CohortMembership voidedMembership = new CohortMembership(7);
    voidedMembership.setVoided(true);
    voidedMembership.setVoidedBy(Context.getAuthenticatedUser());
    voidedMembership.setDateVoided(new Date());
    voidedMembership.setVoidReason("Void reason");
    CohortMembership nonVoidedMembership = new CohortMembership(4);
    Cohort cohort = Context.getCohortService().getCohort(1);
    cohort.addMembership(nonVoidedMembership);
    cohort.addMembership(voidedMembership);
    Context.getCohortService().saveCohort(cohort);
    Collection<CohortMembership> allMemberships = cohort.getMemberships(true);
    assertEquals(3, allMemberships.size());
}
Also used : Cohort(org.openmrs.Cohort) CohortMembership(org.openmrs.CohortMembership) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with CohortMembership

use of org.openmrs.CohortMembership in project openmrs-core by openmrs.

the class CohortServiceTest method getMemberships_shouldReturnUnvoidedMemberships.

/**
 * @verifies return unvoided memberships
 * @see Cohort#getMemberships(boolean)
 */
@Test
public void getMemberships_shouldReturnUnvoidedMemberships() throws Exception {
    executeDataSet(COHORT_XML);
    Cohort cohort = Context.getCohortService().getCohort(1);
    CohortMembership nonVoidedMembership = new CohortMembership(4);
    CohortMembership voidedMembership = new CohortMembership(7);
    voidedMembership.setVoided(true);
    voidedMembership.setVoidedBy(Context.getAuthenticatedUser());
    voidedMembership.setDateVoided(new Date());
    voidedMembership.setVoidReason("Void reason");
    cohort.addMembership(nonVoidedMembership);
    cohort.addMembership(voidedMembership);
    Context.getCohortService().saveCohort(cohort);
    Collection<CohortMembership> unvoidedMemberships = cohort.getMemberships(false);
    assertEquals(2, unvoidedMemberships.size());
}
Also used : Cohort(org.openmrs.Cohort) CohortMembership(org.openmrs.CohortMembership) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with CohortMembership

use of org.openmrs.CohortMembership in project openmrs-core by openmrs.

the class CohortServiceTest method getCohortMemberships_shouldGetMembershipsContainingPatientInDateRange.

@Test
public void getCohortMemberships_shouldGetMembershipsContainingPatientInDateRange() throws Exception {
    executeDataSet(COHORT_XML);
    List<CohortMembership> memberships = service.getCohortMemberships(6, new Date(), false);
    assertThat(memberships.size(), is(1));
    assertThat(memberships.get(0).getCohort().getCohortId(), is(2));
}
Also used : 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