diff --git a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/OrderResource2_2.java b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/OrderResource2_2.java index 07751664a..6d3c3f161 100644 --- a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/OrderResource2_2.java +++ b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/OrderResource2_2.java @@ -17,7 +17,7 @@ import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10.OrderResource1_10; -@Resource(name = RestConstants.VERSION_1 + "/order", supportedClass = Order.class, supportedOpenmrsVersions = { "2.2.* - 9.*" }) +@Resource(name = RestConstants.VERSION_1 + "/order", supportedClass = Order.class, supportedOpenmrsVersions = { "2.2.* - 2.4.*" }) public class OrderResource2_2 extends OrderResource1_10 { /** 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.4/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_4/ServerLogResource2_4Test.java b/omod-2.4/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_4/ServerLogResource2_4Test.java index 3bf2c1ef3..30be17203 100644 --- a/omod-2.4/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_4/ServerLogResource2_4Test.java +++ b/omod-2.4/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_4/ServerLogResource2_4Test.java @@ -35,6 +35,7 @@ public class ServerLogResource2_4Test extends BaseModuleWebContextSensitiveTest private final MockServerLogActionWrapper mockServerLogActionWrapper = new MockServerLogActionWrapper<>( new ServerLogActionWrapper2_4()); + @Autowired RestService restService; diff --git a/omod-2.5/pom.xml b/omod-2.5/pom.xml index f6eca1cef..9c2d75886 100644 --- a/omod-2.5/pom.xml +++ b/omod-2.5/pom.xml @@ -1,16 +1,14 @@ - 4.0.0 - org.openmrs.module webservices.rest + org.openmrs.module 2.45.0-SNAPSHOT + 4.0.0 webservices.rest-omod-2.5 - jar Rest Web Services 2.5 OMOD - OpenMRS module project for Rest Web Services 2.5.0 @@ -33,34 +31,6 @@ test - - ${project.parent.groupId} - ${project.parent.artifactId}-omod-1.8 - ${project.parent.version} - - - - ${project.parent.groupId} - ${project.parent.artifactId}-omod-1.8 - ${project.parent.version} - tests - test - - - - ${project.parent.groupId} - ${project.parent.artifactId}-omod-1.9 - ${project.parent.version} - - - - ${project.parent.groupId} - ${project.parent.artifactId}-omod-1.9 - ${project.parent.version} - tests - test - - ${project.parent.groupId} ${project.parent.artifactId}-omod-1.10 @@ -95,14 +65,6 @@ ${project.parent.version} - - ${project.parent.groupId} - ${project.parent.artifactId}-omod-2.0 - ${project.parent.version} - tests - test - - ${project.parent.groupId} ${project.parent.artifactId}-omod-2.2 @@ -145,6 +107,14 @@ test + + ${project.parent.groupId} + ${project.parent.artifactId}-omod-2.0 + ${project.parent.version} + tests + test + + org.openmrs.api openmrs-api @@ -163,6 +133,12 @@ org.openmrs.web openmrs-web ${openmrs.version.2.5.0} + + + javax.servlet + servlet-api + + 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 new file mode 100644 index 000000000..57594c736 --- /dev/null +++ b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeResource2_5.java @@ -0,0 +1,135 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_5; + +import org.openmrs.Order; +import org.openmrs.OrderAttribute; +import org.openmrs.OrderAttributeType; +import org.openmrs.api.context.Context; +import org.openmrs.api.OrderContext; +import org.openmrs.module.webservices.rest.web.RequestContext; +import org.openmrs.module.webservices.rest.web.annotation.PropertySetter; +import org.openmrs.module.webservices.rest.web.annotation.Resource; +import org.openmrs.module.webservices.rest.web.annotation.SubResource; +import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; +import org.openmrs.module.webservices.rest.web.response.ResponseException; +import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9.BaseAttributeCrudResource1_9; +import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2.OrderResource2_2; + +import java.util.List; + +/** + * {@link Resource} for OrderAttributes, supporting standard CRUD operations + */ +@SubResource(parent = OrderResource2_5.class, path = "attribute", supportedClass = OrderAttribute.class, supportedOpenmrsVersions = { + "2.5.* - 9.*"}) +public class OrderAttributeResource2_5 extends BaseAttributeCrudResource1_9 { + + /** + * Sets attributeType on the given OrderAttribute. + * + * @param instance + * @param attr + */ + @PropertySetter("attributeType") + public static void setAttributeType(OrderAttribute instance, OrderAttributeType attr) { + instance.setAttributeType(attr); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#getParent(java.lang.Object) + */ + @Override + public Order getParent(OrderAttribute instance) { + return instance.getOrder(); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate() + */ + @Override + public OrderAttribute newDelegate() { + return new OrderAttribute(); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#setParent(java.lang.Object, + * java.lang.Object) + */ + @Override + public void setParent(OrderAttribute instance, Order order) { + instance.setOrder(order); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) + */ + @Override + public OrderAttribute getByUniqueId(String uniqueId) { + return Context.getOrderService().getOrderAttributeByUuid(uniqueId); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#doGetAll(java.lang.Object, + * org.openmrs.module.webservices.rest.web.RequestContext) + */ + @Override + public NeedsPaging doGetAll(Order parent, RequestContext context) throws ResponseException { + return new NeedsPaging((List) parent.getActiveAttributes(), context); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object) + */ + @Override + public OrderAttribute save(OrderAttribute delegate) { + // make sure it has not already been added to the order + + delegate.getOrder().addAttribute(delegate); + + 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); + return delegate; + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#delete(java.lang.Object, + * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext) + */ + @Override + protected void delete(OrderAttribute delegate, String reason, RequestContext context) throws ResponseException { + 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); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#purge(java.lang.Object, + * org.openmrs.module.webservices.rest.web.RequestContext) + */ + @Override + public void purge(OrderAttribute delegate, RequestContext context) throws ResponseException { + throw new UnsupportedOperationException("Cannot purge OrderAttribute"); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion() + */ + @Override + public String getResourceVersion() { + return RestConstants2_5.RESOURCE_VERSION; + } +} 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 new file mode 100644 index 000000000..b3e000925 --- /dev/null +++ b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeTypeResource2_5.java @@ -0,0 +1,103 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_5; + +import org.openmrs.OrderAttributeType; +import org.openmrs.api.OrderService; +import org.openmrs.api.context.Context; +import org.openmrs.module.webservices.rest.web.RequestContext; +import org.openmrs.module.webservices.rest.web.RestConstants; +import org.openmrs.module.webservices.rest.web.annotation.Resource; +import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; +import org.openmrs.module.webservices.rest.web.response.ResponseException; +import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9.BaseAttributeTypeCrudResource1_9; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Allows standard CRUD for the {@link OrderAttributeType} domain object + */ +@Resource(name = RestConstants.VERSION_1 + "/orderattributetype", supportedClass = OrderAttributeType.class, supportedOpenmrsVersions = { + "2.5.* - 9.*" }) +public class OrderAttributeTypeResource2_5 extends BaseAttributeTypeCrudResource1_9 { + + public OrderAttributeTypeResource2_5() { + } + + private OrderService service() { + return Context.getOrderService(); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) + */ + @Override + public OrderAttributeType getByUniqueId(String uniqueId) { + return service().getOrderAttributeTypeByUuid(uniqueId); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext) + */ + @Override + protected NeedsPaging doGetAll(RequestContext context) throws ResponseException { + return new NeedsPaging(service().getAllOrderAttributeTypes(), context); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate() + */ + @Override + public OrderAttributeType newDelegate() { + return new OrderAttributeType(); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object) + */ + @Override + public OrderAttributeType save(OrderAttributeType delegate) { + return service().saveOrderAttributeType(delegate); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#purge(java.lang.Object, + * org.openmrs.module.webservices.rest.web.RequestContext) + */ + @Override + public void purge(OrderAttributeType delegate, RequestContext context) throws ResponseException { + service().purgeOrderAttributeType(delegate); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext) + */ + @Override + protected NeedsPaging doSearch(RequestContext context) { + List allAttrs = service().getAllOrderAttributeTypes(); + List queryResult = new ArrayList(); + for (OrderAttributeType locAttr : allAttrs) { + if (locAttr.getName().toLowerCase().contains(context.getParameter("q").toLowerCase())) { + queryResult.add(locAttr); + } + } + return new NeedsPaging(queryResult, context); + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion() + */ + @Override + public String getResourceVersion() { + return RestConstants2_5.RESOURCE_VERSION; + } +} 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 new file mode 100644 index 000000000..3fc716217 --- /dev/null +++ b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderResource2_5.java @@ -0,0 +1,92 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_5; + +import org.openmrs.Order; +import org.openmrs.OrderAttribute; +import org.openmrs.module.webservices.rest.web.RestConstants; +import org.openmrs.module.webservices.rest.web.annotation.PropertySetter; +import org.openmrs.module.webservices.rest.web.annotation.Resource; +import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; +import org.openmrs.module.webservices.rest.web.representation.FullRepresentation; +import org.openmrs.module.webservices.rest.web.representation.Representation; +import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource; +import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; +import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2.OrderResource2_2; +import java.util.Arrays; +import java.util.List; + +@Resource(name = RestConstants.VERSION_1 + "/order", supportedClass = Order.class, supportedOpenmrsVersions = { "2.5.* - 9.*" }) +public class OrderResource2_5 extends OrderResource2_2 { + + /** + * Sets attributes on the given Order. + * + * @param instance + * @param attrs + */ + @PropertySetter("attributes") + public static void setAttributes(Order instance, List attrs) { + for (OrderAttribute attr : attrs) { + attr.setValueReferenceInternal(attr.getValue().toString()); + instance.addAttribute(attr); + } + } + + /** + * @see DelegatingCrudResource#getRepresentationDescription(Representation) + */ + @Override + public DelegatingResourceDescription getRepresentationDescription(Representation rep) { + if (rep instanceof DefaultRepresentation) { + DelegatingResourceDescription description = super.getRepresentationDescription(rep); + description.addProperty("attributes", Representation.REF); + return description; + } else if (rep instanceof FullRepresentation) { + DelegatingResourceDescription description = super.getRepresentationDescription(rep); + description.addProperty("attributes", Representation.FULL); + return description; + } + return null; + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() + */ + @Override + public DelegatingResourceDescription getCreatableProperties() { + DelegatingResourceDescription description = super.getCreatableProperties(); + description.addProperty("attributes"); + return description; + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties() + */ + @Override + public DelegatingResourceDescription getUpdatableProperties() { + DelegatingResourceDescription description = super.getUpdatableProperties(); + description.addProperty("attributes"); + return description; + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getPropertiesToExposeAsSubResources() + */ + @Override + public List getPropertiesToExposeAsSubResources() { + return Arrays.asList("attributes"); + } + + @Override + public String getResourceVersion() { + return RestConstants2_5.RESOURCE_VERSION; + } +} \ No newline at end of file diff --git a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/RestConstants2_5.java b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/RestConstants2_5.java new file mode 100644 index 000000000..17e0cc768 --- /dev/null +++ b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/RestConstants2_5.java @@ -0,0 +1,21 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_5; + +/** + * {@link org.openmrs.module.webservices.rest.web.RestConstants} for 2.0 resources. + */ +public class RestConstants2_5 { + + /** + * A default value for the resource version parameter. + */ + public static final String RESOURCE_VERSION = "2.5"; +} diff --git a/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderAttributeTypeController2_5Test.java b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderAttributeTypeController2_5Test.java new file mode 100644 index 000000000..6f703c350 --- /dev/null +++ b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderAttributeTypeController2_5Test.java @@ -0,0 +1,134 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs2_5; + +import org.apache.commons.beanutils.PropertyUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openmrs.OrderAttributeType; +import org.openmrs.api.context.Context; +import org.openmrs.module.webservices.rest.SimpleObject; +import org.openmrs.module.webservices.rest.test.Util; +import org.openmrs.module.webservices.rest.web.v1_0.resource.RestTestConstants2_5; +import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.context.request.WebRequest; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +public class OrderAttributeTypeController2_5Test extends MainResourceControllerTest { + + /** + * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getURI() + */ + @Override + public String getURI() { + return "orderattributetype"; + } + + /** + * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getUuid() + */ + @Override + public String getUuid() { + return RestTestConstants2_5.ORDER_ATTRIBUTE_TYPE_UUID; + } + + /** + * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getAllCount() + */ + @Override + public long getAllCount() { + return Context.getOrderService().getAllOrderAttributeTypes().size(); + } + + @Before + public void before() throws Exception { + executeDataSet(RestTestConstants2_5.TEST_DATASET); + } + + /** + * @see OrderAttributeTypeController#createOrderAttributeType(SimpleObject,WebRequest) + * @verifies create a new OrderAttributeType + */ + @Test + public void createOrderAttributeType_shouldCreateANewOrderAttributeType() throws Exception { + int before = Context.getOrderService().getAllOrderAttributeTypes().size(); + String json = "{ \"name\":\"Some attributeType\",\"description\":\"Attribute Type for order\",\"datatypeClassname\":\"org.openmrs.customdatatype.datatype.FreeTextDatatype\"}"; + + handle(newPostRequest(getURI(), json)); + + Assert.assertEquals(before + 1, Context.getOrderService().getAllOrderAttributeTypes().size()); + } + + /** + * @see OrderAttributeTypeController#updateOrderAttributeType(OrderAttributeType,SimpleObject,WebRequest) + * @verifies change a property on a order + */ + @Test + public void updateOrderAttributeType_shouldChangeAPropertyOnAOrderAttributeType() throws Exception { + String json = "{\"description\":\"Updated description\"}"; + + handle(newPostRequest(getURI() + "/" + getUuid(), json)); + + Assert.assertEquals("Updated description", Context.getOrderService().getOrderAttributeTypeById(1).getDescription()); + } + + /** + * @see OrderAttributeTypeController#retireOrderAttributeType(OrderAttributeType,String,WebRequest) + * @verifies void a order attribute type + */ + @Test + public void retireOrderAttributeType_shouldRetireAOrderAttributeType() throws Exception { + OrderAttributeType orderAttributeType = Context.getOrderService().getOrderAttributeTypeById(1); + Assert.assertFalse(orderAttributeType.isRetired()); + + MockHttpServletRequest request = request(RequestMethod.DELETE, getURI() + "/" + getUuid()); + request.addParameter("reason", "test"); + handle(request); + + orderAttributeType = Context.getOrderService().getOrderAttributeTypeById(1); + Assert.assertTrue(orderAttributeType.isRetired()); + Assert.assertEquals("test", orderAttributeType.getRetireReason()); + } + + /** + * @see OrderAttributeTypeController#findOrderAttributeTypes(String,WebRequest,HttpServletResponse) + * @verifies return no results if there are no matching order(s) + */ + @Test + public void findOrderAttributeTypes_shouldReturnNoResultsIfThereAreNoMatchingOrders() throws Exception { + SimpleObject result = deserialize(handle(newGetRequest(getURI(), new Parameter("q", "zzzznotype")))); + + Assert.assertEquals(0, Util.getResultsSize(result)); + } + + /** + * @see OrderAttributeTypeController#findOrderAttributeTypes(String,WebRequest,HttpServletResponse) + * @verifies find matching order attribute types + */ + @Test + public void findOrderAttributeTypes_shouldFindMatchingOrderAttributeTypes() throws Exception { + SimpleObject response = deserialize(handle(newGetRequest(getURI(), new Parameter("q", "Dispensing Date")))); + + List results = Util.getResultsList(response); + + Assert.assertEquals(1, results.size()); + Util.log("Found " + results.size() + " OrderAttributeType(s)", results); + Object result = results.get(0); + Assert.assertEquals(RestTestConstants2_5.ORDER_ATTRIBUTE_TYPE_UUID, PropertyUtils.getProperty(result, "uuid")); + Assert.assertNotNull(PropertyUtils.getProperty(result, "links")); + Assert.assertNotNull(PropertyUtils.getProperty(result, "display")); + } + +} 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 new file mode 100644 index 000000000..e8d71aacb --- /dev/null +++ b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderController2_5Test.java @@ -0,0 +1,86 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs2_5; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.function.ThrowingRunnable; +import org.openmrs.Order; +import org.openmrs.api.OrderService; +import org.openmrs.api.context.Context; +import org.openmrs.module.webservices.rest.SimpleObject; +import org.openmrs.module.webservices.rest.test.Util; +import org.openmrs.module.webservices.rest.web.response.ResponseException; +import org.openmrs.module.webservices.rest.web.v1_0.resource.RestTestConstants2_5; +import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.util.List; + + +/** + * Tests functionality of {@link OrderController}. + */ +public class OrderController2_5Test extends MainResourceControllerTest { + + private OrderService service; + + /** + * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getURI() + */ + @Override + 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_UUID; + } + + /** + * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getAllCount() + */ + @Override + public long getAllCount() { + return service.getOrderByUuid(RestTestConstants2_5.ORDER_UUID).getActiveAttributes().size(); + } + + @Before + public void before() throws Exception { + executeDataSet(RestTestConstants2_5.TEST_DATASET); + this.service = Context.getOrderService(); + } + + @Test + public void shouldCreateOrderWithAttribute() throws Exception { + 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)); + 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"); + } + + @Test + @Override + public void shouldGetAll() { + ThrowingRunnable throwingRunnable= () -> { + handle(request(RequestMethod.GET, getURI())); + }; + Assert.assertThrows(ResponseException.class,throwingRunnable); + } + + +} diff --git a/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/RestTestConstants2_5.java b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/RestTestConstants2_5.java new file mode 100644 index 000000000..bcab19d4a --- /dev/null +++ b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/RestTestConstants2_5.java @@ -0,0 +1,22 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.resource; + +public class RestTestConstants2_5 { + + public final static String TEST_DATASET = "customTestDataset2_5.xml"; + + public final static String ORDER_UUID = "204897de-70c6-4d5f-9051-b269fbd0700c"; + + public final static String ORDER_ATTRIBUTE_UUID = "3a2bdb18-6faa-11e0-8414-001e378eb67e"; + + public final static String ORDER_ATTRIBUTE_TYPE_UUID = "c0de4f5c-6626-418e-9f4f-5396a31e68fb"; + +} diff --git a/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeResource2_5Test.java b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeResource2_5Test.java new file mode 100644 index 000000000..a0d03229c --- /dev/null +++ b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeResource2_5Test.java @@ -0,0 +1,68 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_5; + +import java.text.ParseException; +import java.text.SimpleDateFormat; + +import org.junit.Before; +import org.openmrs.OrderAttribute; +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.resource.impl.BaseDelegatingResourceTest; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class OrderAttributeResource2_5Test extends BaseDelegatingResourceTest { + protected final Log log = LogFactory.getLog(this.getClass()); + + @Before + public void before() throws Exception { + executeDataSet(RestTestConstants2_5.TEST_DATASET); + } + + @Override + public OrderAttribute newObject() { + return Context.getOrderService().getOrderAttributeByUuid(getUuidProperty()); + } + + @Override + public void validateDefaultRepresentation() throws Exception { + super.validateDefaultRepresentation(); + assertPropEquals("value", getObject().getValue()); + assertPropPresent("attributeType"); + assertPropEquals("voided", getObject().getVoided()); + } + + @Override + public void validateFullRepresentation() throws Exception { + super.validateFullRepresentation(); + assertPropEquals("value", getObject().getValue()); + assertPropPresent("attributeType"); + assertPropEquals("voided", getObject().getVoided()); + assertPropPresent("auditInfo"); + } + + @Override + public String getDisplayProperty() { + try { + return "Dispensing Date: " + new SimpleDateFormat("yyyy-MM-dd").parse("2011-04-25"); + } + catch (ParseException ex) { + log.error(ex); + return null; + } + } + + @Override + public String getUuidProperty() { + return RestTestConstants2_5.ORDER_ATTRIBUTE_UUID; + } +} diff --git a/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeTypeResource2_5Test.java b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeTypeResource2_5Test.java new file mode 100644 index 000000000..0d47b3245 --- /dev/null +++ b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeTypeResource2_5Test.java @@ -0,0 +1,64 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_5; + +import org.junit.Before; +import org.openmrs.OrderAttributeType; +import org.openmrs.api.context.Context; +import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest; +import org.openmrs.module.webservices.rest.web.v1_0.resource.RestTestConstants2_5; + +public class OrderAttributeTypeResource2_5Test extends BaseDelegatingResourceTest { + + @Before + public void before() throws Exception { + executeDataSet(RestTestConstants2_5.TEST_DATASET); + } + + @Override + public OrderAttributeType newObject() { + return Context.getOrderService().getOrderAttributeTypeByUuid(getUuidProperty()); + } + + @Override + public void validateDefaultRepresentation() throws Exception { + super.validateDefaultRepresentation(); + assertPropEquals("name", getObject().getName()); + assertPropEquals("description", getObject().getDescription()); + assertPropEquals("datatypeClassname", getObject().getDatatypeClassname()); + assertPropEquals("preferredHandlerClassname", getObject().getPreferredHandlerClassname()); + assertPropEquals("retired", getObject().getRetired()); + } + + @Override + public void validateFullRepresentation() throws Exception { + super.validateFullRepresentation(); + assertPropEquals("name", getObject().getName()); + assertPropEquals("description", getObject().getDescription()); + assertPropEquals("minOccurs", getObject().getMinOccurs()); + assertPropEquals("maxOccurs", getObject().getMaxOccurs()); + assertPropEquals("datatypeClassname", getObject().getDatatypeClassname()); + assertPropEquals("datatypeConfig", getObject().getDatatypeConfig()); + assertPropEquals("preferredHandlerClassname", getObject().getPreferredHandlerClassname()); + assertPropEquals("handlerConfig", getObject().getHandlerConfig()); + assertPropEquals("retired", getObject().getRetired()); + assertPropPresent("auditInfo"); + } + + @Override + public String getDisplayProperty() { + return "Dispensing Date"; + } + + @Override + public String getUuidProperty() { + return RestTestConstants2_5.ORDER_ATTRIBUTE_TYPE_UUID; + } +} diff --git a/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderResource2_5Test.java b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderResource2_5Test.java new file mode 100644 index 000000000..c93cca207 --- /dev/null +++ b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderResource2_5Test.java @@ -0,0 +1,46 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_5; + +import org.junit.Before; +import org.openmrs.Order; +import org.openmrs.api.context.Context; + +import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest; +import org.openmrs.module.webservices.rest.web.v1_0.resource.RestTestConstants2_5; + +public class OrderResource2_5Test extends BaseDelegatingResourceTest { + + @Before + public void before() throws Exception { + executeDataSet(RestTestConstants2_5.TEST_DATASET); + } + + @Override + public Order newObject() { + return Context.getOrderService().getOrderByUuid(getUuidProperty()); + } + + @Override + public void validateFullRepresentation() throws Exception { + super.validateFullRepresentation(); + assertPropPresent("attributes"); + } + + @Override + public String getDisplayProperty() { + return "ASPIRIN"; + } + + @Override + public String getUuidProperty() { + return RestTestConstants2_5.ORDER_UUID; + } +} diff --git a/omod-2.5/src/test/resources/customTestDataset2_5.xml b/omod-2.5/src/test/resources/customTestDataset2_5.xml new file mode 100644 index 000000000..4e346e0c5 --- /dev/null +++ b/omod-2.5/src/test/resources/customTestDataset2_5.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +