Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FM2-595: Add support for XML patching operations - AllergyIntolerance Resource #496

Merged
merged 2 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>