Search in sources :

Example 6 with CohortMembership

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

the class CohortServiceTest method getCohortMemberships_shouldNotGetMembershipsContainingPatientOutsideDateRange.

@Test
public void getCohortMemberships_shouldNotGetMembershipsContainingPatientOutsideDateRange() throws Exception {
    executeDataSet(COHORT_XML);
    Date longAgo = DateUtils.parseDate("1999-12-31", "yyyy-MM-dd");
    List<CohortMembership> memberships = service.getCohortMemberships(6, longAgo, false);
    assertThat(memberships.size(), is(0));
}
Also used : Date(java.util.Date) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with CohortMembership

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

the class CohortServiceTest method voidCohortMembership_shouldVoidCohortMembership.

@Test
public void voidCohortMembership_shouldVoidCohortMembership() {
    executeDataSet(COHORT_XML);
    Cohort cohort = service.getCohort(1);
    CohortMembership cm = cohort.getActiveMemberships().iterator().next();
    final String reason = "Some reason";
    service.voidCohortMembership(cm, reason);
    assertTrue(cm.getVoided());
    assertNotNull(cm.getVoidedBy());
    assertNotNull(cm.getDateVoided());
    assertEquals(reason, cm.getVoidReason());
    assertFalse(cohort.contains(cm.getPatientId()));
}
Also used : Cohort(org.openmrs.Cohort) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with CohortMembership

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

the class CohortServiceTest method endCohortMembership_shouldEndTheCohortMembership.

@Test
public void endCohortMembership_shouldEndTheCohortMembership() {
    Date endOnDate = new Date();
    executeDataSet(COHORT_XML);
    Cohort cohort = service.getCohort(1);
    CohortMembership cm = cohort.getActiveMemberships().iterator().next();
    assertNull(cm.getEndDate());
    service.endCohortMembership(cm, endOnDate);
    assertEquals(endOnDate, cm.getEndDate());
    assertFalse(cohort.contains(cm.getPatientId()));
}
Also used : Cohort(org.openmrs.Cohort) Date(java.util.Date) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 9 with CohortMembership

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

the class CohortServiceTest method getMemberships_shouldGetMembershipsAsOfADate.

/**
 * @verifies {@link Cohort#getActiveMemberships(Date)}
 */
@Test
public void getMemberships_shouldGetMembershipsAsOfADate() throws ParseException {
    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 dateToTest = dateFormat.parse("2016-11-01 00:00:00");
    newMember.setStartDate(dateToTest);
    cohort.addMembership(newMember);
    service.saveCohort(cohort);
    Collection<CohortMembership> membersAsOfDate = cohort.getActiveMemberships(dateToTest);
    assertFalse(membersAsOfDate.isEmpty());
    assertTrue(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 10 with CohortMembership

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

the class CohortServiceTest method purgeCohortMembership_shouldRemoveMembershipFromCohort.

@Test
public void purgeCohortMembership_shouldRemoveMembershipFromCohort() {
    executeDataSet(COHORT_XML);
    CohortMembership toPurge = service.getCohortMembershipByUuid("v9a9m5i6-17e6-407c-9d4v-hbi8teu9lf0f");
    Cohort owner = toPurge.getCohort();
    service.purgeCohortMembership(toPurge);
    Context.flushSession();
    assertNull(service.getCohortMembershipByUuid("v9a9m5i6-17e6-407c-9d4v-hbi8teu9lf0f"));
    assertFalse(service.getCohort(owner.getId()).contains(toPurge.getPatientId()));
}
Also used : Cohort(org.openmrs.Cohort) CohortMembership(org.openmrs.CohortMembership) 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