Python的FHIR类

py-fhir的Python项目详细描述


py fhir公司

Python的FHIR资源/元素。由py-fhir-codegen生成的代码。在

简介

这个python包提供了在FHIR specification中指定的资源和元素的python版本。此外,该包还包括实现数据库持久性的第一步(使用SQLAlchemy)和一个客户端。在

如何使用资源和数据类型

运行以下代码将创建一个Patient,并为不同的属性赋值。最后,将对象序列化为JSON表示,并打印结果。在

# Import the relevant classes from fhir.modelfromfhir.modelimportPatient,HumanName,Identifier,CodeableConcept,Coding,uri# Create a new Patient object. Resource attributes can be passed in the constructor. Note# that 'id' is the logical id of the Resource and has no relation to the Medical Record# Number (MRN)p=Patient(id='patient1')# Give the patient an MRNidentifier=Identifier(type=CodeableConcept(coding=[Coding(system="http://hl7.org/fhir/v2/0203",code="MR")]),system='urn:oid:1.2.36.146.595.217.0.1',value='123456789')# Lists can be assigned to attributes.# Alternatively p.identifier.append(identifier) could have been used.p.identifier=[identifier]# Native python values are automatically coerced to FHIR classesp.active=Trueprint(type(p.active))# output: <class 'fhir.model._boolean.boolean'>name=HumanName()name.use='official'name.given=['Melle','Sjoerd']name.family='Sieswerda'p.name=[name]# Serialize to JSON and print the result. To serialize to XML use 'p.toXML()'.print(p.dumps('json'))

这将产生以下输出:

^{pr2}$

也可以从JSON(或XML)表示中整理对象:

jsonstring=p.dumps('json')p2=Patient.loads(jsonstring,'json')p2.id==p.id# output: True

使用客户机

importfhir.modelimportfhir.clientfromfhir.modelimportPatient,HumanNameURL=fhir.client.SERVERS['spark']client=fhir.client.Client(URL)client.set_properties(fhir.model.Resource)# The following is equivalent to# bundle = client.query('Patient')bundle=fhir.model.Patient.query()# Print the first result we receivedforpinbundle:print(p.dumps('json'))break# Create a new patient on the serverp=Patient()p.active=Truename=HumanName(use='official',given=['Melle'],family='Testpatient')p.name=[name]p.save()print('The server assigned id "{}"'.format(p.id))

使用持久存储

Cave: the current implementation should be considered a stub. Searching/querying, updating, etc. is not (yet) supported.

fromfhir.persistanceimportFHIRStoreimportfhir.model# By default FHIRStore creates a sqlite database in the current directory.# Still, be careful when using 'drop_all'!store=FHIRStore(drop_all=True)# Create a new Patientp=fhir.model.Patient()p.id='patient1'p.active=Truename=fhir.model.HumanName(use='official',given=['Melle','Sjoerd'],family='Sieswerda')p.name=[name]# Store the patientstore.post(p)# Retrieve the patient from the store and print the result.print(store.get('patient1'))# output: <fhir.model.patient.Patient object at 0x1096dd828>

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaSpringBootHibernate5忽略@Table和@Column   java readLine是如何工作的?   java除了Oracle的JVM(windows)之外,还有什么BSD许可的替代方案吗?   javascript处理程序执行导致异常:所需的MultipartFile参数“file”不存在   java如何检查url是否与标识符匹配?   java在对象创建之后实现一个接口   java安卓:如何将github库放入项目中   java如何制作自定义文本组件?   如何在java中更新属性文件   java Hibernate持久映射   JavaSpring批处理如何从postgres读取数据,然后在步骤中写入数据   java应用程序已在Android Emulator Eclipse中停止   java找不到参数[org.jetbrains.kotlin:kotlinstdlibjdk7:1.3.50]的方法实现()   java AWS DynamoDB如何从数据库中获取只有一个字段的对象   在使用ajax进行表单提交时,java无法阻止默认表单提交   集合如何在Java中定义基于两个变量进行比较的比较器   多线程基准测试Java中的多线程集合   java如何通过浏览器运行终端程序?