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-594: Add support for XML patching operations - Person Resource #497

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 @@ -52,9 +52,11 @@ public class PersonFhirResourceProviderIntegrationTest extends BaseFhirR4Integra

private static final String XML_CREATE_PERSON = "org/openmrs/module/fhir2/providers/PersonWebTest_create.xml";

private static final String JSON_PATCH_PERSON_PATH = "org/openmrs/module/fhir2/providers/Person_json_merge_patch.json";
private static final String JSON_MERGE_PATCH_PERSON_PATH = "org/openmrs/module/fhir2/providers/Person_json_merge_patch.json";

private static final String JSON_PATCH_PERSON_FILE = "org/openmrs/module/fhir2/providers/Person_json_patch.json";
private static final String JSON_PATCH_PERSON_PATH = "org/openmrs/module/fhir2/providers/Person_json_patch.json";

private static final String XML_PATCH_PERSON_PATH = "org/openmrs/module/fhir2/providers/Person_xmlpatch.xml";

private static final String PERSON_UUID = "5c521595-4e12-46b0-8248-b8f2d3697766";

Expand Down Expand Up @@ -340,7 +342,7 @@ public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchPersonIdAsXML() thro
@Test
public void shouldPatchPersonResourceUsingJsonMergePatch() throws Exception {
String jsonPersonPatch;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_PATCH_PERSON_PATH)) {
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_MERGE_PATCH_PERSON_PATH)) {
Objects.requireNonNull(is);
jsonPersonPatch = inputStreamToString(is, UTF_8);
}
Expand All @@ -364,7 +366,7 @@ public void shouldPatchPersonResourceUsingJsonMergePatch() throws Exception {
@Test
public void shouldPatchPersonResourceUsingJsonPatch() throws Exception {
String jsonPersonPatch;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_PATCH_PERSON_FILE)) {
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_PATCH_PERSON_PATH)) {
Objects.requireNonNull(is);
jsonPersonPatch = inputStreamToString(is, UTF_8);
}
Expand All @@ -385,6 +387,30 @@ public void shouldPatchPersonResourceUsingJsonPatch() throws Exception {
assertThat(person.getGender(), equalTo(Enumerations.AdministrativeGender.FEMALE));
}

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

MockHttpServletResponse response = patch("/Person/" + PERSON_UUID).xmlPatch(xmlPersonPatch)
.accept(FhirMediaTypes.XML).go();

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

Person person = readResponse(response);

assertThat(person, notNullValue());
assertThat(person.getIdElement().getIdPart(), equalTo(PERSON_UUID));
assertThat(person, validResource());

assertThat(person.getGender(), equalTo(Enumerations.AdministrativeGender.FEMALE));
}

@Test
public void shouldDeleteExistingPerson() throws Exception {
MockHttpServletResponse response = delete("/Person/" + PERSON_UUID).accept(FhirMediaTypes.JSON).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:Person/fhir:gender/@value">
female
</replace>
</diff>