Skip to content

Commit

Permalink
Add support for Xml Patch operations - Location Resource
Browse files Browse the repository at this point in the history
  • Loading branch information
mherman22 committed Jul 20, 2023
1 parent 42b8c45 commit 768dbe3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class LocationFhirResourceProviderIntegrationTest extends BaseFhirR4Integ

private static final String JSON_PATCH_LOCATION_PATH = "org/openmrs/module/fhir2/providers/Location_json_patch.json";

private static final String XML_PATCH_LOCATION_PATH= "org/openmrs/module/fhir2/providers/Location_xml_patch.xml";

@Getter(AccessLevel.PUBLIC)
@Autowired
private LocationFhirResourceProvider resourceProvider;
Expand Down Expand Up @@ -478,6 +480,34 @@ public void shouldPatchExistingLocationUsingJsonPatch() throws Exception {
assertThat(location.getAddress().getState(), is("Central Region"));
}

@Test
public void shouldPatchExistingLocationUsingXmlPatch() throws Exception {
String xmlLocationPatch;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_PATCH_LOCATION_PATH)) {
Objects.requireNonNull(is);
xmlLocationPatch = inputStreamToString(is, UTF_8);
}
MockHttpServletResponse response = patch("/Location/" + LOCATION_UUID).xmlPatch(xmlLocationPatch)
.accept(FhirMediaTypes.XML).go();

assertThat(response, isOk());
assertThat(response, notNullValue());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());

Location location = readResponse(response);

assertThat(location, notNullValue());
assertThat(location.getIdElement().getIdPart(), equalTo(LOCATION_UUID));
assertThat(location, validResource());

assertThat(location.getName(), is("Patched Location"));
assertThat(location.getAddress().getCity(), is("Wakiso"));
assertThat(location.getAddress().getCountry(), is("Uganda"));
assertThat(location.getAddress().getPostalCode(), is("0000 WK"));
assertThat(location.getAddress().getState(), is("Central Region"));
}

@Test
public void shouldDeleteExistingLocationAsXML() throws Exception {
MockHttpServletResponse response = delete("/Location/" + LOCATION_UUID).accept(FhirMediaTypes.XML).go();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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:Location/fhir:name/@value">Patched Location</replace>
<replace sel="/fhir:Location/fhir:address">
<address>
<city value="Wakiso"/>
<country value="Uganda"/>
<postalCode value="0000 WK"/>
<state value="Central Region"/>
</address>
</replace>
</diff>

0 comments on commit 768dbe3

Please sign in to comment.