The Bundle resource is a container for a collection of resources.

FHIR Resource: Bundle https://www.hl7.org/fhir/stu3/bundle.html

https://api.healthgorilla.com/fhir/Bundle

Document

Bundle of type document is used to aggregate Clinical Note and related resources in a single document in scope of C-CDA on FHIR implementation.
See FHIR Document http://hl7.org/fhir/stu3/documents.html

1. Create

HTTP RequestMethodAction
/BundlePOSTCreate new document

The operation outcome contains link to the newly created Composition resource.

2. Conditional create

This method also supports conditional create. To use it, you need to set additional header:
If-None-Exist: [search parameters]The only parameter is accepted ‘identifier’.

Example:
If-None-Exist: identifier=00025

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://hl7.org/fhir/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://hl7.org/fhir/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"
            }
         }
      },
      {
         "fullUrl":"urn:uuid:046751b9-210c-4bbf-a914-ec742fd71fc5",
         "resource":{
            "resourceType":"AllergyIntolerance",
            "identifier":[
               {
                  "system":"http://acme.com/ids/patients/risks",
                  "value":"49476534"
               }
            ],
            "recordedDate":"2014-10-09T14:58:00+11:00",
            "recorder":{
               "reference":"Practitioner/example"
            },
            "patient":{
               "reference":"Patient/example"
            },
            "substance":{
               "coding":[
                  {
                     "system":"http://snomed.info/sct",
                     "code":"227493005",
                     "display":"Cashew nuts"
                  }
               ]
            },
            "status":"confirmed",
            "criticality":"CRITH",
            "type":"allergy",
            "category":"food",
            "lastOccurence":"2012-06",
            "reaction":[
               {
                  "substance":{
                     "coding":[
                        {
                           "system":"http://www.nlm.nih.gov/research/umls/rxnorm",
                           "code":"C3214954",
                           "display":"cashew nut allergenic extract Injectable Product"
                        }
                     ]
                  },
                  "manifestation":[
                     {
                        "coding":[
                           {
                              "system":"http://snomed.info/sct",
                              "code":"39579001",
                              "display":"Anaphylactic reaction"
                           }
                        ]
                     }
                  ],
                  "description":"Challenge Protocol. Severe Reaction to 1/8 cashew. Epinephrine administered",
                  "onset":"2012-06-12",
                  "severity":"severe"
               },
               {
                  "certainty":"likely",
                  "manifestation":[
                     {
                        "coding":[
                           {
                              "system":"http://snomed.info/sct",
                              "code":"64305001",
                              "display":"Urticaria"
                           }
                        ]
                     }
                  ],
                  "onset":"2004",
                  "severity":"moderate"
               }
            ]
         }
      }
   ]
}
HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
Location: /fhir/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/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/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/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/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."
                        }
                    ]
                }
            }
        }
    ]
}