python的Aidbox客户端
aidboxp的Python项目详细描述
援助箱py
python的Aidbox客户端。 这个包为Aidbox资源上的CRUD操作提供了一个API。在
这个库是基于fhir-py的,在我们的例子中,库之间的主要区别是它们表示资源引用的方式(请阅读有关differences的更多信息)。在
Aidbox py还将支持Aidbox的一些特性,如:auassoc操作、AidboxQuery等等。在
fhir-py readme中的大多数示例也适用于aidboxpy(但是需要用AsyncAidboxClient/SyncAidboxClient替换FHIR客户机)。请参阅下面的基础辅助框py示例。在
入门
安装
最新版本:
pip install git+https://github.com/beda-software/aidbox-py.git
PyPi:
pip install aidboxpy
异步示例
importasynciofromaidboxpyimportAsyncAidboxClientfromfhirpy.base.exceptionsimport(OperationOutcome,ResourceNotFound,MultipleResourcesFound)asyncdefmain():# Create an instanceclient=AsyncAidboxClient('http://localhost:8080',authorization='Bearer TOKEN')# Search for patientsresources=client.resources('Patient')# Return lazy search setresources=resources.search(name='John').limit(10).page(2).sort('name')patients=awaitresources.fetch()# Returns a list of AsyncAidboxResource# Get exactly one resourcetry:patient=awaitclient.resources('Practitioner') \ .search(id='id').get()exceptResourceNotFound:passexceptMultipleResourcesFound:pass# Validate resourcetry:awaitclient.resource('Person',custom_prop='123',telecom=True).is_valid()exceptOperationOutcomease:print('Error: {}'.format(e))# Create Organization resourceorganization=client.resource('Organization',name='beda.software',active=False)awaitorganization.save()# Get patient resource by reference and deletepatient_ref=client.reference('Patient','new_patient')patient_res=awaitpatient_ref.to_resource()awaitpatient_res.delete()# Iterate over search set and change organizationorg_resources=client.resources('Organization').search(active=False)asyncfororg_resourceinorg_resources:org_resource['active']=Trueawaitorg_resource.save()if__name__=='__main__':loop=asyncio.get_event_loop()loop.run_until_complete(main())
美国石油学会
导入库:
from aidboxpy import SyncAidboxClient
或者
from aidboxpy import AsyncAidboxClient
要创建AidboxClient实例,请使用:
{cd5}
或者
AsyncAidboxClient(url, authorization='', extra_headers={})
返回到服务器的连接实例,该实例提供:
- .reference(resource_type,id,reference,**kwargs)-将
SyncAidboxReference
/AsyncAidboxReference
返回给资源 - .resource(resource_type,**kwargs)-返回
SyncAidboxResource
/AsyncAidboxResource
,如下所述 - .resources(资源类型)-返回
SyncAidboxSearchSet
/AsyncAidboxSearchSet
SyncAidboxResource
/AsyncAidboxResource
提供:
- .serialize()-序列化资源
- .get_by_path(path,默认值=None)–获取资源路径处的值
- .save()-创建或更新资源实例
- .delete()—删除资源实例
- .to_reference(**kwargs)-返回此资源的
SyncAidboxReference
/AsyncAidboxReference
SyncAidboxReference
/AsyncAidboxReference
提供:
- .to_resource()-为此引用返回
SyncAidboxResource
/AsyncAidboxResource
SyncAidboxSearchSet
/AsyncAidboxSearchSet
提供:
- .search(param=值)
- .限制(计数)
- .页(页)
- .sort(*args)
- .elements(*args,exclude=False)
- .include(资源类型,attr=None,recursive=False,iterate=False)
- .revinclude(资源类型,attr=None,recursive=False,iterate=False)
- .has(*args,**kwargs)
- .assoc(元素)
async
.fetch()-查询服务器并返回按资源类型筛选的Resource
列表async
.fetch_all()-对服务器进行查询并返回按资源类型筛选的Resource
的完整列表async
.fetch\u raw()-对服务器进行查询并返回一个原始包Resource
async
.first()-返回Resource
或无async
.get(id=None)-在找不到资源时返回Resource
或引发{},或者在找到多个资源时找到多个资源(参数'id'已弃用) async
.count()-查询服务器并返回与搜索集匹配的资源总数
- 项目
标签: