diff --git a/api-2.3/src/test/java/org/openmrs/module/initializer/api/loaders/LoadersOrderTest.java b/api-2.3/src/test/java/org/openmrs/module/initializer/api/loaders/LoadersOrderTest.java index 448a2f42..dbe682a2 100644 --- a/api-2.3/src/test/java/org/openmrs/module/initializer/api/loaders/LoadersOrderTest.java +++ b/api-2.3/src/test/java/org/openmrs/module/initializer/api/loaders/LoadersOrderTest.java @@ -73,6 +73,7 @@ protected boolean matchesSafely(List loaders, Description mismatchDescri exclude.add(Domain.PAYMENT_MODES.getName()); exclude.add(Domain.BILLABLE_SERVICES.getName()); exclude.add(Domain.CASH_POINTS.getName()); + exclude.add(Domain.CONCEPT_REFERENCE_RANGE.getName()); boolean result = true; Set loaderDomains = loaders.stream().map(Loader::getDomainName).collect(Collectors.toSet()); diff --git a/api-2.7/pom.xml b/api-2.7/pom.xml new file mode 100644 index 00000000..958a47ae --- /dev/null +++ b/api-2.7/pom.xml @@ -0,0 +1,83 @@ + + + + initializer + org.openmrs.module + 2.8.0-SNAPSHOT + + 4.0.0 + + initializer-api-2.7 + jar + Initializer API 2.7 + API 2.7 project for Initializer + + + ${openmrsVersion2.7} + + + + + + org.openmrs.test + openmrs-test + pom + ${openmrsPlatformVersion} + test + + + org.powermock + powermock-api-mockito2 + + + + + + ${project.parent.groupId} + ${project.parent.artifactId}-api + ${project.parent.version} + provided + + + + ${project.parent.groupId} + ${project.parent.artifactId}-api + ${project.parent.version} + test + test-jar + + + + ${project.parent.groupId} + ${project.parent.artifactId}-api-2.2 + ${project.parent.version} + provided + + + + ${project.parent.groupId} + ${project.parent.artifactId}-api-2.2 + ${project.parent.version} + test + test-jar + + + + org.openmrs.module + fhir2-api-2.5 + 2.2.0 + provided + + + + org.openmrs.module + fhir2-api-2.6 + 2.2.0 + provided + + + + + diff --git a/api-2.7/src/main/java/org/openmrs/module/initializer/api/conceptreferencerange/ConceptReferenceRangeLineProcessor.java b/api-2.7/src/main/java/org/openmrs/module/initializer/api/conceptreferencerange/ConceptReferenceRangeLineProcessor.java new file mode 100644 index 00000000..d5eb0dd9 --- /dev/null +++ b/api-2.7/src/main/java/org/openmrs/module/initializer/api/conceptreferencerange/ConceptReferenceRangeLineProcessor.java @@ -0,0 +1,50 @@ +package org.openmrs.module.initializer.api.conceptreferencerange; + +import org.openmrs.api.ConceptService; +import org.openmrs.module.initializer.api.BaseLineProcessor; +import org.openmrs.module.initializer.api.CsvLine; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; +import org.openmrs.ConceptReferenceRange; + +@Component +public class ConceptReferenceRangeLineProcessor extends BaseLineProcessor { + + private final String HEADER_CONCEPT_NUMERIC_UUID = "Concept Numeric UUID"; + + private final String HEADER_ABSOLUTE_LOW = "Absolute Low"; + + private final String HEADER_ABSOLUTE_HIGH = "Absolute High"; + + private final String HEADER_CRITICAL_LOW = "Critical Low"; + + private final String HEADER_CRITICAL_HIGH = "Critical High"; + + private final String HEADER_NORMAL_LOW = "Normal Low"; + + private final String HEADER_NORMAL_HIGH = "Normal High"; + + private final String HEADER_CRITERIA = "Criteria"; + + private final ConceptService conceptService; + + public ConceptReferenceRangeLineProcessor(@Qualifier("conceptService") ConceptService conceptService) { + this.conceptService = conceptService; + } + + public ConceptReferenceRange fill(ConceptReferenceRange conceptReferenceRange, CsvLine line) + throws IllegalArgumentException { + conceptReferenceRange + .setConceptNumeric(conceptService.getConceptNumericByUuid(line.get(HEADER_CONCEPT_NUMERIC_UUID))); + conceptReferenceRange.setHiAbsolute(line.getDouble(HEADER_ABSOLUTE_HIGH)); + conceptReferenceRange.setLowAbsolute(line.getDouble(HEADER_ABSOLUTE_LOW)); + conceptReferenceRange.setHiCritical(line.getDouble(HEADER_CRITICAL_HIGH)); + conceptReferenceRange.setLowCritical(line.getDouble(HEADER_CRITICAL_LOW)); + conceptReferenceRange.setHiNormal(line.getDouble(HEADER_NORMAL_HIGH)); + conceptReferenceRange.setLowNormal(line.getDouble(HEADER_NORMAL_LOW)); + conceptReferenceRange.setCriteria(line.getString(HEADER_CRITERIA)); + + return conceptReferenceRange; + + } +} diff --git a/api-2.7/src/main/java/org/openmrs/module/initializer/api/conceptreferencerange/ConceptReferenceRangeLoader.java b/api-2.7/src/main/java/org/openmrs/module/initializer/api/conceptreferencerange/ConceptReferenceRangeLoader.java new file mode 100644 index 00000000..55cb28b1 --- /dev/null +++ b/api-2.7/src/main/java/org/openmrs/module/initializer/api/conceptreferencerange/ConceptReferenceRangeLoader.java @@ -0,0 +1,24 @@ +package org.openmrs.module.initializer.api.conceptreferencerange; + +import org.openmrs.ConceptReferenceRange; +import org.openmrs.annotation.OpenmrsProfile; +import org.openmrs.module.initializer.api.loaders.BaseCsvLoader; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.io.File; + +@OpenmrsProfile(openmrsPlatformVersion = "2.7.x") +@Component +public class ConceptReferenceRangeLoader extends BaseCsvLoader { + + @Autowired + public void setParser(ConceptReferenceRangeParser parser) { + this.parser = parser; + } + + @Override + protected void preload(File file) { + } + +} diff --git a/api-2.7/src/main/java/org/openmrs/module/initializer/api/conceptreferencerange/ConceptReferenceRangeParser.java b/api-2.7/src/main/java/org/openmrs/module/initializer/api/conceptreferencerange/ConceptReferenceRangeParser.java new file mode 100644 index 00000000..c4ca122f --- /dev/null +++ b/api-2.7/src/main/java/org/openmrs/module/initializer/api/conceptreferencerange/ConceptReferenceRangeParser.java @@ -0,0 +1,45 @@ +package org.openmrs.module.initializer.api.conceptreferencerange; + +import org.openmrs.ConceptReferenceRange; +import org.openmrs.api.ConceptService; +import org.openmrs.module.initializer.Domain; +import org.openmrs.module.initializer.api.BaseLineProcessor; +import org.openmrs.module.initializer.api.CsvLine; +import org.openmrs.module.initializer.api.CsvParser; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +@Component +public class ConceptReferenceRangeParser extends CsvParser> { + + private ConceptService conceptService; + + public ConceptReferenceRangeParser(@Qualifier("conceptService") ConceptService conceptService, + ConceptReferenceRangeLineProcessor lineProcessor) { + super(lineProcessor); + this.conceptService = conceptService; + } + + @Override + public ConceptReferenceRange bootstrap(CsvLine line) throws IllegalArgumentException { + String uuid = line.getUuid(); + ConceptReferenceRange conceptReferenceRange = conceptService.getConceptReferenceRangeByUuid(uuid); + + if (conceptReferenceRange == null) { + conceptReferenceRange = new ConceptReferenceRange(); + conceptReferenceRange.setUuid(uuid); + } + + return conceptReferenceRange; + } + + @Override + public ConceptReferenceRange save(ConceptReferenceRange instance) { + return conceptService.saveConceptReferenceRange(instance); + } + + @Override + public Domain getDomain() { + return Domain.CONCEPT_REFERENCE_RANGE; + } +} diff --git a/api-2.7/src/test/java/org/openmrs/module/initializer/DomainBaseModuleContextSensitive_2_7_Test.java b/api-2.7/src/test/java/org/openmrs/module/initializer/DomainBaseModuleContextSensitive_2_7_Test.java new file mode 100644 index 00000000..f8ff4d38 --- /dev/null +++ b/api-2.7/src/test/java/org/openmrs/module/initializer/DomainBaseModuleContextSensitive_2_7_Test.java @@ -0,0 +1,83 @@ +package org.openmrs.module.initializer; + +import org.openmrs.module.Module; +import org.openmrs.module.ModuleFactory; + +import java.io.File; + +public abstract class DomainBaseModuleContextSensitive_2_7_Test extends DomainBaseModuleContextSensitiveTest { + + @Override + public void initModules() { + { + Module mod = new Module("", "addresshierarchy", "", "", "", "2.17.0", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + { + Module mod = new Module("", "exti18n", "", "", "", "1.0.0", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + { + Module mod = new Module("", "fhir2", "", "", "", "1.6.0", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + { + Module mod = new Module("", "openconceptlab", "", "", "", "1.2.9", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + { + Module mod = new Module("", "htmlformentry", "", "", "", "4.0.0", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + { + Module mod = new Module("", "idgen", "", "", "", "4.6.0", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + { + Module mod = new Module("", "metadatasharing", "", "", "", "1.2.2", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + { + Module mod = new Module("", "metadatamapping", "", "", "", "1.3.4", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + { + Module mod = new Module("", "appointments", "", "", "", "1.2", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + { + Module mod = new Module("", "datafilter", "", "", "", "1.0.0", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + { + Module mod = new Module("", "bahmni.ie.apps", "", "", "", "1.0.0", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + { + Module mod = new Module("", "providermanagement", "", "", "", "1.0.0", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + { + Module mod = new Module("", "cohort", "", "", "", "3.5.0", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + { + Module mod = new Module("", "emrapi", "", "", "", "2.0.0", ""); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + } +} diff --git a/api-2.7/src/test/java/org/openmrs/module/initializer/api/loaders/ConceptReferenceRangeLoaderIntegrationTest.java b/api-2.7/src/test/java/org/openmrs/module/initializer/api/loaders/ConceptReferenceRangeLoaderIntegrationTest.java new file mode 100644 index 00000000..fd37cfc2 --- /dev/null +++ b/api-2.7/src/test/java/org/openmrs/module/initializer/api/loaders/ConceptReferenceRangeLoaderIntegrationTest.java @@ -0,0 +1,76 @@ +package org.openmrs.module.initializer.api.loaders; + +import org.junit.Assert; +import org.junit.Test; +import org.openmrs.ConceptReferenceRange; +import org.openmrs.api.ConceptService; +import org.openmrs.module.initializer.DomainBaseModuleContextSensitive_2_7_Test; +import org.openmrs.module.initializer.api.conceptreferencerange.ConceptReferenceRangeLoader; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; + +public class ConceptReferenceRangeLoaderIntegrationTest extends DomainBaseModuleContextSensitive_2_7_Test { + + @Autowired + @Qualifier("conceptService") + private ConceptService conceptService; + + @Autowired + private ConceptReferenceRangeLoader loader; + + public void setup() { + executeDataSet("testdata/test-concepts.xml"); + executeDataSet("testdata/test-concepts-numeric.xml"); + } + + @Test + public void load_shouldLoadConceptReferenceRangesAccordingToCsvFiles() { + loader.load(); + + { + ConceptReferenceRange conceptReferenceRange = conceptService + .getConceptReferenceRangeByUuid("bc059100-4ace-4af5-afbf-2da7f3a34acf"); + Assert.assertNotNull(conceptReferenceRange); + Assert.assertNotNull(conceptReferenceRange.getConceptNumeric()); + Assert.assertEquals("a09ab2c5-878e-4905-b25d-5784167d0216", conceptReferenceRange.getConceptNumeric().getUuid()); + Assert.assertEquals(-100.5, conceptReferenceRange.getLowAbsolute(), 0.01); + Assert.assertEquals(-85.7, conceptReferenceRange.getLowCritical(), 0.01); + Assert.assertEquals(-50.3, conceptReferenceRange.getLowNormal(), 0.01); + Assert.assertEquals(45.1, conceptReferenceRange.getHiNormal(), 0.01); + Assert.assertEquals(78.0, conceptReferenceRange.getHiCritical(), 0.01); + Assert.assertEquals(98.8, conceptReferenceRange.getHiAbsolute(), 0.01); + Assert.assertEquals("$patient.getAge() > 3", conceptReferenceRange.getCriteria()); + } + + { + ConceptReferenceRange conceptReferenceRange = conceptService + .getConceptReferenceRangeByUuid("930e1fb4-490d-45fe-a137-0cd941c76124"); + Assert.assertNotNull(conceptReferenceRange); + Assert.assertNotNull(conceptReferenceRange.getConceptNumeric()); + Assert.assertEquals("a09ab2c5-878e-4905-b25d-5784167d0216", conceptReferenceRange.getConceptNumeric().getUuid()); + Assert.assertEquals(-100.5, conceptReferenceRange.getLowAbsolute(), 0.01); + Assert.assertEquals(-85.7, conceptReferenceRange.getLowCritical(), 0.01); + Assert.assertEquals(-50.3, conceptReferenceRange.getLowNormal(), 0.01); + Assert.assertEquals(45.1, conceptReferenceRange.getHiNormal(), 0.01); + Assert.assertEquals(78.0, conceptReferenceRange.getHiCritical(), 0.01); + Assert.assertEquals(98.8, conceptReferenceRange.getHiAbsolute(), 0.01); + Assert.assertEquals("$patient.getAge() < 10", conceptReferenceRange.getCriteria()); + } + + { + ConceptReferenceRange conceptReferenceRange = conceptService + .getConceptReferenceRangeByUuid("b5a7b296-e500-4a2c-ab2e-eb012ed9ae1e"); + Assert.assertNotNull(conceptReferenceRange); + Assert.assertNotNull(conceptReferenceRange.getConceptNumeric()); + Assert.assertEquals("a09ab2c5-878e-4905-b25d-5784167d0216", conceptReferenceRange.getConceptNumeric().getUuid()); + Assert.assertEquals(60.0, conceptReferenceRange.getLowAbsolute(), 0.01); + Assert.assertEquals(70.0, conceptReferenceRange.getLowCritical(), 0.01); + Assert.assertEquals(80.0, conceptReferenceRange.getLowNormal(), 0.01); + Assert.assertEquals(120.0, conceptReferenceRange.getHiNormal(), 0.01); + Assert.assertEquals(130.0, conceptReferenceRange.getHiCritical(), 0.01); + Assert.assertEquals(150.0, conceptReferenceRange.getHiAbsolute(), 0.01); + Assert.assertEquals("$fn.getCurrentHour() > 2", conceptReferenceRange.getCriteria()); + } + } + +} diff --git a/api-2.7/src/test/resources/testAppDataDir/configuration/conceptreferencerange/conceptreferencerange.csv b/api-2.7/src/test/resources/testAppDataDir/configuration/conceptreferencerange/conceptreferencerange.csv new file mode 100644 index 00000000..4e853ed3 --- /dev/null +++ b/api-2.7/src/test/resources/testAppDataDir/configuration/conceptreferencerange/conceptreferencerange.csv @@ -0,0 +1,4 @@ +Uuid,Concept Numeric Uuid,Absolute low,Critical low,Normal low,Normal high,Critical high,Absolute high,Criteria +bc059100-4ace-4af5-afbf-2da7f3a34acf,a09ab2c5-878e-4905-b25d-5784167d0216,-100.5,-85.7,-50.3,45.1,78,98.8, $patient.getAge() > 3 +930e1fb4-490d-45fe-a137-0cd941c76124,a09ab2c5-878e-4905-b25d-5784167d0216,-100.5,-85.7,-50.3,45.1,78,98.8, $patient.getAge() < 10 +b5a7b296-e500-4a2c-ab2e-eb012ed9ae1e,a09ab2c5-878e-4905-b25d-5784167d0216,60,70,80,120,130,150, $fn.getCurrentHour() > 2 \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/initializer/Domain.java b/api/src/main/java/org/openmrs/module/initializer/Domain.java index a23d4cf9..af0af6d4 100644 --- a/api/src/main/java/org/openmrs/module/initializer/Domain.java +++ b/api/src/main/java/org/openmrs/module/initializer/Domain.java @@ -26,6 +26,7 @@ public enum Domain { OCL, CONCEPTS, CONCEPT_SETS, + CONCEPT_REFERENCE_RANGE, BILLABLE_SERVICES, PAYMENT_MODES, CASH_POINTS, diff --git a/api/src/test/java/org/openmrs/module/initializer/DomainBaseModuleContextSensitiveTest.java b/api/src/test/java/org/openmrs/module/initializer/DomainBaseModuleContextSensitiveTest.java index 58045350..c8e795ff 100644 --- a/api/src/test/java/org/openmrs/module/initializer/DomainBaseModuleContextSensitiveTest.java +++ b/api/src/test/java/org/openmrs/module/initializer/DomainBaseModuleContextSensitiveTest.java @@ -66,6 +66,21 @@ public InitializerService getService() { */ public DomainBaseModuleContextSensitiveTest() { super(); + initModules(); + { + try { + Class.forName("org.bahmni.module.bahmnicore.Activator"); + Module mod = new Module("", "bahmnicore", "", "", "", "0.94-SNAPSHOT"); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } + catch (Exception e) { + // ignore error since bahmnicore packages are not on the class path. + } + } + } + + protected void initModules() { { Module mod = new Module("", "addresshierarchy", "", "", "", "2.17.0"); mod.setFile(new File("")); @@ -136,17 +151,6 @@ public DomainBaseModuleContextSensitiveTest() { mod.setFile(new File("")); ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); } - { - try { - Class.forName("org.bahmni.module.bahmnicore.Activator"); - Module mod = new Module("", "bahmnicore", "", "", "", "0.94-SNAPSHOT"); - mod.setFile(new File("")); - ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); - } - catch (Exception e) { - // ignore error since bahmnicore packages are not on the class path. - } - } } protected String getAppDataDirPath() { diff --git a/pom.xml b/pom.xml index 6c934048..287acaf6 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,7 @@ api-2.3 api-2.4 api-2.5 + api-2.7 omod @@ -58,6 +59,7 @@ 2.3.6 2.4.5 2.5.5 + 2.7.0 ${openmrsVersion2.1}