Search in sources :

Example 6 with Relationship

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

Example 7 with Relationship

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

Example 8 with Relationship

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

Example 9 with Relationship

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

Example 10 with Relationship

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