Search in sources :

Example 1 with LuhnMod30IdentifierValidator

use of org.openmrs.module.idgen.validator.LuhnMod30IdentifierValidator in project openmrs-module-pihcore by PIH.

the class PihProviderIdentifierGenerator method generateIdentifier.

// this generates a 3digit base 30 identifier with an "M" prefix and a check-digit suffix
// the identifier is seeded on the primary key of the associated provider
// since 30^3 = 27000, this will start to fail if the primary key every goes above 27000
@Override
public String generateIdentifier(Provider provider) {
    if (provider.getId() == null) {
        throw new IllegalStateException("Cannot generate identifier for provider without primary key");
    }
    SequentialIdentifierGenerator generator = new SequentialIdentifierGenerator();
    generator.setBaseCharacterSet("ACDEFGHJKLMNPRTUVWXY1234567890");
    generator.setFirstIdentifierBase("100");
    generator.setPrefix(config.getProviderIdentifierPrefix());
    generator.setMaxLength(3 + config.getProviderIdentifierPrefix().length());
    generator.setMinLength(3 + config.getProviderIdentifierPrefix().length());
    String identifier = generator.getIdentifierForSeed(provider.getId().longValue());
    return new LuhnMod30IdentifierValidator().getValidIdentifier(identifier);
}
Also used : LuhnMod30IdentifierValidator(org.openmrs.module.idgen.validator.LuhnMod30IdentifierValidator) SequentialIdentifierGenerator(org.openmrs.module.idgen.SequentialIdentifierGenerator)

Aggregations

SequentialIdentifierGenerator (org.openmrs.module.idgen.SequentialIdentifierGenerator)1 LuhnMod30IdentifierValidator (org.openmrs.module.idgen.validator.LuhnMod30IdentifierValidator)1