Skip to content

PHR FHIR Envelope

angshuman sarkar edited this page Jun 14, 2020 · 26 revisions

All data that you want to transfer, should be in a FHIR Bundle. A Bundle is a means of packaging multiple information of multiple types - either as disparate Collection or as Document. The entire bundle is referred as data "content".

  • Note the content itself must be encrypted. Please refer to the API documentation of how data should be sent over HTTPS. For encryption of the "content" or "bundle", you should refer to the API and Diffie-Hellman key exchange documentation.
  • The relevant sections only focuses on the packaging information in FHIR resources' format.

The basic Bundle

{
    "resourceType": "Bundle",
    "id": "fe13172d-107f-4004-8d01-ebcc9c2485cb",
    "type": "collection",
    "entry": [
        {
            "fullUrl": "urn:uuid:8789a6c5-c139-4a06-bc4d-7c6ec822fe36",
            "resource": {
                "resourceType": "Media",
                "id": "8789a6c5-c139-4a06-bc4d-7c6ec822fe36",
                ....
            }
        },
        {
            "fullUrl": "urn:uuid:12d593df-dece-4a74-8bd9-b89ee769e316",
            "resource": {
                "resourceType": "Observation",
                "id": "12d593df-dece-4a74-8bd9-b89ee769e316",
                ....
            }
        }, 
        .... 
    ]
}

The above is the basic structure of a FHIR Bundle.

  • resourceType - must be Bundle
  • id - must be unique for each bundle that you want to send.
  • type - must be "collection" or "document". Collection is meant for assembling disparate resources together,while document is meant for contextual grouping of information. We will explain Bundle type "document" in detail later.
  • entry - is an array of FHIR resources. As of now, the reference HIU service supports 5 top level resources like "Media", "Observation", "Condition", "MedicationRequest" & "DiagnosticReport".
    • Notice each entry's fullUrl: prefixed with urn:uuid, followed by the , which is also the "id" of resource. In FHIR specification, this need not be so, but we expect in the format mentioned. (Also as fallback in the HIU User interface, in case we can not resolve the dependencies using the resource id)

Lets proceed with the first resource type.

Media Resource

The most basic type of Resource that can contain Health Information is Media. A media resource, can contain any attachment - usually inline (preferred). The attachments can be any file - PDF, WORD, JPEG, PNG, MPEG etc. For complete details on FHIR Media Resource, please refer to the the FHIR documentation website.

For example of Media resource within the reference stack, please see below.

{
    "resourceType": "Media",
    "id": "8789a6c5-c139-4a06-bc4d-7c6ec822fe36",
    "status": "completed",
    "createdDateTime": "2020-06-05T08:30:00+05:30",
    "note": [ 
        {
            "text": "BILATERAL DIGITAL MAMMOGRAPHY and 3D TOMOSYNTHESIS"
        },
        { 
            "text":"No particular impression"
        }
    ],
    "content": {
        "contentType": "application/pdf",
        "data":"<base 64 encoded content of the file>"
        "title": "BILATERAL DIGITAL MAMMOGRAPHY and 3D TOMOSYNTHESIS"
    }
}

The above is an example of a Media resource with minimal information. Most of it should be self-explanatory, but it is trying to send over a Digital Mammography report as PDF.

  • resourceType - must be specified - in this case Media
  • id - unique Id of the Media resource within the bundle context. Please note the relevance to the entry fullUrl as explained above
  • status - complete. Usually complete - for other status values - check FHIR Media documentation.
  • createdDateTime - time in UTC format. Note, if the Media resource is sent independently, then you must specify the createdDateTime.
  • note - textual notes about the media that you are sending.
  • content - is an attachment, meaning the file you are sending over.
    • contentType - Mime type of the content. It upto the HIU viewer what mimetype they can render/display. But typically stick to the following - application/pdf, image/jpef, image/png, application/msword, application/rtf, audio/mpeg, application/dicom
    • title - optional but useful to express what the attachment is for
    • data - base 64 encoded content of file. For example, if I would want to base64 encode a file from command line I would probably do something like below
openssl base64 -in <infile> -out <outfile>

Putting it altogether

Now if I were to put the "Media Resource" in the bundle's entry section, I would have something like below.

{
  "resourceType": "Bundle",
  "id": "fe13172d-107f-4004-8d01-ebcc9c2485cb",
  "type": "collection",
  "entry": [
    {
      "fullUrl": "urn:uuid:8789a6c5-c139-4a06-bc4d-7c6ec822fe36",
      {
        "resourceType": "Media",
        "id": "8789a6c5-c139-4a06-bc4d-7c6ec822fe36",
        "status": "completed",
        "createdDateTime": "2020-06-05T08:30:00+05:30",
        "note": [
          {
            "text": "BILATERAL DIGITAL MAMMOGRAPHY and 3D TOMOSYNTHESIS"
          },
          {
            "text": "No particular impression"
          }
        ],
        "content": {
          "contentType": "application/pdf",
          "data": "<do not forget to put base 64 encoded content of the file>",
          "title": "BILATERAL DIGITAL MAMMOGRAPHY and 3D TOMOSYNTHESIS"
        }
      }
    }
  ]
}

And thats it, you have your first PHR FHIR bundle ready to be encrypted and sent!

TIPS

  • You are never going to handcode the JSON above. You would use a FHIR client library.
  • During development, if you are hand-coding a resource, its usually a good idea to validate the resource. For this, you may use one of the validators listed in the reference library/resources section. For example, if I were to use the official FHIR validator jar, I would save the file (entire bundle or individual resource) as a json file and use the following command

java -jar org.hl7.fhir.validator.jar AttachedMediaAsReport.json -version 4.0

Clone this wiki locally