FHIR Transaction with conditional create

The conditional create is roughly described as “use an existing resource that matches specific criteria if one exists (and do not modify that resource), or create a new one if not.”

The specific criteria in question can be any set of FHIR search parameters that could be used to otherwise locate the resource to use. The resource identifier field/search parameter is often used for this purpose, but other search parameters can also be used.

In an FHIR Transaction operation, an operation is performed using a conditional create.

This involves creating a Transaction Bundle with the following properties (an Observation being created with a reference to a Conditionally Created Patient is being used for this example):
  • One or more entries containing an Observation resource with a request.method value of POST. This means that the server should create the new Observation resources, and automatically assign them new IDs.
  • The Observation resources contain a reference where the target is the fullUrl UUID for the Patient entry. If the Patient target was created (because it did not already exist) the reference will automatically be replaced with a reference to the newly created resource. If the Patient target was not created (because it already existed), the reference will automatically be replaced with a reference to the pre-existing Patient resource.
  • An entry containing a Patient resource with:
    • A request.method value of POST
    • A fullUrl value containing a temporary UUID. This is used as the target for references to this resource from other resources. A request.ifNoneExist value containing a search URL that could be used to find this resource (in the example below, a search for the Patient by identifier). This indicates to the server that this resource should only be created if no existing resource already matches the given search criteria.

Example: Transaction Bundle

An example Transaction Bundle is shown below. It should be POSTed to the root of the FHIR Endpoint module server.

"resourceType": "Bundle",
  "meta": {
    "lastUpdated": "2014-08-18T01:43:30Z"
  },
  "type": "transaction",
  "entry": [
    {
      "fullUrl": "urn:uuid:61ebe359-bfdc-4613-8bf2-c5e300945f0a",
      "resource": {
        "resourceType": "Patient",
        "text": {
          "status": "generated",
          "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Some narrative</div>"
        },
        "active": true,
        "name": [
          {
            "use": "official",
            "family": "Chalmers",
            "given": [
              "Peter",
              "James"
            ]
          }
        ],
        "gender": "male",
        "birthDate": "1974-12-25"
      },
      "request": {
        "method": "POST",
        "url": "Patient"
      }
    },
    {
      "fullUrl": "http://example.org/fhir/Patient/100058",
      "resource": {
        "resourceType": "Patient",
        "id": "123",
        "text": {
          "status": "generated",
          "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Some narrative</div>"
        },
        "active": true,
        "name": [
          {
            "use": "official",
            "family": "Chalmers",
            "given": [
              "Peter",
              "James"
            ]
          }
        ],
        "gender": "male",
        "birthDate": "1974-12-25"
      },
      "request": {
        "method": "PUT",
        "url": "Patient/100058"
      }
    },
    {
      "request": {
        "method": "GET",
        "url": "Patient?name=Peter"
      }
    },
    {
      "request": {
        "method": "GET",
        "url": "Patient/1",
        "ifNoneMatch": "W/\"4\"",
        "ifModifiedSince": "2015-08-31T08:14:33+10:00"
      }
    }
  ]
}