{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Verify a FHIR Digitally Signing FHIR Bundle or QuestionnaireResponse Object\n", "\n", "This is a Jupyter Notebook using Python 3.7 and openSSl to create JSON Web Signature (JWS)(see RFC 7515) and attach it to a FHIR Bundle or QuestionnaireResponse resource.\n", "\n", "- If the resource is a Bundle use Bundle.signature\n", "- If the resource is a QuestionnaireResponse use its [Signature extension](http://hl7.org/fhir/StructureDefinition/questionnaireresponse-signature\n", ")\n", "\n", "See: http://build.fhir.org/signatures.html\n", "\n", "*Although self-signed certificates are used for the purpose of these examples, they are not recommended for production systems.*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Import Libraries" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "from requests import get, post\n", "from json import dumps, loads\n", "from pathlib import Path\n", "# from datetime import datetime\n", "# import pytz\n", "from jose import jws #python JWS package\n", "from base64 import urlsafe_b64encode, b64decode\n", "from jcs import canonicalize #package for a JCS (RFC 8785) compliant canonicalizer.\n", "from lxml import etree" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "...fetching payload from /Users/ehaas/Documents/FHIR/davinci-ecdx/output/Parameters-cdex-parameters-example2.json ....\n", "Parameters Attachment Content Example\n", "{\n", " \"resourceType\": \"Bundle\",\n", " \"id\": \"cdex-document-digital-sig-example\",\n", " \"identifier\": {\n", " \"system\": \"urn:ietf:rfc:3986\",\n", " \"value\": \"urn:uuid:c173535e-135e-48e3-ab64-38bacc68dba8\"\n", " },\n", " \"type\": \"document\",\n", " \"timestamp\": \"2021-10-25T20:16:29-07:00\",\n", " \"entry\": [\n", " {\n", " \"fullUrl\": \"urn:uuid:17a80a8d-4cf1-4deb-a1fd-2db1130e5f76\",\n", " \"resource\": {\n", " \"resourceType\": \"Composition\",\n", " \"id\": \"17a80a8d-4cf1-4deb-a1fd-2db1130e5f76\",\n", " \"text\": {\n", " \"status\": \"generated\",\n", " \"div\": \"
This document, titled "Active Conditions," was created on October 25, 2021, by Dr. John Hancock, who also legally attested to its accuracy on the same date. It summarizes the active medical conditions for a patient based on an emergency encounter on October 25, 2021. The document includes one section detailing an active condition: Type 2 Diabetes Mellitus.
Dr. John Hancock is a healthcare provider with National Provider Identifier (NPI) 9941339100. He authored and attested to the medical records document.
CDEX Example Patient, a male, is identified by member ID Member123 in the payer system http://example.org/cdex/payer/member-ids. He is the subject of this medical records document. The patient said, "I feel great!"
The patient has an active diagnosis of Type 2 Diabetes Mellitus (SNOMED CT: 44054006), first identified in 2006. This condition was documented by Dr. John Hancock and is listed as a problem on the patient\\u2019s problem list.
An emergency encounter occurred on October 25, 2021, from 8:10 PM to 8:16 PM, involving CDEX Example Patient and attended by Dr. John Hancock at CDEX Example Organization. The encounter type is unspecified (SNOMED CT: 261665006).
CDEX Example Organization, located at 1 CDEX Lane, Boston, MA 01002, USA, is the service provider for the documented encounter. Contact details include phone: (+1) 555-555-5555 and email: customer-service@example.org. The organization's NPI is 1234567893.
This document, titled "Active Conditions," was created on October 25, 2021, by Dr. John Hancock, who also legally attested to its accuracy on the same date. It summarizes the active medical conditions for a patient based on an emergency encounter on October 25, 2021. The document includes one section detailing an active condition: Type 2 Diabetes Mellitus.
Dr. John Hancock is a healthcare provider with National Provider Identifier (NPI) 9941339100. He authored and attested to the medical records document.
CDEX Example Patient, a male, is identified by member ID Member123 in the payer system http://example.org/cdex/payer/member-ids. He is the subject of this medical records document. The patient said, "I feel great!"
The patient has an active diagnosis of Type 2 Diabetes Mellitus (SNOMED CT: 44054006), first identified in 2006. This condition was documented by Dr. John Hancock and is listed as a problem on the patient\\xe2\\x80\\x99s problem list.
An emergency encounter occurred on October 25, 2021, from 8:10 PM to 8:16 PM, involving CDEX Example Patient and attended by Dr. John Hancock at CDEX Example Organization. The encounter type is unspecified (SNOMED CT: 261665006).
CDEX Example Organization, located at 1 CDEX Lane, Boston, MA 01002, USA, is the service provider for the documented encounter. Contact details include phone: (+1) 555-555-5555 and email: customer-service@example.org. The organization\\'s NPI is 1234567893.
This document, titled \"Active Conditions,\" was created on October 25, 2021, by Dr. John Hancock, who also legally attested to its accuracy on the same date. It summarizes the active medical conditions for a patient based on an emergency encounter on October 25, 2021. The document includes one section detailing an active condition: Type 2 Diabetes Mellitus.
Dr. John Hancock is a healthcare provider with National Provider Identifier (NPI) 9941339100. He authored and attested to the medical records document.
CDEX Example Patient, a male, is identified by member ID Member123 in the payer system http://example.org/cdex/payer/member-ids. He is the subject of this medical records document. The patient said, \"I feel great!\"
The patient has an active diagnosis of Type 2 Diabetes Mellitus (SNOMED CT: 44054006), first identified in 2006. This condition was documented by Dr. John Hancock and is listed as a problem on the patient’s problem list.
An emergency encounter occurred on October 25, 2021, from 8:10 PM to 8:16 PM, involving CDEX Example Patient and attended by Dr. John Hancock at CDEX Example Organization. The encounter type is unspecified (SNOMED CT: 261665006).
CDEX Example Organization, located at 1 CDEX Lane, Boston, MA 01002, USA, is the service provider for the documented encounter. Contact details include phone: (+1) 555-555-5555 and email: customer-service@example.org. The organization's NPI is 1234567893.
This document, titled \\\\\"Active Conditions,\\\\\" was created on October 25, 2021, by Dr. John Hancock, who also legally attested to its accuracy on the same date. It summarizes the active medical conditions for a patient based on an emergency encounter on October 25, 2021. The document includes one section detailing an active condition: Type 2 Diabetes Mellitus.
Dr. John Hancock is a healthcare provider with National Provider Identifier (NPI) 9941339100. He authored and attested to the medical records document.
CDEX Example Patient, a male, is identified by member ID Member123 in the payer system http://example.org/cdex/payer/member-ids. He is the subject of this medical records document. The patient said, \\\\\"I feel great!\\\\\"
The patient has an active diagnosis of Type 2 Diabetes Mellitus (SNOMED CT: 44054006), first identified in 2006. This condition was documented by Dr. John Hancock and is listed as a problem on the patient\\xe2\\x80\\x99s problem list.