Skip to content

Commit 5aa4a83

Browse files
author
Maimoona Kausar
committed
MK: Drug Order doesnot return Object for 1.12.x; Bugs fix to get details from arguments instead.
1 parent 5a9db9e commit 5aa4a83

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

openmrs-atomfeed-api/src/main/java/org/openmrs/module/atomfeed/advice/DrugOrderAdvice.java

+38-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.ict4h.atomfeed.server.service.EventServiceImpl;
2222
import org.ict4h.atomfeed.transaction.AFTransactionWorkWithoutResult;
2323
import org.joda.time.DateTime;
24+
import org.openmrs.DrugOrder;
2425
import org.openmrs.Order;
2526
import org.openmrs.User;
2627
import org.openmrs.api.context.Context;
@@ -52,7 +53,13 @@ public DrugOrderAdvice() throws SQLException {
5253
}
5354

5455
@Override
55-
public void afterReturning(Object returnValue, Method method, Object[] arguments, Object target) throws Throwable {
56+
public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
57+
Order o = args.length>0&&args[0] instanceof Order?(Order)args[0]:null;
58+
59+
if(isDrugOrder == false){// checking for drug order again; it doesnot get populated earlier
60+
isDrugOrder = isDrugOrder(o);
61+
}
62+
5663
if (method.getName().equals(SAVE_METHOD) && isDrugOrder) {
5764
logDebug("In method SAVE_DRUG_ORDER for atomfeed with isNewEntry="+isNewEntry);
5865

@@ -66,26 +73,48 @@ public void afterReturning(Object returnValue, Method method, Object[] arguments
6673

6774
if (isNewEntry == null) {
6875
logWarn("DRUG_ORDER: Can not determine the transaction type. Data syncer Service should handle Save and Update on its own");
69-
process((Order) returnValue, "Order", formatDataEntrySource(u));
76+
process(o, "Order", formatDataEntrySource(u));
7077
}
7178
// if new entry and not sent from SRP i.e. skip entry sent via opensrp
7279
else if(isNewEntry){
7380
logDebug("DRUG_ORDER: Insert found. Creating drug_order_save atomfeed for "+u);
74-
process((Order) returnValue, "DrugOrder_Save", formatDataEntrySource(u));
81+
process(o, "DrugOrder_Save", formatDataEntrySource(u));
7582
}
7683
// if not a new entry and no role for data edit found ignorable
7784
else if(isNewEntry == false){
7885
logInfo("ORDER: Creating atomfeed for order_update for "+u);
79-
process((Order) returnValue, "DrugOrder_Update", formatDataEntrySource(u));
86+
process(o, "DrugOrder_Update", formatDataEntrySource(u));
8087
}
8188
}
8289
}
8390

91+
private boolean isDrugOrder(Order o){
92+
boolean drugOrder = false;
93+
if(o != null){
94+
try{
95+
if(o instanceof DrugOrder){
96+
drugOrder = true;
97+
}
98+
else if(o.getOrderType() != null
99+
&& (o.getOrderType().getName().equalsIgnoreCase("drugorder")
100+
|| o.getOrderType().getName().equalsIgnoreCase("drug order"))){
101+
drugOrder = true;
102+
}
103+
}
104+
catch (Exception e) {
105+
e.printStackTrace();
106+
}
107+
}
108+
return drugOrder;
109+
}
110+
84111
@Override
85112
public void before(Method method, Object[] args, Object target) throws Throwable {
86113
Order o = args.length>0&&args[0] instanceof Order?(Order)args[0]:null;
87-
isDrugOrder = o != null && ((Order) o).getOrderType().getName().equalsIgnoreCase("drugorder");
88-
if (method.getName().equals(SAVE_METHOD) && isDrugOrder) {
114+
115+
isDrugOrder = isDrugOrder(o);
116+
117+
if (method.getName().equals(SAVE_METHOD)) {
89118
logDebug("In method SAVE_DRUG_ORDER for atomfeed before advice");
90119

91120
if(o != null){
@@ -103,6 +132,9 @@ public void before(Method method, Object[] args, Object target) throws Throwable
103132
}
104133

105134
private void process(Order order, String title, final String dataEnrySource) {
135+
if(order == null){
136+
return;
137+
}
106138
String contents = String.format(TEMPLATE, order.getUuid());
107139
final Event event = new Event(UUID.randomUUID().toString(), title, DateTime.now(), (URI) null, contents, CATEGORY);
108140
atomFeedSpringTransactionManager.executeWithTransaction(

openmrs-atomfeed-api/src/main/java/org/openmrs/module/atomfeed/advice/EncounterSaveAdvice.java

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ public void before(Method method, Object[] args, Object target) throws Throwable
104104
}
105105

106106
private void process(Encounter encounter, String title, final String dataEnrySource) {
107+
if(encounter == null){
108+
return;
109+
}
107110
String contents = String.format(ENCOUNTER_REST_URL, encounter.getUuid());
108111
final Event event = new Event(UUID.randomUUID().toString(), title, DateTime.now(), (URI) null, contents, CATEGORY);
109112
atomFeedSpringTransactionManager.executeWithTransaction(

openmrs-atomfeed-api/src/main/java/org/openmrs/module/atomfeed/advice/PatientAdvice.java

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public void before(Method method, Object[] args, Object target) throws Throwable
101101
}
102102

103103
private void process(Patient patient, String title, final String dataEnrySource) {
104+
if(patient == null){
105+
return;
106+
}
104107
String contents = String.format(TEMPLATE, patient.getUuid());
105108
final Event event = new Event(UUID.randomUUID().toString(), title, DateTime.now(), (URI) null, contents, CATEGORY);
106109
atomFeedSpringTransactionManager.executeWithTransaction(

0 commit comments

Comments
 (0)