From bd1c216c21d6e56b4b068d013dd7f817d6463672 Mon Sep 17 00:00:00 2001 From: mogoodrich Date: Thu, 24 Oct 2024 16:56:53 -0400 Subject: [PATCH] [#284] - Support "dispositions" domain --- README.md | 2 + .../openmrs/module/initializer/Domain.java | 3 +- .../api/loaders/DispositionsLoader.java | 50 ++++++++++++++++++ .../DomainBaseModuleContextSensitiveTest.java | 5 ++ .../DispositionsLoaderIntegrationTest.java | 28 ++++++++++ .../dispositions/dispositionConfig.json | 51 +++++++++++++++++++ omod/src/main/resources/config.xml | 3 ++ pom.xml | 8 +++ readme/dispositions.md | 14 +++++ 9 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 api/src/main/java/org/openmrs/module/initializer/api/loaders/DispositionsLoader.java create mode 100644 api/src/test/java/org/openmrs/module/initializer/api/DispositionsLoaderIntegrationTest.java create mode 100644 api/src/test/resources/testAppDataDir/configuration/dispositions/dispositionConfig.json create mode 100644 readme/dispositions.md diff --git a/README.md b/README.md index 48dc13f6..b7cbe40e 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ configuration/ ├── concepts/ ├── conceptsets/ ├── datafiltermappings/ + ├── dispositions/ ├── drugs/ ├── encountertypes/ ├── encounterroles/ @@ -159,6 +160,7 @@ This is the list of currently supported domains in their loading order: 1. [AMPATH Forms (JSON files)](readme/ampathforms.md) 1. [AMPATH Forms Translations (JSON files)](readme/ampathformstranslations.md) 1. [HTML Forms (XML files)](readme/htmlforms.md) +1. [Disposition Config (json files)](readme/dispositions.md) ## Try it out Build the master branch and install the built OMOD to your OpenMRS instance: 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 10eb67ad..a23d4cf9 100644 --- a/api/src/main/java/org/openmrs/module/initializer/Domain.java +++ b/api/src/main/java/org/openmrs/module/initializer/Domain.java @@ -52,7 +52,8 @@ public enum Domain { FHIR_PATIENT_IDENTIFIER_SYSTEMS, AMPATH_FORMS, AMPATH_FORMS_TRANSLATIONS, - HTML_FORMS; + HTML_FORMS, + DISPOSITIONS; public int getOrder() { return ArrayUtils.indexOf(values(), this) + 1; diff --git a/api/src/main/java/org/openmrs/module/initializer/api/loaders/DispositionsLoader.java b/api/src/main/java/org/openmrs/module/initializer/api/loaders/DispositionsLoader.java new file mode 100644 index 00000000..b00be4fa --- /dev/null +++ b/api/src/main/java/org/openmrs/module/initializer/api/loaders/DispositionsLoader.java @@ -0,0 +1,50 @@ +package org.openmrs.module.initializer.api.loaders; + +import org.openmrs.annotation.OpenmrsProfile; +import org.openmrs.module.emrapi.disposition.DispositionService; +import org.openmrs.module.initializer.Domain; +import org.openmrs.module.initializer.api.ConfigDirUtil; +import org.springframework.beans.factory.annotation.Autowired; + +import java.io.File; + +@OpenmrsProfile(modules = { "emrapi:2.1.0-SNAPSHOT-9.*" }) +public class DispositionsLoader extends BaseFileLoader { + + @Autowired + private DispositionService dispositionService; + + private boolean fileFound = false; + + @Override + protected Domain getDomain() { + return Domain.DISPOSITIONS; + } + + @Override + protected String getFileExtension() { + return "json"; + } + + @Override + public void load() { + fileFound = false; + super.load(); + } + + @Override + protected void load(File file) throws Exception { + if (fileFound) { + throw new IllegalArgumentException( + "Multiple disposition files found in the disposition configuration directory."); + } + fileFound = true; + dispositionService.setDispositionConfig("file:" + file.getAbsolutePath()); + } + + @Override + public ConfigDirUtil getDirUtil() { + // skip checksums, this needs to be processed every time + return new ConfigDirUtil(iniz.getConfigDirPath(), iniz.getChecksumsDirPath(), getDomainName(), true); + } +} 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 12fb5806..2b6083c1 100644 --- a/api/src/test/java/org/openmrs/module/initializer/DomainBaseModuleContextSensitiveTest.java +++ b/api/src/test/java/org/openmrs/module/initializer/DomainBaseModuleContextSensitiveTest.java @@ -131,6 +131,11 @@ public DomainBaseModuleContextSensitiveTest() { mod.setFile(new File("")); ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); } + { + Module mod = new Module("", "emrapi", "", "", "", "2.1.0-SNAPSHOT"); + mod.setFile(new File("")); + ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod); + } { try { Class.forName("org.bahmni.module.bahmnicore.Activator"); diff --git a/api/src/test/java/org/openmrs/module/initializer/api/DispositionsLoaderIntegrationTest.java b/api/src/test/java/org/openmrs/module/initializer/api/DispositionsLoaderIntegrationTest.java new file mode 100644 index 00000000..a5a5a900 --- /dev/null +++ b/api/src/test/java/org/openmrs/module/initializer/api/DispositionsLoaderIntegrationTest.java @@ -0,0 +1,28 @@ +package org.openmrs.module.initializer.api; + +import org.junit.Test; +import org.openmrs.module.emrapi.disposition.DispositionService; +import org.openmrs.module.initializer.DomainBaseModuleContextSensitiveTest; +import org.openmrs.module.initializer.api.loaders.DispositionsLoader; +import org.springframework.beans.factory.annotation.Autowired; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DispositionsLoaderIntegrationTest extends DomainBaseModuleContextSensitiveTest { + + @Autowired + protected InitializerService iniz; + + @Autowired + private DispositionsLoader loader; + + @Autowired + private DispositionService dispositionService; + + @Test + public void load_shouldLoadDisposition() { + loader.load(); + assertEquals(5, dispositionService.getDispositions().size()); + } + +} diff --git a/api/src/test/resources/testAppDataDir/configuration/dispositions/dispositionConfig.json b/api/src/test/resources/testAppDataDir/configuration/dispositions/dispositionConfig.json new file mode 100644 index 00000000..b5db594e --- /dev/null +++ b/api/src/test/resources/testAppDataDir/configuration/dispositions/dispositionConfig.json @@ -0,0 +1,51 @@ +[ + { + "uuid" : "d2d89630-b698-11e2-9e96-0800200c9a66", + "name" : "disposition.death", + "conceptCode" : "org.openmrs.module.emrapi:Death", + "actions" : [ + "closeCurrentVisitAction", + "markPatientDeadAction" + ], + "additionalObs" : [ + { + "label" : "emr.dateOfDeath", + "conceptCode" : "org.openmrs.module.emrapi:Date of death" + } + ] + }, + { + "uuid" : "66de7f60-b73a-11e2-9e96-0800200c9a66", + "name" : "disposition.admit", + "type" : "ADMIT", + "conceptCode" : "org.openmrs.module.emrapi:Admit to hospital", + "actions" : [ ], + "additionalObs" : [ ] + }, + { + "uuid" : "8297651b-4046-11ef-ba6a-0242ac120002", + "name" : "disposition.transfer", + "type" : "TRANSFER", + "conceptCode" : "org.openmrs.module.emrapi:Transfer out of hospital", + "actions" : [ ], + "additionalObs" : [ ] + }, + { + "uuid" : "687d966bb-9c91-4886-b8b0-e63361f495f0", + "name" : "disposition.observation", + "conceptCode" : "org.openmrs.module.emrapi:ED Observation", + "keepsVisitOpen" : "true", + "actions" : [ ], + "additionalObs" : [ ] + }, + { + "uuid" : "12129630-b698-11e2-9e96-0800200c9a66", + "name" : "disposition.discharge", + "type" : "DISCHARGE", + "conceptCode" : "org.openmrs.module.emrapi:Discharged", + "actions" : [ + "closeCurrentVisitAction" + ], + "additionalObs" : [ ] + } +] \ No newline at end of file diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index d75489a8..8467e6a8 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -57,6 +57,9 @@ org.openmrs.module.cohort + + org.openmrs.module.emrapi + org.openmrs.module.fhir2 diff --git a/pom.xml b/pom.xml index f827fc5e..93dc74ae 100644 --- a/pom.xml +++ b/pom.xml @@ -66,6 +66,7 @@ 1.1.0 0.93-1.1.0 3.5.0 + 2.1.0-SNAPSHOT 4.0.0 4.6.0 1.2.2 @@ -181,6 +182,13 @@ provided + + org.openmrs.module + emrapi-api + ${emrapiModuleVersion} + provided + + org.openmrs.module exti18n-api diff --git a/readme/dispositions.md b/readme/dispositions.md new file mode 100644 index 00000000..06e49cb3 --- /dev/null +++ b/readme/dispositions.md @@ -0,0 +1,14 @@ +## Domain 'dispositions' +**Dispositions** subfolder contains a single JSON that defines the dispositions available in the system:: + +```bash +cashpoints/ + ├──dispositions.json +``` + +#### Requirements +* The [emr-api](https://github.com/openmrs/openmrs-module-emrapi) version 2.1.0 or higher must be installed +* The OpenMRS version must be 2.2.1 or higher most be installed + +#### Further examples: +Please look at the test configuration folder for dispositions file, see [here](../api/src/test/resources/testAppDataDir/configuration/dispositions/dispositionConfig.json). \ No newline at end of file