Search in sources :

Example 1 with Relationship

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

the class PersonServiceTest method getAllRelationships_shouldReturnAllRelationshipExcludingVoidedWhenIncludeVoidedEqualsFalse.

/**
 * @see PersonService#getAllRelationships(null)
 */
@Test
public void getAllRelationships_shouldReturnAllRelationshipExcludingVoidedWhenIncludeVoidedEqualsFalse() throws Exception {
    executeDataSet("org/openmrs/api/include/PersonServiceTest-createRetiredRelationship.xml");
    List<Relationship> relationships = Context.getPersonService().getAllRelationships(false);
    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 2 with Relationship

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

the class PersonServiceTest method voidRelationship_shouldVoidRelationshipAndSetVoidedByToGivenUserIfGivenRelationshipIsNotVoided.

@Test
public void voidRelationship_shouldVoidRelationshipAndSetVoidedByToGivenUserIfGivenRelationshipIsNotVoided() {
    Relationship relationship = personService.getRelationship(1);
    assertFalse("We need an unvoided relationship to test the method", relationship.getVoided());
    String voidReason = "Something";
    User user = Context.getUserService().getUser(501);
    assertNotNull("need a user to void", user);
    relationship.setVoidedBy(user);
    // 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(), user);
}
Also used : User(org.openmrs.User) Relationship(org.openmrs.Relationship) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with Relationship

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

the class PersonServiceTest method getRelationshipsByPerson2_shouldFetchUnvoidedRelationshipsOnly.

/**
 * @see PersonService#getRelationshipsByPerson(Person)
 */
@Test
public void getRelationshipsByPerson2_shouldFetchUnvoidedRelationshipsOnly() throws Exception {
    executeDataSet("org/openmrs/api/include/PersonServiceTest-createRetiredRelationship.xml");
    PersonService personService = Context.getPersonService();
    Person person = personService.getPerson(6);
    List<Relationship> relationships = personService.getRelationshipsByPerson(person, new Date());
    Assert.assertNotNull(relationships);
    assertTrue("There should be no relationship found given the person", relationships.isEmpty());
}
Also used : Relationship(org.openmrs.Relationship) Person(org.openmrs.Person) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with Relationship

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

the class PersonServiceTest method getRelationship_shouldReturnNullWhenRelationshipWithGivenIdDoesNotExist.

/**
 * @see PersonService#getRelationship(Integer)
 */
@Test
public void getRelationship_shouldReturnNullWhenRelationshipWithGivenIdDoesNotExist() throws Exception {
    Relationship relationship = Context.getPersonService().getRelationship(10000);
    Assert.assertNull(relationship);
}
Also used : Relationship(org.openmrs.Relationship) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with Relationship

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

the class PersonServiceTest method getRelationships3_shouldFetchRelationshipsMatchingTheGivenRelType.

/**
 * @see PersonService#getRelationships(Person,Person,RelationshipType,Date,Date)
 */
@Test
public void getRelationships3_shouldFetchRelationshipsMatchingTheGivenRelType() throws Exception {
    PersonService personService = Context.getPersonService();
    RelationshipType relationshipType = personService.getRelationshipType(1);
    List<Relationship> relationships = personService.getRelationships(null, null, relationshipType, new Date(), 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