3668 fhir patch operation returning 500 when patching in a transaction with a resource query in property request.url (#3675)

* Initial test exerting the issue.

* Providing fix and changelog

* Providing fix and changelog

* Providing a searchUrl or matchUrl based on the requestUrl.

* Providing fix and changelog

* Modification on test

* Modification on test

Co-authored-by: peartree <etienne.poirier@smilecdr.com>
Co-authored-by: qingyixia <cherry.xia@smilecdr.com>
This commit is contained in:
Etienne Poirier 2022-06-13 09:15:09 -04:00 committed by GitHub
parent 2c580dfa2f
commit 05cb6c241c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 3668
title: "Fhir patch operation returning 500 when patching in a transaction with a resource query in property request.url."

View File

@ -110,6 +110,38 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test {
assertEquals(false, newPt.getActive());
}
@Test
public void testFhirPatch_TransactionWithSearchParameter() throws Exception {
String methodName = "testFhirPatch_Transaction";
IIdType pid1;
{
Patient patient = new Patient();
patient.setActive(true);
patient.addIdentifier().setSystem("urn:system").setValue("0");
patient.addName().setFamily(methodName).addGiven("Joe");
pid1 = myClient.create().resource(patient).execute().getId().toUnqualifiedVersionless();
}
Parameters patch = new Parameters();
Parameters.ParametersParameterComponent operation = patch.addParameter();
operation.setName("operation");
operation.addPart().setName("type").setValue(new CodeType("replace"));
operation.addPart().setName("path").setValue(new CodeType("Patient.active"));
operation.addPart().setName("value").setValue(new BooleanType(false));
Bundle input = new Bundle();
input.setType(Bundle.BundleType.TRANSACTION);
input.addEntry()
.setFullUrl(pid1.getValue())
.setResource(patch)
.getRequest().setUrl(String.format("Patient?name=%s", methodName))
.setMethod(Bundle.HTTPVerb.PATCH);
myClient.transaction().withBundle(input).execute();
Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute();
assertEquals("2", newPt.getIdElement().getVersionIdPart());
assertEquals(false, newPt.getActive());
}
@Test
public void testPatchAddArray() throws IOException {

View File

@ -133,6 +133,7 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static ca.uhn.fhir.util.StringUtil.toUtf8String;
import static java.util.Objects.isNull;
import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
@ -1079,7 +1080,10 @@ public abstract class BaseTransactionProcessor {
IFhirResourceDao<? extends IBaseResource> dao = toDao(parts, verb, url);
IIdType patchId = myContext.getVersion().newIdType().setValue(parts.getResourceId());
DaoMethodOutcome outcome = dao.patch(patchId, matchUrl, patchType, patchBody, patchBodyParameters, theRequest);
String conditionalUrl = isNull(patchId.getIdPart()) ? url : matchUrl;
DaoMethodOutcome outcome = dao.patch(patchId, conditionalUrl, patchType, patchBody, patchBodyParameters, theRequest);
setConditionalUrlToBeValidatedLater(conditionalUrlToIdMap, matchUrl, outcome.getId());
updatedEntities.add(outcome.getEntity());
if (outcome.getResource() != null) {