Search in sources :

Example 11 with Relationship

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

Example 12 with Relationship

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

Example 13 with Relationship

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

Example 14 with Relationship

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

Example 15 with Relationship

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