Skip to content

Commit

Permalink
FM2-595: Add support for XML patching operations - AllergyIntolerance…
Browse files Browse the repository at this point in the history
… Resource (#496)
  • Loading branch information
mherman22 committed Jul 7, 2023
1 parent b5d5453 commit 4be0eb8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -458,6 +460,31 @@ public void shouldPatchExistingAllergyUsingJsonPatch() throws Exception {
assertThat(allergyIntolerance, validResource());
}

@Test
public void shouldPatchExistingAllergyUsingXmlPatch() throws Exception {
String xmlAllergyPatch;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_PATCH_ALLERGY_PATH)) {
Objects.requireNonNull(is);
xmlAllergyPatch = inputStreamToString(is, UTF_8);
}

MockHttpServletResponse response = patch("/AllergyIntolerance/" + ALLERGY_UUID)
.xmlPatch(xmlAllergyPatch).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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
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.
-->
<diff xmlns:fhir="http://hl7.org/fhir">
<replace sel="/fhir:AllergyIntolerance/fhir:category/@value">
food
</replace>
</diff>

0 comments on commit 4be0eb8

Please sign in to comment.