Search in sources :

Example 6 with RelationshipType

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

the class PersonServiceTest method getRelationshipType_shouldReturnNullWhenNoRelationshipTypeMatchesGivenRelationshipTypeId.

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

Example 7 with RelationshipType

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

the class RelationshipTypeValidator method validate.

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
 * @should fail validation if aIsToB(or A is To B) is null or empty or whitespace
 * @should fail validation if bIsToA(or B is To A) is null or empty or whitespace
 * @should fail validation if description is null or empty or whitespace
 * @should pass validation if all required fields are set
 * @should fail validation if relationshipTypeName already exist
 * @should pass validation if field lengths are correct
 * @should fail validation if field lengths are not correct
 */
@Override
public void validate(Object obj, Errors errors) {
    RelationshipType relationshipType = (RelationshipType) obj;
    if (relationshipType == null) {
        errors.rejectValue("relationshipType", "error.general");
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "aIsToB", "RelationshipType.aIsToB.required");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "bIsToA", "RelationshipType.bIsToA.required");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "RelationshipType.description.required");
        RelationshipType exist = Context.getPersonService().getRelationshipTypeByName(relationshipType.getaIsToB() + "/" + relationshipType.getbIsToA());
        if (exist != null && !exist.getRetired() && !OpenmrsUtil.nullSafeEquals(relationshipType.getUuid(), exist.getUuid())) {
            errors.reject("duplicate.relationshipType");
        }
        ValidateUtil.validateFieldLengths(errors, obj.getClass(), "aIsToB", "bIsToA", "description", "retireReason");
    }
}
Also used : RelationshipType(org.openmrs.RelationshipType)

Example 8 with RelationshipType

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

the class CreateCoreUuids method getUUIDs.

// @Test
@SkipBaseSetup
public void getUUIDs() throws Exception {
    Context.authenticate("admin", "test");
    System.out.println("db: " + OpenmrsConstants.DATABASE_NAME);
    Map<String, List<? extends OpenmrsMetadata>> coremetadatas = new LinkedHashMap<>();
    coremetadatas.put("field_type", Context.getFormService().getAllFieldTypes(true));
    coremetadatas.put("person_attribute_type", Context.getPersonService().getAllPersonAttributeTypes(true));
    coremetadatas.put("encounter_type", Context.getEncounterService().getAllEncounterTypes(true));
    coremetadatas.put("concept_datatype", Context.getConceptService().getAllConceptDatatypes(true));
    coremetadatas.put("concept_class", Context.getConceptService().getAllConceptClasses(true));
    coremetadatas.put("patient_identifier_type", Context.getPatientService().getAllPatientIdentifierTypes(true));
    coremetadatas.put("location", Context.getLocationService().getAllLocations(true));
    coremetadatas.put("hl7_source", Context.getHL7Service().getAllHL7Sources());
    for (Map.Entry<String, List<? extends OpenmrsMetadata>> entry : coremetadatas.entrySet()) {
        System.out.println("new table: " + entry.getKey());
        for (OpenmrsMetadata obj : entry.getValue()) {
            String output = "<update tableName=\"" + entry.getKey() + "\"><column name=\"uuid\" value=\"" + obj.getUuid() + "\"/><where>" + entry.getKey() + "_id" + "= '" + obj.getId() + "' and name = '" + obj.getName().replace("'", "\\'") + "'</where></update>";
            System.out.println(output);
        }
    }
    // /////////////////////////////////////
    // exceptions:
    // 
    // relationship types
    System.out.println("Relationship type");
    for (RelationshipType type : Context.getPersonService().getAllRelationshipTypes()) {
        String output = "<update tableName=\"relationship_type\"><column name=\"uuid\" value=\"" + type.getUuid() + "\"/><where> relationship_type_id = '" + type.getRelationshipTypeId() + "' and a_is_to_b = '" + type.getaIsToB().replace("'", "\\'") + "' and b_is_to_a = '" + type.getbIsToA().replace("'", "\\'") + "'</where></update>";
        System.out.println(output);
    }
    // roles:
    System.out.println("Roles");
    for (Role role : Context.getUserService().getAllRoles()) {
        String output = "<update tableName=\"role\"><column name=\"uuid\" value=\"" + role.getUuid() + "\"/><where> role = '" + role.getRole().replace("'", "\\'") + "'</where></update>";
        System.out.println(output);
    }
    // user:
    System.out.println("Users");
    for (User user : Context.getUserService().getAllUsers()) {
        String output = "<update tableName=\"users\"><column name=\"uuid\" value=\"" + user.getUuid() + "\"/><where> user_id = '" + user.getUserId() + "' and system_id = '" + user.getSystemId().replace("'", "\\'") + "'</where></update>";
        System.out.println(output);
    }
}
Also used : Role(org.openmrs.Role) User(org.openmrs.User) RelationshipType(org.openmrs.RelationshipType) List(java.util.List) OpenmrsMetadata(org.openmrs.OpenmrsMetadata) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with RelationshipType

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

the class RelationshipTypeValidatorTest method validate_shouldFailValidationIfaIsToBIsNullOrEmptyOrWhitespace.

/**
 * @see RelationshipTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfaIsToBIsNullOrEmptyOrWhitespace() {
    RelationshipType type = new RelationshipType();
    Errors errors = new BindException(type, "type");
    new RelationshipTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("aIsToB"));
    type.setaIsToB("");
    errors = new BindException(type, "type");
    new RelationshipTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("aIsToB"));
    type.setaIsToB(" ");
    errors = new BindException(type, "type");
    new RelationshipTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("aIsToB"));
}
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 10 with RelationshipType

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

the class RelationshipTypeValidatorTest method validate_shouldPassEditingEncounterTypeName.

/**
 * @see org.openmrs.validator.RelationshipTypeValidator#validate(Object, Errors)
 */
@Test
public void validate_shouldPassEditingEncounterTypeName() {
    RelationshipType type = new RelationshipType();
    type.setaIsToB("Doctor");
    type.setbIsToA("Patient");
    Errors errors = new BindException(type, "type");
    new RelationshipTypeValidator().validate(type, errors);
    Assert.assertTrue(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)

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