Skip to content

Commit f9bc701

Browse files
committed
filter out demo data
1 parent ccda8a0 commit f9bc701

File tree

4 files changed

+55
-12
lines changed

4 files changed

+55
-12
lines changed

api/src/main/java/org/openmrs/module/labonfhir/LabOnFhirConfig.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ public class LabOnFhirConfig implements ApplicationContextAware {
4141

4242
public static final String GP_KEYSTORE_PATH = "labonfhir.keystorePath";
4343

44-
public static final String GP_KEYSTORE_PASS = "labonfhir.keystorepass";
44+
public static final String GP_KEYSTORE_PASSWORD = "labonfhir.keystorepassword";
4545

4646
public static final String GP_TRUSTSTORE_PATH = "labonfhir.truststorePath";
4747

48-
public static final String GP_TRUSTSTORE_PASS = "labonfhir.truststorepass";
48+
public static final String GP_TRUSTSTORE_PASSWORD = "labonfhir.truststorepassword";
4949

5050
public static final String GP_ACTIVATE_FHIR_PUSH = "labonfhir.activateFhirPush";
5151

5252
private static final String TEMP_DEFAULT_LIS_URL = "https://testapi.openelisci.org:8444/hapi-fhir-jpaserver/fhir";
5353

5454
public static final String GP_AUTH_TYPE = "labonfhir.authType";
5555

56-
public static final String GP_USER_NAME = "labonfhir.userName";
56+
public static final String GP_USER_NAME = "labonfhir.username";
5757

5858
public static final String GP_PASSWORD = "labonfhir.password";
5959

@@ -69,6 +69,10 @@ public class LabOnFhirConfig implements ApplicationContextAware {
6969

7070
public static final String GP_FILTER_ORDER_BY_TEST_UUIDS = "labonfhir.filterOrderBytestUuids";
7171

72+
public static final String GP_FILTER_DEMO_DATA = "labonfhir.filterDemoData";
73+
74+
public static final String DEMO_PATIENT_ATTR = "demo_patient";
75+
7276
public enum AuthType {
7377
SSL,
7478
BASIC
@@ -94,9 +98,9 @@ public SSLContext sslContext() throws Exception {
9498
try {
9599
if (administrationService.getGlobalProperty(GP_KEYSTORE_PATH) != null
96100
&& !administrationService.getGlobalProperty(GP_KEYSTORE_PATH).isEmpty()) {
97-
String keyPassword = ConfigUtil.getProperty(GP_KEYSTORE_PASS);
101+
String keyPassword = ConfigUtil.getProperty(GP_KEYSTORE_PASSWORD);
98102
File truststoreFile = new File(administrationService.getGlobalProperty(GP_TRUSTSTORE_PATH));
99-
String truststorePassword = ConfigUtil.getProperty(GP_TRUSTSTORE_PASS);
103+
String truststorePassword = ConfigUtil.getProperty(GP_TRUSTSTORE_PASSWORD);
100104

101105
KeyStore keystore = loadKeystore(administrationService.getGlobalProperty(GP_KEYSTORE_PATH));
102106

@@ -132,7 +136,7 @@ public String getLisUserUuid() {
132136
}
133137

134138
public String getLisUserName() {
135-
return administrationService.getGlobalProperty(GP_USER_NAME);
139+
return ConfigUtil.getProperty(GP_USER_NAME);
136140
}
137141

138142
public String getLisPassword() {
@@ -158,7 +162,7 @@ public String getLabUpdateTriggerObject() {
158162
}
159163

160164
public Boolean filterOrderByTestUuuids() {
161-
String filterOrders = administrationService.getGlobalProperty(GP_FILTER_ORDER_BY_TEST_UUIDS, "true");
165+
String filterOrders = administrationService.getGlobalProperty(GP_FILTER_ORDER_BY_TEST_UUIDS, "false");
162166
return Boolean.valueOf(filterOrders);
163167
}
164168

@@ -167,6 +171,11 @@ public Boolean addObsAsTaskInput() {
167171
return Boolean.valueOf(addObsAsTaskInPut);
168172
}
169173

174+
public Boolean filterDemoData() {
175+
String filterDemoData = administrationService.getGlobalProperty(GP_FILTER_DEMO_DATA, "true");
176+
return Boolean.valueOf(filterDemoData);
177+
}
178+
170179
public AuthType getAuthType() {
171180
String authTypeGp = administrationService.getGlobalProperty(GP_AUTH_TYPE);
172181
switch (authTypeGp.toUpperCase()) {
@@ -196,7 +205,7 @@ private KeyStore loadKeystore(String filePath) {
196205
is = new FileInputStream(file);
197206
keystore = KeyStore.getInstance(KeyStore.getDefaultType());
198207

199-
String password = ConfigUtil.getProperty(GP_KEYSTORE_PASS);
208+
String password = ConfigUtil.getProperty(GP_KEYSTORE_PASSWORD);
200209

201210
keystore.load(is, password.toCharArray());
202211

api/src/main/java/org/openmrs/module/labonfhir/api/LabOrderHandler.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.openmrs.EncounterProvider;
2121
import org.openmrs.Obs;
2222
import org.openmrs.Order;
23+
import org.openmrs.PersonAttribute;
2324
import org.openmrs.api.db.DAOException;
2425
import org.openmrs.module.fhir2.FhirConstants;
2526
import org.openmrs.module.fhir2.api.FhirObservationService;
@@ -57,6 +58,12 @@ public class LabOrderHandler {
5758
private FhirContext fhirContext;
5859

5960
public Task createOrder(Order order) throws OrderCreationException {
61+
PersonAttribute demoAttr = order.getPatient().getAttribute(LabOnFhirConfig.DEMO_PATIENT_ATTR);
62+
if (config.filterDemoData() && Boolean.valueOf(demoAttr != null ? demoAttr.getValue() : "false")) {
63+
log.info("Skiping Demo Order : " + order.getUuid() + " for Patient " + order.getPatient().getUuid());
64+
return null;
65+
}
66+
6067
//TDO: MAKE THIS A GLOBAL CONFIG
6168
final String REQUIRED_TESTS_UUIDS = config.getOrderTestUuids(); // GeneXpert
6269
// Exit if Test Order doesn't contain required tests
@@ -168,6 +175,11 @@ public Task createOrder(Encounter encounter) throws OrderCreationException {
168175
if (encounter.getOrders().isEmpty()) {
169176
return null;
170177
}
178+
PersonAttribute demoAttr = encounter.getPatient().getAttribute(LabOnFhirConfig.DEMO_PATIENT_ATTR);
179+
if (config.filterDemoData() && Boolean.valueOf(demoAttr != null ? demoAttr.getValue() : "false")) {
180+
log.info("Skiping Demo Encounter : " + encounter.getUuid() + " for Patient " + encounter.getPatient().getUuid());
181+
return null;
182+
}
171183
// Create References
172184
List<Reference> basedOnRefs = encounter.getOrders().stream().map(order -> {
173185
AtomicReference<Order> orders = new AtomicReference<>();

api/src/main/java/org/openmrs/module/labonfhir/api/scheduler/RetryFailedTasks.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
import org.apache.commons.logging.LogFactory;
77
import org.hl7.fhir.r4.model.Bundle;
88
import org.hl7.fhir.r4.model.Task;
9+
import org.openmrs.PersonAttribute;
10+
import org.openmrs.api.PatientService;
911
import org.openmrs.module.fhir2.api.FhirTaskService;
1012
import org.openmrs.module.labonfhir.FhirConfig;
13+
import org.openmrs.module.labonfhir.LabOnFhirConfig;
1114
import org.openmrs.module.labonfhir.api.event.OrderCreationListener;
1215
import org.openmrs.module.labonfhir.api.model.FailedTask;
1316
import org.openmrs.module.labonfhir.api.service.LabOnFhirService;
@@ -32,12 +35,18 @@ public class RetryFailedTasks extends AbstractTask implements ApplicationContext
3235
@Qualifier("labOrderFhirConfig")
3336
private FhirConfig fhirConfig;
3437

38+
@Autowired
39+
private LabOnFhirConfig config;
40+
3541
@Autowired
3642
private FhirTaskService fhirTaskService;
3743

3844
@Autowired
3945
private LabOnFhirService labOnFhirService;
4046

47+
@Autowired
48+
private PatientService patientService;
49+
4150
@Autowired
4251
@Qualifier("labOrderListener")
4352
private OrderCreationListener orderCreationListener;
@@ -70,12 +79,19 @@ private void retrySendingFailedTasks() {
7079
if (task == null) {
7180
return;
7281
}
82+
PersonAttribute demoAttr = patientService.getPatientByUuid(task.getFor().getReferenceElement().getIdPart())
83+
.getAttribute(LabOnFhirConfig.DEMO_PATIENT_ATTR);
84+
if (config.filterDemoData() && Boolean.valueOf(demoAttr != null ? demoAttr.getValue() : "false")) {
85+
log.info("Skiping Demo Task : " + failedTask.getTaskUuid() + " for Patient "
86+
+ task.getFor().getReferenceElement().getIdPart());
87+
return;
88+
}
7389
try {
7490
Bundle labBundle = orderCreationListener.createLabBundle(task);
7591
fhirConfig.getFhirClient().transaction().withBundle(labBundle).execute();
7692
failedTask.setIsSent(true);
7793
labOnFhirService.saveOrUpdateFailedTask(failedTask);
78-
log.info("Resent Failed task:" + failedTask.getTaskUuid());
94+
log.info("Resent Failed task : " + failedTask.getTaskUuid());
7995
log.debug(ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(labBundle));
8096
}
8197
catch (Exception e) {

omod/src/main/resources/config.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<defaultValue> </defaultValue>
6868
</globalProperty>
6969
<globalProperty>
70-
<property>@MODULE_ID@.keystorepass</property>
70+
<property>@MODULE_ID@.keystorepassword</property>
7171
<description>Keystore password</description>
7272
<defaultValue> </defaultValue>
7373
</globalProperty>
@@ -77,7 +77,7 @@
7777
<defaultValue> </defaultValue>
7878
</globalProperty>
7979
<globalProperty>
80-
<property>@MODULE_ID@.truststorepass</property>
80+
<property>@MODULE_ID@.truststorepassword</property>
8181
<description>Truststore password</description>
8282
<defaultValue> </defaultValue>
8383
</globalProperty>
@@ -92,7 +92,7 @@
9292
<defaultValue>Basic</defaultValue>
9393
</globalProperty>
9494
<globalProperty>
95-
<property>@MODULE_ID@.userName</property>
95+
<property>@MODULE_ID@.username</property>
9696
<description>User name for HTTP Basic Auth with the LIS</description>
9797
<defaultValue>user</defaultValue>
9898
</globalProperty>
@@ -136,4 +136,10 @@
136136
<description>Allows filtering Oders by Test Uuuids</description>
137137
<defaultValue>false</defaultValue>
138138
</globalProperty>
139+
140+
<globalProperty>
141+
<property>@MODULE_ID@.filterDemoData</property>
142+
<description>Allows filtering filter Demo Data generated by the Demo Data module</description>
143+
<defaultValue>true</defaultValue>
144+
</globalProperty>
139145
</module>

0 commit comments

Comments
 (0)