Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
cse5810_implementation/hapi_fhir.ipynb
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
203 lines (203 sloc)
4.49 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "913f5326-9c0f-4875-ae26-80406108563b", | |
"metadata": {}, | |
"source": [ | |
"![hapi fhir logo](images/hapi_fhir_banner.png)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "0342149e-30b3-466f-8140-ca74002b9568", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from fhirclient import client\n", | |
"import json\n", | |
"import requests" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "5fcec681-274a-4bdb-b576-7709fd1e120b", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# settings\n", | |
"%run util.py" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "6b1b75e6-6641-4463-aefa-7b2cfeb0ebb3", | |
"metadata": {}, | |
"source": [ | |
"### Check If HAPI Is Live\n", | |
"\n", | |
"check every available resource for a 200 status code" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "20fca573-2e6f-42c2-8a5a-94108bf57450", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"print(is_hapi_live())" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "48172346-a366-438b-9b9b-f5ffaea05e9f", | |
"metadata": {}, | |
"source": [ | |
"### Swagger Page" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "cb587bd6-1efc-4eae-a959-ff4a4160f94c", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# open the swagger web page to view all endpoints\n", | |
"open_swagger()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "2c49c504-b75b-4e6d-ae94-2f452b3a9581", | |
"metadata": {}, | |
"source": [ | |
"### Get Resource List" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "7685af34-5956-46ae-a2d7-caa2504d1299", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# get resource list from hapi fhir running instance\n", | |
"\n", | |
"resources = get_resource_list()\n", | |
"print(f\"There are {len(resources)} resources available\")\n", | |
"print(\"The available resources are: \")\n", | |
"\n", | |
"idx = 0\n", | |
"for resource in resources:\n", | |
" print(f\"{idx}. {resource}\")\n", | |
" idx += 1\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "4a8c5db7-2f09-4125-9fb0-3842fe97320c", | |
"metadata": {}, | |
"source": [ | |
"## Basic Functions" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "bed91136-1210-4d11-ba72-da6f8bc6e89e", | |
"metadata": {}, | |
"source": [ | |
"### Check index" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "88e6ac2b-9f12-4dd5-84ad-c760830dabd0", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# test that getting index by name works\n", | |
"observation_index = get_resource_index(\"observation\")\n", | |
"patient_index = get_resource_index(\"PaTiEnT\")\n", | |
"\n", | |
"print(f\"\\nThe list index for Patient is {patient_index}\")\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "78fc9a1e-f928-4cf1-99e7-692e361970e2", | |
"metadata": {}, | |
"source": [ | |
"### Get resource using index" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "53ae44ff-2710-4027-b28c-c0bc0ffbe600", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Get resource using the index\n", | |
"\n", | |
"all_observations = get_json(resource=resources[observation_index])\n", | |
"all_patients = get_json(resource=resources[patient_index])\n", | |
"all_observations_json = json.loads(all_observations)\n", | |
"\n", | |
"print(f\"Observation keys: {all_observations_json.keys()}\")\n", | |
"\n", | |
"for k,v in all_observations_json.items():\n", | |
" print(f\"\\nkey: {k}\\nvalue: {v}\\n\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "601e59a5-b39c-4e6f-b978-51294098b34e", | |
"metadata": {}, | |
"source": [ | |
"### Print JSON" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "b33366a4-09db-40d8-b9a3-d982a0048f93", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"\n", | |
"all_patients_json = json.loads(all_patients)\n", | |
"print(all_patients_json.keys())\n", | |
"\n", | |
"print(\"PATIENT\")\n", | |
"for elem in all_patients_json['entry']:\n", | |
" print(f\"\\n{elem}\")" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.9.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |