2016-08-24 24 views
2

所以,我必須從「$一切」操作的FHIR患者包JSON: https://www.hl7.org/fhir/operation-patient-everything.html智能上FHIR Python客戶端與捆綁

我現在熱衷於使用智能上FHIR Python客戶端模式,使工作與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 

有沒有可能做一些實例只是一個普通的捆綁對象類是包內能夠訪問不同的資源?

回答

1

是的,您可以實例化一個Bundle,就像您可以實例化任何其他模型一樣,可以從JSON手動執行,也可以從服務器執行read。每個search也會返回一個Bundle。然後,您可以迭代該包的條目並使用它們,例如將它們放在一個數組中:

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

p。 應該有可能與客戶端執行任何$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> 
+0

@帕斯卡爾感謝您的更多詳細信息!我想我收集你的建議。在我的情況下,我已經將所有完整的患者FHIR包(從$所有內容)寫入目錄中的單個json文件,因爲所討論的服務器在FHIR上不使用Smart。所以我希望在這些任意捆綁上手動使用智能模型,而不是遍歷這麼多的字段。它似乎沒有「將fhirclient.models.object.bundle導入爲b」,這使我可以像我發佈的患者示例一樣進行操作。 – Pylander

+0

Hy @Pylander。這應該可以工作,我已經添加了完整的代碼,我剛剛從命令行執行,閱讀FHIR網站上提供的文件'Bundle-example.json'。那是你想要達到的目標嗎? – Pascal