spark icon indicating copy to clipboard operation
spark copied to clipboard

Transaction bundles with conditional create do not apply if-none-exist filters

Open JeremiahSanders opened this issue 3 years ago • 1 comments

Describe the bug When processing a FHIR transaction Bundle which contains POST Patient entries with ifNoneExist conditions, search filters contained within ifNoneExist are not applied, which results in failed requests.

When this occurs, ResourceManipulationOperation.GetSearchInformation() specifically indicates that the parameter was unused.

To Reproduce

The following code is the simplest example I could construct. It uses an HL7-provided Bundle and targets the Spark R4 reference implementation.

Steps to reproduce the behavior:

const string xdsBundleUrl = "http://www.hl7.org/fhir/xds-example.json";
var hl7HttpClient = new HttpClient();
var hl7DocumentReferenceBundleJson = await (await hl7HttpClient.GetAsync(xdsBundleUrl)).Content.ReadAsStringAsync();
var hl7DocumentReferenceBundle = new FhirJsonParser().Parse(hl7DocumentReferenceBundleJson) as Bundle;

var fhirClient = new Hl7.Fhir.Rest.FhirClient("https://spark.incendi.no/fhir/");

var transactionResponse = await fhirClient.TransactionAsync(hl7DocumentReferenceBundle);

The example failure is caused by the following entry.request:

{
  "method": "POST",
  "url": "Patient",
  "ifNoneExist": "Patient?identifier=http://acme.org/xds/patients!89765a87b"
}

Result:

The following result was received from https://spark.incendi.no/fhir/ when tested on 2022/11/09. The error occurred at the line executing FhirClient.TransactionAsync.

FhirOperationException

Operation was unsuccessful because of a client error (PreconditionFailed). OperationOutcome: Overall result: FAILURE (1 errors and 0 warnings)
[ERROR] (no details)(further diagnostics: Multiple matches found when trying to resolve conditional create. Client's criteria were not selective enough.
Search parameters not used:Patient?identifier
Search uri used: Patient?
Number of matches found: 292).

Expected behavior A successful, Bundle response is expected.

Spark version

  • Version: 1.5.14

Operating system + Database Validated against reference implementation at https://spark.incendi.no/fhir/.

Additionally, validated locally in Windows 11 + Docker-hosted MongoDB.

Container service / Cloud infrastructure: Validated against reference implementation at https://spark.incendi.no/fhir/.

Additionally, validated locally in Windows 11 + local Docker Desktop-hosted MongoDB.

JeremiahSanders avatar Nov 09 '22 20:11 JeremiahSanders

The value Patient?identifier=http://acme.org/xds/patients!89765a87b is not a valid value for IfNoneExist, the error we are giving back is not great since we try to interpret and execute the search.

First of all IfNoneExist should only contain the query portion of the URL. From the specification:

This is just the query portion of the URL - what follows the "?" (not including the "?").

https://hl7.org/fhir/R4/bundle-definitions.html#Bundle.entry.request.ifNoneExist

And second the token query for the identifier part contains a ! instead of |

The correct value for IfNoneExist is: identifier=http://acme.org/xds/patients|89765a87b

kennethmyhra avatar May 28 '25 17:05 kennethmyhra

That explanation makes sense. Thanks for following up. 👍

Unfortunately, that seems to indicate that HL7 has a documentation/example error. 😒

The example I was using for testing comes from www.hl7.org/fhir/R4/xds-example.json

I assumed that the official HL7 R4 examples were valid for the spec and intentionally used them verbatim for testing.

You'll find the related JSON segment (from the HL7 documentation) reproduced below:

{
      "fullUrl": "http://localhost:9556/svc/fhir/Patient/a2",
      "resource": {
        "resourceType": "Patient",
        "id": "a2",
        "meta": {
          "lastUpdated": "2013-07-01T13:11:33Z"
        },
        "text": {
          "status": "generated",
          "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Person DOE, John, M, dob: 27/05/1956</div>"
        },
        "identifier": [
          {
            "use": "usual",
            "value": "MRN"
          }
        ],
        "name": [
          {
            "use": "usual",
            "text": "DOE, John",
            "family": "Doe",
            "given": [
              "John"
            ]
          }
        ],
        "birthDate": "1956-05-27"
      },
      "request": {
        "method": "POST",
        "url": "Patient",
        "ifNoneExist": "Patient?identifier=http://acme.org/xds/patients!89765a87b"
      }
    }

I'll close this bug report.

JeremiahSanders avatar Aug 28 '25 19:08 JeremiahSanders