Using FHIR bundles

If your applications needs to create or update multiple FHIR resources at once you can send a bundle.

Read the official specification

The bundle needs to be send as POST request to the FHIR base URL

POST https://test.midata.coop/fhir

Here is an example bundle:

{
  "resourceType": "Bundle", 
  "type": "transaction",
  "entry": [
    {
      "resource": {
        "resourceType": "Observation",
        "status": "registered",
        "code": {
          "coding": [
            {
              "system": "http://loinc.org",
              "display": "Glucose [Mass/volume] in Blood",
              "code": "2339-0"
            }
          ]
        },  
        "effectiveDateTime" : "2019-01-01",      
        "valueQuantity": {
          "value": "12.13",
          "unit": "mg/dL"
        }
      },
      "request": {
        "method": "POST",
        "url": "Observation"
      }
    },
    {
      "resource": {
        "resourceType": "Observation",
        "status": "registered",
        "code": {
          "coding": [
            {
              "system": "http://loinc.org",
              "display": "Glucose [Mass/volume] in Blood",
              "code": "2339-0"
            }
          ]
        },
        "effectiveDateTime" : "2019-01-05",
        "valueQuantity": {
          "value": "11.1",
          "unit": "mg/dL"
        }
      },
      "request": {
        "method": "POST",
        "url": "Observation"
      }
    }
  ]
}

Tipps

  • Just must provide the “type” field with values “transaction”, “batch” or “document”.
  • There is no “/” at the end of the URL “/fhir”
  • If your bundle does not work and you dont know why try to stores resources one by one and search the servers responses for error messages.

References inside the Bundle

Resources in a bundle may reference each other. Give the resource that is referenced a unique id like:

{
   "resourceType" : "Observation",
   "id" : "obs1",
   ...
}

that id will be replaced with a server generated id when the resource is stored. However you can reference the resource like that:

{
  ...
  "derivedFrom" : [{
      "reference" : "Observation/obs1",
      "display" : "My other observation"
  }]
  ...
}

The id “obs1” in the reference will be replaced by the final id of the referenced Observation.

Document-type Bundles

For a bundle of type document you do not need to provide the “request” part of the entries. The platform will automatically determine for each resource in the bundle if it is a create or update operation.