Search code examples
hapi-fhirhl7-fhir

Write correct JSON about PlanDefinition and ActivityDefinition on FHIR


I want to write a JSON to create a PlanDefinition resource with some ActivityDefinition resources inside it to persiste on FHIR r4 server these resources.

My sandbox server is Hapi FHIR

Two questions:

The first: How can I write it

The second: When I'll wirte the correct JSON, the result will be the creation of one PlanDefinition resource and some ActivityDefinition resources, or will be created only one PlanDefinition resource with these informations inside it?

This is my JSON to create a simple PlanDefinition, but I donìt know how to add ActivityDefinition inside it

{
  "resourceType": "PlanDefinition",
  "id": "999999",
  "meta": {
    "versionId": "1",
    "lastUpdated": "2020-04-16T11:10:45.868+00:00",
    "source": "#YS2h8QIqvGKHDy4x"
  },
  "url": "www.myserver.it",
  "identifier": [ {
    "system": "www.myserver.it",
    "value": "jtr-pd1"
  } ],
  "version": "versione 1",
  "status": "active",
  "action": [ {
    "title": "A",
    "definitionCanonical": "#Process_Alex1"
  }, {
    "title": "B",
    "definitionCanonical": "#Process_Alex2"
  }, {
    "title": "C",
    "definitionCanonical": "ActivityDefinition"
  } ]
}

Solution

  • Typically in FHIR we don't contain resources inside each other. References instead point to other independently maintained resource instances. For example, multiple PlanDefinitions might point to the same ActivityDefinition because that one activity is a 'step' in multiple protocols/order sets.

    If you have a situation where an activity definition is tied to a single PlanDefinition and can't exist independent of that PlanDefinition (e.g. if the PlanDefinition were deleted, the ActivityDefinition would go too; no other PlanDefinition can point to the Activity, any update to the activity would be considered an update to the plan, etc.), you can send the ActivityDefinition as a 'contained' resource. Your instance would look like this:

    {
      "resourceType": "PlanDefinition",
      "id": "999999",
      "meta": {
        "versionId": "1",
        "lastUpdated": "2020-04-16T11:10:45.868+00:00",
        "source": "#YS2h8QIqvGKHDy4x"
      },
      "contained": [ {
        "resourceType": "ActivityDefinition",
        "id": "Process_Alex1",
        ...
      },
      {
        "resourceType": "ActivityDefinition",
        "id": "Process_Alex2",
        ...
      } ],
      {
      "url": "www.myserver.it",
      "identifier": [ {
        "system": "www.myserver.it",
        "value": "jtr-pd1"
      } ],
      "version": "versione 1",
      "status": "active",
      "action": [ {
        "title": "A",
        "definitionCanonical": "#Process_Alex1"
      }, {
        "title": "B",
        "definitionCanonical": "#Process_Alex2"
      }, {
        "title": "C",
        "definitionCanonical": "http://somewhere.org/ActivityDefinition/foo"
      } ]
    }