Transaction

A Transaction bundle is used to send multiple FHIR resources as a single request, where each resource is processed as an independent operation but within the same atomic transaction. If any operation fails, the entire transaction will be rolled back to ensure consistency across the resources.

When to Use Transaction Bundles

Use a Transaction bundle when you need to submit multiple related operations (such as creating a new patient, observation, or diagnostic report) and want them to be processed together. If one operation fails, all the resources in the transaction will be rolled back to maintain data integrity.

For example, if you're creating a Patient, Observation, and DiagnosticReport at the same time, and it's crucial that either all succeed or all fail, you should use a Transaction bundle.

Note: Health Gorilla's API supports the use of Transaction bundles for atomic operations. If you use a Transaction bundle, all resources will be treated as a single unit. A failure in any resource operation will result in the rollback of the entire transaction.

Structure of a Transaction Bundle

Each entry in a Transaction bundle contains a resource and an operation (such as POST, PUT, or DELETE). The response will include the result of each operation, including any errors or successes.

Example Request

{
   "resourceType": "Bundle",
   "id": "transaction-example",
   "type": "transaction",
   "entry": [
      {
         "resource": {
            "resourceType": "Patient",
            "id": "12345",
            "name": [
               {
                  "use": "official",
                  "family": "Doe",
                  "given": ["John"]
               }
            ]
         },
         "request": {
            "method": "POST",
            "url": "Patient"
         }
      },
      {
         "resource": {
            "resourceType": "Observation",
            "status": "final",
            "category": [
               {
                  "coding": [
                     {
                        "code": "laboratory",
                        "system": "http://terminology.hl7.org/CodeSystem/observation-category"
                     }
                  ]
               }
            ],
            "code": {
               "coding": [
                  {
                     "code": "3043-7",
                     "system": "http://loinc.org"
                  }
               ],
               "text": "Triglycerides"
            },
            "valueQuantity": {
               "value": 93,
               "unit": "mg/dL"
            }
         },
         "request": {
            "method": "POST",
            "url": "Observation"
         }
      }
   ]
}

Example Response

The response for a successful transaction bundle includes a 201 Created status for each entry:

{
  "resourceType": "Bundle",
  "type": "transaction-response",
  "entry": [
    {
      "response": {
        "status": "201 Created",
        "location": "/fhir/Patient/12345",
        "etag": "1591773003694",
        "lastModified": "2020-06-10T10:10:03.694+03:00"
      }
    },
    {
      "response": {
        "status": "201 Created",
        "location": "/fhir/Observation/67890",
        "etag": "1591773003694",
        "lastModified": "2020-06-10T10:10:03.694+03:00"
      }
    }
  ]
}

Key Notes

  • Atomicity: All operations in a transaction bundle are processed together—either all succeed or none are applied.
  • Error Handling: If any operation fails, the entire transaction is rolled back, and the response will include an error message for the failed entry.

Related Information

Refer to the Bundle resource documentation for overall structure and rules.