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(); }