From c0e54475c772350ac293c240d2ce91c9ed46e512 Mon Sep 17 00:00:00 2001 From: slubwama1 Date: Thu, 13 Jun 2024 20:25:35 +0300 Subject: [PATCH] response to comments --- .../BaseAttributeCrudResource2_5.java | 162 ------------------ .../BaseAttributeTypeCrudResource2_5.java | 127 -------------- .../openmrs2_5/OrderAttributeResource2_5.java | 11 +- .../OrderAttributeTypeResource2_5.java | 3 +- ...5Test.java => OrderController2_5Test.java} | 4 +- .../openmrs2_5/OrderResource2_5Test.java | 8 +- 6 files changed, 16 insertions(+), 299 deletions(-) delete mode 100644 omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/BaseAttributeCrudResource2_5.java delete mode 100644 omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/BaseAttributeTypeCrudResource2_5.java rename omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/{OrderAttributeController2_5Test.java => OrderController2_5Test.java} (95%) diff --git a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/BaseAttributeCrudResource2_5.java b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/BaseAttributeCrudResource2_5.java deleted file mode 100644 index 4b24a915a..000000000 --- a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/BaseAttributeCrudResource2_5.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * 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 io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; -import org.apache.commons.lang.StringUtils; -import org.openmrs.attribute.Attribute; -import org.openmrs.customdatatype.CustomDatatype; -import org.openmrs.customdatatype.CustomDatatypeUtil; -import org.openmrs.customdatatype.NotYetPersistedException; -import org.openmrs.module.webservices.rest.web.RestConstants; -import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; -import org.openmrs.module.webservices.rest.web.annotation.PropertySetter; -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.resource.impl.DelegatingSubResource; - -import java.util.Arrays; -import java.util.List; - -/** - * Subclass of {@link DelegatingSubResource} with helper methods specific to {@link Attribute} - * - * @param The type of the attribute this sub resource is associated to - * @param

The parent/owning type for the type T - * @param The Resource for the parent/owning type P - */ -public abstract class BaseAttributeCrudResource2_5, P, PR> extends DelegatingSubResource> { - - /** - * Sets value on the given attribute. - * - * @param instance - * @param value - */ - @PropertySetter("value") - public static void setValue(Attribute instance, String value) throws Exception { - CustomDatatype datatype = CustomDatatypeUtil.getDatatype(instance.getAttributeType().getDatatypeClassname(), - instance.getAttributeType().getDatatypeConfig()); - if (StringUtils.isNotEmpty(value)) // check empty instead of blank, because " " is meaningful - instance.setValue(datatype.fromReferenceString(value)); - } - - /** - * Gets an attribute value, catching any {@link NotYetPersistedException} and returning null in - * that case - * - * @param instance - * @return - */ - @PropertyGetter("value") - public static Object getValue(Attribute instance) { - try { - return instance.getValue(); - } - catch (NotYetPersistedException ex) { - return null; - } - } - - /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getRepresentationDescription(Representation) - */ - @Override - public DelegatingResourceDescription getRepresentationDescription(Representation rep) { - if (rep instanceof DefaultRepresentation) { - DelegatingResourceDescription description = new DelegatingResourceDescription(); - description.addProperty("display"); - description.addProperty("uuid"); - description.addProperty("attributeType", Representation.REF); - description.addProperty("value"); - description.addProperty("voided"); - description.addSelfLink(); - description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL); - return description; - } else if (rep instanceof FullRepresentation) { - DelegatingResourceDescription description = new DelegatingResourceDescription(); - description.addProperty("display"); - description.addProperty("uuid"); - description.addProperty("attributeType", Representation.REF); - description.addProperty("value"); - description.addProperty("voided"); - description.addProperty("auditInfo"); - description.addSelfLink(); - return description; - } - return null; - } - - @Override - public DelegatingResourceDescription getCreatableProperties() { - DelegatingResourceDescription description = new DelegatingResourceDescription(); - description.addRequiredProperty("attributeType"); - description.addRequiredProperty("value"); - return description; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("attributeType", new StringProperty().example("uuid")) - .property("value", new StringProperty()) - - .required("attributeType").required("value"); - } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("attributeType", new StringProperty()) //FIXME type - .property("value", new StringProperty()) //FIXME type - .property("voided", new BooleanProperty()); - } - return model; - } - - /** - * Gets the display string for an attribute. - * - * @param attr the attribute. - * @return attribute type: value (for concise display purposes) - */ - @PropertyGetter("display") - public String getDisplayString(T attr) { - if (attr.getAttributeType() == null) - return ""; - return attr.getAttributeType().getName() + ": " + attr.getValue(); - } - - /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion() - */ - @Override - public String getResourceVersion() { - return RestConstants2_5.RESOURCE_VERSION; - } - - /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getPropertiesToExposeAsSubResources() - */ - @Override - public List getPropertiesToExposeAsSubResources() { - return Arrays.asList("attributes"); - } -} diff --git a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/BaseAttributeTypeCrudResource2_5.java b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/BaseAttributeTypeCrudResource2_5.java deleted file mode 100644 index 768d6208e..000000000 --- a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/BaseAttributeTypeCrudResource2_5.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * 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 io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.StringProperty; -import org.openmrs.attribute.AttributeType; -import org.openmrs.module.webservices.rest.web.RestConstants; -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.DelegatingResourceDescription; -import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource; - -/** - * Subclass of {@link MetadataDelegatingCrudResource} with helper methods specific to - * {@link AttributeType} - * - * @param - */ -public abstract class BaseAttributeTypeCrudResource2_5> extends MetadataDelegatingCrudResource { - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("minOccurs", new IntegerProperty()) - .property("maxOccurs", new IntegerProperty()) - .property("datatypeClassname", new StringProperty()) - .property("preferredHandlerClassname", new StringProperty()); - } - if (rep instanceof FullRepresentation) { - model - .property("datatypeConfig", new StringProperty()) - .property("handlerConfig", new StringProperty()); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("datatypeClassname", new StringProperty()) - .property("minOccurs", new IntegerProperty()) - .property("maxOccurs", new IntegerProperty()) - .property("datatypeConfig", new StringProperty()) - .property("preferredHandlerClassname", new StringProperty()) - .property("handlerConfig", new StringProperty()) - - .required("datatypeClassname"); - - } - - /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getRepresentationDescription(Representation) - */ - @Override - public DelegatingResourceDescription getRepresentationDescription(Representation rep) { - if (rep instanceof DefaultRepresentation) { - DelegatingResourceDescription description = new DelegatingResourceDescription(); - description.addProperty("uuid"); - description.addProperty("display"); - description.addProperty("name"); - description.addProperty("description"); - description.addProperty("minOccurs"); - description.addProperty("maxOccurs"); - description.addProperty("datatypeClassname"); - description.addProperty("preferredHandlerClassname"); - description.addProperty("retired"); - description.addSelfLink(); - description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL); - return description; - } else if (rep instanceof FullRepresentation) { - DelegatingResourceDescription description = new DelegatingResourceDescription(); - description.addProperty("uuid"); - description.addProperty("display"); - description.addProperty("name"); - description.addProperty("description"); - description.addProperty("minOccurs"); - description.addProperty("maxOccurs"); - description.addProperty("datatypeClassname"); - description.addProperty("datatypeConfig"); - description.addProperty("preferredHandlerClassname"); - description.addProperty("handlerConfig"); - description.addProperty("retired"); - description.addProperty("auditInfo"); - description.addSelfLink(); - return description; - } - return null; - } - - /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() - */ - @Override - public DelegatingResourceDescription getCreatableProperties() { - DelegatingResourceDescription description = new DelegatingResourceDescription(); - description.addRequiredProperty("name"); - description.addRequiredProperty("datatypeClassname"); - description.addProperty("description"); - description.addProperty("minOccurs"); - description.addProperty("maxOccurs"); - description.addProperty("datatypeConfig"); - description.addProperty("preferredHandlerClassname"); - description.addProperty("handlerConfig"); - return description; - } - - /** - * @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/OrderAttributeResource2_5.java b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeResource2_5.java index 16dd55c76..810f16d2c 100644 --- 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 @@ -20,6 +20,7 @@ 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; @@ -29,7 +30,7 @@ */ @SubResource(parent = OrderResource2_5.class, path = "attribute", supportedClass = OrderAttribute.class, supportedOpenmrsVersions = { "2.5.* - 9.*"}) -public class OrderAttributeResource2_5 extends BaseAttributeCrudResource2_5 { +public class OrderAttributeResource2_5 extends BaseAttributeCrudResource1_9 { /** * Sets attributeType on the given OrderAttribute. @@ -91,11 +92,8 @@ public NeedsPaging doGetAll(Order parent, RequestContext context public OrderAttribute save(OrderAttribute delegate) { // make sure it has not already been added to the order boolean needToAdd = true; - for (OrderAttribute orderAttribute : delegate.getOrder().getActiveAttributes()) { - if (orderAttribute.equals(delegate)) { - needToAdd = false; - break; - } + if (delegate.getOrder().getActiveAttributes().contains(delegate)) { + delegate.getOrder().addAttribute(delegate); } if (needToAdd) { delegate.getOrder().addAttribute(delegate); @@ -103,6 +101,7 @@ public OrderAttribute save(OrderAttribute 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; 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 index bbf7aad45..9dcabfadd 100644 --- 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 @@ -17,6 +17,7 @@ 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; @@ -27,7 +28,7 @@ */ @Resource(name = RestConstants.VERSION_1 + "/orderattributetype", supportedClass = OrderAttributeType.class, supportedOpenmrsVersions = { "2.5.* - 9.*" }) -public class OrderAttributeTypeResource2_5 extends BaseAttributeTypeCrudResource2_5 { +public class OrderAttributeTypeResource2_5 extends BaseAttributeTypeCrudResource1_9 { public OrderAttributeTypeResource2_5() { } diff --git a/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderAttributeController2_5Test.java b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderController2_5Test.java similarity index 95% rename from omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderAttributeController2_5Test.java rename to omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderController2_5Test.java index b1854312d..05b47106f 100644 --- a/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderAttributeController2_5Test.java +++ b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_5/OrderController2_5Test.java @@ -19,9 +19,9 @@ /** - * Tests functionality of {@link OrderAttributeController}. + * Tests functionality of {@link OrderController}. */ -public class OrderAttributeController2_5Test extends MainResourceControllerTest { +public class OrderController2_5Test extends MainResourceControllerTest { private OrderService service; 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 index 8fce5135c..c93cca207 100644 --- 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 @@ -9,6 +9,7 @@ */ 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; @@ -16,6 +17,11 @@ 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() { @@ -30,7 +36,7 @@ public void validateFullRepresentation() throws Exception { @Override public String getDisplayProperty() { - return "CD4 COUNT"; + return "ASPIRIN"; } @Override