Skip to content

Commit 44d4055

Browse files
RESTWS-760: Order resource does not include drug strength
1 parent d975149 commit 44d4055

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

omod-common/src/main/java/org/openmrs/module/webservices/rest/web/RestConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ public class RestConstants {
155155
public static String REPRESENTATION_FULL = "full";
156156

157157
public static String REPRESENTATION_CUSTOM_PREFIX = "custom:";
158+
159+
/**
160+
* Used in DrugOrder object representations to indicate the specific strength an instance has
161+
*/
162+
public static String PROPERTY_FOR_STRENGTH = "strength";
158163

159164
// The URI prefix through which clients consuming web services will connect
160165
// to the web application

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
import org.openmrs.Patient;
2222
import org.openmrs.api.context.Context;
2323
import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty;
24+
import org.openmrs.module.webservices.rest.SimpleObject;
2425
import org.openmrs.module.webservices.rest.web.ConversionUtil;
2526
import org.openmrs.module.webservices.rest.web.RequestContext;
2627
import org.openmrs.module.webservices.rest.web.RestConstants;
2728
import org.openmrs.module.webservices.rest.web.annotation.Resource;
2829
import org.openmrs.module.webservices.rest.web.api.RestService;
30+
import org.openmrs.module.webservices.rest.web.representation.CustomRepresentation;
2931
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
3032
import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
3133
import org.openmrs.module.webservices.rest.web.representation.Representation;
@@ -36,6 +38,7 @@
3638
import org.openmrs.module.webservices.rest.web.response.ObjectNotFoundException;
3739
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
3840
import org.openmrs.module.webservices.rest.web.response.ResponseException;
41+
import org.openmrs.module.webservices.rest.web.response.ConversionException;
3942
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.OrderResource1_8;
4043
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PatientResource1_8;
4144

@@ -310,6 +313,27 @@ public int compare(Order o1, Order o2) {
310313
});
311314
return sortedList;
312315
}
316+
317+
/**
318+
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#asRepresentation(Object, Representation)
319+
*/
320+
@Override
321+
public SimpleObject asRepresentation(Order delegate, Representation representation) throws ConversionException {
322+
DelegatingResourceDescription repDescription;
323+
if (representation instanceof CustomRepresentation) {
324+
repDescription = ConversionUtil.getCustomRepresentationDescription((CustomRepresentation) representation);
325+
return convertDelegateToRepresentation(delegate, repDescription);
326+
}
327+
328+
SimpleObject simple = super.asRepresentation(delegate, representation);
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+
}
335+
return simple;
336+
}
313337

314338
/**
315339
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion()

omod/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_10/OrderController1_10Test.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,4 +598,16 @@ public void doSearch_shouldReturnExceptionIfNoPatientUuidIsSpecified() throws Ex
598598
);
599599
handle(req);
600600
}
601+
602+
@Test
603+
public void doSearch_shouldReturnWithDrugStrengthProperty() throws Exception {
604+
MockHttpServletRequest req = newGetRequest(getURI(),
605+
new Parameter("orderTypes", RestTestConstants1_10.DRUG_ORDER_TYPE_UUID),
606+
new Parameter("patient", PATIENT_UUID)
607+
);
608+
609+
SimpleObject orders = deserialize(handle(req));
610+
List<Object> results = orders.get("results");
611+
assertEquals(PropertyUtils.getProperty(results.get(0), "strength"), "325.0mg");
612+
}
601613
}

0 commit comments

Comments
 (0)