Minimal Setup#

[2]:
%load_ext autoreload
%autoreload 2
%pprint off
Pretty printing has been turned OFF
[3]:
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
[4]:
%pprint
Pretty printing has been turned ON

Preamble#

Installing FHIRPACK from PIP (recommended)#

[ ]:
!pip install fhirpack

Using FHIRPACK 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

[ ]:
import sys,os
#sys.path.append(os.getcwd()+'/../src/')

Installing 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.

[ ]:
#!pip install -e .

Imports#

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

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

RESPATH=f"./data/"

FHIR Server Connection#

Configure PACK with Environment File#

[6]:
pack = fp.PACK(envFile='.env.example')

Playground#

[7]:
conditions = pack\
    .getConditions(
            searchParams={
                    "_content":"Coronary Heart Disease",
                    })

conditions.shape

[7]:
(102, 1)
[8]:
conditions[0:1]
[8]:
data
0 {'resourceType': 'Condition', 'id': '617158', 'meta': {'versionId': '1', 'lastUpdated': '2020-02-07T11:51:46.361+00:00', 'source': '#msg5Ia42NNbn9SQ0'}, 'clinicalStatus': {'coding': [{'system': 'http://terminology.hl7.org/CodeSystem/condition-clinical', 'code': 'active'}]}, 'verificationStatus': {'coding': [{'system': 'http://terminology.hl7.org/CodeSystem/condition-ver-status', 'code': 'confirmed'}]}, 'code': {'coding': [{'system': 'http://snomed.info/sct', 'code': '53741008', 'display': 'Coronary Heart Disease'}], 'text': 'Coronary Heart Disease'}, 'subject': {'reference': 'Patient/617077'}, 'encounter': {'reference': 'Encounter/617157'}, 'onsetDateTime': '2003-12-16T02:47:35-05:00', 'recordedDate': '2003-12-16T02:47:35-05:00'}
[9]:
conditions[0:1].pretty
{
    "clinicalStatus": {
        "coding": [
            {
                "code": "active",
                "system": "http://terminology.hl7.org/CodeSystem/condition-clinical"
            }
        ]
    },
    "code": {
        "coding": [
            {
                "code": "53741008",
                "display": "Coronary Heart Disease",
                "system": "http://snomed.info/sct"
            }
        ],
        "text": "Coronary Heart Disease"
    },
    "encounter": {
        "reference": "Encounter/617157"
    },
    "id": "617158",
    "meta": {
        "lastUpdated": "2020-02-07T11:51:46.361+00:00",
        "source": "#msg5Ia42NNbn9SQ0",
        "versionId": "1"
    },
    "onsetDateTime": "2003-12-16T02:47:35-05:00",
    "recordedDate": "2003-12-16T02:47:35-05:00",
    "resourceType": "Condition",
    "subject": {
        "reference": "Patient/617077"
    },
    "verificationStatus": {
        "coding": [
            {
                "code": "confirmed",
                "system": "http://terminology.hl7.org/CodeSystem/condition-ver-status"
            }
        ]
    }
}
[10]:
conditions[:5]\
    .getPatients()\
            .gatherSimplePaths([
                    "id",
                    "name.given",
                    "name.family",
                    "birthDate"
            ])

[10]:
id name.given name.family birthDate
0 [617077] [[[Andres25]]] [[Konopelski743]] [1975-10-07]
1 [ddbf5561-4bfd-4434-89fb-344387ca945b] [[[Adam631]]] [[Keebler762]] [1948-07-09]
2 None None None None
3 [4cee554c-9681-47b7-a3c4-06864ec294a0] [[[Agustín529]]] [[Cintrón695]] [1974-08-25]
4 [1b8a7c69-e0d0-4832-a9a1-b487bbc8af90] [[[Aja848], [Aja848]]] [[Herman763, Hansen121]] [1959-10-02]