Search in sources :

Example 16 with Relationship

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

the class PersonServiceTest method getRelationshipsByPerson2_shouldFetchRelationshipsAssociatedWithTheGivenPerson.

/**
 * @see PersonService#getRelationshipsByPerson(Person)
 */
@Test
public void getRelationshipsByPerson2_shouldFetchRelationshipsAssociatedWithTheGivenPerson() throws Exception {
    PersonService personService = Context.getPersonService();
    Person person = personService.getPerson(2);
    List<Relationship> relationships = personService.getRelationshipsByPerson(person, new Date());
    Assert.assertNotNull(relationships);
    assertTrue("There should be relationship found given the 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 17 with Relationship

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

the class PersonServiceTest method getRelationships2_shouldFetchRelationshipsMatchingTheGivenToPerson.

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

Example 18 with Relationship

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

the class PersonServiceTest method getRelationship_shouldReturnRelationshipWithGivenId.

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

Example 19 with Relationship

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

the class RelationshipValidatorTest method validate_shouldFailIfEndDateIsBeforeStartDate.

/**
 * @throws ParseException
 * @see RelationshipValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfEndDateIsBeforeStartDate() throws ParseException {
    Relationship relationship = new Relationship(1);
    relationship.setStartDate(Context.getDateFormat().parse("18/02/2012"));
    relationship.setEndDate(Context.getDateFormat().parse("18/02/2001"));
    Map<String, String> map = new HashMap<>();
    MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName());
    new RelationshipValidator().validate(relationship, errors);
    Assert.assertEquals(true, errors.hasErrors());
}
Also used : HashMap(java.util.HashMap) Relationship(org.openmrs.Relationship) MapBindingResult(org.springframework.validation.MapBindingResult) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 20 with Relationship

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

the class RelationshipValidatorTest method validate_shouldPassIfStartDateIsNotInFuture.

/**
 * @see RelationshipValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassIfStartDateIsNotInFuture() {
    Relationship relationship = new Relationship(1);
    Map<String, String> map = new HashMap<>();
    MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName());
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.YEAR, -1);
    Date lastYear = cal.getTime();
    relationship.setStartDate(lastYear);
    new RelationshipValidator().validate(relationship, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : HashMap(java.util.HashMap) Relationship(org.openmrs.Relationship) Calendar(java.util.Calendar) MapBindingResult(org.springframework.validation.MapBindingResult) 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