use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method createTestDatedRelationships.
/*
* Helper to create relationships with start and/or endDate. Returns a List of the relationships created.
*/
private List<Relationship> createTestDatedRelationships(Person personA, Person personB, RelationshipType rt) throws Exception {
List<Relationship> rels = new ArrayList<>();
// Start & end dates
// 0
Relationship r = new Relationship();
r.setPersonA(personA);
r.setPersonB(personB);
r.setRelationshipType(rt);
r.setStartDate(df.parse("1980-01-01"));
r.setEndDate(df.parse("2010-01-01"));
personService.saveRelationship(r);
rels.add(r);
// 1
r = new Relationship();
r.setPersonA(personA);
r.setPersonB(personB);
r.setRelationshipType(rt);
r.setStartDate(df.parse("1990-01-01"));
r.setEndDate(df.parse("2010-01-01"));
personService.saveRelationship(r);
rels.add(r);
// 2
r = new Relationship();
r.setPersonA(personA);
r.setPersonB(personB);
r.setRelationshipType(rt);
r.setStartDate(df.parse("1980-01-01"));
r.setEndDate(df.parse("1990-01-01"));
personService.saveRelationship(r);
rels.add(r);
// Only start dates
// 3
r = new Relationship();
r.setPersonA(personA);
r.setPersonB(personB);
r.setRelationshipType(rt);
r.setStartDate(df.parse("1980-01-01"));
personService.saveRelationship(r);
rels.add(r);
// 4
r = new Relationship();
r.setPersonA(personA);
r.setPersonB(personB);
r.setRelationshipType(rt);
r.setStartDate(df.parse("1990-01-01"));
personService.saveRelationship(r);
rels.add(r);
// 5
r = new Relationship();
r.setPersonA(personA);
r.setPersonB(personB);
r.setRelationshipType(rt);
r.setStartDate(df.parse("2010-01-01"));
personService.saveRelationship(r);
rels.add(r);
// Only end dates
// 6
r = new Relationship();
r.setPersonA(personA);
r.setPersonB(personB);
r.setRelationshipType(rt);
r.setEndDate(df.parse("1980-01-01"));
personService.saveRelationship(r);
rels.add(r);
// 7
r = new Relationship();
r.setPersonA(personA);
r.setPersonB(personB);
r.setRelationshipType(rt);
r.setEndDate(df.parse("1990-01-01"));
personService.saveRelationship(r);
rels.add(r);
// 8
r = new Relationship();
r.setPersonA(personA);
r.setPersonB(personB);
r.setRelationshipType(rt);
r.setEndDate(df.parse("2010-01-01"));
personService.saveRelationship(r);
rels.add(r);
return rels;
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationships2_shouldFetchRelationshipsMatchingTheGivenFromPerson.
/**
* @see PersonService#getRelationships(Person,Person,RelationshipType,Date)
*/
@Test
public void getRelationships2_shouldFetchRelationshipsMatchingTheGivenFromPerson() throws Exception {
PersonService personService = Context.getPersonService();
Person firstPerson = personService.getPerson(502);
List<Relationship> relationships = personService.getRelationships(firstPerson, null, null, new Date());
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 getRelationships3_shouldFetchRelationshipsMatchingTheGivenFromPerson.
/**
* @see PersonService#getRelationships(Person,Person,RelationshipType,Date,Date)
*/
@Test
public void getRelationships3_shouldFetchRelationshipsMatchingTheGivenFromPerson() throws Exception {
PersonService personService = Context.getPersonService();
Person firstPerson = personService.getPerson(502);
List<Relationship> relationships = personService.getRelationships(firstPerson, null, null, new Date(), new Date());
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 getAllRelationships_shouldReturnAllUnvoidedRelationships.
/**
* @see PersonService#getAllRelationships()
*/
@Test
public void getAllRelationships_shouldReturnAllUnvoidedRelationships() throws Exception {
executeDataSet("org/openmrs/api/include/PersonServiceTest-createRetiredRelationship.xml");
List<Relationship> relationships = Context.getPersonService().getAllRelationships();
assertTrue("At least one element, otherwise no checking for voided will take place", relationships.size() > 0);
boolean foundVoided = false;
for (Relationship relationship : relationships) {
if (relationship.getVoided()) {
foundVoided = true;
break;
}
}
Assert.assertFalse("There should be no voided relationship here", foundVoided);
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationships3_shouldFetchRelationshipsMatchingTheGivenToPerson.
/**
* @see PersonService#getRelationships(Person,Person,RelationshipType,Date,Date)
*/
@Test
public void getRelationships3_shouldFetchRelationshipsMatchingTheGivenToPerson() throws Exception {
PersonService personService = Context.getPersonService();
Person secondPerson = personService.getPerson(7);
List<Relationship> relationships = personService.getRelationships(null, secondPerson, null, new Date(), new Date());
Assert.assertNotNull(relationships);
assertTrue("There should be relationship found given the to person", relationships.size() > 0);
}
Aggregations