Skip to content

Commit a0469eb

Browse files
authored
Merge pull request #31 from akim1995/provider-directory-bulk-export
Provider directory bulk export example
2 parents bcadddf + cfa2ff3 commit a0469eb

13 files changed

Lines changed: 1003 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ A collection of examples on top of Aidbox FHIR platform
4545
- [Topic-Based Subscription to Kafka](aidbox-features/aidbox-subscriptions-to-kafka/)
4646
- [Aidbox with read-only replica](aidbox-features/aidbox-with-ro-replica/)
4747
- [AWS S3 Aidbox integration](aidbox-features/aws-s3-aidbox-integration/)
48+
- [Medicare Plan Finder (MPF)](aidbox-features/medicare-plan-finder/)
4849
- [Init bundle with environment template](aidbox-features/init-bundle-env-template/)
4950
- [OpenTelemetry](aidbox-features/OpenTelemetry/)
5051
- [Organization-Based Access Control (OrgBAC) Practitioner Application](aidbox-features/orgbac-practitioner-application/)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AIDBOX_LICENSE=<your-aidbox-license-jwt>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.env
2+
output/
3+
node_modules/
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
features: [Bulk API, $export, Plan-Net, Provider Directory, S3, MinIO, Presigned URLs]
3+
languages: [TypeScript]
4+
---
5+
# Medicare Plan Finder (MPF)
6+
7+
A minimal TypeScript provider-directory publishing pipeline on Aidbox. The flow:
8+
9+
1. **Export**: kick off a system-level FHIR [`$export`](https://docs.aidbox.app/api/bulk-api/export) with `_typeFilter`, poll to completion, download the gzipped NDJSON.
10+
2. **Scope filter**: walk references from the kept parents and drop children nothing points at.
11+
3. **Bundle**: partition into FHIR collection `Bundle` files plus an `index.json` manifest.
12+
4. **Publish**: upload through Aidbox-presigned URLs to S3-compatible storage (local [MinIO](https://github.com/minio/minio) here). The script holds no bucket credentials.
13+
14+
This is the shape behind CMS provider-directory feeds (Medicare Plan Finder): a crawler starts from `index.json` and downloads the bundles it lists.
15+
16+
## Layout
17+
18+
| File | Purpose |
19+
|---|---|
20+
| `docker-compose.yml` | Aidbox, PostgreSQL, MinIO (buckets auto-created), and an `export` service that runs the pipeline with [Bun](https://bun.sh). |
21+
| `init-bundle.json` | An `AwsAccount` for MinIO, the `provider-export` client with a least-privilege `AccessPolicy`, and a small Plan-Net dataset (one plan, two networks, practitioners in and out of network). |
22+
| `src/main.ts` | Scope config and orchestration of the four steps. |
23+
| `src/aidbox.ts` | Token mint, `$export` start and polling, presigned uploads. |
24+
| `src/filter.ts` | Two-pass scope filter. |
25+
| `src/bundle.ts` | Bundle partitioning and `index.json`. |
26+
27+
## Run
28+
29+
1. Add an Aidbox license to `.env` (obtain one at [aidbox.app](https://aidbox.app)):
30+
31+
```bash
32+
cp .env.example .env
33+
```
34+
35+
2. Start the stack. `curl http://localhost:8888/health` returns `200` when ready.
36+
37+
```bash
38+
docker compose up -d
39+
```
40+
41+
3. Run the pipeline:
42+
43+
```bash
44+
# "export" is the compose service that runs `bun src/main.ts`. --rm drops the container after
45+
docker compose run --rm export
46+
```
47+
48+
It prints progress and the manifest URL `http://localhost:9000/provider-directory-publish/index.json`. Bundles are also written to `./output`.
49+
50+
## Adapting
51+
52+
Scope IDs live in `src/main.ts`, sample data and the storage account in `init-bundle.json`. To change the data before a rerun, edit `init-bundle.json` and re-seed with `docker compose down -v && docker compose up -d`, or edit it live in the Aidbox console at http://localhost:8888 (admin / secret). Swap MinIO for S3, GCP, or Azure through the `AwsAccount`.

aidbox-features/medicare-plan-finder/bun.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
volumes:
2+
aidbox_pg_data: {}
3+
minio_data: {}
4+
5+
services:
6+
aidbox_db:
7+
image: healthsamurai/aidboxdb:17
8+
volumes:
9+
- aidbox_pg_data:/var/lib/postgresql/data:delegated
10+
environment:
11+
POSTGRES_USER: aidbox
12+
POSTGRES_PORT: "5432"
13+
POSTGRES_DB: aidbox
14+
POSTGRES_PASSWORD: jcRsTCRWqi
15+
16+
aidbox:
17+
image: healthsamurai/aidboxone:edge
18+
depends_on:
19+
- aidbox_db
20+
- createbucket
21+
ports:
22+
- 8888:8888
23+
volumes:
24+
- ./init-bundle.json:/init-bundle/init-bundle.json:ro
25+
environment:
26+
BOX_LICENSE: ${AIDBOX_LICENSE}
27+
AIDBOX_PORT: 8888
28+
AIDBOX_BASE_URL: http://aidbox:8888
29+
AIDBOX_ADMIN_PASSWORD: secret
30+
AIDBOX_CLIENT_SECRET: secret
31+
PGHOST: aidbox_db
32+
PGPORT: "5432"
33+
PGUSER: aidbox
34+
PGPASSWORD: jcRsTCRWqi
35+
PGDATABASE: aidbox
36+
AIDBOX_FHIR_PACKAGES: hl7.fhir.r4.core#4.0.1:hl7.fhir.us.davinci-pdex-plan-net#1.1.0
37+
AIDBOX_FHIR_SCHEMA_VALIDATION: true
38+
BOX_FHIR_TERMINOLOGY_ENGINE: hybrid
39+
BOX_FHIR_TERMINOLOGY_ENGINE_HYBRID_EXTERNAL_TX_SERVER: https://tx.health-samurai.io/fhir
40+
BOX_INIT_BUNDLE: file:///init-bundle/init-bundle.json
41+
BOX_FHIR_BULK_STORAGE_PROVIDER: aws
42+
BOX_FHIR_BULK_STORAGE_AWS_ACCOUNT: minio
43+
BOX_FHIR_BULK_STORAGE_AWS_BUCKET: provider-directory-export
44+
45+
minio:
46+
image: minio/minio:RELEASE.2025-04-22T22-12-26Z-cpuv1
47+
command: server /data --console-address ":9001"
48+
ports:
49+
- "9000:9000"
50+
- "9001:9001"
51+
volumes:
52+
- minio_data:/data
53+
environment:
54+
MINIO_ROOT_USER: minioadmin
55+
MINIO_ROOT_PASSWORD: minioadmin
56+
57+
createbucket:
58+
image: minio/mc:RELEASE.2025-04-16T18-13-26Z-cpuv1
59+
depends_on:
60+
- minio
61+
entrypoint: >
62+
/bin/sh -c "
63+
until mc alias set local http://minio:9000 minioadmin minioadmin; do sleep 1; done;
64+
mc mb --ignore-existing local/provider-directory-export;
65+
mc mb --ignore-existing local/provider-directory-publish;
66+
mc anonymous set download local/provider-directory-publish;
67+
exit 0"
68+
69+
export:
70+
image: oven/bun:1
71+
profiles: ["export"]
72+
depends_on:
73+
- aidbox
74+
working_dir: /app
75+
volumes:
76+
- .:/app
77+
environment:
78+
AIDBOX_URL: http://aidbox:8888
79+
CLIENT_ID: provider-export
80+
CLIENT_SECRET: provider-export-secret
81+
PUBLISH_ACCOUNT: minio
82+
PUBLISH_BUCKET: provider-directory-publish
83+
PUBLIC_BASE: http://localhost:9000/provider-directory-publish
84+
command: bun src/main.ts

0 commit comments

Comments
 (0)