Skip to content

Commit

Permalink
RESTWS-939: Explicitly define form field path property setters (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmale authored Sep 24, 2024
1 parent eb0b5d7 commit ff28935
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<DiagnosisResource2_5, Diagnosis> {


private DiagnosisService diagnosisService;

private EncounterService encounterService;

private PatientService patientService;


@Before
public void before() {
this.diagnosisService = Context.getDiagnosisService();
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit ff28935

Please sign in to comment.