aiofhir 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aiofhir-0.0.0/.github/workflows/ci.yml +23 -0
- aiofhir-0.0.0/.gitignore +9 -0
- aiofhir-0.0.0/.python-version +1 -0
- aiofhir-0.0.0/AGENTS.md +24 -0
- aiofhir-0.0.0/LICENSE +21 -0
- aiofhir-0.0.0/PKG-INFO +19 -0
- aiofhir-0.0.0/justfile +39 -0
- aiofhir-0.0.0/plans/PLAN-merged.md +167 -0
- aiofhir-0.0.0/plans/claude-ROADMAP.md +106 -0
- aiofhir-0.0.0/plans/grok-aiofhir-plan.md +221 -0
- aiofhir-0.0.0/pyproject.toml +42 -0
- aiofhir-0.0.0/src/aiofhir/__init__.py +3 -0
- aiofhir-0.0.0/src/aiofhir/py.typed +0 -0
- aiofhir-0.0.0/tests/test_import.py +26 -0
- aiofhir-0.0.0/uv.lock +455 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
check:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
strategy:
|
|
11
|
+
fail-fast: false
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: astral-sh/setup-uv@v10.4.0
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- run: uv sync --locked --extra dev
|
|
20
|
+
- run: uv run ruff check .
|
|
21
|
+
- run: uv run ruff format --check .
|
|
22
|
+
- run: uv run mypy
|
|
23
|
+
- run: uv run pytest
|
aiofhir-0.0.0/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
aiofhir-0.0.0/AGENTS.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
`aiofhir` is a thin async FHIR R4 and SMART on FHIR client. The design lives in `plans/PLAN-merged.md`. Phase 0 is the repo scaffold. The next implementation phase is Phase 1: discovery, scopes, sign-in, the FHIR client, patient helpers, and summaries. Do not start a later phase in the same change.
|
|
4
|
+
|
|
5
|
+
When a plan item is finished, check it off in `plans/PLAN-merged.md` in the same change. Check it only when its code and tests pass.
|
|
6
|
+
|
|
7
|
+
## Commands
|
|
8
|
+
|
|
9
|
+
- Run `just check` before finishing. It syncs from `uv.lock`, then runs ruff, the format check, mypy, and pytest.
|
|
10
|
+
- `just test` runs pytest. Extra arguments are passed through.
|
|
11
|
+
- Supported Python is 3.11 through 3.13. mypy is strict.
|
|
12
|
+
|
|
13
|
+
## Library rules
|
|
14
|
+
|
|
15
|
+
- Importing `aiofhir` must not load `fastapi`. The FastAPI reference server is a later optional extra and stays out of the core import.
|
|
16
|
+
- The patient id comes only from the token response. Helpers add `patient=` themselves and do not accept it as an argument.
|
|
17
|
+
- Scopes come from the server's SMART `capabilities` and `scopes_supported`. Profiles adjust search and medication behavior. They do not choose scopes.
|
|
18
|
+
- An explicit `scope=` is only for an app registration that allows less than the server advertises.
|
|
19
|
+
- The core library does not store tokens. Tokens never appear in `repr()`, logs, or tracebacks. Patient ids in query strings are redacted in hooks.
|
|
20
|
+
- `verify_state()` uses `hmac.compare_digest`. Storing `state` and `code_verifier`, and using them once, is the caller's job.
|
|
21
|
+
|
|
22
|
+
## Later phases
|
|
23
|
+
|
|
24
|
+
Writes and booking, typed models for every resource, FHIR versions other than R4, bulk data, and token storage in the core stay out until their own phase.
|
aiofhir-0.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Doug Morand
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
aiofhir-0.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: aiofhir
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Async FHIR R4 and SMART on FHIR client
|
|
5
|
+
Author: Doug Morand
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Typing :: Typed
|
|
14
|
+
Requires-Python: >=3.11
|
|
15
|
+
Requires-Dist: httpx>=0.27
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: mypy>=1.14; extra == 'dev'
|
|
18
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
19
|
+
Requires-Dist: ruff>=0.8; extra == 'dev'
|
aiofhir-0.0.0/justfile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# List available commands.
|
|
2
|
+
default:
|
|
3
|
+
@just --list
|
|
4
|
+
|
|
5
|
+
# Install the project and dev tools from uv.lock.
|
|
6
|
+
sync:
|
|
7
|
+
uv sync --locked --extra dev
|
|
8
|
+
|
|
9
|
+
# Refresh uv.lock.
|
|
10
|
+
lock:
|
|
11
|
+
uv lock
|
|
12
|
+
|
|
13
|
+
# Run pytest. Extra arguments are passed through.
|
|
14
|
+
test *args:
|
|
15
|
+
uv run pytest {{args}}
|
|
16
|
+
|
|
17
|
+
# Lint with ruff.
|
|
18
|
+
lint:
|
|
19
|
+
uv run ruff check .
|
|
20
|
+
|
|
21
|
+
# Format with ruff.
|
|
22
|
+
fmt:
|
|
23
|
+
uv run ruff format .
|
|
24
|
+
|
|
25
|
+
# Check formatting without writing files.
|
|
26
|
+
fmt-check:
|
|
27
|
+
uv run ruff format --check .
|
|
28
|
+
|
|
29
|
+
# Typecheck with mypy strict.
|
|
30
|
+
typecheck:
|
|
31
|
+
uv run mypy
|
|
32
|
+
|
|
33
|
+
# Apply ruff autofixes and format.
|
|
34
|
+
fix:
|
|
35
|
+
uv run ruff check --fix .
|
|
36
|
+
uv run ruff format .
|
|
37
|
+
|
|
38
|
+
# Run the same checks as CI: sync, lint, format, mypy, pytest.
|
|
39
|
+
check: sync lint fmt-check typecheck test
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# aiofhir plan
|
|
2
|
+
|
|
3
|
+
`aiofhir` is a thin **async FHIR R4 and SMART on FHIR client** for Python, built on httpx. It handles patient sign-in (`aiofhir.smart`), reading and searching, and patient-scoped helpers that return compact, cited summaries. It has **no LiveKit dependency**. LiveKit tools live in each demo repo.
|
|
4
|
+
|
|
5
|
+
- **Why async httpx:** LiveKit agents run on asyncio, so a blocking client would stall the event loop during FHIR calls and token refreshes. httpx gives pooling, timeouts, HTTP/2 and a mockable transport (respx).
|
|
6
|
+
- **Status:** pre-release. Phase 0 is complete. Phase 1 is in progress on `cursor/phase-1-client`: the client is not implemented yet, and the GitHub Actions run and PyPI name reservation moved here from Phase 0. Nothing has run against a live server. Check a phase item only when its code and tests pass.
|
|
7
|
+
|
|
8
|
+
## Principles
|
|
9
|
+
- **Patient scoping.**
|
|
10
|
+
- The patient id comes only from the token response (`TokenSet.patient`). Helpers add `patient=` themselves and never accept it as an argument.
|
|
11
|
+
- `search_raw()` is limited to a resource allowlist and always gets the forced patient parameter.
|
|
12
|
+
- With `patient/` scopes the server binds the token to that patient's compartment, and the client check is a second layer. If the server only advertises `permission-user`, the token is user-scoped and the server's access policy is the real control.
|
|
13
|
+
- **Tokens server-side by default.**
|
|
14
|
+
- The core library never stores tokens. Apps persist `TokenSet.to_dict()` themselves.
|
|
15
|
+
- The recommended deployment is a backend that holds a `RefreshingToken` for each session. Agents get a `RemoteRecord(session_id)` that never sees a token.
|
|
16
|
+
- A `PatientRecord` running in-process is for local demos and scripts only.
|
|
17
|
+
- **State check is the caller's job, and the docs say so.** Store `state` and `code_verifier` on the server, use them once, and compare with `verify_state()`, which uses `hmac.compare_digest`.
|
|
18
|
+
- **Server-agnostic.** Discovery, scopes, and client auth come from `.well-known/smart-configuration`. Search and medication quirks live in `ServerProfile`s, not in the helpers. Profiles do not choose scopes.
|
|
19
|
+
- **No secrets or PHI in logs.** Tokens never appear in `repr()`. Hooks get redacted URLs, so patient ids in query strings are stripped too.
|
|
20
|
+
|
|
21
|
+
## Public API
|
|
22
|
+
```python
|
|
23
|
+
from aiofhir import FhirClient, PatientRecord, RemoteRecord, AuthExpired
|
|
24
|
+
from aiofhir.smart import SmartClient, RefreshingToken, TokenSet, verify_state
|
|
25
|
+
from aiofhir.display import format_summary
|
|
26
|
+
|
|
27
|
+
smart = SmartClient(fhir_base_url, client_id, redirect_uri, scope=None, client_secret=None, profile=None)
|
|
28
|
+
req = await smart.authorization_request() # discovers, builds scope from capabilities; url, state, code_verifier (S256, aud=base)
|
|
29
|
+
verify_state(expected=saved.state, received=params["state"])
|
|
30
|
+
tokens = await smart.exchange_code(code, saved.code_verifier) # TokenSet: patient, encounter?, need_patient_banner?, fhir_user (UNVERIFIED)
|
|
31
|
+
rt = RefreshingToken(smart, tokens, on_refresh=save) # asyncio.Lock; persists rotated refresh tokens
|
|
32
|
+
|
|
33
|
+
async with FhirClient(fhir_base_url, provider=rt, profile=smart.profile, max_concurrency=4) as fhir:
|
|
34
|
+
rec = PatientRecord(fhir, patient_id=tokens.patient)
|
|
35
|
+
s = await rec.upcoming_appointments(days=90) # frozen Summary with citations
|
|
36
|
+
print(format_summary(s, tz="America/New_York")) # display only; never mutates s
|
|
37
|
+
text = s.to_text(max_chars=4000)
|
|
38
|
+
async for res in fhir.iter_search("Observation", {"patient": tokens.patient, "category": "laboratory"}):
|
|
39
|
+
...
|
|
40
|
+
# AuthExpired carries a fixed message: "Your health record connection expired. Please reconnect to continue."
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Layout
|
|
44
|
+
```
|
|
45
|
+
src/aiofhir/ __init__.py errors.py client.py record.py summary.py display.py remote.py
|
|
46
|
+
smart/ (discovery.py pkce.py scopes.py client.py tokens.py)
|
|
47
|
+
profiles/ (base.py generic.py haste.py epic.py cerner.py)
|
|
48
|
+
server/ (optional extra [server]: reference backend for RemoteRecord)
|
|
49
|
+
tests/ fake_fhir.py (respx) fixtures/{haste,epic,cerner}/ test_*.py live/ (opt-in)
|
|
50
|
+
scripts/seed_haste.py examples/smoke_haste.py
|
|
51
|
+
```
|
|
52
|
+
Extras: `[server]` (fastapi, cryptography) and, later, `[jwt]`. There is **no `[livekit]` extra**.
|
|
53
|
+
|
|
54
|
+
## Server profiles
|
|
55
|
+
| | Haste Health | Epic | Oracle Health (Cerner) | generic |
|
|
56
|
+
|---|---|---|---|---|
|
|
57
|
+
| Discovery | `{base}/.well-known/smart-configuration`, then fallback `/w/{t}/{p}/api/v1/.well-known/smart-configuration` | standard | standard (per-tenant base) | standard |
|
|
58
|
+
| Scopes | from SMART `capabilities` and `scopes_supported` (see Scopes) | same | same | same |
|
|
59
|
+
| Patient context | User linked to Patient via `Membership`; no picker | MyChart login | patient-persona authorize URL | token `patient` |
|
|
60
|
+
| Refresh | `offline_access`; rotation | **confidential client required** | `offline_access` / `online_access` | config |
|
|
61
|
+
| Appointment | `date=ge…&date=lt…&_sort=date` (verify) | `patient` required; no `_sort`, sort on client | **both `ge` and `lt` bounds required**; sorted ascending | as given |
|
|
62
|
+
| Medications | inline concept (Synthea) | `medicationReference` → read `Medication` | mostly inline (verify) | resolve references and contained resources |
|
|
63
|
+
| Observation | standard | expects `category` or `code` (verify); sort on client | `_count` ≤ 200; `code` ignored with `category` | standard |
|
|
64
|
+
|
|
65
|
+
## Scopes
|
|
66
|
+
|
|
67
|
+
`authorization_request()` discovers `.well-known/smart-configuration`, then `scopes_from_capabilities(cfg)` builds the authorize scope. Haste, Epic, Cerner, and any other R4 server use this one function. `READ_RESOURCES` is the helper resource set (`Patient`, `Appointment`, `MedicationRequest`, `Medication`, `AllergyIntolerance`, `Condition`, `Observation`). Phase 5 adds `Immunization`, `Encounter`, `Procedure`, and `DocumentReference` to that set.
|
|
68
|
+
|
|
69
|
+
| Piece | Rule |
|
|
70
|
+
|---|---|
|
|
71
|
+
| Context | `patient` when `permission-patient` is present. `user` only when it is absent and `permission-user` is present. |
|
|
72
|
+
| Permission | `.rs` when `permission-v2` is present and `scopes_supported` lists a `.rs` scope, or when v2 is present and `scopes_supported` is absent. `.read` otherwise. When both syntaxes are listed, prefer v2. |
|
|
73
|
+
| Resources | `{context}/*{permission}` when that wildcard is listed, or when `scopes_supported` is absent. Otherwise the intersection of `READ_RESOURCES` with `scopes_supported`. |
|
|
74
|
+
| Launch | `launch/patient` when it is listed, or when `launch-standalone` is present and the context is `patient`. |
|
|
75
|
+
| Identity | `openid` and `fhirUser` when `sso-openid-connect` is present and those scopes are listed, or when `scopes_supported` is absent. |
|
|
76
|
+
| Refresh | `offline_access` when `permission-offline` is present or the scope is listed. Otherwise `online_access` when it is listed. |
|
|
77
|
+
|
|
78
|
+
These are the SMART configuration fields, not the FHIR `/metadata` CapabilityStatement. An explicit `SmartClient(..., scope="...")` replaces the derived string, for an app registration that allows less than the server advertises. That is the Epic case, where the app's registered scopes are narrower than the sandbox. If `permission-patient` and `permission-user` are both missing, discovery raises `DiscoveryError`.
|
|
79
|
+
|
|
80
|
+
## Phases (each has "done when" criteria; unit tests use respx fixtures)
|
|
81
|
+
**Phase 0: Repo (0.5 d).**
|
|
82
|
+
- [x] Package named `aiofhir`, MIT license, src layout, justfile, and dev tooling.
|
|
83
|
+
- [x] CI workflow runs pytest, ruff, and mypy strict on Python 3.11–3.13.
|
|
84
|
+
- [x] `tests/test_import.py` confirms `import aiofhir` loads no `livekit` or `fastapi`. It passed locally.
|
|
85
|
+
|
|
86
|
+
**Phase 1: Build the core (2.5 d).** Left off after the failing tests. `src/aiofhir` is still only `__init__.py`.
|
|
87
|
+
- [x] GitHub Actions is green on this branch.
|
|
88
|
+
- [ ] Reserve the PyPI name `aiofhir`.
|
|
89
|
+
- [ ] **Discovery:** fallback paths come from the profile; S256 is required; results are cached.
|
|
90
|
+
- *Tests:* Haste returns 404 on the primary path and 200 on the fallback; every path failing raises `DiscoveryError`.
|
|
91
|
+
- [ ] **Scopes:** `scopes_from_capabilities(cfg)` follows the Scopes table. Profiles do not override it. An explicit `scope=` replaces the derived string.
|
|
92
|
+
- *Tests:* recorded configurations for Haste (`permission-v2`, `permission-patient`, `patient/*.rs`), Epic v1 (`.read` only), and Cerner (per-resource `scopes_supported`, no wildcard). Also: user-only capabilities select `user/`; both syntaxes listed prefers v2; explicit `scope=` wins; no patient or user permission raises `DiscoveryError`.
|
|
93
|
+
- [ ] **Auth request:** 256-bit state; verifier is 43–128 unreserved characters; `aud` is sent; `verify_state()` is constant-time.
|
|
94
|
+
- *Tests:* RFC 7636 test vector; a mismatched state is refused; a reused state is refused by the reference store.
|
|
95
|
+
- [ ] **Exchange:** basic or post client auth is chosen from the config; a missing `patient` raises `TokenError` when the request included `launch/patient`; `TokenSet` carries `encounter` and `need_patient_banner`.
|
|
96
|
+
- [ ] **RefreshingToken:** refreshes 60 s early behind a lock with a double-check; persists rotation; `invalid_grant` raises `AuthExpired`.
|
|
97
|
+
- *Tests:* 20 concurrent `get()` calls make exactly 1 `/token` call.
|
|
98
|
+
- [ ] **FhirClient:**
|
|
99
|
+
- Retries 429/502/503/504 twice with backoff and jitter, honoring `Retry-After`.
|
|
100
|
+
- On a 401, refreshes once and retries once, then raises `AuthExpired`.
|
|
101
|
+
- Drops OperationOutcome entries into `.warnings`.
|
|
102
|
+
- Follows only same-origin `next` links, with `max_pages=10`.
|
|
103
|
+
- Configurable timeouts, a concurrency semaphore (default 4), and `iter_search`.
|
|
104
|
+
- [ ] **PatientRecord:** forced patient and allowlist. `upcoming_appointments` uses `date=ge{now}&date=lt{now+days}&_sort=date`, then a client-side booked/pending filter and sort.
|
|
105
|
+
- *Tests:* passing `patient` raises `TypeError`; `search_raw("Account")` is refused; cancelled and proposed appointments are dropped.
|
|
106
|
+
- [ ] **Summary:** frozen; `to_text(max_chars)` cuts on item boundaries with "(+N more)" and keeps `Type/id` citations; FHIR free text is marked as data; `display.format_summary` is pure.
|
|
107
|
+
|
|
108
|
+
**Phase 2: Profiles (1 d).** Scope selection stays in `scopes_from_capabilities`.
|
|
109
|
+
- [ ] `generic`, `haste`, and `epic` are filled in, and `cerner` starts as a stub, using `adapt_search(resource, params)`, `resolve_medication`, and `discovery_paths`.
|
|
110
|
+
- [ ] Switching servers is a one-line change and the helpers have no vendor branches.
|
|
111
|
+
- *Tests:* each profile's `adapt_search`, for example Cerner adds an `lt` bound and Epic drops `_sort`.
|
|
112
|
+
|
|
113
|
+
**Phase 3: Live against Haste (1.5 d).** Run local Haste with docker-compose: API on :3000, admin on :3001, tenant `my-health`, admin `myuser@health.org` / `testing_password`. Create the project `lk-demo`.
|
|
114
|
+
- [ ] **`scripts/seed_haste.py`** is idempotent and creates:
|
|
115
|
+
- a Patient with Practitioners and Locations;
|
|
116
|
+
- Appointments at past, +3/+14/+45 days, one pending and one cancelled;
|
|
117
|
+
- active and stopped MedicationRequests, covering inline codes, references and contained Medications;
|
|
118
|
+
- an AllergyIntolerance, Conditions and lab Observations;
|
|
119
|
+
- a User with a `Membership` linked to the Patient, plus a **read-only, own-patient AccessPolicyV2**;
|
|
120
|
+
- a `ClientApplication` with redirect `http://localhost:8765/callback`, grants `authorization_code` and `refresh_token`, and an allowed scope copied from that server's `scopes_supported` (so the derived request is a subset of what the app may ask for).
|
|
121
|
+
- [ ] **`examples/smoke_haste.py`:** browser login with no `scope=` argument, state check, code exchange, every helper printed, one forced refresh. The requested scope is the one `scopes_from_capabilities` built.
|
|
122
|
+
- [ ] **`tests/live`:** opt-in through environment credentials. It checks that the token has a `patient`, that every resource returned belongs to that patient, and that paging terminates.
|
|
123
|
+
- [ ] **Recorded, de-identified fixtures** go into the unit tests, with a scrubber check.
|
|
124
|
+
- *Done when:* the live tests pass, the cancelled appointment is filtered out, every item has a citation, and no token appears in any output.
|
|
125
|
+
|
|
126
|
+
**Phase 4: Server-side token mode (1 d).** `RemoteRecord` mirrors the `PatientRecord` methods. The optional `aiofhir[server]` reference backend has:
|
|
127
|
+
- [ ] `/auth/start` and `/auth/callback` with single-use state.
|
|
128
|
+
- [ ] `/v1/record/{method}` with a service bearer and a method allowlist.
|
|
129
|
+
- [ ] A Fernet-encrypted store.
|
|
130
|
+
- *Tests:* end to end over ASGI; an unknown session raises `AuthExpired`; no token appears in logs (caplog).
|
|
131
|
+
|
|
132
|
+
**Phase 5: More helpers (1 d).**
|
|
133
|
+
- [ ] `immunizations`, `vital_signs`, `past_visits` (Encounter), `procedures`, and `documents` (titles and dates only), all in one summary style.
|
|
134
|
+
|
|
135
|
+
**Phase 6: Epic and Cerner sandboxes (1.5 d).** Run every helper against the Epic and Cerner sandboxes and record the differences in their profiles.
|
|
136
|
+
- [ ] Epic sandbox. Test users: `fhircamila`, `fhirderrick`, and `fhirdesiree`. They have no appointment data.
|
|
137
|
+
- [ ] Cerner sandbox. Patient endpoint: `fhir-myrecord.cerner.com/r4/ec2458f2-…`.
|
|
138
|
+
- *Done when:* the live tests pass on both, with skips documented.
|
|
139
|
+
|
|
140
|
+
**Phase 7: Auth extensions, later (1.5 d).**
|
|
141
|
+
- [ ] `private_key_jwt` with RS384/ES384 under `aiofhir[jwt]`, which Epic production prefers.
|
|
142
|
+
- [ ] `client_credentials` for seeding and CI.
|
|
143
|
+
- [ ] EHR launch: parse `iss` and `launch`, then discover from `iss`.
|
|
144
|
+
- [ ] POST `_search` (form-encoded), `vread`, and a cached FHIR `/metadata` CapabilityStatement. SMART `capabilities` are already read during discovery.
|
|
145
|
+
- [ ] Request hooks with PHI redaction.
|
|
146
|
+
|
|
147
|
+
**Phase 8: Release (0.5 d).**
|
|
148
|
+
- [ ] Docs (getting started, sign-in and state handling, profiles, helper reference), semver, a changelog, and PyPI trusted publishing.
|
|
149
|
+
|
|
150
|
+
**Effort:** about 5.5 days to reach live against Haste (Phases 0–3), about 8.5 days through Epic and Cerner (Phases 0–6), and about 10.5 days for everything.
|
|
151
|
+
|
|
152
|
+
## Out of scope
|
|
153
|
+
- Writes and booking.
|
|
154
|
+
- Typed models for every resource.
|
|
155
|
+
- FHIR versions other than R4.
|
|
156
|
+
- Bulk data.
|
|
157
|
+
- Token storage in the core (apps persist `TokenSet`; the optional server extra is a reference only).
|
|
158
|
+
- LiveKit tools and UI.
|
|
159
|
+
|
|
160
|
+
## Open questions
|
|
161
|
+
- **Haste:** the base URL, hosted (BAA, rate limits) or self-hosted, and the tenant and project. Can I create Users, Memberships, AccessPolicies and the ClientApplication? Does it support `_sort` and two date bounds? Phase 3 records the live `capabilities` document and the scope string that authorize accepted.
|
|
162
|
+
- **Repo:** `dmorand17/aiofhir` or the LiveKit-Field org? License is MIT.
|
|
163
|
+
- **Scope:** keep aiofhir focused on patient reads for agents rather than a general FHIR client.
|
|
164
|
+
- **Server extra:** keep the reference backend in this repo, or move it to `examples/`?
|
|
165
|
+
|
|
166
|
+
## Next: integrations
|
|
167
|
+
The Agents 2.0 chat demo and its LiveKit tools, built on `RemoteRecord`, get their own plan in the demo repo once Phase 3 passes.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# aiofhir roadmap
|
|
2
|
+
|
|
3
|
+
`aiofhir` is an async FHIR R4 client for Python. It handles SMART on FHIR sign-in, reading and searching, and patient-scoped helpers that return compact summaries for LLM agents. It started as `thinfhir`, built for LiveKit agent demos against Haste Health and Epic.
|
|
4
|
+
|
|
5
|
+
**Goal:** one library that any demo can install to sign a patient in and answer questions like "when is my next appointment?" or "what medications am I taking?", against Haste Health today and Epic later, by changing configuration only.
|
|
6
|
+
|
|
7
|
+
**Status:** pre-release. Sign-in (standalone launch), read and search with paging, token refresh, retries and five patient helpers exist, with unit tests against a mocked server. Nothing has run against a live server yet.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Phase 0: Rename and set up the repo
|
|
12
|
+
|
|
13
|
+
- [ ] Rename the package `thinfhir` → `aiofhir` (`src/aiofhir`, imports, `pyproject.toml`, README)
|
|
14
|
+
- [ ] Add a license
|
|
15
|
+
- [ ] CI with GitHub Actions: `pytest`, `ruff`, `mypy` on Python 3.10–3.13
|
|
16
|
+
- [ ] Optional: publish a placeholder `0.0.1` to PyPI to reserve the name
|
|
17
|
+
|
|
18
|
+
**Done when:** CI is green on `main` and `pip install -e .` gives `import aiofhir`.
|
|
19
|
+
|
|
20
|
+
## Phase 1: A complete async read client
|
|
21
|
+
|
|
22
|
+
- [ ] `vread(type, id, version)`
|
|
23
|
+
- [ ] Search by POST (`_search`) for long queries
|
|
24
|
+
- [ ] `capabilities()`: read and cache `/metadata`
|
|
25
|
+
- [ ] `iter_search(...)`: an async iterator over all pages, so large results stream
|
|
26
|
+
- [ ] A limit on concurrent requests (default 4), so parallel tool calls don't trip rate limits
|
|
27
|
+
- [ ] Configurable timeouts and retry policy
|
|
28
|
+
- [ ] Request and response hooks for logging and auditing, with PHI stripped by default
|
|
29
|
+
|
|
30
|
+
**Done when:** every method has unit tests, and the README shows `async for` paging.
|
|
31
|
+
|
|
32
|
+
## Phase 2: Authentication
|
|
33
|
+
|
|
34
|
+
- [ ] **EHR launch:** parse `iss` and `launch` from the launch URL and discover endpoints from `iss`
|
|
35
|
+
- [ ] **Private-key client authentication** (`private_key_jwt`, RS384 / ES384) for confidential clients
|
|
36
|
+
- [ ] **Backend services** (`client_credentials`) for seeding data and running tests
|
|
37
|
+
- [ ] Put JWT signing behind an optional install: `aiofhir[jwt]`
|
|
38
|
+
- [ ] Return the `encounter` and `need_patient_banner` launch context in `TokenSet`
|
|
39
|
+
|
|
40
|
+
**Done when:** both launch modes and all three client authentication types work against Haste Health.
|
|
41
|
+
|
|
42
|
+
## Phase 3: Server profiles
|
|
43
|
+
|
|
44
|
+
- [ ] A `ServerProfile` that records each server's scope format and search quirks, so they don't end up as special cases throughout the code
|
|
45
|
+
- [ ] Profiles: `generic`, `haste`, `epic`
|
|
46
|
+
- [ ] Haste profile, from Haste's docs:
|
|
47
|
+
- [ ] Scopes: try `patient/*.rs`; fall back to `user/*.rs` + `launch/patient` (the docs disagree about whether `patient/` scopes are accepted)
|
|
48
|
+
- [ ] Standalone launch has no patient picker: the patient comes from the signed-in user's `Membership` link
|
|
49
|
+
- [ ] FHIR base URL: `https://<host>/w/<tenant>/<project>/api/v1/fhir`
|
|
50
|
+
- [ ] Epic profile: filled in during the Epic sandbox pass (Phase 5)
|
|
51
|
+
|
|
52
|
+
**Done when:** switching servers is a one-line profile change and the helpers need no server-specific code.
|
|
53
|
+
|
|
54
|
+
## Phase 4: More patient helpers
|
|
55
|
+
|
|
56
|
+
Existing: `upcoming_appointments`, `active_medications`, `allergies`, `conditions`, `recent_labs`.
|
|
57
|
+
|
|
58
|
+
- [ ] `immunizations()`
|
|
59
|
+
- [ ] `past_visits()` (Encounter)
|
|
60
|
+
- [ ] `procedures()`
|
|
61
|
+
- [ ] `vital_signs()` (Observation, `category=vital-signs`)
|
|
62
|
+
- [ ] `documents()` (DocumentReference, titles and dates only)
|
|
63
|
+
- [ ] One consistent summary style across all helpers
|
|
64
|
+
- [ ] Time zone handling everywhere a date is shown
|
|
65
|
+
|
|
66
|
+
**Done when:** each helper has unit tests and returns useful data from the seeded Haste patient.
|
|
67
|
+
|
|
68
|
+
## Phase 5: Testing against real servers
|
|
69
|
+
|
|
70
|
+
- [ ] **Haste seed script** that creates:
|
|
71
|
+
- a test Patient with Practitioners and Locations
|
|
72
|
+
- past, upcoming and cancelled Appointments
|
|
73
|
+
- active and stopped MedicationRequests (inline codes, references and contained Medications)
|
|
74
|
+
- AllergyIntolerance, Condition and lab Observations
|
|
75
|
+
- a user linked to the Patient through `Membership`
|
|
76
|
+
- a `ClientApplication` with redirect URI, grants and scopes
|
|
77
|
+
- [ ] **Live tests** that run only when credentials are set: sign in, check the token has `patient`, and call each helper
|
|
78
|
+
- [ ] **Epic sandbox pass:** run every helper against Epic's test patients and record the differences in the Epic profile
|
|
79
|
+
- [ ] **Saved fixtures:** de-identified responses from both servers, used in the regular unit tests
|
|
80
|
+
|
|
81
|
+
**Done when:** live tests pass against Haste Health and the Epic sandbox.
|
|
82
|
+
|
|
83
|
+
## Phase 6: LiveKit and release
|
|
84
|
+
|
|
85
|
+
- [ ] Optional `aiofhir[livekit]` add-on with ready-made function tools
|
|
86
|
+
- [ ] `examples/livekit_text_agent/`: a complete text-chat agent with sign-in
|
|
87
|
+
- [ ] Docs: getting started, sign-in flow, server profiles, helper reference
|
|
88
|
+
- [ ] Semantic versioning and a changelog
|
|
89
|
+
- [ ] Publish to PyPI from GitHub Actions (trusted publishing)
|
|
90
|
+
|
|
91
|
+
**Done when:** `pip install aiofhir[livekit]` and the example agent run end to end against Haste Health.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Out of scope
|
|
96
|
+
|
|
97
|
+
- Writing data (create, update, delete)
|
|
98
|
+
- Typed models for every FHIR resource
|
|
99
|
+
- Storing tokens: each app stores its own `TokenSet` (`to_dict` / `from_dict` are provided)
|
|
100
|
+
- FHIR versions other than R4
|
|
101
|
+
|
|
102
|
+
## Open questions
|
|
103
|
+
|
|
104
|
+
- **How general should aiofhir be?** This roadmap keeps it focused on reading patient data for agents. A general-purpose async FHIR client would bring writes and typed models into scope, which is a much bigger project.
|
|
105
|
+
- **License:** MIT or Apache-2.0?
|
|
106
|
+
- **Does Haste Health accept `patient/` scopes?** Settle it in Phase 5 and update the Haste profile.
|