use of org.openmrs.Relationship 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.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method saveRelationship_shouldCreateNewObjectWhenRelationshipIdIsNull.
/**
* @see PersonService#saveRelationship(Relationship)
*/
@Test
public void saveRelationship_shouldCreateNewObjectWhenRelationshipIdIsNull() throws Exception {
PersonService personService = Context.getPersonService();
Relationship relationship = new Relationship();
relationship.setPersonA(personService.getPerson(1));
relationship.setPersonB(personService.getPerson(2));
relationship.setRelationshipType(personService.getRelationshipType(1));
Assert.assertNull(relationship.getRelationshipId());
Relationship savedRelationship = personService.saveRelationship(relationship);
Assert.assertNotNull(savedRelationship.getRelationshipId());
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method unvoidRelationship_shouldUnvoidVoidedRelationship.
/**
* @see PersonService#unvoidRelationship(Relationship)
*/
@Test
public void unvoidRelationship_shouldUnvoidVoidedRelationship() throws Exception {
Relationship relationship = Context.getPersonService().getRelationship(1);
Relationship voidedRelationship = Context.getPersonService().voidRelationship(relationship, "Test Voiding Relationship");
assertTrue(voidedRelationship.getVoided());
Assert.assertNotNull(voidedRelationship.getVoidedBy());
Assert.assertNotNull(voidedRelationship.getVoidReason());
Assert.assertNotNull(voidedRelationship.getDateVoided());
Relationship unvoidedRelationship = Context.getPersonService().unvoidRelationship(voidedRelationship);
Assert.assertFalse(unvoidedRelationship.getVoided());
Assert.assertNull(unvoidedRelationship.getVoidedBy());
Assert.assertNull(unvoidedRelationship.getVoidReason());
Assert.assertNull(unvoidedRelationship.getDateVoided());
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method saveRelationship_shouldUpdateExistingObjectWhenRelationshipIdIsNotNull.
/**
* @see PersonService#saveRelationship(Relationship)
*/
@Test
public void saveRelationship_shouldUpdateExistingObjectWhenRelationshipIdIsNotNull() throws Exception {
PersonService personService = Context.getPersonService();
Relationship savedRelationship = personService.getRelationship(1);
Assert.assertNotNull(savedRelationship.getRelationshipId());
savedRelationship.setRelationshipType(personService.getRelationshipType(2));
Relationship updatedRelationship = personService.saveRelationship(savedRelationship);
Assert.assertEquals(personService.getRelationshipType(2), updatedRelationship.getRelationshipType());
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method voidRelationship_shouldVoidRelationshipIfGivenRelationshipIsNotVoided.
@Test
public void voidRelationship_shouldVoidRelationshipIfGivenRelationshipIsNotVoided() {
Relationship relationship = personService.getRelationship(1);
assertFalse("We need an unvoided relationship to test the method", relationship.getVoided());
String voidReason = "Something";
// TODO - voiding is done by the BaseVoidHandler called via AOP before voidRelationship
// is executed. Coverage of voidRelationship is low because relationship.getVoided() is true
// when entering voidRelationship
// Documented at TRUNK-5151
personService.voidRelationship(relationship, voidReason);
Relationship voidedRelationship = personService.getRelationship(1);
assertTrue(voidedRelationship.getVoided());
assertThat(voidedRelationship.getVoidReason(), is(voidReason));
assertNotNull(voidedRelationship.getDateVoided());
assertEquals(voidedRelationship.getVoidedBy(), Context.getAuthenticatedUser());
}
Aggregations