FHIRPACK Minimal Example#

The purpose behind this Notebook is to quickly show you how to use FHIRPACK.

Don’t be intimidated, start using what you need and slowly get acquainted with more complex workflows and functionality as described in the Detailed Usage Notebook.

Feel free to refer to our Documentation, our GitLab and GitHub trackers or our Slack channel.

Preamble#

Jupyter Configuration#

[5]:
%load_ext autoreload
%autoreload 2
%pprint off

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

import pandas                       as pd
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', None)

The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
Pretty printing has been turned OFF

Installing FHIRPACK#

From PyPI via pip#

⚠️ this is the recommended way if installing FHIRPACK

[2]:
!pip install -q fhirpack

From Source#

Alternatively, you can installed the latest version of this repository in edit mode if you want to play around and modify FHIRPACK.

[3]:
# uncomment to install FHIRPACK from source
# !pip install -e .

Use without Installation by Modifying PYTHONPATH#

You can use FHIRPACK without installing it, this is mostly used for testing purposes during development, but it’s listed here for reference.

Simply clone the FHIRPACK repository using git clone git@github.com:fhirpack/main.git or git clone git@gitlab.com:fhirpack/main.git

[4]:
import sys,os
# uncomment to add FHIRPACK's src directory to PYTHONPATH
# sys.path.append(os.getcwd()+'/../src/')

Using FHIRPACK#

Imports#

[2]:
import fhirpack     as fp
import pandas       as pd
import numpy        as np
import json

RESPATH=f"./data/"

Server Connection#

Configure PACK with Environment File#

[8]:
pack = fp.PACK(envFile='./.env.example')
[9]:
pack.client
[9]:
<SyncFHIRClient https://hapi.fhir.org/baseR4>

Playground#

[10]:
conditions = pack\
    .getConditions(["gtc106"])

conditions.shape
GET[Condition]> :   0%|          | 0/1 [00:00<?, ?it/s]
[10]:
(1, 2)
[27]:
conditions[0:1]
[27]:
data Condition
0 {'resourceType': 'Condition', 'id': 'gtc106', 'meta': {'versionId': '1', 'lastUpdated': '2019-09-18T18:45:55.877+00:00', 'source': '#2fc9ee4c29f0eff4'}, 'code': {'coding': [{'system': 'http://hl7.org/fhir/sid/icd-10', 'code': 'I46.9', 'display': 'Cardiac arrest, cause unspecified'}]}, 'subject': {'reference': 'Patient/gtp101'}, 'onsetDateTime': '2019-07-30T01:00:00.000-05:00'} gtc106
[28]:
conditions[0:1].pretty
[
    {
        "code": {
            "coding": [
                {
                    "code": "I46.9",
                    "display": "Cardiac arrest, cause unspecified",
                    "system": "http://hl7.org/fhir/sid/icd-10"
                }
            ]
        },
        "id": "gtc106",
        "meta": {
            "lastUpdated": "2019-09-18T18:45:55.877+00:00",
            "source": "#2fc9ee4c29f0eff4",
            "versionId": "1"
        },
        "onsetDateTime": "2019-07-30T01:00:00.000-05:00",
        "resourceType": "Condition",
        "subject": {
            "reference": "Patient/gtp101"
        }
    }
]
[29]:
conditions[:5].getPatients()

[29]:
data Patient Condition
0 {'resourceType': 'Patient', 'id': 'gtp101', 'meta': {'versionId': '4', 'lastUpdated': '2020-12-11T19:17:27.172+00:00', 'source': '#f4P6OZY8WX2WA4Hq'}, 'text': {'status': 'generated', 'div': '<div xmlns="http://www.w3.org/1999/xhtml"><div class="hapiHeaderText">Herbert <b>HOOVER </b></div><table class="hapiPropertyTable"><tbody><tr><td>Identifier</td><td>078-05-1120</td></tr><tr><td>Address</td><td><span>123 Main Street North </span><br/><span>Everytown </span><span>USA </span></td></tr><tr><td>Date of birth</td><td><span>04 July 1990</span></td></tr></tbody></table></div>'}, 'identifier': [{'use': 'usual', 'system': 'urn:oid:2.16.840.1.113883.4.642.2.30', 'value': '078-05-1120', 'assigner': {'display': 'U.S. Social Security Administration'}}], 'active': True, 'name': [{'use': 'official', 'family': 'Hoover', 'given': ['Herbert']}], 'telecom': [{'system': 'phone', 'value': '8885551234', 'use': 'home'}], 'gender': 'male', 'birthDate': '1990-07-04', 'deceasedDateTime': '2019-07-30T02:34:06.000-05:00', 'address': [{'use': 'home', 'line': ['123 Main Street North'], 'city': 'Everytown', 'state': 'USA', 'postalCode': '99999'}]} gtp101 gtc106
[30]:
conditions[:5]\
    .getPatients()\
            .gatherSimplePaths([
                    "id",
                    "name.given",
                    "name.family",
                    "birthDate"
            ])

[30]:
id name.given name.family birthDate
0 gtp101 [[Herbert]] [Hoover] 1990-07-04