/** * @see org.openmrs.api.CohortService#removePatientFromCohort(org.openmrs.Cohort, * org.openmrs.Patient) */ @Override public Cohort removePatientFromCohort(Cohort cohort, Patient patient) { List<CohortMembership> memberships = getCohortMemberships(patient.getPatientId(), null, false); List<CohortMembership> toVoid = memberships.stream() .filter(m -> m.getCohort().equals(cohort)) .collect(Collectors.toList()); for (CohortMembership membership : toVoid) { Context.getCohortService().voidCohortMembership(membership, "removePatientFromCohort"); } return cohort; }
@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())); }
@Override protected void delete(CohortMembership delegate, String reason, RequestContext context) throws ResponseException { Context.getCohortService().voidCohortMembership(delegate, reason); }