Skip to content

Aidbox/aidbox-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aidbox-Py

Install

pip install git+https://github.com/Aidbox/aidbox-python

Auth

Environment has to contain three variables AIDBOX_URL, AIDBOX_CLIENT_USERNAME and AIDBOX_CLIENT_PASSWORD (username and password from aidbox basic client). It can be solved with code below that loads variables from the .env file.

from dotenv import load_dotenv
from os.path import join, dirname

dotenv_path = join(dirname(__file__), ".env")
load_dotenv(dotenv_path)

Example

from aidbox.resource.appointment import Appointment, Appointment_Participant
from aidbox.resource.patient import Patient
from aidbox.resource.practitioner import Practitioner
from aidbox.base import Reference, HumanName

import requests

patient = Patient(name=[HumanName(family="Bourne", given=["Jason"])])
practitioner = Practitioner(name=[HumanName(family="Smith", given=["John"])])

patient.save()
practitioner.save()

try:
    Appointment(
        status="booked",
        participant=[
            Appointment_Participant(
                status="accepted",
                actor=Reference(reference="Practitioner/" + (practitioner.id or "")),
            ),
            Appointment_Participant(
                status="accepted",
                actor=Reference(reference="Patient/" + (patient.id or "")),
            ),
        ],
    ).save()
except requests.exceptions.RequestException as e:
    if e.response is not None:
        print(e.response.json())

API

Save resource to aidbox .save()

from aidbox.resource.patient import Patient
from aidbox.base import HumanName

patient = Patient()
patient.name = [HumanName(family="Bourne", given=["Jason"])]

patient.save()

Delete resource by id .delete()

from aidbox.resource.patient import Patient

patient = Patient(id="patient-1")
patient.delete()

Get resource by id .from_id()

from aidbox.resource.patient import Patient

patient = Patient.from_id("patient-1")

Get resource list .get()

from aidbox.resource.patient import Patient
from aidbox.base import Page, Count, Sort, Where

patients = Patient.get(Where('active', True), Count(10), Page(3), Sort('created_at', 'desc'))

Authorized request to any of Aidbox endpoints .make_request()

from aidbox.base import API

API.make_request(endpoint="/AidboxTask", method="GET")

API.make_request(
    endpoint="/rpc",
    method="POST",
    json={
        "method": "awf.task/list",
        "params": { "filter": { "excludeDefinitions": ["awf.workflow/decision-task"] }},
    },
)

Serialize to JSON dumps()

from aidbox.resource.patient import Patient
from aidbox.base import Page, Count, Sort, Where

patient = Patient.from_id('patient-1')
patient_json = patient.dumps(exclude_unset=True)

Bundle .bundle()

from aidbox.base import API

entry = []

entry.append(
    {
        "resource": patient.dumps(exclude_unset=True),
        "request": {"method": "POST", "url": "Patient"},
    },
    {
        "resource": patient.dumps(exclude_unset=True),
        "request": {"method": "POST", "url": "Patient"},
    },
)

try:
    API.bundle(entry=entry, type="transaction")
except requests.exceptions.RequestException as e:
    if e.response is not None:
        print(e.response.json())

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages