-
Notifications
You must be signed in to change notification settings - Fork 521
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
base: master
Are you sure you want to change the base?
Changes from all commits
90bfbe1
51e9927
fabd6ac
9f74240
9d87b93
5f1756a
48a8078
e77fb1a
540c59f
6cd7ba0
8bb76d2
67b90a2
c0e5447
949c59f
611ec39
14a16a4
ceff5c5
a1f0521
8ef2d27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this dependency