Search in sources :

Example 21 with RelationshipType

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

the class PatientServiceTest method mergePatients_shouldNotVoidRelationshipsForSameTypeAndSideWithDifferentRelatives.

/**
 * @see PatientService#mergePatients(Patient,Patient)
 */
@Test
public void mergePatients_shouldNotVoidRelationshipsForSameTypeAndSideWithDifferentRelatives() throws Exception {
    executeDataSet(PATIENT_RELATIONSHIPS_XML);
    Patient preferred = patientService.getPatient(999);
    Patient notPreferred = patientService.getPatient(2);
    voidOrders(Collections.singleton(notPreferred));
    // expected relationships before merge:
    // * 2->1 (type 2)
    // * 999->2 (type 5)
    // * 999->1 (type 2)
    // * 7->999 (type 4)
    // * 502->2 (type 1)
    // * 7->999 (type 1)
    patientService.mergePatients(preferred, notPreferred);
    // expected relationships after merge:
    // * 999->1 (type 2)
    // * 7->999 (type 4)
    // * 502->999 (type 1)
    // * 7->999 (type 1)
    // check for relationships that should not be removed: 7->999 (type 4)
    // and 7->999 (type 1)
    List<Relationship> rels = personService.getRelationships(new Person(7), preferred, new RelationshipType(4));
    assertEquals("7->999 (type 4) was removed", 1, rels.size());
    rels = personService.getRelationships(new Person(7), preferred, new RelationshipType(1));
    assertEquals("7->999 (type 1) was removed", 1, rels.size());
}
Also used : Relationship(org.openmrs.Relationship) RelationshipType(org.openmrs.RelationshipType) Patient(org.openmrs.Patient) Person(org.openmrs.Person) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 22 with RelationshipType

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

the class RelationshipTypeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * Test for all the field being set to some values
 * @see RelationshipTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    RelationshipType type = new RelationshipType();
    type.setaIsToB("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    type.setbIsToA("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    type.setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    type.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    Errors errors = new BindException(type, "type");
    new RelationshipTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("aIsToB"));
    Assert.assertTrue(errors.hasFieldErrors("bIsToA"));
    Assert.assertTrue(errors.hasFieldErrors("description"));
    Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
Also used : Errors(org.springframework.validation.Errors) RelationshipType(org.openmrs.RelationshipType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 23 with RelationshipType

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

the class RelationshipTypeValidatorTest method validate_shouldFailValidationIfDescriptionIsNullOrEmptyOrWhitespace.

/**
 * @see RelationshipTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfDescriptionIsNullOrEmptyOrWhitespace() {
    RelationshipType type = new RelationshipType();
    Errors errors = new BindException(type, "type");
    new RelationshipTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("description"));
    type.setDescription("");
    errors = new BindException(type, "type");
    new RelationshipTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("description"));
    type.setDescription(" ");
    errors = new BindException(type, "type");
    new RelationshipTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("description"));
}
Also used : Errors(org.springframework.validation.Errors) RelationshipType(org.openmrs.RelationshipType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 24 with RelationshipType

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

the class RelationshipTypeValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsAreSet.

/**
 * Test for all the field being set to some values
 * @see RelationshipTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsAreSet() {
    RelationshipType type = new RelationshipType();
    type.setaIsToB("A is To B");
    type.setbIsToA("B is To A");
    type.setDescription("Description");
    Errors errors = new BindException(type, "type");
    new RelationshipTypeValidator().validate(type, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) RelationshipType(org.openmrs.RelationshipType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 25 with RelationshipType

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

the class RelationshipTypeValidatorTest method validate_shouldFailValidationIfbIsToAIsNullOrEmptyOrWhitespace.

/**
 * @see RelationshipTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfbIsToAIsNullOrEmptyOrWhitespace() {
    RelationshipType type = new RelationshipType();
    Errors errors = new BindException(type, "type");
    new RelationshipTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("bIsToA"));
    type.setbIsToA("");
    errors = new BindException(type, "type");
    new RelationshipTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("bIsToA"));
    type.setbIsToA(" ");
    errors = new BindException(type, "type");
    new RelationshipTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("bIsToA"));
}
Also used : Errors(org.springframework.validation.Errors) RelationshipType(org.openmrs.RelationshipType) BindException(org.springframework.validation.BindException) 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