use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationshipsByPerson_shouldFetchRelationshipsThatWereActiveDuringEffectiveDate.
/**
* Creates several relationships. Tests that a relationship is returned only when the effective
* date is as follows: - for relationships with both a start date and an end date, the effective
* date falls between the start and end dates; - for relationships with only a start date, the
* effective date falls after the start date; - for relationships with only an end date, the
* effective date falls before the end date; - relationship with neither a start nor end date
* are always returned.
*
* @see PersonService#getRelationshipsByPerson(Person,Date)
*/
@Test
public void getRelationshipsByPerson_shouldFetchRelationshipsThatWereActiveDuringEffectiveDate() 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 1988-01-01
List<Relationship> res = personService.getRelationshipsByPerson(patient, 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 with effeciveDate of 1988-01-01");
} else if (rr.equals(rels.get(4))) {
fail("unexpected relationship 4 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
} else if (rr.equals(rels.get(5))) {
fail("unexpected relationship 5 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
} else if (rr.equals(rels.get(6))) {
fail("unexpected relationship 6 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
} else {
fail("unrecognized unexpected relationship in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
}
}
}
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationships3_shouldReturnEmptyListWhenNoRelationshipMatchingGivenParametersExist.
/**
* @see PersonService#getRelationships(Person,Person,RelationshipType,Date,Date)
*/
@Test
public void getRelationships3_shouldReturnEmptyListWhenNoRelationshipMatchingGivenParametersExist() throws Exception {
PersonService personService = Context.getPersonService();
Person firstPerson = personService.getPerson(501);
Person secondPerson = personService.getPerson(2);
RelationshipType relationshipType = personService.getRelationshipType(1);
List<Relationship> relationships = personService.getRelationships(firstPerson, secondPerson, relationshipType, new Date(), new Date());
Assert.assertNotNull(relationships);
assertTrue("There should be no relationship found given the from person", relationships.isEmpty());
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationships2_shouldFetchRelationshipsThatWereActiveDuringEffectiveDate.
/**
* @see PersonService#getRelationships(Person,Person,RelationshipType,Date)
*/
@Test
public void getRelationships2_shouldFetchRelationshipsThatWereActiveDuringEffectiveDate() 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 1988-01-01
List<Relationship> res = personService.getRelationships(ps.getPatient(2), patient, null, 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 with effeciveDate of 1988-01-01");
} else if (rr.equals(rels.get(4))) {
fail("unexpected relationship 4 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
} else if (rr.equals(rels.get(5))) {
fail("unexpected relationship 5 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
} else if (rr.equals(rels.get(6))) {
fail("unexpected relationship 6 in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
} else {
fail("unrecognized unexpected relationship in results from getRelationshipsByPerson with effeciveDate of 1988-01-01");
}
}
}
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationships_shouldFetchRelationshipsMatchingTheGivenFromPerson.
/**
* @see PersonService#getRelationships(Person,Person,RelationshipType)
*/
@Test
public void getRelationships_shouldFetchRelationshipsMatchingTheGivenFromPerson() throws Exception {
PersonService personService = Context.getPersonService();
Person firstPerson = personService.getPerson(502);
List<Relationship> relationships = personService.getRelationships(firstPerson, null, null);
Assert.assertNotNull(relationships);
assertTrue("There should be relationship found given the from person", relationships.size() > 0);
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationships2_shouldFetchRelationshipsMatchingTheGivenRelType.
/**
* @see PersonService#getRelationships(Person,Person,RelationshipType,Date)
*/
@Test
public void getRelationships2_shouldFetchRelationshipsMatchingTheGivenRelType() throws Exception {
PersonService personService = Context.getPersonService();
RelationshipType relationshipType = personService.getRelationshipType(1);
List<Relationship> relationships = personService.getRelationships(null, null, relationshipType, new Date());
Assert.assertNotNull(relationships);
assertTrue("There should be relationship found given the relationship type", relationships.size() > 0);
}
Aggregations