Batch

Bundle resource of type 'batch' can be used for batch import of resources.

1. Submit the Batch
Pack all records into a Bundle of type 'batch'. And send HTTP POST request to the Bundle endpoint.

📘

Tip

If you want to handle individual operation results then you can add Entry.fullUrl attribute to each entry to identify them later.
The value should be in the following format:

urn:uuid:UUIDV4

For example:

"fullUrl":"urn:uuid:7f9724ed-ef8d-4434-aacb-41869db83233"

For each entry of the bundle we will execute Create operation and put the result of this Create operation into the bundle of 'batch-response' type. Creation of resources of Observation type will automatically create corresponding DiagnosticReport resources and individual Observations will be grouped into the same DiagnosticReport resource based on the observation date.
In the response of your POST to the Bundle end point you will get the reference to the batch-response bundle. Batch-response bundle for your POST operation will be available via the returned reference for 10 minutes since the completion of POST.
If Create operation is not supported for the given resource in the bundle then corresponding batch-response entry will include "operation not supported" error.

If you expect that creation of all resources in the batch bundle can take more than a minute to complete then you need to execute asynchronous call

{
   "resourceType":"Bundle",
   "id":"batch",
   "type":"batch",
   "entry":[
      {
         "fullUrl":"urn:uuid:7f9724ed-ef8d-4434-aacb-41869db83233",
         "resource":{
            "resourceType":"Observation",
            "status":"final",
            "category":[{
               "coding":[
                  {
                     "code":"laboratory",
                     "system":"http://terminology.hl7.org/CodeSystem/observation-category"
                  }
               ],
               "text":"Laboratory"
            }],
            "code":{
               "coding":[
                  {
                     "code":"3043-7",
                     "system":"http://loinc.org"
                  }
               ],
               "text":"Triglycerides"
            },
            "issued":"2017-03-18T00:00:00Z",
            "referenceRange":[
               {
                  "high":{
                     "code":"mg/dL",
                     "system":"http://unitsofmeasure.org",
                     "unit":"mg/dL",
                     "value":250
                  },
                  "low":{
                     "code":"mg/dL",
                     "system":"http://unitsofmeasure.org",
                     "unit":"mg/dL",
                     "value":10
                  },
                  "text":"10 to 250 mg/dL"
               }
            ],
            "valueQuantity":{
               "code":"mg/dL",
               "system":"http://unitsofmeasure.org",
               "unit":"mg/dL",
               "value":93
            },
            "subject":{
               "display":"James Ellroy"
            }
         }
      },
      {
         "fullUrl":"urn:uuid:d5d0848a-6610-4053-8663-42a8c9423a13",
         "resource":{
            "resourceType":"Observation",
            "status":"final",
            "category":{
               "coding":[
                  {
                     "code":"laboratory",
                     "system":"http://terminology.hl7.org/CodeSystem/observation-category"
                  }
               ],
               "text":"Laboratory"
            },
            "code":{
               "coding":[
                  {
                     "code":"3043-8",
                     "system":"http://loinc.org"
                  }
               ],
               "text":"Triglycerides - plasma"
            },
            "issued":"2017-03-18T00:00:00Z",
            "referenceRange":[
               {
                  "high":{
                     "code":"mg/dL",
                     "system":"http://unitsofmeasure.org",
                     "unit":"mg/dL",
                     "value":250
                  },
                  "low":{
                     "code":"mg/dL",
                     "system":"http://unitsofmeasure.org",
                     "unit":"mg/dL",
                     "value":10
                  },
                  "text":"10 to 250 mg/dL"
               }
            ],
            "valueQuantity":{
               "code":"mg/dL",
               "system":"http://unitsofmeasure.org",
               "unit":"mg/dL",
               "value":25
            },
            "subject":{
               "display":"James Ellroy"
            }
         }
      }
   ]
}
HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
Location: /fhir/R4/Bundle/7007aba0-4b2c-4ded-87e1-bbbf956675cb
X-Hg-Request-Id: 15e2305e94845d4d2f3f7796
Content-Length: 0
Date: Tue, 6 Feb 2020 14:33:16 GMT

To get the outcome of the operation in the batch-response bundle you should use the value of the Location header.

/fhir/R4/Bundle/7007aba0-4b2c-4ded-87e1-bbbf956675cb

2. Read operation results
In order to review the outcome of batch bundle POST operation you need to send HTTP GET request to the URL of the batch-response bundle.

The response is a Bundle resource that contains individual operations results. The lifetime of batch-response bundle is 10 minutes.

GET /fhir/R4/Bundle/7007aba0-4b2c-4ded-87e1-bbbf956675cb HTTP/1.1 
Host: api.healthgorilla.com 
Authorization: Bearer sldfksgkkG78dsdff787
{
    "resourceType": "Bundle",
    "type": "batch-response",
    "entry": [
        {
            "fullUrl": "urn:uuid:7f9724ed-ef8d-4434-aacb-41869db83233",
            "response": {
                "status": "201 Created",
                "location": "/fhir/R4/Observation/4b87e05eb81b1461891a49cd-grp-7f9724ed-ef8d-4434-aacb-41869db83233",
                "etag": "1591773003694",
                "lastModified": "2020-06-10T10:10:03.694+03:00"
            }
        },
        {
            "fullUrl": "urn:uuid:d5d0848a-6610-4053-8663-42a8c9423a13",
            "response": {
                "status": "201 Created",
                "location": "/fhir/R4/Observation/4b87e05eb81b1461891a49cd-grp-d5d0848a-6610-4053-8663-42a8c9423a13",
                "etag": "1591773003694",
                "lastModified": "2020-06-10T10:10:03.694+03:00"
            }
        },
        {
            "fullUrl": "urn:uuid:046751b9-210c-4bbf-a914-ec742fd71fc5",
            "response": {
                "extension": [
                    {
                        "url": "http://hl7.org/fhir/StructureDefinition/http-response-header",
                        "extension": [
                            {
                                "url": "Existing-Resource-Id",
                                "valueString": "462bde5e608913edccadbbe0"
                            }
                        ]
                    }
                ],
                "status": "422",
                "outcome": {
                    "resourceType": "OperationOutcome",
                    "issue": [
                        {
                            "severity": "error",
                            "code": "duplicate",
                            "details": {
                                "text": "The supplied record duplicates the existing one."
                            },
                            "diagnostics": "Failed to create duplicate."
                        }
                    ]
                }
            }
        }
    ]
}