From 68ef6981cb88c3e001fec8f623119420e54baaa4 Mon Sep 17 00:00:00 2001 From: herman Date: Tue, 4 Jul 2023 10:33:16 +0300 Subject: [PATCH 1/2] Add support for XML patching operations - AllergyIntolerance Resource --- ...ceFhirResourceProviderIntegrationTest.java | 27 +++++++++++++++++++ .../providers/AllergyIntolerance_xmlpatch.xml | 14 ++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test-data/src/main/resources/org/openmrs/module/fhir2/providers/AllergyIntolerance_xmlpatch.xml diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java index 8f6ca7e4d..4e866ca26 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java @@ -45,6 +45,8 @@ public class AllergyIntoleranceFhirResourceProviderIntegrationTest extends BaseF private static final String JSON_PATCH_ALLERGY_PATH = "org/openmrs/module/fhir2/providers/AllergyIntolerance_json_patch.json"; + private static final String XML_PATCH_ALLERGY_PATH = "org/openmrs/module/fhir2/providers/AllergyIntolerance_xmlpatch.xml"; + private static final String JSON_CREATE_ALLERGY_DOCUMENT = "org/openmrs/module/fhir2/providers/AllergyIntoleranceWebTest_create.json"; private static final String XML_CREATE_ALLERGY_DOCUMENT = "org/openmrs/module/fhir2/providers/AllergyIntoleranceWebTest_create.xml"; @@ -458,6 +460,31 @@ public void shouldPatchExistingAllergyUsingJsonPatch() throws Exception { assertThat(allergyIntolerance, validResource()); } + @Test + public void shouldPatchExistingAllergyUsingXmlPatch() throws Exception { + String jsonAllergyPatch; + try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_PATCH_ALLERGY_PATH)) { + Objects.requireNonNull(is); + jsonAllergyPatch = inputStreamToString(is, UTF_8); + } + + MockHttpServletResponse response = patch("/AllergyIntolerance/" + ALLERGY_UUID) + .xmlPatch(jsonAllergyPatch).accept(FhirMediaTypes.XML).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + AllergyIntolerance allergyIntolerance = readResponse(response); + + assertThat(allergyIntolerance, notNullValue()); + assertThat(allergyIntolerance.getIdElement().getIdPart(), equalTo(ALLERGY_UUID)); + + //ensure category has been patched + assertThat(allergyIntolerance.getCategory().get(0).getCode(), equalTo("food")); + assertThat(allergyIntolerance, validResource()); + } + @Test public void shouldDeleteExistingAllergyAsXML() throws Exception { MockHttpServletResponse response = delete("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.XML).go(); diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/providers/AllergyIntolerance_xmlpatch.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/providers/AllergyIntolerance_xmlpatch.xml new file mode 100644 index 000000000..f4833ba36 --- /dev/null +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/providers/AllergyIntolerance_xmlpatch.xml @@ -0,0 +1,14 @@ + + + + + food + + From 98c661b20ee5437dc680dae758789acf1ccf2ad3 Mon Sep 17 00:00:00 2001 From: herman Date: Fri, 7 Jul 2023 07:07:10 +0300 Subject: [PATCH 2/2] give proper variable name --- ...lergyIntoleranceFhirResourceProviderIntegrationTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java index 4e866ca26..da3d81830 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/AllergyIntoleranceFhirResourceProviderIntegrationTest.java @@ -462,14 +462,14 @@ public void shouldPatchExistingAllergyUsingJsonPatch() throws Exception { @Test public void shouldPatchExistingAllergyUsingXmlPatch() throws Exception { - String jsonAllergyPatch; + String xmlAllergyPatch; try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_PATCH_ALLERGY_PATH)) { Objects.requireNonNull(is); - jsonAllergyPatch = inputStreamToString(is, UTF_8); + xmlAllergyPatch = inputStreamToString(is, UTF_8); } MockHttpServletResponse response = patch("/AllergyIntolerance/" + ALLERGY_UUID) - .xmlPatch(jsonAllergyPatch).accept(FhirMediaTypes.XML).go(); + .xmlPatch(xmlAllergyPatch).accept(FhirMediaTypes.XML).go(); assertThat(response, isOk()); assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));