FHIR Pipeline Demo — Spec (v2, 2026-11-12)¶
Purpose. Learn the FHIR APIs that Innovare's job uses, and show Andrew Jones at his Innovare interview (Fri 2026-11-13, noon) two pipelines side by side, both fed by the same synthetic FHIR data, built on the stack Innovare actually uses: - C# .NET 9/10 and ASP.NET Core - EF Core and SQL Server / Azure SQL - a Vue 3 front end - Azure
Everything lives in this repo: the app, the DB schema as EF migrations, local orchestration (.NET Aspire), cloud infrastructure (cdktn in C#), and BI dashboards provisioned by code.
- Track A, "SSM-style lakehouse". Reproduces how Andrew moved Epic data into the data lake, then gold tables, then Power BI at SSM Health. DuckDB stands in for Databricks and the lake, accessed through Andrew's own EF Core provider
JonesGaffney.EntityFrameworkCore.DuckDB(repo../EFCore.DuckDB). Metabase (open source, Tableau/Power BI-like, with the official MotherDuck DuckDB driver) stands in for Power BI. - Track B, "Innovare-style operational ETL". Pulls FHIR R4/R4B incrementally and upserts into application tables in SQL Server via EF Core (Azure SQL in production). Serves an ASP.NET Core Web API consumed by a Vue 3 + Vuetify 3 + TypeScript (Vite) front end (Vuetify = what Andrew knows best), the way the Innovare job works.
Hard rules
- Synthetic data only. Sources are Synthea patients from a public FHIR test server plus committed fixture bundles. No real PHI, ever. Every page shows a "synthetic data" banner.
- .NET for all backend, data and infrastructure code (C#, EF Core, Aspire, cdktn C#). Vue 3 + TypeScript is used for the front end because Innovare uses Vue 3. Metabase is a third-party BI tool run as a container.
- Never write to the public FHIR server. Write-back is simulated: we build the FHIR JSON that would be sent and store it in an outbox table.
- Offline-first demo. Committed fixture bundles make the demo work with no network.
- No secrets in the repo. The Metabase admin for the LOCAL container uses generated test credentials from user-secrets / env vars. The Grok key comes from env XAI_API_KEY.
Data source¶
- Primary (live):
https://r4.smarthealthit.org(SMART Health IT R4 sandbox, Synthea data). Fallback:https://hapi.fhir.org/baseR4. - Offline fixtures:
data/fixtures/*.json, about 10 patients' Bundles (Patient, Encounter, Observation, Condition, AllergyIntolerance, Immunization, MedicationRequest). Captured verbatim from the live server by acapturecommand, with the origin URL and capture date recorded indata/fixtures/SOURCE.md. This follows the contract-test rule: fixtures come from the producer and are never hand-built.
Solution layout¶
fhir-pipeline-demo/
src/FhirDemo.AppHost/ # .NET Aspire AppHost: SQL Server container, Api, Worker, Vue app (AddViteApp/AddNpmApp), Metabase container
src/FhirDemo.ServiceDefaults/# Aspire service defaults (OpenTelemetry, health checks)
src/FhirDemo.Core/ # Firely Hl7.Fhir.R4 client wrapper, mapping, Risk library
src/FhirDemo.Data/ # EF Core: AppDbContext (SQL Server) + migrations; LakehouseDbContext (EFCore.DuckDB)
src/FhirDemo.Lakehouse/ # Track A: bronze/silver/gold via EFCore.DuckDB (gold SQL via ExecuteSqlRaw where clearer)
src/FhirDemo.Operational/ # Track B: incremental sync worker, upsert, quarantine, outbox
src/FhirDemo.Api/ # ASP.NET Core Web API + CDS Hooks endpoints + OpenAPI
src/FhirDemo.Cli/ # capture | lakehouse run | operational sync | metabase provision | ai-summary
web/ # Vue 3 + TypeScript + Vite front end (dashboard, patient chart with CDS cards, compare page)
infra/FhirDemo.Infra/ # cdktn (CDK Terrain) C#: Azure stack (Container Apps, Azure SQL, Key Vault, Service Bus, Log Analytics). SYNTH ONLY, never apply.
bi/metabase/ # driver download script, dashboards-as-code (JSON) + provisioning via Metabase REST from FhirDemo.Cli
tests/FhirDemo.Tests/ # xUnit
docs/ # SPEC, LEARNINGS, SSM-vs-INNOVARE, VERIFY, levels/{plain,middle,complex}.md
..\EFCore.DuckDB\src\EFCore.DuckDB\EFCore.DuckDB.csproj through a Directory.Build.props property EfDuckDbPath that defaults to that path. If the provider can't do something, fall back to DuckDB.NET.Data.Full for that statement only, and log the gap in LEARNINGS.md (that's useful feedback for the provider).
- No Docker? The AppHost must still start. SQL Server falls back to UseSqlite behind a config switch (Data:Provider=Sqlite), and Metabase is skipped with a warning.
Track A: Lakehouse (DuckDB as the Databricks proxy)¶
- Bronze:
bronze_fhir(resource_type, id, version_id, last_updated, source, ingested_at, raw_json). Append only, exactly as received (as with the lake's raw zone). - Silver: typed tables built with DuckDB SQL
json_extract: silver_patientsilver_encountersilver_observation(LOINC code, value, unit, effective date)silver_condition(SNOMED)silver_allergysilver_immunization(CVX)silver_medication(RxNorm)
Deduplicate to the latest version_id per id.
3. Gold:
- gold_patient_summary: age, sex, active conditions, allergy count, latest vitals (BP, BMI, A1c if present), last encounter.
- gold_immunization_status: has flu shot in the last 12 months, has COVID vaccine. Rules stated in SQL comments.
- gold_lab_trends: per patient per LOINC, a time series.
- gold_population: condition prevalence and age bands.
4. Reports (Metabase, the open-source Power BI/Tableau proxy):
- Runs as a container in Aspire, with the MotherDuck DuckDB driver jar in its plugins folder. bi/metabase/get-driver.ps1 downloads the pinned release from github.com/motherduckdb/metabase_duckdb_driver.
- Connects to data/lakehouse.duckdb read-only.
- FhirDemo.Cli metabase provision sets up the LOCAL admin with test credentials from env, adds the DuckDB database, and creates dashboards from bi/metabase/*.json:
- Population overview
- Chronic conditions
- Immunization gaps
- Lab trends
- Population risk (with the care-manager outreach list)
- Fallback if Metabase is unavailable: the API exposes /api/reports/* JSON, and the Vue app renders basic charts with no extra JS chart library (simple SVG bars).
5. Write docs/SSM-vs-INNOVARE.md: map each step to SSM's real stack. Epic extract → ADLS raw → Databricks notebooks (PySpark) → Delta gold → Power BI.
Track B: Operational (the Innovare-style job)¶
- Incremental pull per resource type:
GET {type}?_lastUpdated=gt{watermark}&_count=100, following Bundlenextlinks. The watermark is stored per type in thesync_statetable. Fixture mode replays the bundles. - Staging:
staging_fhir(raw JSON plus metadata). - Map and upsert (EF Core, SQL Server): map with Firely POCOs into EF entities and tables
patients,allergies,immunizations,observations,conditions,medications. Upsert keyed on (fhir_id). Update only when the incomingversion_idis newer. Translate codes and display text. - Idempotency: a second run with the same input must make 0 row changes. Print
inserted/updated/unchanged/quarantinedcounts. - Quarantine: resources that fail to parse or map go to
quarantine(resource_type, id, error, raw_json)and never crash the run (dead-letter pattern). - API (ASP.NET Core Web API with OpenAPI):
GET /api/patientsGET /api/patients/{id}/summaryPOST /api/patients/{id}/allergies: validates the input, builds a FHIRAllergyIntoleranceJSON (R4), stores it in anoutboxtable, and returns it. This simulates write-back, which is the bidirectional part.- Vue 3 front end (
web/, TypeScript, Vite, mobile-first, synthetic banner; Andrew presents from a phone): - Dashboard: run stats for both tracks, plus a "Run sync again" button that shows idempotency live.
- Patient chart: CDS risk cards on top, then allergies, immunizations, labs and conditions, plus an "Add allergy" form that POSTs and shows the outbox FHIR JSON.
- Compare page: Track A vs Track B, plus "Predictive medicine, two ways".
- Reports link: opens Metabase dashboards.
- Aspire wires the API URL through env.
Predictive medicine: the same risk logic, two delivery models (the centerpiece)¶
Implement transparent, rule- and formula-based risk flags in one C# library, FhirDemo.Core/Risk, and reuse it in both tracks. This is not an ML black box. Every flag cites its inputs.
- Prediabetes / diabetes trajectory: HbA1c (LOINC 4548-4) of 5.7–6.4 is prediabetes; ≥6.5 is diabetes range. Flag a rising trend across the last 3 results.
- Uncontrolled hypertension: 2 or more of the last 3 BP readings (LOINC 85354-9 panel; systolic 8480-6, diastolic 8462-4) at ≥140/90.
- 10-year ASCVD risk: Pooled Cohort Equations (2013 ACC/AHA). Inputs: age, sex, total cholesterol (2093-3), HDL (2085-9), systolic BP, BP treated, diabetes, smoker. Clearly label the race coefficient caveat and the "educational demo, not clinical use" banner. If any input is missing, return "insufficient data" with the missing inputs listed. Never impute.
- Care gap: no flu immunization (CVX 140/141/150/155/158/161/166/171/185/186/197/205) in the last 12 months.
Track A (SSM way), population and batch: gold_risk_flags (patient × flag × score × inputs × as_of), computed in DuckDB SQL. The Metabase dashboard "Population risk" shows risk distribution, a prediabetes trend cohort, and a care-manager outreach list sorted by risk. That is how SSM did it: gold tables, then a model, then Power BI, then outreach.
Track B (Innovare way), patient and point of care: a CDS Hooks service (HL7 open standard):
- GET /cds-services lists the services.
- POST /cds-services/patient-risk accepts a patient-view hook request (patient id, plus optional prefetch) and returns CDS cards: summary, indicator (info/warning/critical), detail with cited FHIR ids, and a source label.
- The patient page renders these cards at the top, the way an EHR would when the doctor opens the chart.
Compare page section "Predictive medicine, two ways": batch vs real-time, population vs patient, report vs in-workflow card, refresh cadence, data latency, who acts on it (care manager vs doctor), where the AI summary fits.
Test: the risk library gets unit tests: A1c thresholds, BP rule, ASCVD with a published reference case where the expected value is within ±0.5%, and insufficient data → no score.
AI pre-visit summary (optional and pluggable)¶
- Interface
IVisitSummarizer. Providers:None(a deterministic template built from gold data, the default) andGrok(xAI API; the key comes from an env var and is never committed). - Input: only the gold/silver facts for one synthetic patient.
- Output: 4–6 bullet points. Every bullet must cite the source FHIR ids, e.g.
[Observation/abc]. The page also shows the cited records. - Banner: "Synthetic data. Production use with PHI requires a BAA and zero-data-retention terms with the model vendor, minimum-necessary data, and clinician review."
Tests (xUnit, must pass)¶
- Contract: parse at least one verbatim fixture Bundle for each resource type with Firely, and assert key fields. The fixture origin is commented.
- Mapping: Observation LOINC, value and unit end up in the correct columns. Assert the negative too (a wrong path yields null and the test fails).
- Idempotency: run the operational sync twice on the fixtures; the second run reports 0 inserted and 0 updated.
- Version rule: a higher
version_idupdates the row; a lower one is ignored. - Quarantine: a malformed resource goes to quarantine and the run continues.
- Lakehouse: after a run, the gold tables have rows and
gold_patient_summarycount = distinct patients.
Run (definition of done)¶
dotnet buildwith no errors.dotnet testpasses, with the count of tests run printed and greater than 0.dotnet run --project src/FhirDemo.Cli -- lakehouse run --fixturescreatesdata/lakehouse.duckdbwith gold rows.dotnet run --project src/FhirDemo.Cli -- operational sync --fixtures, run twice, prints counts. The second run is all unchanged.dotnet run --project src/FhirDemo.AppHoststarts everything. The Aspire dashboard shows all resources healthy.cdktn synthin infra/FhirDemo.Infra produces Terraform JSON for Azure. Put the synth output summary in VERIFY.md. Never apply.FhirDemo.Cli metabase provisioncreates the dashboards. Put the API JSON of the dashboard list in VERIFY.md.- The Vue app (
npm run devvia Aspire) renders every page. The API returns JSON. README.mdholds a 3-minute demo script.
docs/LEARNINGS.md¶
A running log of what we learned using the real FHIR APIs: paging, _lastUpdated behavior, missing or odd fields in Synthea data, code systems seen, any surprises. One dated bullet per learning. This is the knowledge-tracking doc.
Decisions (2026-11-12)¶
- Hosting = C: a public link (Cloudflare tunnel declared in fleet-infra code; Andrew approves the apply) plus a laptop/phone fallback. The Azure cdktn stack in infra/ is synth-only, to show how it would deploy at Innovare.
- AI summary provider = Grok (env
XAI_API_KEY), falling back to None. Synthetic data only. - Knowledge tracking: docs/LEARNINGS.md, plus 3-level docs (plain / middle / complex) in docs/levels/ for the demo, written after the build.