Search in sources :

Example 41 with Relationship

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");
            }
        }
    }
}
Also used : Relationship(org.openmrs.Relationship) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 42 with Relationship

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());
}
Also used : Relationship(org.openmrs.Relationship) RelationshipType(org.openmrs.RelationshipType) Person(org.openmrs.Person) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 43 with Relationship

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");
            }
        }
    }
}
Also used : Relationship(org.openmrs.Relationship) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 44 with Relationship

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);
}
Also used : Relationship(org.openmrs.Relationship) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 45 with Relationship

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);
}
Also used : Relationship(org.openmrs.Relationship) RelationshipType(org.openmrs.RelationshipType) Date(java.util.Date) 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