FHIR资源作为模型类
fhir.resources的Python项目详细描述
fhir®资源(r4、stu3、dstu2)
所有FHIR Resources都可以作为内置python类使用 初始验证,导出为json值。
- 提供Resource Factory类(参见示例4)以更方便的方式创建资源对象。
- FHIR®资源的早期版本可用。
- 免费软件:BSD许可证
FHIR®版本信息
默认情况下,FHIR(R4又名4.0.0)可用。以前的版本也作为python子包提供 (每个版本名字符串变为子包名,即STU3)。
以前的版本可用:
- STU3(3.0.1)
- DSTU2(1.0.2)
安装
只要一个简单的pip install fhir.resources或easy_install fhir.resources就足够了。但如果你想发展 版本,只需从https://github.com/nazrulworld/fhir.resources和python setup.py install克隆。
示例:1:从json字符串创建的资源对象:
>>> from fhir.resources.organization import Organization >>> from fhir.resources.address import Address >>> json_dict = {"resourceType": "Organization", ... "id": "mmanu", ... "active": True, ... "name": "Acme Corporation", ... "address": [{"country": "Swizterland"}] ... } >>> org = Organization(json_dict) >>> isinstance(org.address[0], Address) >>> True >>> org.address[0].country == "Swizterland" True >>> org.as_json()['active'] is True True
示例:2:用python方法构造资源对象:
>>> org = Organization() >>> org.id = "mmanu" >>> org.active = True >>> org.name = "Acme Corporation" >>> org.address = list() >>> address = Address() >>> address.country = "Swizterland" >>> org.address.append(address) >>> org.as_json() == json_dict True
示例:3:提供错误数据类型时自动验证:
>>> from fhir.resources.fhirabstractbase import FHIRValidationError >>> try: ... org = Organization({"id": "fmk", "address": ["i am wrong type"]}) ... raise AssertionError("Code should not come here") ... except FHIRValidationError: ... pass
示例:4:使用资源工厂:
This package provides a convenient factory to create FHIR® resource, you never need to import manually each resource class. >>> from fhir.resources.fhirelementfactory import FHIRElementFactory >>> json_dict = {"resourceType": "Organization", ... "id": "mmanu", ... "active": True, ... "name": "Acme Corporation", ... "address": [{"country": "Swizterland"}] ... } >>> org = FHIRElementFactory.instantiate('Organization', json_dict) >>> org.address[0].country == "Swizterland" True >>> org.as_json()['active'] is True True
发布和版本策略
从版本5.0.0开始,我们遵循自己的发布策略,尽管我们遵循像fhir®版本这样的语义版本控制方案。 与前面的声明(如下)不同,现在发布并不依赖于FHIR。
已删除语句
This package is following FHIR® release and versioning policy, for example say, FHIR releases next version 4.0.1, we also release same version here.
学分
所有fhir®资源(python类)都是使用fhir-parser生成的。
这个包框架是用Cookiecutter和audreyr/cookiecutter-pypackage项目模板创建的。
版权所有HL7?徽标、FHIR?徽标和火焰是注册商标 属于Health Level Seven International
历史记录
5.0.0(2019-06-08)
- 只发布稳定版本。
5.0.0b2(2019-05-13)
中断或改进
- elementProperties:元素现在有额外的属性type_name。现在格式化成(name, json_name, type, type_name, is_list, "of_many", not_optional)type_name引用了fhir结构定义中的原始类型名(代码),在 进行红外搜索,红外导航。
5.0.0b1(2019-01-19)
新功能
- 实现了自己的构建策略,现在FHIR®资源的早期版本作为Python子包提供。
生成信息
- 默认版本为R4(请参见4.0.0b1(2019-01-13)部分的版本信息)
- STU3(请参见3.0.1(2019-01-13)部分的版本信息)
4.0.0(2019-01-14)
- 请参阅4.0.0b1部分的版本信息。
4.0.0b1(2019-01-13)
[FHIR] FhirVersion=4.0.0-a53ec6ee1b version=4.0.0 buildId=a53ec6ee1b date=20181227223754
3.0.1(2019-01-13)
[FHIR] FhirVersion=3.0.1.11917 version=3.0.1 revision=11917 date=20170419074443