将FHIR数据集转换为
fhir2dataset的Python项目详细描述
FHIR查询
使用SQL查询任何FHIR api。在
使用
importfhir2datasetasquerysql_query="SELECT p.name.family, p.address.city FROM Patient AS p WHERE p.birthdate=1944 AND p.gender = 'female'"query.sql(sql_query)^{pr2}$
FHIR查询仍在积极开发中,欢迎反馈和投稿!在
安装
pip install fhir2dataset
来源
克隆此存储库后,可以安装所需的依赖项
pip install -r requirements.txt npm install --prefix ./fhir2dataset/metadata
入门
输入查询有两种可能的方法:作为SQL查询或JSON配置文件
SQL查询
您可以定义以下形式的SQL查询:
sql_query="""SELECT (alias n°1).a, (alias n°1).b, (alias n°2).a FROM (Resource type 1) as (alias n°1)INNER JOIN (Resource type 2) as (alias n°2) ON (alias n°1).d = (alias n°2)WHERE (alias n°2).c = "value1"AND (alias n°2).d = "value2""""
请注意,我们只支持SQL关键字的一个子集。在
默认情况下,FHIR查询将使用HAPI FHIR Api。但您可以使用以下语法使用自己的api:
importfhir2datasetasqueryfhir_api_url='https://api.awesome.fhir.org/baseR4/'query.sql(sql_query,fhir_api_url=fhir_api_url)
JSON配置文件
您还可以使用JSON配置文件
fromfhir2dataset.queryimportQueryfromfhir2dataset.fhirrules_getterimportFHIRRulesfhir_api_url='http://hapi.fhir.org/baseR4/'fhir_rules=FHIRRules(fhir_api_url=fhir_api_url)query=Query(fhir_api_url,fhir_rules=fhir_rules)
config.json
:
{"select":{"alias n°1":["a","b","c"],"alias n°2":["a"]},"from":{"alias n°1":"Resource type 1","alias n°2":"Resource type 2","alias n°3":"Resource type 3"},"join":{"inner":{"alias n°1":{"d":"alias n°2"},"alias n°2":{"b":"alias n°3"}}},"where":{"alias n°2":{"c":"value 1","d":"value 2"},"alias n°3":{"a":"value 3","b":"value 4"}}}
# Enter in dirname the path of config.jsonfilename_config='config.json'withopen(os.path.join(dirname,filename_config))asjson_file:config=json.load(json_file)query.from_config(config)query.execute()df=query.main_dataframe
对于扩展用法,您可以引用这个tutorial,然后引用这个Jupyter Notebook
更多示例
看看查询的例子,以及它们是如何在调用FHIR api时转换的!在
- Select the gender and name for patients born after 2000
- Get clinical information about patients that were in intensive care unit because of Coronavirus
贡献
终端和虚拟环境中的以下命令允许您在每次提交之前执行一些最小的本地测试:
pip install -r requirements-dev.txt pre-commit install
如果您想删除它们,只需:
pre-commit clean
- 项目
标签: