From ff289350d7d494e990b45a7766b76ed63afad3a1 Mon Sep 17 00:00:00 2001 From: Samuel Male Date: Tue, 24 Sep 2024 17:23:33 +0300 Subject: [PATCH] RESTWS-939: Explicitly define form field path property setters (#627) --- .../openmrs2_5/DiagnosisResource2_5.java | 23 +++++++++++++++++++ .../openmrs2_5/DiagnosisResource2_5Test.java | 20 ++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java index 4a55be051..010a4ed5e 100644 --- a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java +++ b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java @@ -14,6 +14,7 @@ import io.swagger.models.properties.StringProperty; import org.openmrs.Diagnosis; import org.openmrs.module.webservices.rest.web.RestConstants; +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.representation.DefaultRepresentation; import org.openmrs.module.webservices.rest.web.representation.FullRepresentation; @@ -89,4 +90,26 @@ private Model addNewProperties(Model model, Representation rep) { } return model; } + + /** + * Annotated setter for formFieldPath + * + * @param diagnosis + * @param formFieldPath + */ + @PropertySetter("formFieldPath") + public static void setFormFieldPath(Diagnosis diagnosis, Object formFieldPath) { + diagnosis.setFormField(diagnosis.getFormFieldNamespace(), (String)formFieldPath); + } + + /** + * Annotated setter for formFieldNamespace + * + * @param diagnosis + * @param namespace + */ + @PropertySetter("formFieldNamespace") + public static void setFormFieldNamespace(Diagnosis diagnosis, Object namespace) { + diagnosis.setFormField((String)namespace, diagnosis.getFormFieldPath()); + } } diff --git a/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5Test.java b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5Test.java index d260cbd48..6a745ffbe 100644 --- a/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5Test.java +++ b/omod-2.5/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5Test.java @@ -20,19 +20,19 @@ import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest; import org.openmrs.module.webservices.rest.web.v1_0.RestTestConstants2_2; +import static org.junit.Assert.assertEquals; + /** * Tests functionality of {@link DiagnosisResource2_5}. */ public class DiagnosisResource2_5Test extends BaseDelegatingResourceTest { - private DiagnosisService diagnosisService; private EncounterService encounterService; private PatientService patientService; - @Before public void before() { this.diagnosisService = Context.getDiagnosisService(); @@ -70,6 +70,22 @@ public String getDisplayProperty() { return ""; } + @Test + public void setFormFieldPath_shouldSetFormFieldPath() { + Diagnosis diagnosis = new Diagnosis(); + String formFieldPath = "form-field-path"; + DiagnosisResource2_5.setFormFieldPath(diagnosis, formFieldPath); + assertEquals(formFieldPath, diagnosis.getFormFieldPath()); + } + + @Test + public void formFieldNamespace_shouldSetFormFieldNamespace() { + Diagnosis diagnosis = new Diagnosis(); + String namespace = "o3forms"; + DiagnosisResource2_5.setFormFieldNamespace(diagnosis, namespace); + assertEquals(namespace, diagnosis.getFormFieldNamespace()); + } + @Test public void testFormFieldNamespaceAndPath() { String uuid = "a303bbfb-w5w4-25d1-9f11-4f33f99d456r";