org.openmrs.api
openmrs-api
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/ChangePasswordController1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ChangePasswordController1_9.java
similarity index 98%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/ChangePasswordController1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ChangePasswordController1_9.java
index abac32aea..c34f992ec 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/ChangePasswordController1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ChangePasswordController1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
@@ -37,7 +37,7 @@
@Controller
@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/password")
-public class ChangePasswordController1_8 extends BaseRestController {
+public class ChangePasswordController1_9 extends BaseRestController {
@Qualifier("userService")
@Autowired
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/HL7MessageController1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/HL7MessageController1_9.java
similarity index 95%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/HL7MessageController1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/HL7MessageController1_9.java
index 4b3344453..6e635c819 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/HL7MessageController1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/HL7MessageController1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9;
import java.io.IOException;
@@ -27,7 +27,7 @@
import org.openmrs.module.webservices.rest.web.response.ResponseException;
import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController;
import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController;
-import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.HL7MessageResource1_8;
+import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9.HL7MessageResource1_9;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
@@ -43,13 +43,13 @@
import ca.uhn.hl7v2.util.Terser;
/**
- * Controller for {@link HL7MessageResource1_8}.
+ * Controller for {@link HL7MessageResource1_9}.
*
* It is provided, because we want to support posting plain HL7 messages in addition to those in
* json.
*/
@Controller
-public class HL7MessageController1_8 extends BaseRestController {
+public class HL7MessageController1_9 extends BaseRestController {
@Autowired
@Qualifier("mainResourceController")
@@ -92,7 +92,7 @@ public Object create(@RequestBody String hl7, HttpServletRequest request, HttpSe
throw new ConversionException(e.getMessage(), e);
}
- Object created = ((HL7MessageResource1_8) Context.getService(RestService.class).getResourceByName(
+ Object created = ((HL7MessageResource1_9) Context.getService(RestService.class).getResourceByName(
RestConstants.VERSION_1 + "/hl7")).create(post, context);
return RestUtil.created(response, created);
}
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/ObsComplexValueController1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ObsComplexValueController1_9.java
similarity index 97%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/ObsComplexValueController1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ObsComplexValueController1_9.java
index ef6ddc4e3..976ea24d3 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/ObsComplexValueController1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/ObsComplexValueController1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.io.IOUtils;
@@ -34,7 +34,7 @@
@Controller
@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/obs")
-public class ObsComplexValueController1_8 extends BaseRestController {
+public class ObsComplexValueController1_9 extends BaseRestController {
@Autowired
ObsService obsService;
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/converter/openmrs1_8/UserConverter1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/converter/openmrs1_9/UserConverter1_9.java
similarity index 85%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/converter/openmrs1_8/UserConverter1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/converter/openmrs1_9/UserConverter1_9.java
index adcffe92a..bfda5df9e 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/converter/openmrs1_8/UserConverter1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/converter/openmrs1_9/UserConverter1_9.java
@@ -7,7 +7,7 @@
* 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.converter.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.converter.openmrs1_9;
import org.openmrs.User;
import org.openmrs.annotation.Handler;
@@ -18,15 +18,15 @@
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.resource.api.Converter;
import org.openmrs.module.webservices.rest.web.response.ConversionException;
-import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.UserResource1_8;
-import org.openmrs.module.webservices.rest.web.v1_0.wrapper.openmrs1_8.UserAndPassword1_8;
+import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9.UserResource1_9;
+import org.openmrs.module.webservices.rest.web.v1_0.wrapper.openmrs1_9.UserAndPassword1_9;
/**
* An implementation of Converter to be able to create a representation from a User when User is
* used in another resource. Currently UserAndPassword doesn't convert User
*/
@Handler(supports = User.class, order = 0)
-public class UserConverter1_8 implements Converter {
+public class UserConverter1_9 implements Converter {
/**
* @see org.openmrs.module.webservices.rest.web.resource.api.Converter#getByUniqueId(java.lang.String)
@@ -50,8 +50,8 @@ public User newInstance(String type) {
*/
@Override
public SimpleObject asRepresentation(User instance, Representation rep) throws ConversionException {
- UserAndPassword1_8 userPass = new UserAndPassword1_8(instance);
- UserResource1_8 userResource = (UserResource1_8) Context.getService(RestService.class).getResourceByName(
+ UserAndPassword1_9 userPass = new UserAndPassword1_9(instance);
+ UserResource1_9 userResource = (UserResource1_9) Context.getService(RestService.class).getResourceByName(
RestConstants.VERSION_1 + "/user");
return userResource.asRepresentation(userPass, rep);
}
@@ -62,8 +62,8 @@ public SimpleObject asRepresentation(User instance, Representation rep) throws C
*/
@Override
public Object getProperty(User instance, String propertyName) throws ConversionException {
- UserAndPassword1_8 userPass = new UserAndPassword1_8(instance);
- UserResource1_8 userResource = (UserResource1_8) Context.getService(RestService.class).getResourceByName(
+ UserAndPassword1_9 userPass = new UserAndPassword1_9(instance);
+ UserResource1_9 userResource = (UserResource1_9) Context.getService(RestService.class).getResourceByName(
RestConstants.VERSION_1 + "/user");
return userResource.getProperty(userPass, propertyName);
}
@@ -74,8 +74,8 @@ public Object getProperty(User instance, String propertyName) throws ConversionE
*/
@Override
public void setProperty(Object instance, String propertyName, Object value) throws ConversionException {
- UserAndPassword1_8 userPass = new UserAndPassword1_8((User) instance);
- UserResource1_8 userResource = (UserResource1_8) Context.getService(RestService.class).getResourceByName(
+ UserAndPassword1_9 userPass = new UserAndPassword1_9((User) instance);
+ UserResource1_9 userResource = (UserResource1_9) Context.getService(RestService.class).getResourceByName(
RestConstants.VERSION_1 + "/user");
userResource.setProperty(userPass, propertyName, value);
}
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ActiveListTypeResource1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ActiveListTypeResource1_9.java
similarity index 96%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ActiveListTypeResource1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ActiveListTypeResource1_9.java
index c12ea2ba3..c4059c702 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ActiveListTypeResource1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ActiveListTypeResource1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import org.openmrs.activelist.ActiveListType;
import org.openmrs.module.webservices.rest.web.RequestContext;
@@ -23,8 +23,8 @@
* {@link Resource} for ActiveListType, supporting standard CRUD operations
*/
@Resource(name = RestConstants.VERSION_1 + "/activelisttype", supportedClass = ActiveListType.class, supportedOpenmrsVersions = {
- "1.8.* - 1.12.*" })
-public class ActiveListTypeResource1_8 extends MetadataDelegatingCrudResource {
+ "1.9.* - 1.12.*" })
+public class ActiveListTypeResource1_9 extends MetadataDelegatingCrudResource {
/**
* @see DelegatingCrudResource#newDelegate()
diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/AllergyResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/AllergyResource1_9.java
index 942126455..588aaeac2 100644
--- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/AllergyResource1_9.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/AllergyResource1_9.java
@@ -9,15 +9,120 @@
*/
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
+import org.openmrs.Patient;
import org.openmrs.activelist.Allergy;
+import org.openmrs.activelist.AllergySeverity;
+import org.openmrs.activelist.AllergyType;
+import org.openmrs.api.context.Context;
+import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty;
+import org.openmrs.module.webservices.rest.web.RequestContext;
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.annotation.Resource;
-import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.AllergyResource1_8;
+import org.openmrs.module.webservices.rest.web.api.RestService;
+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.api.PageableResult;
+import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
+import org.openmrs.module.webservices.rest.web.resource.impl.EmptySearchResult;
+import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9.PatientResource1_9;
+
+import io.swagger.models.Model;
+import io.swagger.models.ModelImpl;
+import io.swagger.models.properties.ObjectProperty;
+import io.swagger.models.properties.RefProperty;
+import io.swagger.models.properties.StringProperty;
@Resource(name = RestConstants.VERSION_1 + "/allergy", supportedClass = Allergy.class, supportedOpenmrsVersions = { "1.9.*",
"1.10.* - 1.12.*" })
-public class AllergyResource1_9 extends AllergyResource1_8 {
+public class AllergyResource1_9 extends BaseActiveListItemResource1_9 {
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation)
+ */
+ @Override
+ public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
+ if (rep instanceof DefaultRepresentation) {
+ DelegatingResourceDescription description = super.getRepresentationDescription(rep);
+ description.addProperty("allergyType");
+ description.addProperty("reaction", Representation.REF);
+ description.addProperty("severity");
+ description.addProperty("allergen", Representation.REF);
+ return description;
+ } else if (rep instanceof FullRepresentation) {
+ DelegatingResourceDescription description = super.getRepresentationDescription(rep);
+ description.addProperty("allergyType");
+ description.addProperty("reaction", Representation.DEFAULT);
+ description.addProperty("severity");
+ description.addProperty("allergen", Representation.DEFAULT);
+ return description;
+ }
+ return null;
+ }
+
+ @Override
+ public Model getGETModel(Representation rep) {
+ ModelImpl model = ((ModelImpl) super.getGETModel(rep))
+ .property("allergyType", new EnumProperty(AllergyType.class))
+ .property("reaction", new RefProperty("#/definitions/ConceptGetRef"))
+ .property("severity", new EnumProperty(AllergySeverity.class))
+ .property("allergen", new RefProperty("#/definitions/ConceptGetRef"));
+ if (rep instanceof FullRepresentation) {
+ model
+ .property("reaction", new RefProperty("#/definitions/ConceptGet"))
+ .property("allergen", new RefProperty("#/definitions/ConceptGet"));
+ }
+ return model;
+ }
+
+ @Override
+ public Model getCREATEModel(Representation rep) {
+ return ((ModelImpl) super.getCREATEModel(rep))
+ .property("allergyType", new EnumProperty(AllergyType.class))
+ .property("reaction", new ObjectProperty()
+ .property("uuid", new StringProperty()))
+ .property("severity", new EnumProperty(AllergySeverity.class))
+ .property("allergen", new StringProperty());
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate()
+ */
+ @Override
+ public Allergy newDelegate() {
+ return new Allergy();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties()
+ */
+ @Override
+ public DelegatingResourceDescription getCreatableProperties() {
+ DelegatingResourceDescription description = super.getCreatableProperties();
+ description.addRequiredProperty("allergyType");
+ description.addRequiredProperty("allergen");
+ description.addProperty("reaction");
+ description.addProperty("severity");
+
+ return description;
+ }
+
+ /**
+ * Display string for allergy
+ *
+ * @param allergy
+ * @return String ConceptName
+ */
+ @PropertyGetter("display")
+ public String getDisplayString(Allergy allergy) {
+ if (allergy.getAllergen() == null)
+ return "";
+
+ return allergy.getAllergen().getName().toString();
+ }
/**
* Annotated setter for allergen
@@ -29,4 +134,27 @@ public class AllergyResource1_9 extends AllergyResource1_8 {
public static void setAllergen(Allergy allergy, Object value) {
allergy.setAllergen(new ConceptResource1_9().getByUniqueId((String) value));
}
+
+ /**
+ * Gets allergies for a given patient (paged according to context if necessary) only if a
+ * patient parameter exists in the request set on the {@link RequestContext}
+ *
+ * @param context
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(RequestContext)
+ */
+ @Override
+ protected PageableResult doSearch(RequestContext context) {
+ String patientUuid = context.getRequest().getParameter("patient");
+ if (patientUuid != null) {
+ Patient patient = ((PatientResource1_9) Context.getService(RestService.class).getResourceBySupportedClass(
+ Patient.class)).getByUniqueId(patientUuid);
+ if (patient == null)
+ return new EmptySearchResult();
+
+ return new NeedsPaging(Context.getPatientService().getAllergies(patient), context);
+ }
+
+ //currently this is not supported since the superclass throws an exception
+ return super.doSearch(context);
+ }
}
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/BaseActiveListItemResource1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseActiveListItemResource1_9.java
similarity index 99%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/BaseActiveListItemResource1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseActiveListItemResource1_9.java
index 9ef1b74c0..64b1d4df9 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/BaseActiveListItemResource1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseActiveListItemResource1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
@@ -30,7 +30,7 @@
* Subclass of {@link DataDelegatingCrudResource} with helper methods specific to
* {@link ActiveListItem}
*/
-public abstract class BaseActiveListItemResource1_8 extends DataDelegatingCrudResource {
+public abstract class BaseActiveListItemResource1_9 extends DataDelegatingCrudResource {
@Override
public Model getCREATEModel(Representation rep) {
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortMemberResource1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CohortMemberResource1_9.java
similarity index 87%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortMemberResource1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CohortMemberResource1_9.java
index e062d1db3..1983d97b9 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortMemberResource1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CohortMemberResource1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import java.util.ArrayList;
import java.util.List;
@@ -36,33 +36,33 @@
import org.openmrs.module.webservices.rest.web.response.ObjectNotFoundException;
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
import org.openmrs.module.webservices.rest.web.response.ResponseException;
-import org.openmrs.module.webservices.rest.web.v1_0.wrapper.openmrs1_8.CohortMember1_8;
+import org.openmrs.module.webservices.rest.web.v1_0.wrapper.openmrs1_9.CohortMember1_9;
/**
* Sub-resource for cohort members
*/
-@SubResource(parent = CohortResource1_8.class, path = "member", supportedClass = CohortMember1_8.class, supportedOpenmrsVersions = {
- "1.8.* - 2.0.*" })
-public class CohortMemberResource1_8 extends DelegatingSubResource {
+@SubResource(parent = CohortResource1_9.class, path = "member", supportedClass = CohortMember1_9.class, supportedOpenmrsVersions = {
+ "1.9.* - 2.0.*" })
+public class CohortMemberResource1_9 extends DelegatingSubResource {
/**
* @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(Cohort parent, RequestContext context) throws ResponseException {
- List members = new ArrayList();
+ public NeedsPaging doGetAll(Cohort parent, RequestContext context) throws ResponseException {
+ List members = new ArrayList();
for (Patient cohortMember : Context.getService(RestHelperService.class).getPatients(parent.getMemberIds())) {
- members.add(new CohortMember1_8(cohortMember, parent));
+ members.add(new CohortMember1_9(cohortMember, parent));
}
- return new NeedsPaging(members, context);
+ return new NeedsPaging(members, context);
}
/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#getParent(java.lang.Object)
*/
@Override
- public Cohort getParent(CohortMember1_8 instance) {
+ public Cohort getParent(CohortMember1_9 instance) {
return instance.getCohort();
}
@@ -71,7 +71,7 @@ public Cohort getParent(CohortMember1_8 instance) {
* java.lang.Object)
*/
@Override
- public void setParent(CohortMember1_8 instance, Cohort parent) {
+ public void setParent(CohortMember1_9 instance, Cohort parent) {
instance.setCohort(parent);
}
@@ -80,7 +80,7 @@ public void setParent(CohortMember1_8 instance, Cohort parent) {
* java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext)
*/
@Override
- protected void delete(CohortMember1_8 delegate, String reason, RequestContext context) throws ResponseException {
+ protected void delete(CohortMember1_9 delegate, String reason, RequestContext context) throws ResponseException {
removeMemberFromCohort(delegate);
}
@@ -88,8 +88,8 @@ protected void delete(CohortMember1_8 delegate, String reason, RequestContext co
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String)
*/
@Override
- public CohortMember1_8 getByUniqueId(String uniqueId) {
- return new CohortMember1_8(Context.getPatientService().getPatientByUuid(uniqueId), null);
+ public CohortMember1_9 getByUniqueId(String uniqueId) {
+ return new CohortMember1_9(Context.getPatientService().getPatientByUuid(uniqueId), null);
}
/**
@@ -175,8 +175,8 @@ public DelegatingResourceDescription getUpdatableProperties() {
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate()
*/
@Override
- public CohortMember1_8 newDelegate() {
- return new CohortMember1_8();
+ public CohortMember1_9 newDelegate() {
+ return new CohortMember1_9();
}
/**
@@ -184,7 +184,7 @@ public CohortMember1_8 newDelegate() {
* org.openmrs.module.webservices.rest.web.RequestContext)
*/
@Override
- public void purge(CohortMember1_8 delegate, RequestContext context) throws ResponseException {
+ public void purge(CohortMember1_9 delegate, RequestContext context) throws ResponseException {
throw new ResourceDoesNotSupportOperationException();
}
@@ -192,7 +192,7 @@ public void purge(CohortMember1_8 delegate, RequestContext context) throws Respo
* Should add patient to cohort
*/
@Override
- public CohortMember1_8 save(CohortMember1_8 delegate) {
+ public CohortMember1_9 save(CohortMember1_9 delegate) {
addMemberToCohort(delegate);
return delegate;
}
@@ -200,7 +200,7 @@ public CohortMember1_8 save(CohortMember1_8 delegate) {
/**
* @param member the patient to be added to cohort
*/
- public void addMemberToCohort(CohortMember1_8 member) {
+ public void addMemberToCohort(CohortMember1_9 member) {
getParent(member).addMember(member.getPatient().getId());
Context.getCohortService().saveCohort(getParent(member));
}
@@ -208,7 +208,7 @@ public void addMemberToCohort(CohortMember1_8 member) {
/**
* @param member the patient to be removed from cohort
*/
- public void removeMemberFromCohort(CohortMember1_8 member) {
+ public void removeMemberFromCohort(CohortMember1_9 member) {
getParent(member).removeMember(member.getPatient().getId());
Context.getCohortService().saveCohort(getParent(member));
}
@@ -221,7 +221,7 @@ public void removeMemberFromCohort(CohortMember1_8 member) {
@Override
public Object create(String parentUniqueId, SimpleObject post, RequestContext context) throws ResponseException {
Cohort parent = Context.getCohortService().getCohortByUuid(parentUniqueId);
- CohortMember1_8 delegate = newDelegate();
+ CohortMember1_9 delegate = newDelegate();
setParent(delegate, parent);
delegate.setPatient(Context.getPatientService().getPatientByUuid(post.get("patient").toString()));
delegate = save(delegate);
@@ -235,7 +235,7 @@ public Object create(String parentUniqueId, SimpleObject post, RequestContext co
*/
@Override
public void delete(String parentUniqueId, String uuid, String reason, RequestContext context) throws ResponseException {
- CohortMember1_8 delegate = getByUniqueId(uuid);
+ CohortMember1_9 delegate = getByUniqueId(uuid);
if (delegate == null)
throw new ObjectNotFoundException();
Cohort parent = Context.getCohortService().getCohortByUuid(parentUniqueId);
@@ -249,7 +249,7 @@ public void delete(String parentUniqueId, String uuid, String reason, RequestCon
*/
@Override
public Object retrieve(String parentUniqueId, String uuid, RequestContext context) throws ResponseException {
- CohortMember1_8 delegate = getByUniqueId(uuid);
+ CohortMember1_9 delegate = getByUniqueId(uuid);
if (delegate == null)
throw new ObjectNotFoundException();
delegate.setCohort(Context.getCohortService().getCohortByUuid(parentUniqueId));
@@ -262,7 +262,7 @@ public Object retrieve(String parentUniqueId, String uuid, RequestContext contex
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUniqueId(java.lang.Object)
*/
@Override
- protected String getUniqueId(CohortMember1_8 delegate) {
+ protected String getUniqueId(CohortMember1_9 delegate) {
return delegate.getPatient().getUuid();
}
@@ -271,7 +271,7 @@ protected String getUniqueId(CohortMember1_8 delegate) {
* @return string that contains cohort member's identifier and full name
*/
@PropertyGetter("display")
- public String getDisplayString(CohortMember1_8 member) {
+ public String getDisplayString(CohortMember1_9 member) {
if (member.getPatient().getPatientIdentifier() == null)
return "";
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortResource1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CohortResource1_9.java
similarity index 98%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortResource1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CohortResource1_9.java
index ff12bc660..0ec72e021 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortResource1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CohortResource1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import java.util.List;
@@ -33,8 +33,8 @@
/**
* {@link Resource} for Cohorts, supporting standard CRUD operations
*/
-@Resource(name = RestConstants.VERSION_1 + "/cohort", supportedClass = Cohort.class, supportedOpenmrsVersions = { "1.8.* - 2.0.*" })
-public class CohortResource1_8 extends DataDelegatingCrudResource {
+@Resource(name = RestConstants.VERSION_1 + "/cohort", supportedClass = Cohort.class, supportedOpenmrsVersions = { "1.9.* - 2.0.*" })
+public class CohortResource1_9 extends DataDelegatingCrudResource {
/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#delete(java.lang.Object,
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptClassResource1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptClassResource1_9.java
similarity index 96%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptClassResource1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptClassResource1_9.java
index e4a8e25a0..2ec231b56 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptClassResource1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptClassResource1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import io.swagger.models.Model;
import org.openmrs.ConceptClass;
@@ -25,8 +25,8 @@
* {@link Resource} for {@link ConceptClass}, supporting standard CRUD operations
*/
@Resource(name = RestConstants.VERSION_1 + "/conceptclass", supportedClass = ConceptClass.class, supportedOpenmrsVersions = {
- "1.8.* - 9.*" })
-public class ConceptClassResource1_8 extends MetadataDelegatingCrudResource {
+ "1.9.* - 9.*" })
+public class ConceptClassResource1_9 extends MetadataDelegatingCrudResource {
/**
* @see DelegatingCrudResource#newDelegate()
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDatatypeResource1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptDatatypeResource1_9.java
similarity index 98%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDatatypeResource1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptDatatypeResource1_9.java
index 0de73cceb..ca6203c27 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDatatypeResource1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptDatatypeResource1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
@@ -33,8 +33,8 @@
* {@link Resource} for {@link ConceptDatatype}, supporting standard CRUD operations
*/
@Resource(name = RestConstants.VERSION_1 + "/conceptdatatype", supportedClass = ConceptDatatype.class, supportedOpenmrsVersions = {
- "1.8.* - 1.12.*" })
-public class ConceptDatatypeResource1_8 extends MetadataDelegatingCrudResource {
+ "1.9.* - 1.12.*" })
+public class ConceptDatatypeResource1_9 extends MetadataDelegatingCrudResource {
/**
* @see DelegatingCrudResource#getRepresentationDescription(Representation)
diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptDescriptionResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptDescriptionResource1_9.java
index e6d3a3d27..1516d6cf2 100644
--- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptDescriptionResource1_9.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptDescriptionResource1_9.java
@@ -9,16 +9,209 @@
*/
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
+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.PropertyGetter;
import org.openmrs.module.webservices.rest.web.annotation.SubResource;
-import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.ConceptDescriptionResource1_8;
+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.RefRepresentation;
+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.DelegatingSubResource;
+import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+import io.swagger.models.Model;
+import io.swagger.models.ModelImpl;
+import io.swagger.models.properties.StringProperty;
/**
* Implemented to increase the resource version.
*/
@SubResource(parent = ConceptResource1_9.class, path = "description", supportedClass = ConceptDescription.class, supportedOpenmrsVersions = {
"1.9.* - 9.*" })
-public class ConceptDescriptionResource1_9 extends ConceptDescriptionResource1_8 {
+public class ConceptDescriptionResource1_9 extends DelegatingSubResource {
+
+ @Override
+ public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
+ if (rep instanceof RefRepresentation) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("display");
+ description.addSelfLink();
+ return description;
+ } else if (rep instanceof DefaultRepresentation) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("display");
+ description.addProperty("uuid");
+ description.addProperty("description");
+ description.addProperty("locale");
+ 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("description");
+ description.addProperty("locale");
+ description.addProperty("auditInfo");
+ description.addSelfLink();
+ return description;
+ }
+ return null;
+ }
+
+ public Model getGETModel(Representation rep) {
+ ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep);
+ if (rep instanceof RefRepresentation) {
+ modelImpl
+ .property("uuid", new StringProperty())
+ .property("display", new StringProperty());
+ } else if (rep instanceof DefaultRepresentation) {
+ modelImpl
+ .property("uuid", new StringProperty())
+ .property("display", new StringProperty())
+ .property("description", new StringProperty())
+ .property("locale", new StringProperty());
+ } else if (rep instanceof FullRepresentation) {
+ modelImpl
+ .property("uuid", new StringProperty())
+ .property("display", new StringProperty())
+ .property("description", new StringProperty())
+ .property("locale", new StringProperty());
+ }
+ return modelImpl;
+ }
+
+ @Override
+ public Model getCREATEModel(Representation representation) {
+ return new ModelImpl()
+ .property("description", new StringProperty())
+ .property("locale", new StringProperty().example("fr"))
+ .required("description").required("locale");
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties()
+ */
+ @Override
+ public DelegatingResourceDescription getCreatableProperties() {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addRequiredProperty("description");
+ description.addRequiredProperty("locale");
+ return description;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#getParent(java.lang.Object)
+ */
+ @Override
+ public Concept getParent(ConceptDescription instance) {
+ return instance.getConcept();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#setParent(java.lang.Object,
+ * java.lang.Object)
+ */
+ @Override
+ public void setParent(ConceptDescription instance, Concept concept) {
+ instance.setConcept(concept);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.api.SubResource#doGetAll(java.lang.Object,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public NeedsPaging doGetAll(Concept parent, RequestContext context) throws ResponseException {
+ //convert from a collection to a list
+ List descriptions = new ArrayList();
+ if (parent != null) {
+ for (ConceptDescription description : parent.getDescriptions()) {
+ descriptions.add(description);
+ }
+ }
+ return new NeedsPaging(descriptions, context);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String)
+ */
+ @Override
+ public ConceptDescription getByUniqueId(String uuid) {
+ return Context.getConceptService().getConceptDescriptionByUuid(uuid);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#delete(java.lang.Object,
+ * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public void delete(ConceptDescription cd, String reason, RequestContext context) throws ResponseException {
+ //concept descriptions are neither voidable nor retireable, so delegate to purge
+ purge(cd, context);
+ }
+
+ /**
+ * @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(ConceptDescription cd, RequestContext context) throws ResponseException {
+ cd.getConcept().removeDescription(cd);
+ Context.getConceptService().saveConcept(cd.getConcept());
+ }
+
+ /**
+ * @param newDescription
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object)
+ */
+ @Override
+ public ConceptDescription save(ConceptDescription newDescription) {
+ newDescription.getConcept().addDescription(newDescription);
+ Context.getConceptService().saveConcept(newDescription.getConcept());
+ return newDescription;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate()
+ */
+ @Override
+ public ConceptDescription newDelegate() {
+ return new ConceptDescription();
+ }
+
+ /**
+ * Gets the display string for a concept description including its locale.
+ *
+ * @param conceptDescription the concept description object.
+ * @return the display string.
+ */
+ @PropertyGetter("display")
+ public String getDisplayString(ConceptDescription conceptDescription) {
+ return conceptDescription.getDescription();
+ }
+
+ /**
+ * Returns the locale as a string
+ *
+ * @param instance
+ * @return
+ */
+ @PropertyGetter("locale")
+ public String getLocaleAsString(ConceptDescription instance) {
+ if (instance.getLocale() == null)
+ return "";
+
+ return instance.getLocale().toString();
+ }
/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion()
diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapResource1_9.java
index 420153e67..e204b1826 100644
--- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapResource1_9.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapResource1_9.java
@@ -12,25 +12,36 @@
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.RefProperty;
+
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.commons.lang.StringUtils;
+import org.openmrs.Concept;
import org.openmrs.ConceptMap;
+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.PropertyGetter;
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.api.RestHelperService;
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.api.PageableResult;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
-import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.ConceptMapResource1_8;
-import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.ConceptResource1_8;
+import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource;
+import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
/**
* {@link Resource} for {@link ConceptMap}, supporting standard CRUD operations
*/
-@SubResource(path = "mapping", parent = ConceptResource1_8.class, supportedClass = ConceptMap.class, supportedOpenmrsVersions = {
+@SubResource(path = "mapping", parent = ConceptResource1_9.class, supportedClass = ConceptMap.class, supportedOpenmrsVersions = {
"1.9.* - 9.*" })
-public class ConceptMapResource1_9 extends ConceptMapResource1_8 {
+public class ConceptMapResource1_9 extends DelegatingSubResource {
@Override
public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
@@ -108,7 +119,6 @@ public String getResourceVersion() {
* @param conceptMap the concept map object.
* @return the display string.
*/
- @Override
@PropertyGetter("display")
public String getDisplayString(ConceptMap conceptMap) {
if (conceptMap.getConceptReferenceTerm() == null || conceptMap.getConceptReferenceTerm().getConceptSource() == null) {
@@ -122,4 +132,75 @@ public String getDisplayString(ConceptMap conceptMap) {
}
return display;
}
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#newDelegate()
+ */
+ @Override
+ public ConceptMap newDelegate() {
+ return new ConceptMap();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object)
+ */
+ @Override
+ public ConceptMap save(ConceptMap newMap) {
+ newMap.getConcept().addConceptMapping(newMap);
+ Context.getConceptService().saveConcept(newMap.getConcept());
+ return newMap;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#getParent(java.lang.Object)
+ */
+ @Override
+ public Concept getParent(ConceptMap instance) {
+ return instance.getConcept();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#setParent(java.lang.Object,
+ * java.lang.Object)
+ */
+ @Override
+ public void setParent(ConceptMap instance, Concept parent) {
+ instance.setConcept(parent);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#doGetAll(java.lang.Object,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public PageableResult doGetAll(Concept parent, RequestContext context) throws ResponseException {
+ List maps = new ArrayList(parent.getConceptMappings());
+ return new NeedsPaging(maps, context);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String)
+ */
+ @Override
+ public ConceptMap getByUniqueId(String uniqueId) {
+ return Context.getService(RestHelperService.class).getObjectByUuid(ConceptMap.class, uniqueId);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#delete(java.lang.Object,
+ * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ protected void delete(ConceptMap delegate, String reason, RequestContext context) throws ResponseException {
+ throw new ResourceDoesNotSupportOperationException();
+ }
+
+ /**
+ * @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(ConceptMap delegate, RequestContext context) throws ResponseException {
+ delegate.getConcept().removeConceptMapping(delegate);
+ }
}
diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptNameResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptNameResource1_9.java
index f096b5e4d..ab27cb374 100644
--- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptNameResource1_9.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptNameResource1_9.java
@@ -9,16 +9,226 @@
*/
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.openmrs.Concept;
import org.openmrs.ConceptName;
+import org.openmrs.api.ConceptNameType;
+import org.openmrs.api.context.Context;
+import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty;
+import org.openmrs.module.webservices.rest.web.RequestContext;
+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.SubResource;
-import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.ConceptNameResource1_8;
+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.DelegatingSubResource;
+import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+import io.swagger.models.Model;
+import io.swagger.models.ModelImpl;
+import io.swagger.models.properties.BooleanProperty;
+import io.swagger.models.properties.StringProperty;
/**
* Implemented to increase the resource version.
*/
@SubResource(parent = ConceptResource1_9.class, path = "name", supportedClass = ConceptName.class, supportedOpenmrsVersions = {
"1.9.* - 9.*" })
-public class ConceptNameResource1_9 extends ConceptNameResource1_8 {
+public class ConceptNameResource1_9 extends DelegatingSubResource {
+
+ @Override
+ public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
+ if (rep instanceof DefaultRepresentation) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("display");
+ description.addProperty("uuid");
+ description.addProperty("name");
+ description.addProperty("locale");
+ description.addProperty("localePreferred");
+ description.addProperty("conceptNameType");
+ 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("name");
+ description.addProperty("locale");
+ description.addProperty("localePreferred");
+ description.addProperty("conceptNameType");
+ description.addProperty("auditInfo");
+ description.addSelfLink();
+ return description;
+ }
+ return null;
+ }
+
+ public Model getGETModel(Representation rep) {
+ ModelImpl model = ((ModelImpl) super.getGETModel(rep))
+ .property("uuid", new StringProperty())
+ .property("display", new StringProperty());
+
+ if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) {
+ model
+ .property("name", new StringProperty())
+ .property("locale", new StringProperty().example("en"))
+ .property("localePreferred", new BooleanProperty())
+ .property("conceptNameType", new EnumProperty(ConceptNameType.class));
+ }
+ return model;
+ }
+
+ @Override
+ public Model getCREATEModel(Representation rep) {
+ return new ModelImpl()
+ .property("name", new StringProperty())
+ .property("locale", new StringProperty().example("en"))
+ .property("localePreferred", new BooleanProperty()._default(false))
+ .property("conceptNameType", new EnumProperty(ConceptNameType.class))
+ .required("name").required("locale");
+ }
+
+ @Override
+ public Model getUPDATEModel(Representation representation) {
+ return new ModelImpl()
+ .property("name", new StringProperty()); //FIXME missing props
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties()
+ */
+ @Override
+ public DelegatingResourceDescription getCreatableProperties() {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addRequiredProperty("name");
+ description.addRequiredProperty("locale");
+ description.addProperty("localePreferred");
+ description.addProperty("conceptNameType");
+ return description;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#getParent(java.lang.Object)
+ */
+ @Override
+ public Concept getParent(ConceptName instance) {
+ return instance.getConcept();
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#setParent(java.lang.Object,
+ * java.lang.Object)
+ */
+ @Override
+ public void setParent(ConceptName instance, Concept concept) {
+ instance.setConcept(concept);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.api.SubResource#doGetAll(java.lang.Object,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public NeedsPaging doGetAll(Concept parent, RequestContext context) throws ResponseException {
+ List names = new ArrayList();
+ if (parent != null) {
+ for (ConceptName name : parent.getNames()) {
+ if (!name.isVoided())
+ names.add(name);
+ }
+ }
+ return new NeedsPaging(names, context);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String)
+ */
+ @Override
+ public ConceptName getByUniqueId(String uuid) {
+ return Context.getConceptService().getConceptNameByUuid(uuid);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#delete(java.lang.Object,
+ * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public void delete(ConceptName cn, String reason, RequestContext context) throws ResponseException {
+ cn.setVoided(true);
+ cn.setVoidedBy(Context.getAuthenticatedUser());
+ cn.setVoidReason(reason);
+ cn.setDateVoided(new Date());
+ Context.getConceptService().saveConcept(cn.getConcept());
+ }
+
+ /**
+ * @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(ConceptName cn, RequestContext context) throws ResponseException {
+ cn.getConcept().removeName(cn);
+ Context.getConceptService().saveConcept(cn.getConcept());
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object)
+ */
+ @Override
+ public ConceptName save(ConceptName newName) {
+ // make sure that the name has actually been added to the concept
+ boolean needToAdd = true;
+ for (ConceptName cn : newName.getConcept().getNames()) {
+ if (cn.equals(newName)) {
+ needToAdd = false;
+ break;
+ }
+ }
+ if (needToAdd)
+ newName.getConcept().addName(newName);
+ Context.getConceptService().saveConcept(newName.getConcept());
+ return newName;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate()
+ */
+ @Override
+ public ConceptName newDelegate() {
+ return new ConceptName();
+ }
+
+ /**
+ * Gets the display string for a concept name.
+ *
+ * @param conceptName the concept name object.
+ * @return the display string.
+ */
+ @PropertyGetter("display")
+ public String getDisplayString(ConceptName conceptName) {
+ return conceptName.getName();
+ }
+
+ /**
+ * Gets the locale as a string
+ *
+ * @param instance
+ * @return
+ */
+ @PropertyGetter("locale")
+ public String getLocaleAsString(ConceptName instance) {
+
+ if (instance.getLocale() == null)
+ return "";
+
+ return instance.getLocale().toString();
+ }
/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion()
diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptResource1_9.java
index e612e9aee..984e592b4 100644
--- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptResource1_9.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptResource1_9.java
@@ -9,18 +9,504 @@
*/
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
import org.openmrs.Concept;
+import org.openmrs.ConceptAnswer;
+import org.openmrs.ConceptClass;
+import org.openmrs.ConceptDatatype;
+import org.openmrs.ConceptDescription;
+import org.openmrs.ConceptMap;
+import org.openmrs.ConceptName;
+import org.openmrs.ConceptNumeric;
+import org.openmrs.ConceptSearchResult;
+import org.openmrs.Drug;
+import org.openmrs.OpenmrsObject;
+import org.openmrs.api.ConceptService;
import org.openmrs.api.context.Context;
+import org.openmrs.module.webservices.helper.HibernateCollectionHelper;
+import org.openmrs.module.webservices.rest.SimpleObject;
+import org.openmrs.module.webservices.rest.web.ConversionUtil;
+import org.openmrs.module.webservices.rest.web.RequestContext;
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.annotation.RepHandler;
import org.openmrs.module.webservices.rest.web.annotation.Resource;
-import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.ConceptResource1_8;
+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.NamedRepresentation;
+import org.openmrs.module.webservices.rest.web.representation.RefRepresentation;
+import org.openmrs.module.webservices.rest.web.representation.Representation;
+import org.openmrs.module.webservices.rest.web.resource.api.PageableResult;
+import org.openmrs.module.webservices.rest.web.resource.impl.AlreadyPaged;
+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.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.response.ConversionException;
+import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+import org.openmrs.util.LocaleUtility;
+
+import io.swagger.models.Model;
+import io.swagger.models.ModelImpl;
+import io.swagger.models.properties.ArrayProperty;
+import io.swagger.models.properties.BooleanProperty;
+import io.swagger.models.properties.ObjectProperty;
+import io.swagger.models.properties.RefProperty;
+import io.swagger.models.properties.StringProperty;
+import org.openmrs.util.OpenmrsUtil;
/**
* Implemented to increase the resource version since the mapping subresource changed.
*/
@Resource(name = RestConstants.VERSION_1 + "/concept", order = 1, supportedClass = Concept.class, supportedOpenmrsVersions = {
"1.9.* - 1.10.*" })
-public class ConceptResource1_9 extends ConceptResource1_8 {
+public class ConceptResource1_9 extends DelegatingCrudResource {
+
+ public ConceptResource1_9() {
+ //RESTWS-439
+ //Concept numeric fields
+ allowedMissingProperties.add("hiNormal");
+ allowedMissingProperties.add("hiAbsolute");
+ allowedMissingProperties.add("hiCritical");
+ allowedMissingProperties.add("lowNormal");
+ allowedMissingProperties.add("lowAbsolute");
+ allowedMissingProperties.add("lowCritical");
+ allowedMissingProperties.add("units");
+ allowedMissingProperties.add("precise");
+ allowedMissingProperties.add("allowDecimal");
+ allowedMissingProperties.add("displayPrecision");
+ }
+
+ @RepHandler(RefRepresentation.class)
+ public SimpleObject asRef(Concept delegate) throws ConversionException {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("display", "displayString", Representation.DEFAULT);
+ if (delegate.isRetired()) {
+ description.addProperty("retired");
+ }
+ description.addSelfLink();
+ return convertDelegateToRepresentation(delegate, description);
+ }
+
+ @RepHandler(FullRepresentation.class)
+ public SimpleObject asFull(Concept delegate) throws ConversionException {
+ DelegatingResourceDescription description = fullRepresentationDescription(delegate);
+ return convertDelegateToRepresentation(delegate, description);
+ }
+
+ @RepHandler(value = NamedRepresentation.class, name = "fullchildren")
+ public SimpleObject asFullChildren(Concept delegate) throws ConversionException {
+ Set path = new HashSet();
+ path.add(delegate.getUuid());
+ assertNoCycles(delegate, path);
+
+ return asFullChildrenInternal(delegate);
+ }
+
+ protected void assertNoCycles(Concept delegate, Set path) throws ConversionException {
+ for (Concept member : delegate.getSetMembers()) {
+ if (path.add(member.getUuid())) {
+ assertNoCycles(member, path);
+ } else {
+ throw new ConversionException("Cycles in children are not supported. Concept with uuid "
+ + delegate.getUuid() + " repeats in a set.");
+ }
+ path.remove(member.getUuid());
+ }
+ }
+
+ /**
+ * It is used internally for the fullchildren representation. Contrary to the fullchildren
+ * handler it does not check for cycles.
+ *
+ * @param delegate
+ * @return
+ * @throws ConversionException
+ */
+ @RepHandler(value = NamedRepresentation.class, name = "fullchildreninternal")
+ public SimpleObject asFullChildrenInternal(Concept delegate) throws ConversionException {
+ DelegatingResourceDescription description = fullRepresentationDescription(delegate);
+ description.removeProperty("setMembers");
+ description.addProperty("setMembers", new NamedRepresentation("fullchildreninternal"));
+ description.removeProperty("answers");
+ description.addProperty("answers", Representation.FULL);
+ return convertDelegateToRepresentation(delegate, description);
+ }
+
+ @Override
+ public List getAvailableRepresentations() {
+ List availableRepresentations = super.getAvailableRepresentations();
+ availableRepresentations.add(new NamedRepresentation("fullchildren"));
+ return availableRepresentations;
+ }
+
+ protected DelegatingResourceDescription fullRepresentationDescription(Concept delegate) {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("display");
+ description.addProperty("name", Representation.DEFAULT);
+ description.addProperty("datatype", Representation.DEFAULT);
+ description.addProperty("conceptClass", Representation.DEFAULT);
+ description.addProperty("set");
+ description.addProperty("version");
+ description.addProperty("retired");
+
+ description.addProperty("names", Representation.DEFAULT);
+ description.addProperty("descriptions", Representation.DEFAULT);
+
+ description.addProperty("mappings", Representation.DEFAULT);
+
+ description.addProperty("answers", Representation.DEFAULT);
+ description.addProperty("setMembers", Representation.DEFAULT);
+ description.addProperty("auditInfo");
+ description.addSelfLink();
+
+ if (delegate.isNumeric()) {
+ description.addProperty("hiNormal");
+ description.addProperty("hiAbsolute");
+ description.addProperty("hiCritical");
+ description.addProperty("lowNormal");
+ description.addProperty("lowAbsolute");
+ description.addProperty("lowCritical");
+ description.addProperty("units");
+ description.addProperty("precise");
+ }
+ return description;
+ }
+
+ /**
+ * @see DelegatingCrudResource#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", Representation.DEFAULT);
+ description.addProperty("datatype", Representation.REF);
+ description.addProperty("conceptClass", Representation.REF);
+ description.addProperty("set");
+ description.addProperty("version");
+ description.addProperty("retired");
+
+ description.addProperty("names", Representation.REF);
+ description.addProperty("descriptions", Representation.REF);
+
+ description.addProperty("mappings", Representation.REF);
+
+ description.addProperty("answers", Representation.REF);
+ description.addProperty("setMembers", Representation.REF);
+ //description.addProperty("conceptMappings", Representation.REF); add as subresource
+
+ description.addSelfLink();
+ description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
+ return description;
+ }
+ return null;
+ }
+
+ public Model getGETModel(Representation rep) {
+ ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep))
+ .property("uuid", new StringProperty())
+ .property("display", new StringProperty());
+ if (rep instanceof DefaultRepresentation) {
+ modelImpl
+ .property("name", new RefProperty("#/definitions/ConceptNameGet"))
+ .property("datatype", new RefProperty("#/definitions/ConceptdatatypeGetRef"))
+ .property("conceptClass", new RefProperty("#/definitions/ConceptclassGetRef"))
+ .property("set", new BooleanProperty())
+ .property("version", new StringProperty())
+ .property("retired", new BooleanProperty())
+ .property("names", new ArrayProperty(new RefProperty("#/definitions/ConceptNameGetRef"))) //FIXME
+ .property("descriptions", new ArrayProperty(new RefProperty("#/definitions/ConceptDescriptionGetRef"))) //FIXME
+ .property("mappings", new ArrayProperty(new RefProperty("#/definitions/ConceptMappingGetRef"))) //FIXME
+ .property("answers", new ArrayProperty(new ObjectProperty())) //FIXME
+ .property("setMembers", new ArrayProperty(new ObjectProperty())); //FIXME
+ }
+ return modelImpl;
+ }
+
+ @Override
+ public Model getCREATEModel(Representation rep) {
+ ModelImpl model = new ModelImpl()
+ .property("names", new ArrayProperty(new RefProperty("#/definitions/ConceptNameCreate")))
+ .property("datatype", new StringProperty().example("uuid"))
+ .property("set", new BooleanProperty())
+ .property("version", new StringProperty())
+ .property("answers", new ArrayProperty(new StringProperty().example("uuid")))
+ .property("setMembers", new ArrayProperty(new StringProperty().example("uuid")))
+
+ //ConceptNumeric properties
+ .property("hiNormal", new StringProperty())
+ .property("hiAbsolute", new StringProperty())
+ .property("hiCritical", new StringProperty())
+ .property("lowNormal", new StringProperty())
+ .property("lowAbsolute", new StringProperty())
+ .property("lowCritical", new StringProperty())
+ .property("units", new StringProperty())
+ .property("allowDecimal", new StringProperty())
+ .property("displayPrecision", new StringProperty())
+
+ .required("names").required("datatype").required("conceptClass");
+ if (rep instanceof DefaultRepresentation) {
+ model
+ .property("conceptClass", new StringProperty())
+ .property("descriptions", new ArrayProperty(new StringProperty()))
+ .property("mappings", new ArrayProperty(new StringProperty()));
+ }
+ else if (rep instanceof FullRepresentation) {
+ model
+ .property("conceptClass", new RefProperty("#/definitions/ConceptclassCreate"))
+ .property("descriptions", new ArrayProperty(new RefProperty("#/definitions/ConceptDescriptionCreate")))
+ .property("mappings", new ArrayProperty(new RefProperty("#/definitions/ConceptMappingCreate")));
+ }
+ return model;
+ }
+
+ @Override
+ public Model getUPDATEModel(Representation representation) {
+ return new ModelImpl()
+ .property("name", new RefProperty("#/definitions/ConceptNameCreate"))
+ .property("names", new ArrayProperty(new RefProperty("#/definitions/ConceptNameCreate")))
+ .property("descriptions", new ArrayProperty(new RefProperty("#/definitions/ConceptDescriptionCreate")));
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties()
+ */
+ @Override
+ public DelegatingResourceDescription getCreatableProperties() {
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addRequiredProperty("names");
+ description.addRequiredProperty("datatype");
+ description.addRequiredProperty("conceptClass");
+
+ description.addProperty("descriptions");
+ description.addProperty("set");
+ description.addProperty("version");
+ description.addProperty("mappings");
+ description.addProperty("answers");
+ description.addProperty("setMembers");
+
+ //ConceptNumeric properties
+ description.addProperty("hiNormal");
+ description.addProperty("hiAbsolute");
+ description.addProperty("hiCritical");
+ description.addProperty("lowNormal");
+ description.addProperty("lowAbsolute");
+ description.addProperty("lowCritical");
+ description.addProperty("units");
+ description.addProperty("allowDecimal");
+ description.addProperty("displayPrecision");
+ return description;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties()
+ */
+ @Override
+ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException {
+ DelegatingResourceDescription description = super.getUpdatableProperties();
+
+ description.addProperty("name");
+ description.addProperty("names");
+ description.addProperty("descriptions");
+
+ return description;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getPropertiesToExposeAsSubResources()
+ */
+ @Override
+ public List getPropertiesToExposeAsSubResources() {
+ return Arrays.asList("names", "descriptions", "conceptMappings");
+ }
+
+ /**
+ * Sets the name property to be the fully specified name of the Concept in the current locale
+ *
+ * @param instance
+ * @param name
+ */
+ @PropertySetter("name")
+ public static void setFullySpecifiedName(Concept instance, String name) {
+ ConceptName fullySpecifiedName = new ConceptName(name, Context.getLocale());
+ instance.setFullySpecifiedName(fullySpecifiedName);
+ }
+
+ /**
+ * It's needed, because of ConversionException: Don't know how to handle collection class:
+ * interface java.util.Collection If request to update Concept updates ConceptName, adequate
+ * resource takes care of it, so this method just adds new and removes deleted names.
+ *
+ * @param instance
+ * @param names
+ */
+ @PropertySetter("names")
+ public static void setNames(Concept instance, List names) {
+
+ new HibernateCollectionHelper(instance) {
+
+ @Override
+ public int compare(ConceptName left, ConceptName right) {
+ if (OpenmrsUtil.nullSafeEquals(left.getUuid(), right.getUuid())) {
+ return 0;
+ }
+
+ int result = OpenmrsUtil.compareWithNullAsLowest(left.getName(), right.getName());
+
+ if (result == 0) {
+ result = OpenmrsUtil.compareWithNullAsLowest(left.getConceptNameType(), right.getConceptNameType());
+ }
+
+ if (result == 0) {
+ result = OpenmrsUtil.compareWithNullAsLowest(left.getLocale().toString(), right.getLocale().toString());
+ }
+
+ return result;
+ }
+
+ @Override
+ public Collection getAll() {
+ return instance.getNames();
+ }
+
+ @Override
+ public void add(ConceptName item) {
+ instance.addName(item);
+ }
+
+ @Override
+ public void remove(ConceptName item) {
+ instance.removeName(item);
+ }
+ }.set(names);
+ }
+
+ /**
+ * It's needed, because of ConversionException: Don't know how to handle collection class:
+ * interface java.util.Collection
+ *
+ * @param instance
+ * @param descriptions
+ */
+ @PropertySetter("descriptions")
+ public static void setDescriptions(Concept instance, List descriptions) {
+ new HibernateCollectionHelper(instance) {
+ @Override
+ public int compare(ConceptDescription left, ConceptDescription right) {
+ int result = OpenmrsUtil.compareWithNullAsLowest(left.getUuid(), right.getUuid());
+
+ if (result == 0) {
+ result = OpenmrsUtil.compareWithNullAsLowest(left.getDescription(), right.getDescription());
+ }
+
+ if (result == 0) {
+ result = OpenmrsUtil.compareWithNullAsLowest(left.getLocale().toString(), right.getLocale().toString());
+ }
+
+ return result;
+ }
+
+ @Override
+ public Collection getAll() {
+ return instance.getDescriptions();
+ }
+
+ @Override
+ public void add(ConceptDescription item) {
+ instance.addDescription(item);
+ }
+
+ @Override
+ public void remove(ConceptDescription item) {
+ instance.removeDescription(item);
+ }
+ }.set(descriptions);
+ }
+
+ /**
+ * It's needed, because of ConversionException: Don't know how to handle collection class:
+ * interface java.util.Collection
+ *
+ * @param instance
+ * @param mappings
+ */
+ @PropertySetter("mappings")
+ public static void setMappings(Concept instance, List mappings) {
+ instance.getConceptMappings().clear();
+ for (ConceptMap map : mappings) {
+ instance.addConceptMapping(map);
+ }
+ }
+
+ @PropertyGetter("mappings")
+ public static List getMappings(Concept instance) {
+ return new ArrayList(instance.getConceptMappings());
+ }
+
+ /**
+ * Gets the display name of the Concept delegate
+ *
+ * @param instance the delegate instance to get the display name off
+ */
+ @PropertyGetter("display")
+ public String getDisplayName(Concept instance) {
+ String locationalization = getLocalization(Concept.class.getSimpleName(), instance.getUuid());
+
+ if (StringUtils.isNotBlank(locationalization)) {
+ return locationalization;
+ }
+
+ ConceptName cn = instance.getName();
+ if (cn != null) {
+ return cn.getName();
+ } else {
+ return instance.toString();
+ }
+ }
+
+ /**
+ * {@link #newDelegate(SimpleObject)} is used instead to support ConceptNumeric
+ *
+ * @see DelegatingCrudResource#newDelegate()
+ */
+ @Override
+ public Concept newDelegate() {
+ throw new ResourceDoesNotSupportOperationException("Should use newDelegate(SimpleObject) instead");
+ }
+
+ @Override
+ public Concept newDelegate(SimpleObject object) {
+ String datatypeUuid = object.get("datatype");
+ if (ConceptDatatype.NUMERIC_UUID.equals(datatypeUuid)) {
+ return new ConceptNumeric();
+ } else {
+ return new Concept();
+ }
+ }
+
+ /**
+ * @see DelegatingCrudResource#save(java.lang.Object)
+ */
+ @Override
+ public Concept save(Concept c) {
+ return Context.getConceptService().saveConcept(c);
+ }
/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getResourceVersion()
@@ -46,4 +532,208 @@ public Concept getByUniqueId(String identifier) {
return concept;
}
+
+ /**
+ * @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(Concept concept, RequestContext context) throws ResponseException {
+ if (concept == null) {
+ return;
+ }
+
+ Context.getConceptService().purgeConcept(concept);
+ }
+
+ /**
+ * This does not include retired concepts
+ *
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ protected NeedsPaging doGetAll(RequestContext context) {
+ List allConcepts = Context.getConceptService().getAllConcepts(null, true, context.getIncludeAll());
+ return new NeedsPaging(allConcepts, context);
+ }
+
+ /**
+ * Concept searches support the following additional query parameters:
+ *
+ * - answerTo=(uuid): restricts results to concepts that are answers to the given concept uuid
+ *
+ * - memberOf=(uuid): restricts to concepts that are set members of the given concept set's
+ * uuid
+ *
+ *
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(RequestContext)
+ */
+ @Override
+ protected PageableResult doSearch(RequestContext context) {
+ ConceptService service = Context.getConceptService();
+ Integer startIndex = null;
+ Integer limit = null;
+ boolean canPage = true;
+
+ // Collect information for answerTo and memberOf query parameters
+ String answerToUuid = context.getRequest().getParameter("answerTo");
+ String memberOfUuid = context.getRequest().getParameter("memberOf");
+ Concept answerTo = null;
+ List memberOfList = null;
+ if (StringUtils.isNotBlank(answerToUuid)) {
+ try {
+ answerTo = (Concept) ConversionUtil.convert(answerToUuid, Concept.class);
+ }
+ catch (ConversionException ex) {
+ log.error("Unexpected exception while retrieving answerTo Concept with UUID " + answerToUuid, ex);
+ }
+ }
+
+ if (StringUtils.isNotBlank(memberOfUuid)) {
+ Concept memberOf = service.getConceptByUuid(memberOfUuid);
+ memberOfList = service.getConceptsByConceptSet(memberOf);
+ canPage = false; // ConceptService does not support memberOf searches, so paging must be deferred.
+ }
+
+ // Only set startIndex and limit if we can return paged results
+ if (canPage) {
+ startIndex = context.getStartIndex();
+ limit = context.getLimit();
+ }
+
+ List searchResults;
+
+ // get the user's locales...and then convert that from a set to a list
+ List locales = new ArrayList(LocaleUtility.getLocalesInOrder());
+
+ searchResults = service.getConcepts(context.getParameter("q"), locales, context.getIncludeAll(), null, null, null,
+ null, answerTo, startIndex, limit);
+
+ // convert search results into list of concepts
+ List results = new ArrayList(searchResults.size());
+ for (ConceptSearchResult csr : searchResults) {
+ // apply memberOf filter
+ if (memberOfList == null || memberOfList.contains(csr.getConcept()))
+ results.add(csr.getConcept());
+ }
+
+ PageableResult result = null;
+ if (canPage) {
+ Integer count = service.getCountOfConcepts(context.getParameter("q"), locales, false,
+ Collections. emptyList(), Collections. emptyList(),
+ Collections. emptyList(), Collections. emptyList(), answerTo);
+ boolean hasMore = count > startIndex + limit;
+ result = new AlreadyPaged(context, results, hasMore, Long.valueOf(count));
+ } else {
+ result = new NeedsPaging(results, context);
+ }
+
+ return result;
+ }
+
+ @Override
+ protected void delete(Concept c, String reason, RequestContext context) throws ResponseException {
+ if (c.isRetired()) {
+ // since DELETE should be idempotent, we return success here
+ return;
+ }
+ Context.getConceptService().retireConcept(c, reason);
+ }
+
+ /**
+ * @param instance
+ * @return the list of Concepts or Drugs
+ */
+ @PropertyGetter("answers")
+ public static Object getAnswers(Concept instance) {
+ List conceptAnswers = new ArrayList(instance.getAnswers(false));
+ Collections.sort(conceptAnswers);
+
+ List answers = new ArrayList();
+ for (ConceptAnswer conceptAnswer : conceptAnswers) {
+ if (conceptAnswer.getAnswerDrug() != null) {
+ answers.add(conceptAnswer.getAnswerDrug());
+ } else if (conceptAnswer.getAnswerConcept() != null) {
+ answers.add(conceptAnswer.getAnswerConcept());
+ }
+ }
+
+ return answers;
+ }
+
+ /**
+ * @param instance
+ * @param answerUuids the list of Concepts or Drugs
+ * @throws ResourceDoesNotSupportOperationException
+ */
+ @PropertySetter("answers")
+ public static void setAnswers(Concept instance, List answerUuids /*Concept or Drug uuid*/)
+ throws ResourceDoesNotSupportOperationException {
+
+ // remove answers that are not in the new list
+ for (ConceptAnswer answer : instance.getAnswers(false)) {
+ String conceptUuid = answer.getConcept().getUuid();
+ String drugUuid = (answer.getAnswerDrug() != null) ? answer.getAnswerDrug().getUuid() : null;
+
+ if (answerUuids.contains(conceptUuid)) {
+ answerUuids.remove(conceptUuid); // remove from passed in list
+ } else if (answerUuids.contains(drugUuid)) {
+ answerUuids.remove(drugUuid); // remove from passed in list
+ } else {
+ instance.removeAnswer(answer); // remove from concept question object
+ }
+ }
+
+ List answerObjects = new ArrayList(answerUuids.size());
+ for (String uuid : answerUuids) {
+ Concept c = Context.getConceptService().getConceptByUuid(uuid);
+ if (c != null) {
+ answerObjects.add(c);
+ } else {
+ // it is a drug
+ Drug drug = Context.getConceptService().getDrugByUuid(uuid);
+ if (drug != null) {
+ answerObjects.add(drug);
+ } else {
+ throw new ResourceDoesNotSupportOperationException("There is no concept or drug with given uuid: "
+ + uuid);
+ }
+ }
+ }
+
+ // add in new answers
+ for (OpenmrsObject obj : answerObjects) {
+ ConceptAnswer answerToAdd;
+ if (obj.getClass().isAssignableFrom(Concept.class)) {
+ answerToAdd = new ConceptAnswer((Concept) obj);
+ } else if (obj.getClass().isAssignableFrom(Drug.class)) {
+ answerToAdd = new ConceptAnswer(((Drug) obj).getConcept(), (Drug) obj);
+ } else {
+ continue;
+ }
+
+ answerToAdd.setCreator(Context.getAuthenticatedUser());
+ answerToAdd.setDateCreated(new Date());
+ instance.addAnswer(answerToAdd);
+ }
+ }
+
+ /**
+ * @param instance
+ * @param setMembers the list of Concepts
+ */
+ @PropertySetter("setMembers")
+ public static void setSetMembers(Concept instance, List setMembers) {
+ instance.getConceptSets().clear();
+
+ if (setMembers == null || setMembers.isEmpty()) {
+ instance.setSet(false);
+ } else {
+ instance.setSet(true);
+
+ for (Concept setMember : setMembers) {
+ instance.addSetMember(setMember);
+ }
+ }
+ }
}
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptSourceResource1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptSourceResource1_9.java
similarity index 98%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptSourceResource1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptSourceResource1_9.java
index 58bf17ce0..95072c2cb 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptSourceResource1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptSourceResource1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
@@ -36,8 +36,8 @@
* {@link Resource} for {@link ConceptSource}, supporting standard CRUD operations
*/
@Resource(name = RestConstants.VERSION_1 + "/conceptsource", supportedClass = ConceptSource.class, supportedOpenmrsVersions = {
- "1.8.* - 1.12.*" })
-public class ConceptSourceResource1_8 extends MetadataDelegatingCrudResource {
+ "1.9.* - 1.12.*" })
+public class ConceptSourceResource1_9 extends MetadataDelegatingCrudResource {
/**
* @see DelegatingCrudResource#getRepresentationDescription(Representation)
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugOrderSubclassHandler1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/DrugOrderSubclassHandler1_9.java
similarity index 94%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugOrderSubclassHandler1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/DrugOrderSubclassHandler1_9.java
index f1d82939d..926881bbb 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugOrderSubclassHandler1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/DrugOrderSubclassHandler1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import java.util.List;
@@ -38,12 +38,12 @@
import org.openmrs.util.OpenmrsConstants;
/**
- * Exposes the {@link DrugOrder} subclass as a type in {@link OrderResource1_8}
+ * Exposes the {@link DrugOrder} subclass as a type in {@link OrderResource1_9}
*/
-@SubClassHandler(supportedClass = DrugOrder.class, supportedOpenmrsVersions = { "1.8.* - 1.9.*" })
-public class DrugOrderSubclassHandler1_8 extends BaseDelegatingSubclassHandler implements DelegatingSubclassHandler {
+@SubClassHandler(supportedClass = DrugOrder.class, supportedOpenmrsVersions = { "1.9.* - 1.9.*" })
+public class DrugOrderSubclassHandler1_9 extends BaseDelegatingSubclassHandler implements DelegatingSubclassHandler {
- public DrugOrderSubclassHandler1_8() {
+ public DrugOrderSubclassHandler1_9() {
//RESTWS-439
//Order subclass fields
allowedMissingProperties.add("dose");
@@ -88,7 +88,7 @@ public PageableResult getAllByType(RequestContext context) throws ResourceDoesNo
@Override
public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
if (rep instanceof DefaultRepresentation) {
- OrderResource1_8 orderResource = (OrderResource1_8) Context.getService(RestService.class)
+ OrderResource1_9 orderResource = (OrderResource1_9) Context.getService(RestService.class)
.getResourceBySupportedClass(Order.class);
DelegatingResourceDescription d = orderResource.getRepresentationDescription(rep);
d.addProperty("dose");
@@ -100,7 +100,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
d.addProperty("drug", Representation.REF);
return d;
} else if (rep instanceof FullRepresentation) {
- OrderResource1_8 orderResource = (OrderResource1_8) Context.getService(RestService.class)
+ OrderResource1_9 orderResource = (OrderResource1_9) Context.getService(RestService.class)
.getResourceBySupportedClass(Order.class);
DelegatingResourceDescription d = orderResource.getRepresentationDescription(rep);
d.addProperty("dose");
@@ -120,7 +120,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
*/
@Override
public DelegatingResourceDescription getCreatableProperties() {
- OrderResource1_8 orderResource = (OrderResource1_8) Context.getService(RestService.class)
+ OrderResource1_9 orderResource = (OrderResource1_9) Context.getService(RestService.class)
.getResourceBySupportedClass(Order.class);
DelegatingResourceDescription d = orderResource.getCreatableProperties();
d.addProperty("dose");
@@ -138,7 +138,7 @@ public DelegatingResourceDescription getCreatableProperties() {
@Override
public Model getGETModel(Representation rep) {
- OrderResource1_8 orderResource = (OrderResource1_8) Context.getService(RestService.class)
+ OrderResource1_9 orderResource = (OrderResource1_9) Context.getService(RestService.class)
.getResourceBySupportedClass(Order.class);
ModelImpl orderModel = (ModelImpl) orderResource.getGETModel(rep);
orderModel
@@ -161,7 +161,7 @@ public Model getGETModel(Representation rep) {
@Override
public Model getCREATEModel(Representation rep) {
- OrderResource1_8 orderResource = (OrderResource1_8) Context.getService(RestService.class)
+ OrderResource1_9 orderResource = (OrderResource1_9) Context.getService(RestService.class)
.getResourceBySupportedClass(Order.class);
ModelImpl orderModel = (ModelImpl) orderResource.getCREATEModel(rep);
orderModel
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugResource1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/DrugResource1_9.java
similarity index 98%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugResource1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/DrugResource1_9.java
index f34e6df7f..804998345 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugResource1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/DrugResource1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
@@ -35,8 +35,8 @@
/**
* {@link Resource} for {@link Drug}, supporting standard CRUD operations
*/
-@Resource(name = RestConstants.VERSION_1 + "/drug", supportedClass = Drug.class, supportedOpenmrsVersions = { "1.8.* - 1.9.*" })
-public class DrugResource1_8 extends MetadataDelegatingCrudResource {
+@Resource(name = RestConstants.VERSION_1 + "/drug", supportedClass = Drug.class, supportedOpenmrsVersions = { "1.9.*" })
+public class DrugResource1_9 extends MetadataDelegatingCrudResource {
/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String)
diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterResource1_9.java
index 92e413727..fd01eae80 100644
--- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterResource1_9.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterResource1_9.java
@@ -11,18 +11,37 @@
import org.openmrs.Encounter;
import org.openmrs.EncounterProvider;
+import org.openmrs.Obs;
+import org.openmrs.Order;
+import org.openmrs.Patient;
+import org.openmrs.api.EncounterService;
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.PropertyGetter;
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.api.RestService;
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.api.PageableResult;
+import org.openmrs.module.webservices.rest.web.resource.impl.DataDelegatingCrudResource;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
+import org.openmrs.module.webservices.rest.web.resource.impl.EmptySearchResult;
+import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.resource.impl.ServiceSearcher;
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+import io.swagger.models.Model;
+import io.swagger.models.ModelImpl;
+import io.swagger.models.properties.ArrayProperty;
+import io.swagger.models.properties.BooleanProperty;
+import io.swagger.models.properties.DateProperty;
+import io.swagger.models.properties.RefProperty;
+import io.swagger.models.properties.StringProperty;
+import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -32,29 +51,105 @@
*/
@Resource(name = RestConstants.VERSION_1 + "/encounter", supportedClass = Encounter.class, supportedOpenmrsVersions = {
"1.9.* - 2.1.*" })
-public class EncounterResource1_9 extends org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.EncounterResource1_8 {
+public class EncounterResource1_9 extends DataDelegatingCrudResource {
/**
- * @see DelegatingCrudResource#getRepresentationDescription(Representation)
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation)
*/
@Override
public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
if (rep instanceof DefaultRepresentation) {
- DelegatingResourceDescription description = super.getRepresentationDescription(rep);
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("display");
+ description.addProperty("encounterDatetime");
+ description.addProperty("patient", Representation.REF);
+ description.addProperty("location", Representation.REF);
+ description.addProperty("form", Representation.REF);
+ description.addProperty("encounterType", Representation.REF);
+ description.addProperty("provider", Representation.REF);
+ description.addProperty("obs", Representation.REF);
+ description.addProperty("orders", Representation.REF);
+ description.addProperty("voided");
description.addProperty("visit", Representation.REF);
description.removeProperty("provider");
- description.addProperty("encounterProviders", Representation.REF);
+ description.addProperty("encounterProviders", Representation.DEFAULT);
+ description.addSelfLink();
+ description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL);
return description;
} else if (rep instanceof FullRepresentation) {
- DelegatingResourceDescription description = super.getRepresentationDescription(rep);
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+ description.addProperty("uuid");
+ description.addProperty("display");
+ description.addProperty("encounterDatetime");
+ description.addProperty("patient", Representation.REF);
+ description.addProperty("location");
+ description.addProperty("form");
+ description.addProperty("encounterType");
+ description.addProperty("provider");
+ description.addProperty("obs");
+ description.addProperty("orders");
+ description.addProperty("voided");
+ description.addProperty("auditInfo");
description.addProperty("visit", Representation.DEFAULT);
description.removeProperty("provider");
description.addProperty("encounterProviders", Representation.DEFAULT);
+ description.addSelfLink();
return description;
}
return null;
}
+ public Model getGETModel(Representation rep) {
+ ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep);
+ if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) {
+ modelImpl
+ .property("uuid", new StringProperty())
+ .property("display", new StringProperty())
+ .property("encounterDatetime", new DateProperty())
+ .property("provider", new StringProperty()) //FIXME
+ .property("voided", new BooleanProperty());
+ }
+ if (rep instanceof DefaultRepresentation) {
+ modelImpl
+ .property("patient", new RefProperty("#/definitions/PatientGetRef")) //FIXME
+ .property("location", new RefProperty("#/definitions/LocationGetRef")) //FIXME
+ .property("form", new RefProperty("#/definitions/FormGetRef")) //FIXME
+ .property("encounterType", new RefProperty("#/definitions/EncountertypeGetRef")) //FIXME
+ .property("obs", new ArrayProperty(new RefProperty("#/definitions/ObsGetRef"))) //FIXME
+ .property("orders", new ArrayProperty(new RefProperty("#/definitions/OrderGetRef"))); //FIXME
+ } else if (rep instanceof FullRepresentation) {
+ modelImpl
+ .property("patient", new RefProperty("#/definitions/PatientGet")) //FIXME
+ .property("location", new RefProperty("#/definitions/LocationGet")) //FIXME
+ .property("form", new RefProperty("#/definitions/FormGet")) //FIXME
+ .property("encounterType", new RefProperty("#/definitions/EncountertypeGet")) //FIXME
+ .property("obs", new ArrayProperty(new RefProperty("#/definitions/ObsGet"))) //FIXME
+ .property("orders", new ArrayProperty(new RefProperty("#/definitions/OrderGet"))); //FIXME
+ }
+ return modelImpl;
+ }
+
+ @Override
+ public Model getCREATEModel(Representation rep) {
+ return new ModelImpl()
+ .property("patient", new RefProperty("#/definitions/PatientCreate"))
+ .property("encounterType", new RefProperty("#/definitions/EncountertypeCreate"))
+ .property("encounterDatetime", new DateProperty())
+ .property("location", new RefProperty("#/definitions/LocationCreate"))
+ .property("form", new RefProperty("#/definitions/FormCreate"))
+ .property("provider", new StringProperty())
+ .property("orders", new ArrayProperty(new RefProperty("#/definitions/OrderCreate")))
+ .property("obs", new ArrayProperty(new RefProperty("#/definitions/ObsCreate")))
+
+ .required("patient").required("encounterType");
+ }
+
+ @Override
+ public Model getUPDATEModel(Representation rep) {
+ return getCREATEModel(rep);
+ }
+
@Override
public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException {
DelegatingResourceDescription description = super.getUpdatableProperties();
@@ -64,15 +159,43 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe
/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties()
+ * Should create an encounter type
*/
@Override
public DelegatingResourceDescription getCreatableProperties() {
- DelegatingResourceDescription description = super.getCreatableProperties();
- description.addProperty("visit");
+ DelegatingResourceDescription description = new DelegatingResourceDescription();
+
+ description.addProperty("encounterDatetime"); // has a default value set, hence not required here
+ description.addRequiredProperty("patient");
+ description.addRequiredProperty("encounterType");
+
+ description.addProperty("location");
+ description.addProperty("form");
+ description.addProperty("provider");
+ description.addProperty("orders");
+ description.addProperty("obs");
description.addProperty("encounterProviders");
+ description.addProperty("visit");
+
return description;
}
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#newDelegate()
+ */
+ @Override
+ public Encounter newDelegate() {
+ Encounter enc = new Encounter();
+ // default to now(), so a web client can create a real-time encounter based on the server time
+ enc.setEncounterDatetime(new Date());
+ // As of 2012-04-27 there is a bug in Encounter.getOrders() where, if null, it returns an empty list without keeping a reference to it
+ enc.setOrders(new LinkedHashSet());
+ return enc;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#save(org.openmrs.Encounter)
+ */
@Override
public Encounter save(Encounter delegate) {
//This is a hack to save encounterProviders correctly. Without this they are created without encounter_id in
@@ -84,6 +207,111 @@ public Encounter save(Encounter delegate) {
return delegate;
}
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getByUniqueId(java.lang.String)
+ */
+ @Override
+ public Encounter getByUniqueId(String uuid) {
+ return Context.getEncounterService().getEncounterByUuid(uuid);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#delete(org.openmrs.Encounter,
+ * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public void delete(Encounter enc, String reason, RequestContext context) throws ResponseException {
+ if (enc.isVoided()) {
+ // DELETE is idempotent, so we return success here
+ return;
+ }
+ Context.getEncounterService().voidEncounter(enc, reason);
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#undelete(java.lang.Object,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ protected Encounter undelete(Encounter enc, RequestContext context) throws ResponseException {
+ if (enc.isVoided()) {
+ enc = Context.getEncounterService().unvoidEncounter(enc);
+ }
+ return enc;
+ }
+
+ /**
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#purge(org.openmrs.Encounter,
+ * org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ public void purge(Encounter enc, RequestContext context) throws ResponseException {
+ if (enc == null) {
+ // DELETE is idempotent, so we return success here
+ return;
+ }
+ Context.getEncounterService().purgeEncounter(enc);
+ }
+
+ /**
+ * @param encounter
+ * @return encounter type and date
+ */
+ @PropertyGetter("display")
+ public String getDisplayString(Encounter encounter) {
+ String ret = encounter.getEncounterType() == null ? "?" : encounter.getEncounterType().getName();
+ ret += " ";
+ ret += encounter.getEncounterDatetime() == null ? "?" : Context.getDateFormat().format(
+ encounter.getEncounterDatetime());
+ return ret;
+ }
+
+ /**
+ * @param instance
+ * @return all non-voided top-level obs from the given encounter
+ */
+ @PropertyGetter("obs")
+ public static Object getObsAtTopLevel(Encounter instance) {
+ return instance.getObsAtTopLevel(false);
+ }
+
+ @PropertySetter("obs")
+ public static void setObs(Encounter instance, Set obs) {
+ instance.getAllObs(true).clear();
+ for (Obs o : obs)
+ instance.addObs(o);
+ }
+
+ @PropertySetter("orders")
+ public static void setOrders(Encounter instance, Set orders) {
+ for (Order o : orders)
+ instance.addOrder(o);
+ }
+
+ /**
+ * Gets encounters for the given patient (paged according to context if necessary) only if a
+ * patient parameter exists in the request set on the {@link RequestContext} otherwise searches
+ * for encounters that match the specified query
+ *
+ * @param context
+ * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext)
+ */
+ @Override
+ protected PageableResult doSearch(RequestContext context) {
+ String patientUuid = context.getRequest().getParameter("patient");
+ if (patientUuid != null) {
+ Patient patient = ((PatientResource1_9) Context.getService(RestService.class).getResourceBySupportedClass(
+ Patient.class)).getByUniqueId(patientUuid);
+ if (patient == null)
+ return new EmptySearchResult();
+ List encs = Context.getEncounterService().getEncountersByPatient(patient);
+ return new NeedsPaging(encs, context);
+ }
+
+ return new ServiceSearcher(EncounterService.class, "getEncounters", "getCountOfEncounters").search(
+ context.getParameter("q"), context);
+ }
+
@PropertyGetter("encounterProviders")
public static Set getActiveEncounterProviders(Encounter instance) {
Set encounterProviders = instance.getEncounterProviders();
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterTypeResource1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterTypeResource1_9.java
similarity index 97%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterTypeResource1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterTypeResource1_9.java
index 952889804..5cc8a2efd 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterTypeResource1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterTypeResource1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
@@ -27,8 +27,8 @@
* {@link Resource} for {@link EncounterType}, supporting standard CRUD operations
*/
@Resource(name = RestConstants.VERSION_1 + "/encountertype", supportedClass = EncounterType.class, supportedOpenmrsVersions = {
- "1.8.* - 9.*" })
-public class EncounterTypeResource1_8 extends MetadataDelegatingCrudResource {
+ "1.9.* - 9.*" })
+public class EncounterTypeResource1_9 extends MetadataDelegatingCrudResource {
/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties()
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldAnswerResource1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FieldAnswerResource1_9.java
similarity index 97%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldAnswerResource1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FieldAnswerResource1_9.java
index 61e70b452..78f8e5b3d 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldAnswerResource1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FieldAnswerResource1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import java.util.ArrayList;
import java.util.List;
@@ -39,9 +39,9 @@
/**
* {@link Resource} for {@link FieldAnswer}, supporting standard CRUD operations
*/
-@SubResource(parent = FieldResource1_8.class, path = "answer", supportedClass = FieldAnswer.class, supportedOpenmrsVersions = {
- "1.8.* - 9.*" })
-public class FieldAnswerResource1_8 extends DelegatingSubResource {
+@SubResource(parent = FieldResource1_9.class, path = "answer", supportedClass = FieldAnswer.class, supportedOpenmrsVersions = {
+ "1.9.* - 9.*" })
+public class FieldAnswerResource1_9 extends DelegatingSubResource {
@Override
@RepHandler(RefRepresentation.class)
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldResource1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FieldResource1_9.java
similarity index 98%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldResource1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FieldResource1_9.java
index 7eb26f5c2..ffc838173 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldResource1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FieldResource1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
@@ -33,8 +33,8 @@
/**
* {@link Resource} for {@link Field}, supporting standard CRUD operations
*/
-@Resource(name = RestConstants.VERSION_1 + "/field", supportedClass = Field.class, supportedOpenmrsVersions = { "1.8.* - 9.*" })
-public class FieldResource1_8 extends MetadataDelegatingCrudResource {
+@Resource(name = RestConstants.VERSION_1 + "/field", supportedClass = Field.class, supportedOpenmrsVersions = { "1.9.* - 9.*" })
+public class FieldResource1_9 extends MetadataDelegatingCrudResource {
public Model getGETModel(Representation rep) {
ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep);
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldTypeResource1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FieldTypeResource1_9.java
similarity index 98%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldTypeResource1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FieldTypeResource1_9.java
index ba62a0174..fddddb4de 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldTypeResource1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FieldTypeResource1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
@@ -29,8 +29,8 @@
* {@link Resource} for {@link FieldType}, supporting standard CRUD operations
*/
@Resource(name = RestConstants.VERSION_1 + "/fieldtype", supportedClass = FieldType.class, supportedOpenmrsVersions = {
- "1.8.* - 9.*" })
-public class FieldTypeResource1_8 extends MetadataDelegatingCrudResource {
+ "1.9.* - 9.*" })
+public class FieldTypeResource1_9 extends MetadataDelegatingCrudResource {
public Model getGETModel(Representation rep) {
ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep);
diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormFieldResource1_8.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormFieldResource1_9.java
similarity index 98%
rename from omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormFieldResource1_8.java
rename to omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormFieldResource1_9.java
index 4b7ddfece..ab1abb97b 100644
--- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormFieldResource1_8.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormFieldResource1_9.java
@@ -7,7 +7,7 @@
* 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.openmrs1_8;
+package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9;
import java.util.ArrayList;
import java.util.List;
@@ -38,9 +38,9 @@
/**
* {@link Resource} for {@link FormField}, supporting standard CRUD operations
*/
-@SubResource(parent = FormResource1_8.class, path = "formfield", supportedClass = FormField.class, supportedOpenmrsVersions = {
- "1.8.* - 9.*" })
-public class FormFieldResource1_8 extends DelegatingSubResource {
+@SubResource(parent = FormResource1_9.class, path = "formfield", supportedClass = FormField.class, supportedOpenmrsVersions = {
+ "1.9.* - 9.*" })
+public class FormFieldResource1_9 extends DelegatingSubResource {
public Model getGETModel(Representation rep) {
ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep);
diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormResource1_9.java
index 81c1e2de7..d3e24d73d 100644
--- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormResource1_9.java
+++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormResource1_9.java
@@ -13,6 +13,7 @@
import org.openmrs.FormResource;
import org.openmrs.api.FormService;
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.PropertyGetter;
import org.openmrs.module.webservices.rest.web.annotation.PropertySetter;
@@ -21,33 +22,199 @@
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.v1_0.resource.openmrs1_8.FormResource1_8;
+import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource;
+import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
+import org.openmrs.module.webservices.rest.web.response.ResponseException;
+import io.swagger.models.Model;
+import io.swagger.models.ModelImpl;
+import io.swagger.models.properties.ArrayProperty;
+import io.swagger.models.properties.BooleanProperty;
+import io.swagger.models.properties.IntegerProperty;
+import io.swagger.models.properties.RefProperty;
+import io.swagger.models.properties.StringProperty;
+import java.util.Arrays;
import java.util.List;
@Resource(name = RestConstants.VERSION_1 + "/form", supportedClass = Form.class, order = 10, supportedOpenmrsVersions = {
"1.9.* - 9.*" })
-public class FormResource1_9 extends FormResource1_8 {
-
- // TODO: Find out why autowiring is failing, in the mean time use Context.getService
- // @Autowired
- // private FormService formService;
+public class FormResource1_9 extends MetadataDelegatingCrudResource