use of org.openmrs.patient.IdentifierValidator in project openmrs-core by openmrs.
the class PatientServiceTest method getIdentifierValidator_shouldReturnPatientIdentifierValidatorGivenClassName.
/**
* @see PatientService#getIdentifierValidator(String)
*/
@Test
public void getIdentifierValidator_shouldReturnPatientIdentifierValidatorGivenClassName() throws Exception {
IdentifierValidator identifierValidator = Context.getPatientService().getIdentifierValidator("org.openmrs.patient.impl.LuhnIdentifierValidator");
Assert.assertNotNull(identifierValidator);
Assert.assertEquals("Luhn CheckDigit Validator", identifierValidator.getName());
identifierValidator = Context.getPatientService().getIdentifierValidator("org.openmrs.patient.impl.VerhoeffIdentifierValidator");
Assert.assertNotNull(identifierValidator);
Assert.assertEquals("Verhoeff Check Digit Validator.", identifierValidator.getName());
}
use of org.openmrs.patient.IdentifierValidator in project openmrs-core by openmrs.
the class PatientIdentifierValidator method validateIdentifier.
/**
* Validates that a given identifier string is valid for a given {@link PatientIdentifierType}
* Checks for things like blank identifiers, invalid check digits, and invalid format.
*
* @param pit - the {@link PatientIdentifierType} to validate against
* @param identifier - the identifier to check against the passed {@link PatientIdentifierType}
* @throws PatientIdentifierException if the identifier is invalid
* @should fail validation if PatientIdentifierType is null
* @should fail validation if identifier is blank
* @see #checkIdentifierAgainstFormat(String, String, String)
* @see #checkIdentifierAgainstValidator(String, IdentifierValidator)
*/
public static void validateIdentifier(String identifier, PatientIdentifierType pit) throws PatientIdentifierException {
log.debug("Checking identifier: " + identifier + " for type: " + pit);
// Validate input parameters
if (pit == null) {
throw new BlankIdentifierException("PatientIdentifierType.null");
}
if (StringUtils.isBlank(identifier)) {
throw new BlankIdentifierException("PatientIdentifier.error.nullOrBlank");
}
checkIdentifierAgainstFormat(identifier, pit.getFormat(), pit.getFormatDescription());
// Check identifier against IdentifierValidator
if (pit.hasValidator()) {
IdentifierValidator validator = Context.getPatientService().getIdentifierValidator(pit.getValidator());
checkIdentifierAgainstValidator(identifier, validator);
}
log.debug("The identifier check was successful");
}
Aggregations