Topic-Based Subscription context for python aiohttp web applications
Project description
fhir-tbs-py
Topic-based subscription extension for python aiohttp web applications
Install
Install fhir-tbs[r4b]
or fhir-tbs[r5]
using poetry/pipenv/pip.
Usage
Create subscriptions.py
with the following content:
import logging
from collections.abc import AsyncGenerator
from fhirpy import AsyncFHIRClient
import fhirpy_types_r4b as r4b
from fhir_tbs import SubscriptionDefinition
from fhir_tbs.r4b impotr r4b_tbs_ctx_factory
from aiohttp import web
# Make sure that app has fhir_client_key
fhir_client_key = web.AppKey("fhir_client_key", AsyncFHIRClient)
async def new_appointment_sub(app: web.Application, appointment_ref: str, _timestamp: str) -> None:
fhir_client = app[fhir_client_key]
appointment = r4b.Appointment(**(await fhir_client.get(appointment_ref)))
logging.error("New appointment %s", appointment.model_dump())
subscriptions: list[SubscriptionDefinition] = [
{
"topic": "https://example.com/SubscriptionTopic/new-appointment-event",
"handler": new_appointment_sub,
"filterBy": [
{"resourceType": "Appointment", "filterParameter": "status", "value": "booked"}
],
},
]
def tbs_ctx(app: web.Application) -> AsyncGenerator[None, None]:
return r4b_tbs_ctx_factory(
app,
"http://app:8080",
"webhook",
app[fhir_client_key],
subscriptions,
)
Add tbs_ctx
to app.cleanup_ctx
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fhir_tbs-0.0.1b1.tar.gz
(5.4 kB
view details)
Built Distribution
File details
Details for the file fhir_tbs-0.0.1b1.tar.gz
.
File metadata
- Download URL: fhir_tbs-0.0.1b1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63be3b165f4e46c56130492bbbe339c597af758bd5702cc0ff46dd0f2b0e42ad |
|
MD5 | 447a1ebbed7ddfd8b44d124e97f2e7aa |
|
BLAKE2b-256 | 7319e1c90592ef066efb98bf3408c158807ec983d074a80cf02eda1b688f8ace |
File details
Details for the file fhir_tbs-0.0.1b1-py3-none-any.whl
.
File metadata
- Download URL: fhir_tbs-0.0.1b1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f54c273c9f0197870fe8f24ea855c5f88b09269b099b755d0e8999d2a3e51a1 |
|
MD5 | e49674a71a12155840937feabe7a5c02 |
|
BLAKE2b-256 | 44177b35aa6152dbabb34ba86d25636ee7272875833cba0a62aaebdf4e80d44a |