[英]How to extend a fhir class?
I want to append some relevant data to FHIR lets say patient or condition object for further processing.我想 append 一些与 FHIR 相关的数据,比如患者或状况 object 以进行进一步处理。 I tried to extend the FHIR patient class in python.
我试图在 python 中扩展 FHIR 患者 class。 Getting the following error.
收到以下错误。 Could somebody give me some helpful pointers here?
有人可以在这里给我一些有用的指示吗? Thanks!
谢谢!
import fhir.resources.patient as pt
patient = pt.Patient.parse_file('patient.json')
class Patient2(pt.Patient):
def __init__(self,validDia):
self.validDia=validDia
newPatient = Patient2(1)
print(newPatient)
---------------------
File "pydantic\main.py", line 357, in pydantic.main.BaseModel.__setattr__
ValueError: "Patient2" object has no field "validDia" ```
If you want to extend your model you have to use Pydantic models.如果你想扩展你的 model 你必须使用Pydantic 模型。
For patient.json
file i used data from fhir dock对于
patient.json
文件,我使用了来自fhir dock的数据
Code example:代码示例:
import json
import fhir.resources.patient as pt
class Patient2(pt.Patient):
validDia: int
with open("patient.json", "r") as file:
json_obj = json.load(file)
json_obj.update({"validDia": 1})
newPatient = Patient2.parse_obj(json_obj)
print(newPatient)
print(newPatient.validDia)
And the output:和 output:
>>> resource_type='Patient' fhir_comments=None id='p001' ...cut out... validDia=1
>>> 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.