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