microsoft / fhir-server

A service that implements the FHIR standard
MIT License
1.19k stars 512 forks source link

X-Provenance on transaction bundle only adds Provenance for first Resource #3361

Open LodewijkSioen opened 1 year ago

LodewijkSioen commented 1 year ago

Describe the bug When adding the X-Provenance header to a POST of a Transaction Bundle, only the first resource that is created or updated will have a linked Provenance.

FHIR Version? R4

Data provider? SQL Server

To Reproduce Steps to reproduce the behavior:

Add some resources in a Transaction:

POST https://server_url
content-type: application/json
X-Provenance: { "resourceType": "Provenance", "recorded": "2023-06-19T11:05:24+02:00", "agent": [ { "who": { "reference": "Device/Test" } } ]  }

{
    "resourceType": "Bundle",
    "type": "transaction",
    "entry": [
        {
            "fullUrl": "Patient?identifier=urn%3Apatient%7C6108116119",
            "resource": {
                "resourceType": "Patient",
                "identifier": [
                    {
                        "system": "urn:patient",
                        "value": "6108116119"
                    }
                ],
                "name": [
                    {
                        "family": "Doe",
                        "given": [
                            "Jane"
                        ]
                    }
                ]
            },
            "request": {
                "method": "PUT",
                "url": "Patient?identifier=urn%3Apatient%7C6108116119"
            }
        },
        {
            "fullUrl": "Encounter?identifier=urn%3Adossier%7C80554680",
            "resource": {
                "resourceType": "Encounter",                
                "identifier": [
                    {
                        "system": "urn:dossier",
                        "value": "80554680"
                    }
                ],
                "status": "in-progress",
                "class": {
                    "system": "http://terminology.hl7.org/CodeSystem/v3-ActCode",
                    "code": "IMP"
                },
                "subject": {
                    "reference": "Patient?identifier=urn%3Apatient%7C6108116119"
                },
                "period": {
                    "start": "2014-12-11T08:31:00+01:00"
                }
            },
            "request": {
                "method": "PUT",
                "url": "Encounter?identifier=urn%3Adossier%7C80554680"
            }
        }
    ]
}

Only the patient will have a linked Provenance.

Expected behavior Every Resource that has been created or updated by the transaction should have a linked Provenance.

Actual behavior Only the first Resource created or updaten by the transaction has a linked Provenance.

AB#104579

brendankowitz commented 1 year ago

Thanks for reporting this @LodewijkSioen. @fhibf can you take a look at this?

LodewijkSioen commented 1 year ago

Related (but perhaps for another issue): I've been looking at your FhirClient and noticed that it is not possible to add the provenance header to the following operations:

Also, as a user of the Client, it would be nice to pass a Provenance object instead of a string.

LodewijkSioen commented 1 year ago

One more thing to think about: If using the X-Provenance header on a (transaction) bundle, should you create one Provenance per resource created/updated. Or should you create only one Provenance with multiple references in Target.

(I would think the last one)

EXPEkesheth commented 1 year ago

@LodewijkSioen thanks for reaching out ! Provenance header is used during PUT and POST. Will add work item in the backlog to address the issue related to not enabling for Patch, PostBundle and Post. #110273

FHIR spec does not call out support for Delete operation. https://www.hl7.org/fhir/provenance.html. For the question related to the creating one provenance per resource or one provenance with multiple references in the target, have reached out to FHIR community.

LodewijkSioen commented 1 year ago

Another thing: I was expecting the target in the Provenace resource to be version-specific. I was suprised to find out it wasn't.

EXPEkesheth commented 1 year ago

@LodewijkSioen - thanks for reporting. In the spec, it states target usually should be version specific. Item created in the backlog: #112074

Is this a blocker for you or nice to have?

LodewijkSioen commented 1 year ago

I would consider it a blocker, but I have a workaround by adding Provenance manually to a transaction bundle. It also misses the version, but at least I have a Provenance resource for everything in the Bundle.