spark icon indicating copy to clipboard operation
spark copied to clipboard

Bundle processing - generated ids

Open andy-a-o opened this issue 5 years ago • 1 comments

Describe the bug When transaction bundle contains relations between entries, and one of the entries is a POST request, it will receive a new generated ID, but relations will still use its old ID.

To Reproduce

  1. POST
{
  "type": "transaction",
  "entry": [
    {
      "resource": {
        "id": "foo",
        "meta": {
          "tag": [
            {
              "system": "http://projectcrucible.org",
              "code": "testdata"
            }
          ]
        },
        "name": [
          {
            "family": "Emerald",
            "given": [
              "Caro"
            ]
          }
        ],
        "resourceType": "Patient"
      },
      "request": {
        "method": "POST",
        "url": "Patient"
      }
    },
    {
      "resource": {
        "target": [
          {
            "reference": "Patient/foo"
          }
        ],
        "recorded": "2020-11-28T10:32:20.114Z",
        "reason": [
          {
            "system": "http://hl7.org/fhir/v3/ActReason",
            "code": "PATADMIN",
            "display": "patient administration"
          }
        ],
        "agent": [
          {
            "role": {
              "coding": {
                "system": "http://hl7.org/fhir/provenance-participant-role",
                "code": "author",
                "display": "Author"
              }
            }
          }
        ],
        "resourceType": "Provenance"
      },
      "request": {
        "method": "POST",
        "url": "Provenance"
      }
    }
  ],
  "resourceType": "Bundle"
}

Result:

{
   "resourceType":"Bundle",
   "type":"transaction-response",
   "entry":[
      {
         "fullUrl":"http://localhost:5000/fhir/Patient/1071/_history/1",
         "resource":{
            "resourceType":"Patient",
            "id":"1071",
            "meta":{
               "versionId":"1",
               "lastUpdated":"2020-11-28T10:32:20.3605823+03:00",
               "tag":[
                  {
                     "system":"http://projectcrucible.org",
                     "code":"testdata"
                  }
               ]
            },
            "name":[
               {
                  "family":"Emerald",
                  "given":[
                     "Caro"
                  ]
               }
            ]
         },
         "response":{
            "status":"201 Created",
            "location":"http://localhost:5000/fhir/Patient/1071/_history/1",
            "etag":"W/\"1\"",
            "lastModified":"2020-11-28T10:32:20.3605823+03:00"
         }
      },
      {
         "fullUrl":"http://localhost:5000/fhir/Provenance/4/_history/1",
         "resource":{
            "resourceType":"Provenance",
            "id":"4",
            "meta":{
               "versionId":"1",
               "lastUpdated":"2020-11-28T10:32:20.3635841+03:00"
            },
            "target":[
               {
                  "reference":"Patient/foo"
               }
            ],
            "recorded":"2020-11-28T10:32:20.114+00:00",
            "reason":[
               {
                  "system":"http://hl7.org/fhir/v3/ActReason",
                  "code":"PATADMIN",
                  "display":"patient administration"
               }
            ],
            "agent":[
               {
                  "role":[
                     {
                        "coding":[
                           {
                              "system":"http://hl7.org/fhir/provenance-participant-role",
                              "code":"author",
                              "display":"Author"
                           }
                        ]
                     }
                  ]
               }
            ]
         },
         "response":{
            "status":"201 Created",
            "location":"http://localhost:5000/fhir/Provenance/4/_history/1",
            "etag":"W/\"1\"",
            "lastModified":"2020-11-28T10:32:20.3635841+03:00"
         }
      }
   ]
}

Expected behavior According to http://hl7.org/fhir/STU3/http.html#2.21.0.17.2:

A transaction may include references from one resource to another in the bundle, including circular references where resources refer to each other. If the server assigns a new id to any resource in the bundle as part of the processing rules above, it SHALL also update any references to that resource in the same bundle as they are processed. References to resources that are not part of the bundle are left untouched. Version-specific references should remain as version-specific references after the references have been updated. Servers SHALL replace all matching links in the bundle, whether they are found in the resource ids, resource references, url elements, or <a href="" & <img src="" in the narrative.

So in the returned bundle it should be:

...
      {
         "resource":{
            "resourceType":"Provenance",
...
            "target":[
               {
                  "reference":"Patient/1071"
               }
  ...

Failing tests

At least this one: ConnectathonAuditEventAndProvenanceTrackTest

andy-a-o avatar Nov 28 '20 07:11 andy-a-o

To document an additional test case using published example data, I encountered this bug when attempting to verify processing of the DocumentReference-related "XDS example" Bundle provided by HL7 (XML JSON).

Using that example, wherein all bundle entries have a .request.method of POST, all 5 resources are created. None maintain their original IDs (as expected). However, all references are maintained in their original state - meaning that none can be retrieved by reference. E.g., the DocumentReference still has a .subject of Patient/a2 and .author references to Practitioner/a3 and Practitioner/a4.

This verification was performed using Spark.Engine.R4@1.5.14 (with Hl7.Fhir.R4@4.3.0).

JeremiahSanders avatar Nov 08 '22 20:11 JeremiahSanders