Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EA-205: Support loading dispositionConfig.json from the file system b… #248

Merged
merged 5 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
mseaton marked this conversation as resolved.
Show resolved Hide resolved
dispositionDescriptor = ContextSensitiveMetadataTestUtils.setupDispositionDescriptor(conceptService, dispositionService);
ContextSensitiveMetadataTestUtils.setupAdmissionDecisionConcept(conceptService, emrApiProperties);
query = new AwaitingAdmissionVisitQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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?
// can also be overwritten by Iniz
private String dispositionConfig = "dispositionConfig.json";

public DispositionServiceImpl(ConceptService conceptService, EmrConceptService emrConceptService) {
Expand Down Expand Up @@ -176,12 +176,15 @@ private List<Disposition> getDispositionsFrom(String configFile) {

String path;

if (configFile.indexOf("file:") == -1) {
if (!configFile.startsWith("file:")) { // this is a classpath resource
path = "classpath*:/" + configFile;
}
else {
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;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only remaining change... Iniz is going to load via an absolute path, so EMR-API needs to be smart ignore to recognize this and not prepend the application data directory path.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may not actually want or need this anymore, given feedback on the Iniz ticket, right @mogoodrich ? I think it's a matter of whether or not we think it is a good idea to support absolute paths or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, your point on the other PR about the dangers of supporting absolute path makes sense, duh on my part. This can likely go away


Resource[] dispositionDefinitions = resourceResolver.getResources(path);
for (Resource dispositionDefinition : dispositionDefinitions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down