-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
714ca3e
commit 26222b4
Showing
11 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
api/src/main/java/org/openmrs/module/initializer/api/loaders/DispositionsLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
api/src/test/java/org/openmrs/module/initializer/api/DispositionsLoaderIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
api/src/test/resources/testAppDataDir/configuration/dispositions/dispositionConfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" : [ ] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters