Search in sources :

Example 46 with Relationship

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

the class PersonServiceTest method getRelationships2_shouldReturnEmptyListWhenNoRelationshipMatchingGivenParametersExist.

/**
 * @see PersonService#getRelationships(Person,Person,RelationshipType,Date)
 */
@Test
public void getRelationships2_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());
    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 47 with Relationship

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

the class PersonServiceTest method purgeRelationship_shouldDeleteRelationshipFromTheDatabase.

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

Example 48 with Relationship

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

the class PersonServiceTest method saveRelationship_shouldThrowAPIException.

/**
 * @see PersonService#saveRelationship(Relationship)
 */
@Test(expected = APIException.class)
public void saveRelationship_shouldThrowAPIException() {
    Relationship relationship = new Relationship();
    Person person = new Person();
    relationship.setPersonA(person);
    relationship.setPersonB(person);
    personService.saveRelationship(relationship);
}
Also used : Relationship(org.openmrs.Relationship) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 49 with Relationship

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

the class PersonServiceTest method getRelationshipsByPerson_shouldFetchUnvoidedRelationshipsOnly.

/**
 * @see PersonService#getRelationshipsByPerson(Person)
 */
@Test
public void getRelationshipsByPerson_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);
    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) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 50 with Relationship

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

the class PersonServiceTest method getAllRelationships_shouldReturnAllRelationshipIncludingVoidedWhenIncludeVoidedEqualsTrue.

/**
 * @see PersonService#getAllRelationships(null)
 */
@Test
public void getAllRelationships_shouldReturnAllRelationshipIncludingVoidedWhenIncludeVoidedEqualsTrue() throws Exception {
    executeDataSet("org/openmrs/api/include/PersonServiceTest-createRetiredRelationship.xml");
    List<Relationship> relationships = Context.getPersonService().getAllRelationships(true);
    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;
        }
    }
    assertTrue("There should be voided relationship here", foundVoided);
}
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