Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESTWS-920: Endpoint for OrderAttribute and OrderAttributeType. #587

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
90bfbe1
RESTWS-920 Create API endpoint for OrderAttribute and OrderAttributeType
slubwama Sep 8, 2023
51e9927
removing unnecessary tests and files
slubwama Sep 10, 2023
fabd6ac
Changing logging approach in OrderAttributeResource2_5Test
slubwama Sep 10, 2023
9f74240
adding OrderAttributeController2_5Test and OrderAttributeTypeControll…
slubwama Sep 11, 2023
9d87b93
Changing order to include order attribute
slubwama Sep 22, 2023
5f1756a
changing test to focus on creation of order with attribute
slubwama Mar 3, 2024
48a8078
Merge branch 'master' of github.com:openmrs/openmrs-module-webservice…
slubwama Mar 4, 2024
e77fb1a
change version in omod-2.5 to match other module poms
slubwama Mar 4, 2024
540c59f
Merge branch 'master' of github.com:openmrs/openmrs-module-webservice…
slubwama Jun 12, 2024
6cd7ba0
change version to 2.44.0-SNAPSHOT
slubwama Jun 12, 2024
8bb76d2
change Dispensing Date order_attribute_type uuid to c0de4f5c-6626-4…
slubwama Jun 12, 2024
67b90a2
make changes to test data
slubwama Jun 13, 2024
c0e5447
response to comments
slubwama Jun 13, 2024
949c59f
response to comments
slubwama Jul 20, 2024
611ec39
Merge branch 'master' of github.com:openmrs/openmrs-module-webservice…
slubwama Jul 20, 2024
14a16a4
change to snapshot 2.45.0-SNAPSHOT
slubwama Jul 20, 2024
ceff5c5
add override for shouldGetAll() to one that throws an exception.
slubwama Sep 20, 2024
a1f0521
Merge branch 'master' of github.com:openmrs/openmrs-module-webservice…
slubwama Sep 20, 2024
8ef2d27
clean pom
slubwama Sep 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
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 @@ -35,6 +35,7 @@ public class ServerLogResource2_4Test extends BaseModuleWebContextSensitiveTest
private final MockServerLogActionWrapper<ServerLogActionWrapper2_4> mockServerLogActionWrapper = new MockServerLogActionWrapper<>(
new ServerLogActionWrapper2_4());


@Autowired
RestService restService;

Expand Down
56 changes: 16 additions & 40 deletions omod-2.5/pom.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest</artifactId>
<groupId>org.openmrs.module</groupId>
<version>2.45.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>webservices.rest-omod-2.5</artifactId>
<packaging>jar</packaging>
<name>Rest Web Services 2.5 OMOD</name>
<description>OpenMRS module project for Rest Web Services</description>

<properties>
<openmrs.version.2.5.0>2.5.0</openmrs.version.2.5.0>
Expand All @@ -33,34 +31,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-1.8</artifactId>
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-1.8</artifactId>
<version>${project.parent.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-1.9</artifactId>
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-1.9</artifactId>
<version>${project.parent.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this dependency

<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-1.10</artifactId>
Expand Down Expand Up @@ -95,14 +65,6 @@
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-2.0</artifactId>
<version>${project.parent.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-2.2</artifactId>
Expand Down Expand Up @@ -145,6 +107,14 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-2.0</artifactId>
<version>${project.parent.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
Expand All @@ -163,6 +133,12 @@
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
<version>${openmrs.version.2.5.0}</version> <!-- $NO-MVN-MAN-VER$ -->
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<OrderAttribute, Order, OrderResource2_5> {

/**
* 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<OrderAttribute> doGetAll(Order parent, RequestContext context) throws ResponseException {
return new NeedsPaging<OrderAttribute>((List<OrderAttribute>) 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());
ibacher marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}
Original file line number Diff line number Diff line change
@@ -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<OrderAttributeType> {

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<OrderAttributeType> doGetAll(RequestContext context) throws ResponseException {
return new NeedsPaging<OrderAttributeType>(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<OrderAttributeType> doSearch(RequestContext context) {
List<OrderAttributeType> allAttrs = service().getAllOrderAttributeTypes();
List<OrderAttributeType> queryResult = new ArrayList<OrderAttributeType>();
for (OrderAttributeType locAttr : allAttrs) {
if (locAttr.getName().toLowerCase().contains(context.getParameter("q").toLowerCase())) {
queryResult.add(locAttr);
}
}
Comment on lines +88 to +92
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be ideal, I think, if we could extend the order server to handle this search for use. Anything where we're loading all database entries into memory is going to perform slowly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want the ability (and to default!) to not returning any retired order attributes without the user explicitly requesting it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, if possible, it might be nice to order the results so that prefix matches come before "containing" matches. (This shouldn't block the PR)

return new NeedsPaging<OrderAttributeType>(queryResult, context);
}

/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion()
*/
@Override
public String getResourceVersion() {
return RestConstants2_5.RESOURCE_VERSION;
}
}
Loading
Loading