|
16 | 16 | import io.swagger.models.properties.StringProperty; |
17 | 17 | import org.apache.commons.lang.StringUtils; |
18 | 18 | import org.openmrs.CareSetting; |
| 19 | +import org.openmrs.Drug; |
| 20 | +import org.openmrs.DrugOrder; |
19 | 21 | import org.openmrs.Order; |
20 | 22 | import org.openmrs.OrderType; |
21 | 23 | import org.openmrs.Patient; |
22 | 24 | import org.openmrs.api.context.Context; |
23 | 25 | import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; |
| 26 | +import org.openmrs.module.webservices.rest.SimpleObject; |
24 | 27 | import org.openmrs.module.webservices.rest.web.ConversionUtil; |
25 | 28 | import org.openmrs.module.webservices.rest.web.RequestContext; |
26 | 29 | import org.openmrs.module.webservices.rest.web.RestConstants; |
27 | 30 | import org.openmrs.module.webservices.rest.web.annotation.Resource; |
28 | 31 | import org.openmrs.module.webservices.rest.web.api.RestService; |
| 32 | +import org.openmrs.module.webservices.rest.web.representation.CustomRepresentation; |
29 | 33 | import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; |
30 | 34 | import org.openmrs.module.webservices.rest.web.representation.FullRepresentation; |
31 | 35 | import org.openmrs.module.webservices.rest.web.representation.Representation; |
32 | 36 | import org.openmrs.module.webservices.rest.web.resource.api.PageableResult; |
33 | 37 | import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; |
34 | | -import org.openmrs.module.webservices.rest.web.resource.impl.EmptySearchResult; |
35 | 38 | import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; |
| 39 | +import org.openmrs.module.webservices.rest.web.response.ConversionException; |
36 | 40 | import org.openmrs.module.webservices.rest.web.response.InvalidSearchException; |
37 | 41 | import org.openmrs.module.webservices.rest.web.response.ObjectNotFoundException; |
38 | 42 | import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; |
@@ -311,7 +315,42 @@ public int compare(Order o1, Order o2) { |
311 | 315 | }); |
312 | 316 | return sortedList; |
313 | 317 | } |
314 | | - |
| 318 | + |
| 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 | + |
| 338 | + /** |
| 339 | + * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#asRepresentation(Object, Representation) |
| 340 | + */ |
| 341 | + @Override |
| 342 | + public SimpleObject asRepresentation(Order delegate, Representation representation) throws ConversionException { |
| 343 | + DelegatingResourceDescription repDescription; |
| 344 | + if (representation instanceof CustomRepresentation) { |
| 345 | + repDescription = ConversionUtil.getCustomRepresentationDescription((CustomRepresentation) representation); |
| 346 | + return convertDelegateToRepresentation(delegate, repDescription); |
| 347 | + } |
| 348 | + |
| 349 | + SimpleObject simple = super.asRepresentation(delegate, representation); |
| 350 | + decorateWithStrengthProperty(simple, delegate); |
| 351 | + return simple; |
| 352 | + } |
| 353 | + |
315 | 354 | /** |
316 | 355 | * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion() |
317 | 356 | */ |
|
0 commit comments