Skip to content

Commit 6a720bc

Browse files
RESTWS-760: Order resource does not include drug strength
1 parent c677942 commit 6a720bc

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugOrderSubclassHandler1_10.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import org.apache.commons.lang.StringUtils;
1515
import org.openmrs.CareSetting;
16+
import org.openmrs.Drug;
1617
import org.openmrs.DrugOrder;
1718
import org.openmrs.Order;
1819
import org.openmrs.OrderType;
@@ -202,4 +203,16 @@ public static String getDisplay(DrugOrder delegate) {
202203

203204
return ret.toString();
204205
}
206+
207+
@PropertyGetter("strength")
208+
public String getStrength(DrugOrder delegate) {
209+
StringBuilder ret = new StringBuilder();
210+
if (delegate.getDrug() != null) {
211+
Drug drug = delegate.getDrug();
212+
ret.append(drug.getStrength() != null ? drug.getStrength() : "[no strength]");
213+
} else {
214+
ret.append("[no strength]");
215+
}
216+
return ret.toString();
217+
}
205218
}

omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import io.swagger.models.properties.StringProperty;
1717
import org.apache.commons.lang.StringUtils;
1818
import org.openmrs.CareSetting;
19-
import org.openmrs.Drug;
20-
import org.openmrs.DrugOrder;
2119
import org.openmrs.Order;
2220
import org.openmrs.OrderType;
2321
import org.openmrs.Patient;
@@ -316,25 +314,6 @@ public int compare(Order o1, Order o2) {
316314
return sortedList;
317315
}
318316

319-
/**
320-
* If this resource is a DrugOrder, then we add a strength property to the input, and return it
321-
*
322-
* @param simple simplified representation which will be decorated with the strength property
323-
*
324-
* @param delegate the DrugOrder object that simple represents
325-
*/
326-
private void decorateWithStrengthProperty(SimpleObject simple, Order delegate) {
327-
OrderType drugOrderType = Context.getOrderService().getOrderTypeByName("Drug order");
328-
if (delegate.getOrderType().equals(drugOrderType)) {
329-
Drug drug = ((DrugOrder) delegate).getDrug();
330-
if (drug != null) {
331-
simple.add(RestConstants.PROPERTY_FOR_STRENGTH, drug.getStrength() != null ? drug.getStrength() : "[no strength]");
332-
} else {
333-
simple.add(RestConstants.PROPERTY_FOR_STRENGTH,"[no strength]");
334-
}
335-
}
336-
}
337-
338317
/**
339318
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#asRepresentation(Object, Representation)
340319
*/
@@ -347,7 +326,12 @@ public SimpleObject asRepresentation(Order delegate, Representation representati
347326
}
348327

349328
SimpleObject simple = super.asRepresentation(delegate, representation);
350-
decorateWithStrengthProperty(simple, delegate);
329+
OrderType drugOrderType = Context.getOrderService().getOrderTypeByName("Drug order");
330+
if (delegate.getOrderType().equals(drugOrderType)) {
331+
String strength = (String) findAndInvokeSubclassHandlerMethod("drugorder",
332+
"getStrength", delegate);
333+
simple.add(RestConstants.PROPERTY_FOR_STRENGTH, strength);
334+
}
351335
return simple;
352336
}
353337

omod-2.3/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/search/openmrs2_3/OrderSearchHandler2_3Test.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,5 @@ public void getSearchConfig_shouldReturnOrdersByAccessionNumber() throws Excepti
220220
Assert.assertEquals(1, orders.size());
221221
Assert.assertEquals(PropertyUtils.getProperty(orders.get(0), "uuid"), "e1f95924-697a-11e3-bd76-0800271c1b75");
222222
}
223+
223224
}

0 commit comments

Comments
 (0)