Workflow Interactions¶
The helpers in imednet_workflows combine multiple endpoint calls to
automate common tasks. The diagrams below outline the main steps in each workflow.
Data Extraction¶
The data extraction process involves fetching records and applying mapping logic.
For detailed API information, see DataExtractionWorkflow
and the underlying RecordMapper utility used to transform raw data.
Record Update¶
Subject Data¶
Query Management¶
Background Sync Worker¶
SyncWorker runs incremental record
synchronisation in a background thread so that the main application thread
(e.g. a Streamlit rendering loop) never blocks on API calls.
Concurrency model
SQLite is opened in WAL mode (PRAGMA journal_mode=WAL) so multiple reader
connections can query the cache while a single writer holds the write-lock.
A filelock.FileLock placed next to the database file serialises
concurrent writers without blocking readers at all.
Usage example¶
from imednet import ImednetSDK
from imednet_workflows.cached_loader import CachedRecordsLoader
from imednet_workflows.sync_worker import SyncWorker, SyncWorkerConfig
import threading
sdk = ImednetSDK(api_key="...", security_key="...")
from typing import Any, cast
loader = CachedRecordsLoader(cast(Any, sdk))
worker = SyncWorker(
loader,
config=SyncWorkerConfig(study_key="PROT-01", interval_seconds=900),
)
# Start the worker in a daemon thread so it stops when the main process exits.
t = threading.Thread(target=worker.run_forever, daemon=True)
t.start()
# Your application reads from the cache without waiting for the API.
records = loader.get_cached_records("PROT-01")
worker.stop()
t.join()