Search in sources :

Example 1 with IdentifierValidator

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());
}
Also used : LuhnIdentifierValidator(org.openmrs.patient.impl.LuhnIdentifierValidator) IdentifierValidator(org.openmrs.patient.IdentifierValidator) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 2 with IdentifierValidator

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

Aggregations

IdentifierValidator (org.openmrs.patient.IdentifierValidator)2 Test (org.junit.Test)1 BlankIdentifierException (org.openmrs.api.BlankIdentifierException)1 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)1 LuhnIdentifierValidator (org.openmrs.patient.impl.LuhnIdentifierValidator)1 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)1