Resource Provenance

Resource Provenance

Any time a FHIR resource is created, updated, or deleted, the Oystehr FHIR API automatically creates a Provenance resource (opens in a new tab) to track the change. This provides you with an audit trail for all other FHIR resources. The automatically created FHIR Provenance records include the following details:

  • What resource was changed (in the target property).
  • Who made the change (in the agent property).
  • When the change was was made (in the recorded property).

Here is an example Provenance resource that was automatically created when a Patient resource was created:

{
  "resourceType": "Provenance",
  "id": "794d3c6b-8ef4-4c51-9fd8-cccf976e5227",
  "target": [
    {
      "reference": "Patient/eb683ca9-0e64-4a3e-98c6-c83ed8f383c3/_history/e4525e35-1914-4962-86fa-be52a617a30d"
    }
  ],
  "recorded": "2023-03-24T07:16:35.722Z",
  "activity": {
    "coding": [
      {
        "code": "CREATE"
      }
    ]
  },
  "agent": [
    {
      "who": {
        "reference": "Practitioner/eab11834-8082-44c4-8b4f-f5cbfbd8c6a3"
      }
    }
  ],
  "meta": {
    "versionId": "96e221a0-30b8-4626-9571-fcf12a408f6f",
    "lastUpdated": "2023-03-24T07:16:35.722Z"
  }
}

Determining the history of a resource

In combination with resource history, changes can be tracked to resources over time, including when the changes were made, and who made them.

Consider the Patient resource referenced above. After calling https://fhir-api.zapehr.com/r4/Patient/eb683ca9-0e64-4a3e-98c6-c83ed8f383c3/_history, we get:

{
  "resourceType":"Bundle",
  "type":"history",
  "entry":[
    {
      "fullUrl":"https://testing.fhir-api.zapehr.com/r4/Patient/eb683ca9-0e64-4a3e-98c6-c83ed8f383c3",
      "request":{
        "method":"POST",
        "url":"Patient"
      },
      "response":{
        "status":"200",
        "outcome":{
          "resourceType":"OperationOutcome",
          "id":"ok",
          "issue":[
            {
              "severity":"information",
              "code":"informational",
              "details":{
                "text":"All OK"
              }
            }
          ]
        },
        "lastModified":"2023-03-24T07:16:35.355Z"
      },
      "resource":{
        "resourceType":"Patient",
        "name":[
          {
            "given":[
              "Jon"
            ],
            "family":"Snow"
          }
        ],
        "id":"eb683ca9-0e64-4a3e-98c6-c83ed8f383c3",
        "meta":{
          "versionId":"e4525e35-1914-4962-86fa-be52a617a30d",
          "lastUpdated":"2023-03-24T07:16:35.355Z"
        }
      }
    }
  ]
}

We can call https://fhir-api.zapehr.com/r4/Provenance?target=Patient/eb683ca9-0e64-4a3e-98c6-c83ed8f383c3 to get all of the Provenance records for the Patient resource. This returns a Bundle of Provenance records, including the one above. From this resource we can determine that Practitioner/eab11834-8082-44c4-8b4f-f5cbfbd8c6a3 created the Patient.