Search in sources :

Example 1 with KghIdGeneratorProcessor

use of org.openmrs.module.pihcore.identifier.sierraLeone.KghIdGeneratorProcessor in project openmrs-module-pihcore by PIH.

the class KghIdGeneratorProcessorTest method setup.

@Before
public void setup() throws Exception {
    mockStatic(Context.class);
    testDate = new SimpleDateFormat("yyyy-MM-dd").parse("2020-01-31");
    generator = new SequentialIdentifierGenerator();
    generator.setName("KGH ID Identifier Generator");
    generator.setUuid(ConfigureSierraLeoneIdGenerators.KGH_ID_IDENTIFIER_SOURCE_UUID);
    generator.setPrefix("'KGH'yyMM");
    generator.setMinLength(11);
    generator.setMaxLength(12);
    generator.setBaseCharacterSet("1234567890");
    generator.setFirstIdentifierBase("0001");
    lastLogEntry = new LogEntry(generator, "KGH2019120012", testDate, new User(), "Test");
    processor = new KghIdGeneratorProcessor() {

        public Date getDate() {
            return testDate;
        }
    };
    processor.setIdentifierSourceService(new BaseIdentifierSourceService() {

        long nextSequenceNum = 1L;

        public void saveSequenceValue(SequentialIdentifierGenerator sequentialIdentifierGenerator, long l) {
            nextSequenceNum = l;
            lastLogEntry.setIdentifier("KGH" + new SimpleDateFormat("yyMM").format(testDate));
        }

        public Long getSequenceValue(SequentialIdentifierGenerator sequentialIdentifierGenerator) {
            return nextSequenceNum;
        }

        public LogEntry getMostRecentLogEntry(IdentifierSource source) throws APIException {
            return lastLogEntry;
        }
    });
}
Also used : User(org.openmrs.User) APIException(org.openmrs.api.APIException) KghIdGeneratorProcessor(org.openmrs.module.pihcore.identifier.sierraLeone.KghIdGeneratorProcessor) BaseIdentifierSourceService(org.openmrs.module.idgen.service.BaseIdentifierSourceService) IdentifierSource(org.openmrs.module.idgen.IdentifierSource) SequentialIdentifierGenerator(org.openmrs.module.idgen.SequentialIdentifierGenerator) SimpleDateFormat(java.text.SimpleDateFormat) LogEntry(org.openmrs.module.idgen.LogEntry) Date(java.util.Date) Before(org.junit.Before)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Before (org.junit.Before)1 User (org.openmrs.User)1 APIException (org.openmrs.api.APIException)1 IdentifierSource (org.openmrs.module.idgen.IdentifierSource)1 LogEntry (org.openmrs.module.idgen.LogEntry)1 SequentialIdentifierGenerator (org.openmrs.module.idgen.SequentialIdentifierGenerator)1 BaseIdentifierSourceService (org.openmrs.module.idgen.service.BaseIdentifierSourceService)1 KghIdGeneratorProcessor (org.openmrs.module.pihcore.identifier.sierraLeone.KghIdGeneratorProcessor)1