use of org.openmrs.Patient in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationships3_shouldFetchRelationshipsThatWereActiveDuringTheSpecifiedDateRange.
/**
* @see PersonService#getRelationships(Person,Person,RelationshipType,Date,Date)
*/
@Test
public void getRelationships3_shouldFetchRelationshipsThatWereActiveDuringTheSpecifiedDateRange() throws Exception {
executeDataSet(CREATE_PATIENT_XML);
executeDataSet(CREATE_RELATIONSHIP_XML);
// TODO use xml imported in BaseContextSensitiveTest#baseSetupWithStandardDataAndAuthentication()
Patient patient = createTestPatient();
List<Relationship> rels = createTestDatedRelationships(ps.getPatient(2), patient, personService.getRelationshipType(4));
// Get relationships effective between 1987-01-01 and 1988-01-01
List<Relationship> res = personService.getRelationships(ps.getPatient(2), patient, null, df.parse("1987-01-01"), df.parse("1988-01-01"));
// Verify # of results and which results we have received
assertEquals(5, res.size());
for (Relationship rr : res) {
if (!rr.equals(rels.get(0)) && !rr.equals(rels.get(2)) && !rr.equals(rels.get(3)) && !rr.equals(rels.get(7)) && !rr.equals(rels.get(8))) {
if (rr.equals(rels.get(1))) {
fail("unexpected relationship 1 in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
} else if (rr.equals(rels.get(4))) {
fail("unexpected relationship 4 in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
} else if (rr.equals(rels.get(5))) {
fail("unexpected relationship 5 in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
} else if (rr.equals(rels.get(6))) {
fail("unexpected relationship 6 in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
} else {
fail("unrecognized unexpected relationship in results from getRelationshipsByPerson effective between 1987-01-01 and 1988-01-01");
}
}
}
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class CohortServiceTest method addPatientToCohort_shouldAddAPatientAndSaveTheCohort.
/**
* @see CohortService#addPatientToCohort(Cohort,Patient)
*/
@Test
public void addPatientToCohort_shouldAddAPatientAndSaveTheCohort() {
executeDataSet(COHORT_XML);
// make a patient, add it using the method
Patient patientToAdd = Context.getPatientService().getPatient(3);
service.addPatientToCohort(service.getCohort(2), patientToAdd);
// proof of "save the cohort": see if the patient is in the cohort
assertTrue(service.getCohort(2).contains(3));
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class CohortServiceTest method removePatientFromCohort_shouldSaveCohortAfterRemovingPatient.
@Test
public void removePatientFromCohort_shouldSaveCohortAfterRemovingPatient() {
executeDataSet(COHORT_XML);
Cohort cohort = service.getCohort(2);
Integer patientId = cohort.getMemberships().iterator().next().getPatientId();
Patient patient = Context.getPatientService().getPatient(patientId);
service.removePatientFromCohort(cohort, patient);
assertFalse(cohort.contains(patientId));
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class CohortServiceTest method patientVoided_shouldVoidMemberships.
@Test
public void patientVoided_shouldVoidMemberships() {
executeDataSet(COHORT_XML);
Cohort cohort = Context.getCohortService().getCohort(2);
Patient voidedPatient = new Patient(7);
voidedPatient.setVoided(true);
voidedPatient.setDateVoided(new Date());
voidedPatient.setVoidedBy(Context.getAuthenticatedUser());
voidedPatient.setVoidReason("Voided as a result of the associated patient getting voided");
CohortMembership newMemberContainingVoidedPatient = new CohortMembership(voidedPatient.getPatientId());
cohort.addMembership(newMemberContainingVoidedPatient);
assertTrue(cohort.contains(voidedPatient.getPatientId()));
assertEquals(1, service.getCohortsContainingPatientId(voidedPatient.getId()).size());
service.notifyPatientVoided(voidedPatient);
assertTrue(newMemberContainingVoidedPatient.getVoided());
assertEquals(newMemberContainingVoidedPatient.getDateVoided(), voidedPatient.getDateVoided());
assertEquals(newMemberContainingVoidedPatient.getVoidedBy(), voidedPatient.getVoidedBy());
assertEquals(newMemberContainingVoidedPatient.getVoidReason(), voidedPatient.getVoidReason());
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class CohortValidator method validate.
@Override
public void validate(Object obj, Errors errors) {
if (obj == null || !(obj instanceof Cohort)) {
throw new IllegalArgumentException("The parameter obj should not be null and must be of type" + Cohort.class);
}
Cohort cohort = (Cohort) obj;
if (!cohort.getVoided()) {
Collection<CohortMembership> members = cohort.getMemberships();
if (!CollectionUtils.isEmpty(members)) {
for (CohortMembership member : members) {
Patient p = Context.getPatientService().getPatient(member.getPatientId());
int dateCompare = OpenmrsUtil.compareWithNullAsLatest(member.getStartDate(), member.getEndDate());
if (p != null && p.getVoided() && !member.getVoided()) {
String message = "Patient " + p.getPatientId() + " is voided, cannot add voided members to a cohort";
errors.rejectValue("memberships", "Cohort.patientAndMemberShouldBeVoided", message);
}
if (dateCompare == 1) {
String message = "Start date is null or end date is before start date";
errors.rejectValue("memberships", "Cohort.startDateShouldNotBeNullOrBeforeEndDate", message);
}
}
}
}
}
Aggregations