【问题标题】:Smart-on-FHIR Python Client with Bundles带有捆绑包的 Smart-on-FHIR Python 客户端
【发布时间】:2016-08-31 15:05:26
【问题描述】:

所以我有一个来自“$everything”操作的 FHIR 患者包 json: https://www.hl7.org/fhir/operation-patient-everything.html

我现在有兴趣在 FHIR Python 客户端模型上使用 Smart 来更轻松地处理 json 文件。给出的示例如下:

import json
import fhirclient.models.patient as p
with open('path/to/patient.json', 'r') as h:
     pjs = json.load(h)
patient = p.Patient(pjs)
patient.name[0].given
# prints patient's given name array in the first `name` property

是否有可能只用一个通用的包对象类来实例化一些东西,以便能够访问包内的不同资源?

【问题讨论】:

  • 您好,您有从 FHIR 将数据导入 python 的完整示例吗?您可以分享一下吗?我想了解如何将 FHIR 数据导入 R

标签: python json hl7-fhir


【解决方案1】:

是的,您可以实例化 Bundle,就像您可以实例化任何其他模型一样,可以从 JSON 手动或通过服务器上的 read。每个search 也返回一个Bundle。然后你可以遍历包的条目并使用它们,就像把它们放在一个数组中:

resources = []
if bundle.entry is not None:
    for entry in bundle.entry:
        resources.append(entry.resource)

附言 应该可以使用客户端执行任何$operation,返回您提到的Bundle,但我必须检查我们是否已经暴露了它或者它是否尚未提交。


命令行示例:

import fhirclient.models.bundle as b
import json
with open('fhir-parser/downloads/bundle-example.json', 'r') as h:
    js = json.load(h)
bundle = b.Bundle(js)
bundle.entry
[<fhirclient.models.bundle.BundleEntry object at 0x10f40ae48>, 
 <fhirclient.models.bundle.BundleEntry object at 0x10f40ac88>]
for entry in bundle.entry:
    print(entry.resource)

// prints
<fhirclient.models.medicationorder.MedicationOrder object at 0x10f407390>
<fhirclient.models.medication.Medication object at 0x10f407e48>

【讨论】:

  • @Pascal 感谢您提供更多详细信息!我想我收集了你的建议。在我的情况下,我已将所有完整的患者 FHIR 包(来自 $everything)写入目录中的单个 json 文件中,因为有问题的服务器没有在 FHIR 上使用 Smart。所以我希望在这些任意捆绑包上手动使用智能模型,而不是遍历这么多字段。 “import fhirclient.models.object.bundle as b”似乎不允许我做与我发布的患者示例相同的操作。
  • 你好@Pylander。这绝对可行,我添加了刚刚从命令行执行的完整代码,读取了 FHIR 网站上的文件Bundle-example.json。这就是你想要达到的目标吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多