Skip to content

Commit

Permalink
[#284] - Support "dispositions" domain (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
mogoodrich authored Oct 30, 2024
1 parent 714ca3e commit 26222b4
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ configuration/
├── concepts/
├── conceptsets/
├── datafiltermappings/
├── dispositions/
├── drugs/
├── encountertypes/
├── encounterroles/
Expand Down Expand Up @@ -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 file)](readme/dispositions.md)

## Try it out
Build the master branch and install the built OMOD to your OpenMRS instance:
Expand Down
3 changes: 2 additions & 1 deletion api/src/main/java/org/openmrs/module/initializer/Domain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.openmrs.module.initializer.api;

import java.io.InputStream;
import java.nio.file.Path;
import java.util.List;

import org.openmrs.Concept;
Expand All @@ -20,6 +21,11 @@

public interface InitializerService extends OpenmrsService {

/**
* @return A Path object representing the base path of the application data directory
*/
Path getBasePath();

/**
* @return The path to the configuration folder (with NO trailing forward slash), eg.
* "/opt/openmrs/configuration"
Expand Down
Original file line number Diff line number Diff line change
@@ -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.0.0-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:" + iniz.getBasePath().relativize(file.toPath()));
}

@Override
public ConfigDirUtil getDirUtil() {
// skip checksums, this needs to be processed every time
return new ConfigDirUtil(iniz.getConfigDirPath(), iniz.getChecksumsDirPath(), getDomainName(), true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public DomainBaseModuleContextSensitiveTest() {
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);
}
{
try {
Class.forName("org.bahmni.module.bahmnicore.Activator");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.openmrs.module.initializer.api;

import org.apache.commons.io.FileUtils;
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 java.io.File;

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

@Test
public void load_shouldReloadOnMultipleLoads() {
loader.load();
// sanity check
assertEquals(5, dispositionService.getDispositions().size());

dispositionService.setDispositionConfig(null);
loader.load();
assertEquals(5, dispositionService.getDispositions().size());
}

@Test(expected = RuntimeException.class)
public void load_shouldThrowExceptionInUnsafeModeIfMultipleFiles() throws Exception {
String existingFilePath = loader.getDirUtil().getDomainDirPath() + "/dispositionConfig.json";
String additionalFilePath = loader.getDirUtil().getDomainDirPath() + "/additionalDispositionConfig.json";
File srcFile = new File(existingFilePath);
File dstFile = new File(additionalFilePath);
FileUtils.copyFile(srcFile, dstFile);

try {
loader.loadUnsafe(null, true);
}
finally {
FileUtils.deleteQuietly(dstFile);
}
}
}
Original file line number Diff line number Diff line change
@@ -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" : [ ]
}
]
3 changes: 3 additions & 0 deletions omod/src/main/resources/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<aware_of_module version="${cohortModuleVersion}">
org.openmrs.module.cohort
</aware_of_module>
<aware_of_module version="${emrapiModuleVersion}">
org.openmrs.module.emrapi
</aware_of_module>
<aware_of_module version="${fhir2Version}">
org.openmrs.module.fhir2
</aware_of_module>
Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<bahmniIeAppsVersion>1.1.0</bahmniIeAppsVersion>
<bahmniCoreVersion>0.93-1.1.0</bahmniCoreVersion>
<cohortModuleVersion>3.5.0</cohortModuleVersion>
<emrapiModuleVersion>2.0.0</emrapiModuleVersion>
<htmlformentryVersion>4.0.0</htmlformentryVersion>
<idgenVersion>4.6.0</idgenVersion>
<metadatasharingVersion>1.2.2</metadatasharingVersion>
Expand Down Expand Up @@ -181,6 +182,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>emrapi-api</artifactId>
<version>${emrapiModuleVersion}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>exti18n-api</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions readme/dispositions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Domain 'dispositions'
**Dispositions** subfolder contains a single JSON that defines the dispositions available in the system::

```bash
dispositions/
├──dispositions.json
```

#### Requirements
* The [emr-api](https://github.com/openmrs/openmrs-module-emrapi) version 2.0.0 or higher must 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).
8 changes: 8 additions & 0 deletions validator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,14 @@
<type>jar</type>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>emrapi-api</artifactId>
<version>${emrapiModuleVersion}</version>
<scope>runtime</scope>
<type>jar</type>
</dependency>

</dependencies>

<build>
Expand Down

0 comments on commit 26222b4

Please sign in to comment.