Search in sources :

Example 31 with RelationshipType

use of org.openmrs.RelationshipType 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 32 with RelationshipType

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

the class PersonServiceTest method saveRelationshipType_shouldUpdateExistingObjectWhenRelationshipTypeIdIsNotNull.

/**
 * @see PersonService#saveRelationshipType(RelationshipType)
 */
@Test
public void saveRelationshipType_shouldUpdateExistingObjectWhenRelationshipTypeIdIsNotNull() throws Exception {
    RelationshipType savedRelationshipType = Context.getPersonService().getRelationshipType(1);
    Assert.assertNotNull(savedRelationshipType.getRelationshipTypeId());
    savedRelationshipType.setPreferred(true);
    RelationshipType updatedRelationshipType = personService.saveRelationshipType(savedRelationshipType);
    Assert.assertEquals(true, updatedRelationshipType.getPreferred());
}
Also used : RelationshipType(org.openmrs.RelationshipType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 33 with RelationshipType

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

the class PersonServiceTest method purgeRelationshipType_shouldDeleteRelationshipTypeFromTheDatabase.

/**
 * @see PersonService#purgeRelationshipType(RelationshipType)
 */
@Test
public void purgeRelationshipType_shouldDeleteRelationshipTypeFromTheDatabase() throws Exception {
    PersonService personService = Context.getPersonService();
    RelationshipType relationshipType = new RelationshipType();
    relationshipType.setDescription("Test relationship");
    relationshipType.setaIsToB("Sister");
    relationshipType.setbIsToA("Brother");
    relationshipType = personService.saveRelationshipType(relationshipType);
    assertNotNull(relationshipType.getId());
    personService.purgeRelationshipType(relationshipType);
    RelationshipType deletedRelationshipType = personService.getRelationshipType(relationshipType.getId());
    Assert.assertNull(deletedRelationshipType);
}
Also used : RelationshipType(org.openmrs.RelationshipType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 34 with RelationshipType

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

the class PersonServiceTest method getRelationships_shouldFetchRelationshipsMatchingTheGivenRelType.

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

Example 35 with RelationshipType

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

the class PersonServiceTest method retireRelationshipType_shouldRetireGivenRelationshipType.

@Test
public void retireRelationshipType_shouldRetireGivenRelationshipType() {
    RelationshipType rt = personService.getRelationshipType(1);
    assertFalse(rt.getRetired());
    String reason = "reason";
    personService.retireRelationshipType(rt, reason);
    assertTrue(rt.getRetired());
    assertThat(rt.getRetiredBy(), is(Context.getAuthenticatedUser()));
    assertNotNull(rt.getDateRetired());
    assertThat(rt.getRetireReason(), is(reason));
}
Also used : RelationshipType(org.openmrs.RelationshipType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

RelationshipType (org.openmrs.RelationshipType)35 Test (org.junit.Test)29 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)29 Relationship (org.openmrs.Relationship)13 Person (org.openmrs.Person)8 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 Patient (org.openmrs.Patient)6 PersonService (org.openmrs.api.PersonService)5 Message (ca.uhn.hl7v2.model.Message)4 Date (java.util.Date)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 HashSet (java.util.HashSet)3 List (java.util.List)3 ProviderAttributeType (org.openmrs.ProviderAttributeType)2 Role (org.openmrs.Role)2 User (org.openmrs.User)2 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)2