Skip to content

Commit 949c59f

Browse files
committed
response to comments
1 parent c0e5447 commit 949c59f

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

omod-2.4/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/MainResourceControllerTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public void shouldGetFullByUuid() throws Exception {
6767
@Test
6868
public void shouldGetAll() throws Exception {
6969
SimpleObject result = deserialize(handle(request(RequestMethod.GET, getURI())));
70-
7170
Assert.assertNotNull(result);
7271
Assert.assertEquals(getAllCount(), Util.getResultsSize(result));
7372
}

omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeResource2_5.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,9 @@ public NeedsPaging<OrderAttribute> doGetAll(Order parent, RequestContext context
9191
@Override
9292
public OrderAttribute save(OrderAttribute delegate) {
9393
// make sure it has not already been added to the order
94-
boolean needToAdd = true;
95-
if (delegate.getOrder().getActiveAttributes().contains(delegate)) {
96-
delegate.getOrder().addAttribute(delegate);
97-
}
98-
if (needToAdd) {
99-
delegate.getOrder().addAttribute(delegate);
100-
}
94+
95+
delegate.getOrder().addAttribute(delegate);
96+
10197
OrderContext orderContext = new OrderContext();
10298
orderContext.setCareSetting(delegate.getOrder().getCareSetting());
10399
orderContext.setOrderType(delegate.getOrder().getOrderType());
@@ -113,7 +109,11 @@ public OrderAttribute save(OrderAttribute delegate) {
113109
*/
114110
@Override
115111
protected void delete(OrderAttribute delegate, String reason, RequestContext context) throws ResponseException {
116-
throw new UnsupportedOperationException("Cannot purge OrderAttribute");
112+
OrderContext orderContext = new OrderContext();
113+
orderContext.setCareSetting(delegate.getOrder().getCareSetting());
114+
orderContext.setOrderType(delegate.getOrder().getOrderType());
115+
delegate.getOrder().setAction(Order.Action.REVISE);
116+
Context.getOrderService().saveOrder(delegate.getOrder(), orderContext);
117117
}
118118

119119
/**

omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeTypeResource2_5.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ protected NeedsPaging<OrderAttributeType> doSearch(RequestContext context) {
8686
List<OrderAttributeType> allAttrs = service().getAllOrderAttributeTypes();
8787
List<OrderAttributeType> queryResult = new ArrayList<OrderAttributeType>();
8888
for (OrderAttributeType locAttr : allAttrs) {
89-
if (Pattern.compile(Pattern.quote(context.getParameter("q")), Pattern.CASE_INSENSITIVE)
90-
.matcher(locAttr.getName()).find()) {
89+
if (locAttr.getName().toLowerCase().contains(context.getParameter("q").toLowerCase())) {
9190
queryResult.add(locAttr);
9291
}
9392
}

omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderResource2_5.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class OrderResource2_5 extends OrderResource2_2 {
3535
@PropertySetter("attributes")
3636
public static void setAttributes(Order instance, List<OrderAttribute> attrs) {
3737
for (OrderAttribute attr : attrs) {
38+
attr.setValueReferenceInternal(attr.getValue().toString());
3839
instance.addAttribute(attr);
3940
}
4041
}

omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderController2_5Test.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
import org.junit.Assert;
1313
import org.junit.Before;
1414
import org.junit.Test;
15+
import org.openmrs.Order;
1516
import org.openmrs.api.OrderService;
1617
import org.openmrs.api.context.Context;
1718
import org.openmrs.module.webservices.rest.web.v1_0.resource.RestTestConstants2_5;
1819
import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest;
1920

21+
import java.util.List;
22+
2023

2124
/**
2225
* Tests functionality of {@link OrderController}.
@@ -32,15 +35,15 @@ public class OrderController2_5Test extends MainResourceControllerTest {
3235
public String getURI() {
3336
return "order";
3437
}
35-
38+
3639
/**
3740
* @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getUuid()
3841
*/
3942
@Override
4043
public String getUuid() {
4144
return RestTestConstants2_5.ORDER_ATTRIBUTE_UUID;
4245
}
43-
46+
4447
/**
4548
* @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getAllCount()
4649
*/
@@ -57,12 +60,12 @@ public void before() throws Exception {
5760

5861
@Test
5962
public void shouldCreateOrderWithAttribute() throws Exception {
60-
int before = service.getOrderByUuid(RestTestConstants2_5.ORDER_UUID).getAttributes().size();
61-
6263
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\"}]}";
6364
handle(newPostRequest(getURI(), json));
64-
int after = service.getOrderByUuid(RestTestConstants2_5.ORDER_UUID).getAttributes().size();
65-
Assert.assertEquals(before + 1, after);
65+
List<Order> orderList= Context.getOrderService().getActiveOrders(Context.getPatientService().getPatientByUuid("5946f880-b197-400b-9caa-a3c661d23041"),Context.getOrderService().getOrderTypeByUuid("2d3fb1d0-ae06-22e3-a5e2-0140211c9a66"),null,null);
66+
Assert.assertEquals(orderList.size(),1);
67+
Assert.assertEquals(orderList.get(0).getAttributes().size(),1);
68+
Assert.assertEquals(orderList.get(0).getAttributes().iterator().next().getAttributeType().getUuid(),"c0de4f5c-6626-418e-9f4f-5396a31e68fb");
6669
}
6770

6871
}

0 commit comments

Comments
 (0)