From 9026df434fbe79a92840571624785de1d301b62c Mon Sep 17 00:00:00 2001 From: freddy Date: Thu, 30 Aug 2018 16:26:27 +0200 Subject: [PATCH] Solving RESTWS-713 --- .../openmrs1_11/PersonResource1_11.java | 2 +- .../openmrs2_2/PersonResource2_2.java | 52 +++++++++++++++++++ .../openmrs2_2/PersonResource2_2Test.java | 40 ++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/PersonResource2_2.java create mode 100644 omod-2.2/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/PersonResource2_2Test.java diff --git a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/PersonResource1_11.java b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/PersonResource1_11.java index ddef0c9f1..add1f50b5 100644 --- a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/PersonResource1_11.java +++ b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/PersonResource1_11.java @@ -28,7 +28,7 @@ * {@link Resource} for Person, supporting standard CRUD operations */ @Resource(name = RestConstants.VERSION_1 + "/person", order = 1, supportedClass = Person.class, supportedOpenmrsVersions = { - "1.11.*", "1.12.*", "2.0.*", "2.1.*", "2.2.*" }) + "1.11.*", "1.12.*", "2.0.*", "2.1.*" }) public class PersonResource1_11 extends PersonResource1_8 { /** diff --git a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/PersonResource2_2.java b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/PersonResource2_2.java new file mode 100644 index 000000000..2745fc0dc --- /dev/null +++ b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/PersonResource2_2.java @@ -0,0 +1,52 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ + +package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2; + +import org.openmrs.Person; +import org.openmrs.module.webservices.rest.web.RestConstants; +import org.openmrs.module.webservices.rest.web.annotation.Resource; +import org.openmrs.module.webservices.rest.web.representation.FullRepresentation; +import org.openmrs.module.webservices.rest.web.representation.Representation; +import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource; +import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; +import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; +import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11.PersonResource1_11; + +/** + * {@link Resource} for Person, supporting standard CRUD operations + */ +@Resource(name = RestConstants.VERSION_1 + "/person", supportedClass = Person.class, supportedOpenmrsVersions = { + "2.2.*" }) +public class PersonResource2_2 extends PersonResource1_11 { + + /** + * @see DelegatingCrudResource#getRepresentationDescription(Representation) + */ + @Override + public DelegatingResourceDescription getRepresentationDescription(Representation rep) { + DelegatingResourceDescription description = super.getRepresentationDescription(rep); + + if (description != null && rep instanceof FullRepresentation) { + description.addProperty("causeOfDeathNonCoded"); + } + return description; + } + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() + */ + @Override + public DelegatingResourceDescription getCreatableProperties() { + DelegatingResourceDescription description = super.getCreatableProperties(); + description.addProperty("causeOfDeathNonCoded"); + return description; + } +} diff --git a/omod-2.2/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/PersonResource2_2Test.java b/omod-2.2/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/PersonResource2_2Test.java new file mode 100644 index 000000000..8b978ded3 --- /dev/null +++ b/omod-2.2/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/PersonResource2_2Test.java @@ -0,0 +1,40 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2; + +import org.openmrs.Person; +import org.openmrs.api.context.Context; +import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest; +import org.openmrs.module.webservices.rest.web.v1_0.RestTestConstants2_2; + +public class PersonResource2_2Test extends BaseDelegatingResourceTest { + + @Override + public Person newObject() { + return Context.getPersonService().getPersonByUuid(getUuidProperty()); + } + + @Override + public String getDisplayProperty() { + return "Mr. Horatio Test Hornblower"; + } + + @Override + public String getUuidProperty() { + return RestTestConstants2_2.PERSON_UUID; + } + + @Override + public void validateFullRepresentation() throws Exception { + super.validateFullRepresentation(); + assertPropEquals("causeOfDeathNonCoded", getObject().getCauseOfDeathNonCoded()); + } + +}