use of org.openmrs.api.InvalidCheckDigitException in project openmrs-core by openmrs.
the class PatientIdentifierValidator method checkIdentifierAgainstValidator.
/**
* Validates that a given identifier string is valid for a given IdentifierValidator
*
* @param identifier the identifier to check against the passed {@link PatientIdentifierType}
* @param validator the IdentifierValidator to use to check the identifier
* @throws PatientIdentifierException if the identifier is does not match the format
* @should fail validation if identifier is blank
* @should fail validation if identifier is invalid
* @should pass validation if identifier is valid
* @should pass validation if validator is null
*/
public static void checkIdentifierAgainstValidator(String identifier, IdentifierValidator validator) throws PatientIdentifierException {
log.debug("Checking identifier: " + identifier + " against validator: " + validator);
if (StringUtils.isBlank(identifier)) {
throw new BlankIdentifierException("PatientIdentifier.error.nullOrBlank");
}
if (validator == null) {
log.debug("Validator is null, identifier passes.");
return;
}
// Check identifier against IdentifierValidator
try {
if (!validator.isValid(identifier)) {
throw new InvalidCheckDigitException(getMessage("PatientIdentifier.error.checkDigitWithParameter", identifier));
}
} catch (UnallowedIdentifierException e) {
throw new InvalidCheckDigitException(getMessage("PatientIdentifier.error.unallowedIdentifier", identifier, validator.getName()));
}
log.debug("The identifier passed validation.");
}
Aggregations