From 949c59f6e061aed82798c8b53b3e3f46a2d3a3a5 Mon Sep 17 00:00:00 2001 From: slubwama1 Date: Sat, 20 Jul 2024 13:41:21 +0300 Subject: [PATCH] response to comments --- .../controller/MainResourceControllerTest.java | 1 - .../openmrs2_5/OrderAttributeResource2_5.java | 16 ++++++++-------- .../OrderAttributeTypeResource2_5.java | 3 +-- .../resource/openmrs2_5/OrderResource2_5.java | 1 + .../openmrs2_5/OrderController2_5Test.java | 15 +++++++++------ 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/omod-2.4/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/MainResourceControllerTest.java b/omod-2.4/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/MainResourceControllerTest.java index a344cabad..b0846cb2a 100644 --- a/omod-2.4/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/MainResourceControllerTest.java +++ b/omod-2.4/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/MainResourceControllerTest.java @@ -67,7 +67,6 @@ public void shouldGetFullByUuid() throws Exception { @Test public void shouldGetAll() throws Exception { SimpleObject result = deserialize(handle(request(RequestMethod.GET, getURI()))); - Assert.assertNotNull(result); Assert.assertEquals(getAllCount(), Util.getResultsSize(result)); } diff --git a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeResource2_5.java b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeResource2_5.java index 810f16d2c..57594c736 100644 --- a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeResource2_5.java +++ b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeResource2_5.java @@ -91,13 +91,9 @@ public NeedsPaging doGetAll(Order parent, RequestContext context @Override public OrderAttribute save(OrderAttribute delegate) { // make sure it has not already been added to the order - boolean needToAdd = true; - if (delegate.getOrder().getActiveAttributes().contains(delegate)) { - delegate.getOrder().addAttribute(delegate); - } - if (needToAdd) { - delegate.getOrder().addAttribute(delegate); - } + + delegate.getOrder().addAttribute(delegate); + OrderContext orderContext = new OrderContext(); orderContext.setCareSetting(delegate.getOrder().getCareSetting()); orderContext.setOrderType(delegate.getOrder().getOrderType()); @@ -113,7 +109,11 @@ public OrderAttribute save(OrderAttribute delegate) { */ @Override protected void delete(OrderAttribute delegate, String reason, RequestContext context) throws ResponseException { - throw new UnsupportedOperationException("Cannot purge OrderAttribute"); + OrderContext orderContext = new OrderContext(); + orderContext.setCareSetting(delegate.getOrder().getCareSetting()); + orderContext.setOrderType(delegate.getOrder().getOrderType()); + delegate.getOrder().setAction(Order.Action.REVISE); + Context.getOrderService().saveOrder(delegate.getOrder(), orderContext); } /** diff --git a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeTypeResource2_5.java b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeTypeResource2_5.java index 9dcabfadd..b3e000925 100644 --- a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeTypeResource2_5.java +++ b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeTypeResource2_5.java @@ -86,8 +86,7 @@ protected NeedsPaging doSearch(RequestContext context) { List allAttrs = service().getAllOrderAttributeTypes(); List queryResult = new ArrayList(); for (OrderAttributeType locAttr : allAttrs) { - if (Pattern.compile(Pattern.quote(context.getParameter("q")), Pattern.CASE_INSENSITIVE) - .matcher(locAttr.getName()).find()) { + if (locAttr.getName().toLowerCase().contains(context.getParameter("q").toLowerCase())) { queryResult.add(locAttr); } } diff --git a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderResource2_5.java b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderResource2_5.java index a433d9061..3fc716217 100644 --- a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderResource2_5.java +++ b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderResource2_5.java @@ -35,6 +35,7 @@ public class OrderResource2_5 extends OrderResource2_2 { @PropertySetter("attributes") public static void setAttributes(Order instance, List attrs) { for (OrderAttribute attr : attrs) { + attr.setValueReferenceInternal(attr.getValue().toString()); instance.addAttribute(attr); } } diff --git a/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderController2_5Test.java b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderController2_5Test.java index 05b47106f..535f19a01 100644 --- a/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderController2_5Test.java +++ b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderController2_5Test.java @@ -12,11 +12,14 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.openmrs.Order; import org.openmrs.api.OrderService; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.v1_0.resource.RestTestConstants2_5; import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest; +import java.util.List; + /** * Tests functionality of {@link OrderController}. @@ -32,7 +35,7 @@ public class OrderController2_5Test extends MainResourceControllerTest { public String getURI() { return "order"; } - + /** * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getUuid() */ @@ -40,7 +43,7 @@ public String getURI() { public String getUuid() { return RestTestConstants2_5.ORDER_ATTRIBUTE_UUID; } - + /** * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getAllCount() */ @@ -57,12 +60,12 @@ public void before() throws Exception { @Test public void shouldCreateOrderWithAttribute() throws Exception { - int before = service.getOrderByUuid(RestTestConstants2_5.ORDER_UUID).getAttributes().size(); - String json = "{\"encounter\":\"d2d69553-2247-414c-b0c5-46be893605af\",\"orderType\":\"2d3fb1d0-ae06-22e3-a5e2-0140211c9a66\",\"type\":\"order\",\"action\":\"NEW\",\"accessionNumber\":\"string\",\"patient\":\"5946f880-b197-400b-9caa-a3c661d23041\",\"concept\":\"d144d24f-6913-4b63-9660-a9108c2bebef\",\"careSetting\":\"6f0c9a92-6f24-11e3-af88-005056821db0\",\"orderer\":\"c2299800-cca9-11e0-9572-0800200c9a66\",\"previousOrder\":\"\",\"urgency\":\"ROUTINE\",\"orderReason\":\"\",\"orderReasonNonCoded\":\"for Test\",\"instructions\":\"string\",\"commentToFulfiller\":\"string\",\"attributes\":[{\"attributeType\":\"c0de4f5c-6626-418e-9f4f-5396a31e68fb\",\"value\":\"2023-08-14 17:11:39\"}]}"; handle(newPostRequest(getURI(), json)); - int after = service.getOrderByUuid(RestTestConstants2_5.ORDER_UUID).getAttributes().size(); - Assert.assertEquals(before + 1, after); + List orderList= Context.getOrderService().getActiveOrders(Context.getPatientService().getPatientByUuid("5946f880-b197-400b-9caa-a3c661d23041"),Context.getOrderService().getOrderTypeByUuid("2d3fb1d0-ae06-22e3-a5e2-0140211c9a66"),null,null); + Assert.assertEquals(orderList.size(),1); + Assert.assertEquals(orderList.get(0).getAttributes().size(),1); + Assert.assertEquals(orderList.get(0).getAttributes().iterator().next().getAttributeType().getUuid(),"c0de4f5c-6626-418e-9f4f-5396a31e68fb"); } }