Transaction bundles with conditional create do not apply if-none-exist filters
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
Bundleand 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 executingFhirClient.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.
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
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.