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-py[r4b]
or fhir-tbs-py[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.1b0.tar.gz
(5.5 kB
view details)
Built Distribution
File details
Details for the file fhir_tbs-0.0.1b0.tar.gz
.
File metadata
- Download URL: fhir_tbs-0.0.1b0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 155f9b7b16d4e6519e0ec1827485febc754c00319677206b6dd00b2d1a566f41 |
|
MD5 | 0dc60ecd8547c4989c06a800b09639dc |
|
BLAKE2b-256 | 705c6b0faf93a154302849c58da18f87cd6252c73d8d8552e18c735bae3a18ea |
File details
Details for the file fhir_tbs-0.0.1b0-py3-none-any.whl
.
File metadata
- Download URL: fhir_tbs-0.0.1b0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b456bcea46b05e516ede944218e859a3013330a1008913ed7e84e75e3acda24 |
|
MD5 | d1b106587b04219b6bd1e59ecb1f9ed9 |
|
BLAKE2b-256 | 8db06d5248398053b8130a92319721caad8439ae2ca32e240b73ad851d477f1c |