Skip to content

Commit

Permalink
response to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
slubwama committed Jul 20, 2024
1 parent c0e5447 commit 949c59f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,9 @@ public NeedsPaging<OrderAttribute> 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());
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ protected NeedsPaging<OrderAttributeType> doSearch(RequestContext context) {
List<OrderAttributeType> allAttrs = service().getAllOrderAttributeTypes();
List<OrderAttributeType> queryResult = new ArrayList<OrderAttributeType>();
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class OrderResource2_5 extends OrderResource2_2 {
@PropertySetter("attributes")
public static void setAttributes(Order instance, List<OrderAttribute> attrs) {
for (OrderAttribute attr : attrs) {
attr.setValueReferenceInternal(attr.getValue().toString());
instance.addAttribute(attr);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -32,15 +35,15 @@ public class OrderController2_5Test extends MainResourceControllerTest {
public String getURI() {
return "order";
}

/**
* @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getUuid()
*/
@Override
public String getUuid() {
return RestTestConstants2_5.ORDER_ATTRIBUTE_UUID;
}

/**
* @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getAllCount()
*/
Expand All @@ -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<Order> 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");
}

}

0 comments on commit 949c59f

Please sign in to comment.