use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientValidatorTest method validate_shouldNotFailWhenPatientHasOnlyOneIdentifierAndItsNotPreferred.
@Test
public void validate_shouldNotFailWhenPatientHasOnlyOneIdentifierAndItsNotPreferred() {
PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0);
Patient patient = new Patient();
PersonName pName = new PersonName();
pName.setGivenName("Tom");
pName.setMiddleName("E.");
pName.setFamilyName("Patient");
patient.addName(pName);
patient.setGender("male");
PersonAddress pAddress = new PersonAddress();
pAddress.setAddress1("123 My street");
pAddress.setAddress2("Apt 402");
pAddress.setCityVillage("Anywhere city");
pAddress.setCountry("Some Country");
Set<PersonAddress> pAddressList = patient.getAddresses();
pAddressList.add(pAddress);
patient.setAddresses(pAddressList);
patient.addAddress(pAddress);
PatientIdentifier patientIdentifier1 = new PatientIdentifier();
patientIdentifier1.setLocation(new Location(1));
patientIdentifier1.setIdentifier("012345678");
patientIdentifier1.setDateCreated(new Date());
patientIdentifier1.setIdentifierType(patientIdentifierType);
patient.addIdentifier(patientIdentifier1);
Errors errors = new BindException(patient, "patient");
validator.validate(patient, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientIdentifierTypeValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.
/**
* @see PatientIdentifierTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
PatientIdentifierType type = new PatientIdentifierType();
type.setName("restraining");
type.setDescription(":(");
Errors errors = new BindException(type, "type");
new PatientIdentifierTypeValidator().validate(type, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientIdentifierTypeValidatorTest method validate_shouldPassValidationIfRegExFieldLengthIsNotTooLong.
/**
* @see PatientIdentifierTypeValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassValidationIfRegExFieldLengthIsNotTooLong() {
PatientIdentifierType type = new PatientIdentifierType();
type.setName("Martin");
type.setDescription("helps");
String valid50charInput = "12345678901234567890123456789012345678901234567890";
type.setFormat(valid50charInput);
Errors errors = new BindException(type, "type");
new PatientIdentifierTypeValidator().validate(type, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientIdentifierTypeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see PatientIdentifierTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
PatientIdentifierType type = new PatientIdentifierType();
type.setName("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.setFormat("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.setFormatDescription("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.setValidator("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 PatientIdentifierTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertTrue(errors.hasFieldErrors("format"));
Assert.assertTrue(errors.hasFieldErrors("formatDescription"));
Assert.assertTrue(errors.hasFieldErrors("validator"));
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientIdentifierTypeValidatorTest method validate_shouldFailValidationIfNameFieldLengthIsTooLong.
/**
* @see PatientIdentifierTypeValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfNameFieldLengthIsTooLong() {
PatientIdentifierType type = new PatientIdentifierType();
String invalid51charInput = "123456789012345678901234567890123456789012345678901";
type.setName(invalid51charInput);
type.setDescription("helps");
type.setFormat("format");
Errors errors = new BindException(type, "type");
new PatientIdentifierTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasErrors());
Assert.assertEquals(1, errors.getFieldErrorCount("name"));
}
Aggregations