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));
}
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()));
}
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()));
}
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)));
}
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()));
}
Aggregations