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);
}
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");
}
}
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);
}
}
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"));
}
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());
}
Aggregations