Search in sources :

Example 26 with PersonAttributeType

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));
}
Also used : PersonAttributeType(org.openmrs.PersonAttributeType) Patient(org.openmrs.Patient) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 27 with PersonAttributeType

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());
}
Also used : Errors(org.springframework.validation.Errors) PersonAttributeType(org.openmrs.PersonAttributeType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 28 with PersonAttributeType

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"));
}
Also used : Errors(org.springframework.validation.Errors) PersonAttributeType(org.openmrs.PersonAttributeType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 29 with PersonAttributeType

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");
}
Also used : PersonService(org.openmrs.api.PersonService) PersonAttributeType(org.openmrs.PersonAttributeType)

Example 30 with PersonAttributeType

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());
}
Also used : PersonAttributeType(org.openmrs.PersonAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

PersonAttributeType (org.openmrs.PersonAttributeType)40 Test (org.junit.Test)33 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)33 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 PersonAttribute (org.openmrs.PersonAttribute)4 Location (org.openmrs.Location)3 PatientIdentifierType (org.openmrs.PatientIdentifierType)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Patient (org.openmrs.Patient)2 ImportPatientFromWebService (org.openmrs.module.importpatientfromws.api.ImportPatientFromWebService)2 RemoteServerConfiguration (org.openmrs.module.importpatientfromws.api.RemoteServerConfiguration)2 DLD (ca.uhn.hl7v2.model.v25.datatype.DLD)1 IS (ca.uhn.hl7v2.model.v25.datatype.IS)1 File (java.io.File)1 URL (java.net.URL)1 Random (java.util.Random)1 Ignore (org.junit.Ignore)1 GlobalProperty (org.openmrs.GlobalProperty)1