Package: aidboxpy
aidbox-pyAidbox client for python.
This package provides an API for CRUD operations over Aidbox resources.The library is based onfhir-pyand the main difference between libraries in our case is the way they represent resource references (read more aboutdifferences).Aidbox-py also going to support some Aidbox features like _assoc operation, AidboxQuery and so on.Most examples fromfhir-py readmealso work for aidbox-py (but you need to replace FHIR client with AsyncAidboxClient/SyncAidboxClient). See base aidbox-py example below.Getting startedInstallMost recent version:pip install git+https://github.com/beda-software/aidbox-py.gitPyPi:pip install aidboxpyAsync exampleimportasynciofromaidboxpyimportAsyncAidboxClientfromfhirpy.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())APIImport library:from aidboxpy import SyncAidboxClientorfrom aidboxpy import AsyncAidboxClientTo create AidboxClient instance use:SyncAidboxClient(url, authorization='', extra_headers={})orAsyncAidboxClient(url, authorization='', extra_headers={})Returns an instance of the connection to the server which provides:.reference(resource_type, id, reference, **kwargs) - returnsSyncAidboxReference/AsyncAidboxReferenceto the resource.resource(resource_type, **kwargs) - returnsSyncAidboxResource/AsyncAidboxResourcewhich described below.resources(resource_type) - returnsSyncAidboxSearchSet/AsyncAidboxSearchSetSyncAidboxResource/AsyncAidboxResourceprovides:.serialize() - serializes resource.get_by_path(path, default=None) – gets the value at path of resource.save() - creates or updates resource instance.delete() - deletes resource instance.to_reference(**kwargs) - returnsSyncAidboxReference/AsyncAidboxReferencefor this resourceSyncAidboxReference/AsyncAidboxReferenceprovides:.to_resource() - returnsSyncAidboxResource/AsyncAidboxResourcefor this referenceSyncAidboxSearchSet/AsyncAidboxSearchSetprovides:.search(param=value).limit(count).page(page).sort(*args).elements(*args, exclude=False).include(resource_type, attr=None, recursive=False, iterate=False).revinclude(resource_type, attr=None, recursive=False, iterate=False).has(*args, **kwargs).assoc(elements)async.fetch() - makes query to the server and returns a list ofResourcefiltered by resource typeasync.fetch_all() - makes query to the server and returns a full list ofResourcefiltered by resource typeasync.fetch_raw() - makes query to the server and returns a raw BundleResourceasync.first() - returnsResourceor Noneasync.get(id=None) - returnsResourceor raisesResourceNotFoundwhen no resource found or MultipleResourcesFound when more than one resource found (parameter 'id' is deprecated)async.count() - makes query to the server and returns the total number of resources that match the SearchSet