Search in sources :

Example 86 with APIException

use of org.openmrs.api.APIException 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

APIException (org.openmrs.api.APIException)86 Date (java.util.Date)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 File (java.io.File)9 Obs (org.openmrs.Obs)7 List (java.util.List)6 Map (java.util.Map)6 User (org.openmrs.User)6 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)5 Concept (org.openmrs.Concept)5 OpenmrsObject (org.openmrs.OpenmrsObject)5 InputStream (java.io.InputStream)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 Order (org.openmrs.Order)4 FileNotFoundException (java.io.FileNotFoundException)3 OutputStreamWriter (java.io.OutputStreamWriter)3 MessageDigest (java.security.MessageDigest)3 HashMap (java.util.HashMap)3