Search in sources :

Example 51 with Relationship

use of org.openmrs.Relationship in project openmrs-core by openmrs.

the class PersonServiceTest method getRelationships_shouldFetchRelationshipsMatchingTheGivenToPerson.

/**
 * @see PersonService#getRelationships(Person,Person,RelationshipType)
 */
@Test
public void getRelationships_shouldFetchRelationshipsMatchingTheGivenToPerson() throws Exception {
    PersonService personService = Context.getPersonService();
    Person secondPerson = personService.getPerson(7);
    List<Relationship> relationships = personService.getRelationships(null, secondPerson, null);
    Assert.assertNotNull(relationships);
    assertTrue("There should be relationship found given the to person", relationships.size() > 0);
}
Also used : Relationship(org.openmrs.Relationship) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 52 with Relationship

use of org.openmrs.Relationship in project openmrs-core by openmrs.

the class PersonServiceTest method getRelationships_shouldFetchRelationshipsMatchingTheGivenRelType.

/**
 * @see PersonService#getRelationships(Person,Person,RelationshipType)
 */
@Test
public void getRelationships_shouldFetchRelationshipsMatchingTheGivenRelType() throws Exception {
    PersonService personService = Context.getPersonService();
    RelationshipType relationshipType = personService.getRelationshipType(1);
    List<Relationship> relationships = personService.getRelationships(null, null, relationshipType);
    Assert.assertNotNull(relationships);
    assertTrue("There should be relationship found given the relationship type", relationships.size() > 0);
}
Also used : Relationship(org.openmrs.Relationship) RelationshipType(org.openmrs.RelationshipType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 53 with Relationship

use of org.openmrs.Relationship in project openmrs-core by openmrs.

the class PersonServiceTest method getRelationshipByUuid_shouldFindObjectGivenValidUuid.

/**
 * @see PersonService#getRelationshipByUuid(String)
 */
@Test
public void getRelationshipByUuid_shouldFindObjectGivenValidUuid() throws Exception {
    String uuid = "c18717dd-5d78-4a0e-84fc-ee62c5f0676a";
    Relationship relationship = Context.getPersonService().getRelationshipByUuid(uuid);
    Assert.assertEquals(1, (int) relationship.getRelationshipId());
}
Also used : Relationship(org.openmrs.Relationship) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 54 with Relationship

use of org.openmrs.Relationship in project openmrs-core by openmrs.

the class PersonServiceTest method getRelationshipsByPerson_shouldOnlyGetUnvoidedRelationshipsRegardlessOfEffectiveDate.

/**
 * Tests a voided relationship between personA and Person B to see if it is still listed when
 * retrieving unvoided relationships for personA and if it is still listed when retrieving
 * unvoided relationships for personB.
 *
 * @see PersonService#getRelationshipsByPerson(Person,Date)
 */
@Test
public void getRelationshipsByPerson_shouldOnlyGetUnvoidedRelationshipsRegardlessOfEffectiveDate() throws Exception {
    executeDataSet(CREATE_PATIENT_XML);
    executeDataSet(CREATE_RELATIONSHIP_XML);
    Patient p1 = ps.getPatient(6);
    Patient p2 = ps.getPatient(8);
    // Create a sibling relationship between o1 and p2
    Relationship sibling = new Relationship();
    sibling.setPersonA(p1);
    sibling.setPersonB(p2);
    sibling.setRelationshipType(personService.getRelationshipType(4));
    personService.saveRelationship(sibling);
    // Make p2 the Doctor of p1.
    Relationship doctor = new Relationship();
    doctor.setPersonB(p1);
    doctor.setPersonA(p2);
    doctor.setRelationshipType(personService.getRelationshipType(3));
    personService.saveRelationship(doctor);
    // Void all relationships.
    List<Relationship> allRels = personService.getAllRelationships();
    for (Relationship r : allRels) {
        personService.voidRelationship(r, "Because of a JUnit test.");
    }
    // Get unvoided relationships after voiding all of them.
    // (specified date should not matter as no relationships have date specified)
    List<Relationship> updatedARels = personService.getRelationshipsByPerson(p1, new Date());
    List<Relationship> updatedBRels = personService.getRelationshipsByPerson(p2, new Date());
    // Neither p1 or p2 should have any relationships now.
    assertEquals(0, updatedARels.size());
    assertEquals(updatedARels, updatedBRels);
}
Also used : Relationship(org.openmrs.Relationship) Patient(org.openmrs.Patient) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 55 with Relationship

use of org.openmrs.Relationship in project openmrs-core by openmrs.

the class PersonServiceTest method getRelationshipsByPerson_shouldFetchRelationshipsAssociatedWithTheGivenPerson.

/**
 * @see PersonService#getRelationshipsByPerson(Person)
 */
@Test
public void getRelationshipsByPerson_shouldFetchRelationshipsAssociatedWithTheGivenPerson() throws Exception {
    PersonService personService = Context.getPersonService();
    Person person = personService.getPerson(2);
    List<Relationship> relationships = personService.getRelationshipsByPerson(person);
    Assert.assertNotNull(relationships);
    assertTrue("There should be relationship found given the person", relationships.size() > 0);
}
Also used : Relationship(org.openmrs.Relationship) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Relationship (org.openmrs.Relationship)55 Test (org.junit.Test)49 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)49 Person (org.openmrs.Person)19 Date (java.util.Date)14 Patient (org.openmrs.Patient)13 RelationshipType (org.openmrs.RelationshipType)13 HashMap (java.util.HashMap)7 PersonService (org.openmrs.api.PersonService)6 MapBindingResult (org.springframework.validation.MapBindingResult)6 Message (ca.uhn.hl7v2.model.Message)4 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)4 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)3 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)3 ArrayList (java.util.ArrayList)3 Calendar (java.util.Calendar)2 HashSet (java.util.HashSet)2 List (java.util.List)2 User (org.openmrs.User)2 HL7Exception (ca.uhn.hl7v2.HL7Exception)1