use of org.openmrs.PersonAttributeType in project openmrs-core by openmrs.
the class PatientDAOTest method getPatients_shouldFindOnlySearchablePersonAttributes.
@Test
public void getPatients_shouldFindOnlySearchablePersonAttributes() {
PersonAttributeType attributeType = personService.getPersonAttributeTypeByName("Birthplace");
attributeType.setSearchable(false);
personService.savePersonAttributeType(attributeType);
List<Patient> patients = patientService.getPatients("London");
assertThat(patients, is(empty()));
attributeType = personService.getPersonAttributeTypeByName("Birthplace");
attributeType.setSearchable(true);
personService.savePersonAttributeType(attributeType);
patients = patientService.getPatients("London");
Patient patient = patientService.getPatient(2);
assertThat(patients, contains(patient));
}
use of org.openmrs.PersonAttributeType in project openmrs-core by openmrs.
the class PersonAttributeTypeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see PersonAttributeTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
PersonAttributeType type = new PersonAttributeType();
type.setName("name");
type.setFormat("java.lang.String");
type.setRetireReason("retireReason");
Errors errors = new BindException(type, "patObj");
new PersonAttributeTypeValidator().validate(type, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.PersonAttributeType in project openmrs-core by openmrs.
the class PersonAttributeTypeValidatorTest method validate_shouldFailValidationIfNameIsNull.
/**
* @see PersonAttributeTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfNameIsNull() {
PersonAttributeType type = new PersonAttributeType();
Errors errors = new BindException(type, "patObj");
new PersonAttributeTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
}
use of org.openmrs.PersonAttributeType in project openmrs-core by openmrs.
the class PersonAttributeTypeValidator method validate.
/**
* @see org.springframework.validation.Validator#validate(java.lang.Object,
* org.springframework.validation.Errors)
* @should fail validation if name is null
* @should fail validation if format is empty
* @should fail validation if name already in use
* @should pass validation if description is null or empty or whitespace
* @should pass validation if all fields are correct
* @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) {
PersonAttributeType patObj = (PersonAttributeType) obj;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "PersonAttributeType.error.nameEmpty");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "format", "PersonAttributeType.error.formatEmpty");
PersonService ps = Context.getPersonService();
PersonAttributeType pat = ps.getPersonAttributeTypeByName(patObj.getName());
if (pat != null && !pat.getUuid().equals(patObj.getUuid())) {
errors.rejectValue("name", "PersonAttributeType.error.nameAlreadyInUse");
}
ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "format", "retireReason");
}
use of org.openmrs.PersonAttributeType in project openmrs-core by openmrs.
the class PersonServiceTest method savePersonAttributeType_shouldSetTheDateChangedAndChangedByOnUpdate.
/**
* @see PersonService#savePersonAttributeType(PersonAttributeType)
*/
@Test
public void savePersonAttributeType_shouldSetTheDateChangedAndChangedByOnUpdate() throws Exception {
PersonService service = Context.getPersonService();
// get the type and change something about it
PersonAttributeType pat = service.getPersonAttributeType(2);
pat.setName("attr type name");
// save the type again
service.savePersonAttributeType(pat);
assertEquals(1, pat.getChangedBy().getId().intValue());
assertNotNull(pat.getDateChanged());
}
Aggregations