From afb7ce898c2c3c3fe0972f626906ee2773d32cdc Mon Sep 17 00:00:00 2001 From: mogoodrich Date: Fri, 18 Oct 2024 14:01:38 -0400 Subject: [PATCH 1/4] EA-205: Support loading dispositionConfig.json from the file system by default --- ...itingAdmissionVisitQueryEvaluatorTest.java | 1 + ...dmissionRequestVisitDataEvaluatorTest.java | 1 + .../disposition/DispositionServiceImpl.java | 70 ++++++++++++------- .../emrapi/adt/AdtServiceComponentTest.java | 2 +- .../module/emrapi/adt/AdtServiceImplTest.java | 1 + .../disposition/DispositionServiceTest.java | 1 + .../maternal/MaternalServiceImplTest.java | 1 + .../VisitDomainWrapperComponentTest.java | 1 + ...Config.json => testDispositionConfig.json} | 0 .../EmrApiConfigurationControllerTest.java | 1 + 10 files changed, 52 insertions(+), 27 deletions(-) rename api/src/test/resources/{dispositionConfig.json => testDispositionConfig.json} (100%) diff --git a/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java b/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java index 13611dbf..dcc8ddd7 100644 --- a/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java +++ b/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/AwaitingAdmissionVisitQueryEvaluatorTest.java @@ -67,6 +67,7 @@ public class AwaitingAdmissionVisitQueryEvaluatorTest extends BaseReportingTest @Before public void setup() throws Exception { executeDataSet("baseTestDataset.xml"); + dispositionService.setDispositionConfig("testDispositionConfig.json"); // use demo disposition config from test resources dispositionDescriptor = ContextSensitiveMetadataTestUtils.setupDispositionDescriptor(conceptService, dispositionService); ContextSensitiveMetadataTestUtils.setupAdmissionDecisionConcept(conceptService, emrApiProperties); query = new AwaitingAdmissionVisitQuery(); diff --git a/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluatorTest.java b/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluatorTest.java index 91f7c990..1cb1c5ce 100644 --- a/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluatorTest.java +++ b/api-reporting/src/test/java/org/openmrs/module/emrapi/adt/reporting/evaluator/MostRecentAdmissionRequestVisitDataEvaluatorTest.java @@ -67,6 +67,7 @@ public class MostRecentAdmissionRequestVisitDataEvaluatorTest extends BaseReport @Before public void setup() throws Exception { executeDataSet("baseTestDataset.xml"); + dispositionService.setDispositionConfig("testDispositionConfig.json"); // use demo disposition config from test resources def = new MostRecentAdmissionRequestVisitDataDefinition(); dispositionDescriptor = ContextSensitiveMetadataTestUtils.setupDispositionDescriptor(conceptService, dispositionService); diagnosisMetadata = ContextSensitiveMetadataTestUtils.setupDiagnosisMetadata(conceptService, emrApiProperties); diff --git a/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java b/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java index 324c22f3..618622b4 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java @@ -31,7 +31,11 @@ public class DispositionServiceImpl extends BaseOpenmrsService implements Dispos private PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); // TODO inject this in some better way than using a setter to override? - private String dispositionConfig = "dispositionConfig.json"; + private String dispositionConfig; + + private final String DEFAULT_DISPOSITION_CONFIG_LOCATION = "file:" + OpenmrsUtil.getApplicationDataDirectory() + "/configuration/dispositions/dispositionConfig.json"; + + private final String LEGACY_DEFAULT_DISPOSITION_CONFIG_LOCATION = "classpath*:/dispositionConfig.json"; // prior to 2.1.0 release public DispositionServiceImpl(ConceptService conceptService, EmrConceptService emrConceptService) { this.conceptService = conceptService; @@ -62,9 +66,47 @@ public DispositionDescriptor getDispositionDescriptor() { @Override public List getDispositions() { - return getDispositionsFrom(dispositionConfig); + + if (dispositionConfig !=null) { + try { + String path; + if (!dispositionConfig.contains("file:")) { + path = "classpath*:/" + dispositionConfig; + } else { + path = "file:" + OpenmrsUtil.getApplicationDataDirectory() + "/" + dispositionConfig.replace("file:", ""); + } + return getDispositionsFrom(path); + } catch (IOException ignored) { + // if this fails for some reason, we will try the default locations below + } + } + + // if no config file specified, try the default locations + try { + return getDispositionsFrom(DEFAULT_DISPOSITION_CONFIG_LOCATION); + } catch (IOException ignored) { + // exception will be thrown below if needed + } + + try { + return getDispositionsFrom(LEGACY_DEFAULT_DISPOSITION_CONFIG_LOCATION); + } catch (IOException ignored) { + // exception will be thrown below if needed + } + + throw new RuntimeException("No disposition file found at: " + dispositionConfig + " or " + DEFAULT_DISPOSITION_CONFIG_LOCATION + " or " + LEGACY_DEFAULT_DISPOSITION_CONFIG_LOCATION); } + private List getDispositionsFrom(String path) throws IOException { + Resource[] dispositionDefinitions = resourceResolver.getResources(path); + for (Resource dispositionDefinition : dispositionDefinitions) { + return objectMapper.readValue(dispositionDefinition.getInputStream(), new TypeReference>() { + }); + } + throw new IOException("No disposition file found at " + path); + } + + @Override @Transactional(readOnly = true) public Disposition getDispositionByUniqueId(String uniqueId) { @@ -170,30 +212,6 @@ public void setDispositionConfig(String dispositionConfig) { this.dispositionConfig = dispositionConfig; } - private List getDispositionsFrom(String configFile) { - - try { - - String path; - - if (configFile.indexOf("file:") == -1) { - path = "classpath*:/" + configFile; - } - else { - path = "file:" + OpenmrsUtil.getApplicationDataDirectory() + "/" + configFile.replace("file:",""); - } - - Resource[] dispositionDefinitions = resourceResolver.getResources(path); - for (Resource dispositionDefinition : dispositionDefinitions) { - return objectMapper.readValue(dispositionDefinition.getInputStream(), new TypeReference>() {}); - } - return null; - } - catch (IOException e) { - throw new RuntimeException ("Unable to read disposition file " + configFile, e); - } - - } // TODO handle this better--this property is only used to allow use to inject a mock disposition descriptor private DispositionDescriptor dispositionDescriptor; diff --git a/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceComponentTest.java index de808342..deefb27f 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceComponentTest.java @@ -45,7 +45,6 @@ import org.openmrs.module.emrapi.disposition.DispositionService; import org.openmrs.module.emrapi.test.ContextSensitiveMetadataTestUtils; import org.openmrs.module.emrapi.visit.VisitDomainWrapper; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; @@ -108,6 +107,7 @@ public boolean evaluate(Object o) { @Before public void setUp() throws Exception { executeDataSet("baseTestDataset.xml"); + dispositionService.setDispositionConfig("testDispositionConfig.json"); // use demo disposition config from test resources } @Test diff --git a/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceImplTest.java b/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceImplTest.java index b0944a4e..f96f4449 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/adt/AdtServiceImplTest.java @@ -72,6 +72,7 @@ public class AdtServiceImplTest extends EmrApiContextSensitiveTest { @Before public void setup() throws Exception { executeDataSet("baseTestDataset.xml"); + dispositionService.setDispositionConfig("testDispositionConfig.json"); // use demo disposition config from test resources dispositionDescriptor = ContextSensitiveMetadataTestUtils.setupDispositionDescriptor(conceptService, dispositionService); ContextSensitiveMetadataTestUtils.setupAdmissionDecisionConcept(conceptService, emrApiProperties); visitLocation = testDataManager.location().name("Hospital").tag("Visit Location").save(); diff --git a/api/src/test/java/org/openmrs/module/emrapi/disposition/DispositionServiceTest.java b/api/src/test/java/org/openmrs/module/emrapi/disposition/DispositionServiceTest.java index 4c7fa1b4..ccc103db 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/disposition/DispositionServiceTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/disposition/DispositionServiceTest.java @@ -56,6 +56,7 @@ public void setUp(){ dispositionService = new DispositionServiceImpl(concertService, emrConceptService); dispositionService.setDispositionDescriptor(dispositionDescriptor); + dispositionService.setDispositionConfig("testDispositionConfig.json"); // use demo disposition config from test resources } @Test diff --git a/api/src/test/java/org/openmrs/module/emrapi/maternal/MaternalServiceImplTest.java b/api/src/test/java/org/openmrs/module/emrapi/maternal/MaternalServiceImplTest.java index 81a6f5e3..01bcec40 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/maternal/MaternalServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/maternal/MaternalServiceImplTest.java @@ -61,6 +61,7 @@ public class MaternalServiceImplTest extends EmrApiContextSensitiveTest { @Before public void setUp() { executeDataSet("baseTestDataset.xml"); + dispositionService.setDispositionConfig("testDispositionConfig.json"); // use demo disposition config from test resources ContextSensitiveMetadataTestUtils.setupDispositionDescriptor(conceptService, dispositionService); ContextSensitiveMetadataTestUtils.setupAdmissionDecisionConcept(conceptService, emrApiProperties); } diff --git a/api/src/test/java/org/openmrs/module/emrapi/visit/VisitDomainWrapperComponentTest.java b/api/src/test/java/org/openmrs/module/emrapi/visit/VisitDomainWrapperComponentTest.java index f11d3ace..c50e2367 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/visit/VisitDomainWrapperComponentTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/visit/VisitDomainWrapperComponentTest.java @@ -71,6 +71,7 @@ public class VisitDomainWrapperComponentTest extends EmrApiContextSensitiveTest @Before public void setup() throws Exception { executeDataSet("baseTestDataset.xml"); + dispositionService.setDispositionConfig("testDispositionConfig.json"); // use demo disposition config from test resources dispositionDescriptor = ContextSensitiveMetadataTestUtils.setupDispositionDescriptor(conceptService, dispositionService); ContextSensitiveMetadataTestUtils.setupAdmissionDecisionConcept(conceptService, emrApiProperties); ContextSensitiveMetadataTestUtils.setupDiagnosisMetadata(conceptService, emrApiProperties); diff --git a/api/src/test/resources/dispositionConfig.json b/api/src/test/resources/testDispositionConfig.json similarity index 100% rename from api/src/test/resources/dispositionConfig.json rename to api/src/test/resources/testDispositionConfig.json diff --git a/omod/src/test/java/org/openmrs/module/emrapi/web/controller/EmrApiConfigurationControllerTest.java b/omod/src/test/java/org/openmrs/module/emrapi/web/controller/EmrApiConfigurationControllerTest.java index c357dfe1..f6a2eceb 100644 --- a/omod/src/test/java/org/openmrs/module/emrapi/web/controller/EmrApiConfigurationControllerTest.java +++ b/omod/src/test/java/org/openmrs/module/emrapi/web/controller/EmrApiConfigurationControllerTest.java @@ -51,6 +51,7 @@ public class EmrApiConfigurationControllerTest extends BaseModuleWebContextSensi @Before public void setUp() { executeDataSet("baseTestDataset.xml"); + dispositionService.setDispositionConfig("testDispositionConfig.json"); // use demo disposition config from test resources request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); } From 044d370038abb10e9638d9dce698276053cec56a Mon Sep 17 00:00:00 2001 From: mogoodrich Date: Thu, 24 Oct 2024 16:45:02 -0400 Subject: [PATCH 2/4] EA-205: Support loading dispositionConfig.json from the file system by default --- .../disposition/DispositionServiceImpl.java | 75 ++++++++----------- 1 file changed, 30 insertions(+), 45 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java b/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java index 618622b4..50520d05 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java @@ -30,12 +30,8 @@ public class DispositionServiceImpl extends BaseOpenmrsService implements Dispos private PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); - // TODO inject this in some better way than using a setter to override? - private String dispositionConfig; - - private final String DEFAULT_DISPOSITION_CONFIG_LOCATION = "file:" + OpenmrsUtil.getApplicationDataDirectory() + "/configuration/dispositions/dispositionConfig.json"; - - private final String LEGACY_DEFAULT_DISPOSITION_CONFIG_LOCATION = "classpath*:/dispositionConfig.json"; // prior to 2.1.0 release + // can also be overwritten by Iniz + private String dispositionConfig = "dispositionConfig.json"; public DispositionServiceImpl(ConceptService conceptService, EmrConceptService emrConceptService) { this.conceptService = conceptService; @@ -66,47 +62,9 @@ public DispositionDescriptor getDispositionDescriptor() { @Override public List getDispositions() { - - if (dispositionConfig !=null) { - try { - String path; - if (!dispositionConfig.contains("file:")) { - path = "classpath*:/" + dispositionConfig; - } else { - path = "file:" + OpenmrsUtil.getApplicationDataDirectory() + "/" + dispositionConfig.replace("file:", ""); - } - return getDispositionsFrom(path); - } catch (IOException ignored) { - // if this fails for some reason, we will try the default locations below - } - } - - // if no config file specified, try the default locations - try { - return getDispositionsFrom(DEFAULT_DISPOSITION_CONFIG_LOCATION); - } catch (IOException ignored) { - // exception will be thrown below if needed - } - - try { - return getDispositionsFrom(LEGACY_DEFAULT_DISPOSITION_CONFIG_LOCATION); - } catch (IOException ignored) { - // exception will be thrown below if needed - } - - throw new RuntimeException("No disposition file found at: " + dispositionConfig + " or " + DEFAULT_DISPOSITION_CONFIG_LOCATION + " or " + LEGACY_DEFAULT_DISPOSITION_CONFIG_LOCATION); - } - - private List getDispositionsFrom(String path) throws IOException { - Resource[] dispositionDefinitions = resourceResolver.getResources(path); - for (Resource dispositionDefinition : dispositionDefinitions) { - return objectMapper.readValue(dispositionDefinition.getInputStream(), new TypeReference>() { - }); - } - throw new IOException("No disposition file found at " + path); + return getDispositionsFrom(dispositionConfig); } - @Override @Transactional(readOnly = true) public Disposition getDispositionByUniqueId(String uniqueId) { @@ -212,6 +170,33 @@ public void setDispositionConfig(String dispositionConfig) { this.dispositionConfig = dispositionConfig; } + private List getDispositionsFrom(String configFile) { + + try { + + String path; + + if (!configFile.startsWith("file:")) { // this is a classpath resource + path = "classpath*:/" + configFile; + } + else if (!configFile.startsWith("file:/")) { // this is a non-absolute file reference, so we need to prepend the application data directory + path = "file:" + OpenmrsUtil.getApplicationDataDirectory() + "/" + configFile.replace("file:",""); + } + else { // this is an absolute file reference + path = configFile; + } + + Resource[] dispositionDefinitions = resourceResolver.getResources(path); + for (Resource dispositionDefinition : dispositionDefinitions) { + return objectMapper.readValue(dispositionDefinition.getInputStream(), new TypeReference>() {}); + } + return null; + } + catch (IOException e) { + throw new RuntimeException ("Unable to read disposition file " + configFile, e); + } + + } // TODO handle this better--this property is only used to allow use to inject a mock disposition descriptor private DispositionDescriptor dispositionDescriptor; From 96391d73a74cc65189d8a662073b6bdbb09a46d9 Mon Sep 17 00:00:00 2001 From: mogoodrich Date: Fri, 25 Oct 2024 09:49:33 -0400 Subject: [PATCH 3/4] (chore) move location of test disposition file to give explicit test name --- .../module/emrapi/disposition/DispositionServiceImpl.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java b/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java index 50520d05..3940bb75 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java @@ -176,15 +176,12 @@ private List getDispositionsFrom(String configFile) { String path; - if (!configFile.startsWith("file:")) { // this is a classpath resource + if (configFile.indexOf("file:") == -1) { path = "classpath*:/" + configFile; } - else if (!configFile.startsWith("file:/")) { // this is a non-absolute file reference, so we need to prepend the application data directory + else { path = "file:" + OpenmrsUtil.getApplicationDataDirectory() + "/" + configFile.replace("file:",""); } - else { // this is an absolute file reference - path = configFile; - } Resource[] dispositionDefinitions = resourceResolver.getResources(path); for (Resource dispositionDefinition : dispositionDefinitions) { From 17ef6d727309770e2bd5ecb2327a9f9ca9e0a9a9 Mon Sep 17 00:00:00 2001 From: mogoodrich Date: Fri, 25 Oct 2024 09:52:47 -0400 Subject: [PATCH 4/4] (chore) move location of test disposition file to give explicit test name --- .../module/emrapi/disposition/DispositionServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java b/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java index 3940bb75..ac4ebb30 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/emrapi/disposition/DispositionServiceImpl.java @@ -30,7 +30,7 @@ public class DispositionServiceImpl extends BaseOpenmrsService implements Dispos private PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(); - // can also be overwritten by Iniz + // can be overridden by Initializer starting with Iniz version 2.8.0 private String dispositionConfig = "dispositionConfig.json"; public DispositionServiceImpl(ConceptService conceptService, EmrConceptService emrConceptService) {