Skip to content

Add ELM-to-SQL library, HAPI FHIR SQL views, and CMS demo fixtures (resolves #16, #21, refs #18)#25

Draft
aks129 wants to merge 6 commits intocqframework:masterfrom
aks129:feature/sql-on-fhir
Draft

Add ELM-to-SQL library, HAPI FHIR SQL views, and CMS demo fixtures (resolves #16, #21, refs #18)#25
aks129 wants to merge 6 commits intocqframework:masterfrom
aks129:feature/sql-on-fhir

Conversation

@aks129
Copy link
Copy Markdown
Collaborator

@aks129 aks129 commented Apr 12, 2026

Summary

  • Issue Create standalone JavaScript library for ELM->SQL transpilation and MeasureReport generation #16 (done): Standalone @cqframework/elm-to-sql library — pure ESM TypeScript, zero runtime deps, Apache 2.0. Transpiles ELM JSON → SQL WITH CTEs → FHIR MeasureReport. Pluggable DB adapter, pluggable fetch for FHIR value set loading.
  • Issue Create SQL-on-FHIR views for latest version of HAPI FHIR JPA server #21 (done): HAPI FHIR JPA SQL-on-FHIR boot scripts (scripts/hapi-fhir-sql-on-fhir/). Idempotent install.sql creates 12 PostgreSQL views over HFJ_RESOURCE/HFJ_RES_VER. Covers all US Core 6.1 / US CDI v3 eCQM resources.
  • Issue Find a few good CMS examples/use cases for SQL demo purposes #18 (partial): CMS125 (Breast Cancer Screening) and CMS130 (Colorectal Cancer Screening) ELM fixtures and transpiler tests. Full population logic, UNION patterns, value set lookups.
  • Value set support: extractValueSets, loadValueSetExpansions (FHIR $expand + Bundle fallback), generateValueSetSeedScript for static PostgreSQL seeding.
  • Data quality: scripts/hapi-fhir-sql-on-fhir/data-quality/dq_checks.sql — 14 CRITICAL/WARNING/INFO checks covering view existence, patient coverage, null rates, date sanity, and value set expansion completeness.

New views (US Core 6.1)

View Resource Key CQL columns
coverage_view Coverage beneficiary_id, payer_id, period_start/end
allergy_intolerance_view AllergyIntolerance clinical_status, verification_status, code, onset_datetime
immunization_view Immunization vaccine_code, occurrence_datetime, primary_source
service_request_view ServiceRequest code, authored_on, do_not_perform, occurrence_datetime, insurance_id

Test coverage

  • 102 Jest tests (up from 37 at branch start) — transpiler, MeasureReport generator, value set extractor/loader/SQL, and US Core 6.1 ViewDefinition column contracts
  • scripts/hapi-fhir-sql-on-fhir/test/run_tests.sql — PostgreSQL integration test with 17 synthetic FHIR R4 resources, assertions for all 12 views, deleted-resource exclusion; always ROLLBACKs (no side effects)

Test plan

Pending (not in this PR)

Linked issues

Closes #16
Closes #21
References #18
Part of #15

🤖 Generated with Claude Code

aks129 and others added 3 commits April 12, 2026 18:17
Implements the @cqframework/elm-to-sql package as a pure ESM TypeScript
library with zero runtime Node.js dependencies (Apache 2.0). Includes:

- ElmToSqlTranspiler: converts HL7 ELM JSON to SQL WITH CTEs
- generateMeasureReport: produces FHIR R4 MeasureReport from population counts
- STANDARD_VIEW_DEFINITIONS: SQL-on-FHIR ViewDefinition resources + DDL
- 24 Jest tests passing against a CMS125 Breast Cancer Screening ELM fixture
- FAQ.md documenting current support state, known gaps, and roadmap
- CLAUDE.md updated with SQL-on-FHIR tracking table and demo sequence

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Creates scripts/hapi-fhir-sql-on-fhir/ with an idempotent install.sql
that runs in a single transaction and registers 8 CREATE OR REPLACE VIEWs
(patient, observation, condition, procedure, encounter, medication_request,
diagnostic_report, value_set_expansion) over HAPI FHIR JPA 6.x/7.x
PostgreSQL tables HFJ_RESOURCE and HFJ_RES_VER. Satisfies the view
contracts expected by @cqframework/elm-to-sql.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ework#18)

Adds ELM JSON fixture for CMS130 (ages 45-75 colorectal cancer screening)
covering Union patterns for Denominator Exclusion (Condition + Procedure)
and Numerator (Colonoscopy/FOBT/Sigmoidoscopy). Adds 15 new Jest tests in
a CMS130 describe block; total test count is now 39, all passing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@aks129 aks129 changed the title Add standalone ELM-to-SQL library (resolves #16) Add ELM-to-SQL library, HAPI FHIR SQL views, and CMS demo fixtures (resolves #16, #21, refs #18) Apr 13, 2026
@aks129 aks129 requested a review from preston April 13, 2026 01:45
aks129 and others added 3 commits April 12, 2026 21:58
Adds packages/elm-to-sql/src/valueset/ with three modules:

- value-set-extractor.ts: extractValueSets() / extractUsedValueSets()
  reads valueSets.def from ELM JSON and returns { name, url } references
  matching the value_set_expansion view contract

- value-set-loader.ts: loadValueSetExpansions() fetches pre-expanded
  ValueSet resources from a FHIR R4 server ($expand with Bundle fallback),
  flattens expansion.contains[] including nested hierarchies; zero Node.js
  deps (accepts pluggable fetch); per-set errors captured, never thrown

- value-set-sql.ts: generateValueSetTableDdl/InsertSql/UpsertSql/SeedScript
  for environments without the HAPI FHIR JPA view (DuckDB, plain PostgreSQL)

27 new tests (66 total, all passing). Tested against CMS125 and CMS130 fixtures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
HAPI FHIR JPA boot scripts (scripts/hapi-fhir-sql-on-fhir/):
- 009_coverage_view.sql     — Coverage: type, period, payor, class (plan)
- 010_allergy_intolerance_view.sql — AllergyIntolerance: substance, clinical
  status, reaction severity; US Core 6.1 MustSupport elements
- 011_immunization_view.sql — Immunization: CVX vaccine codes, occurrence,
  statusReason (not-done support), site/route, lot number
- 012_service_request_view.sql — ServiceRequest (new in US Core 6.1):
  orders/referrals, occurrence, doNotPerform flag, insurance reference

data-quality/dq_checks.sql — standalone pre-flight DQ script:
- 14 sections: views installed, resource volumes, per-resource field
  nullability (CRITICAL/WARNING), date sanity, code system spot-check,
  value set expansion coverage
- Emits structured RAISE NOTICE report; never aborts the session
- CRITICAL = will produce wrong measure results; WARNING = may undercount

packages/elm-to-sql/src/views/view-definitions.ts:
- serviceRequestViewDefinition() added (11th standard view)
- Remove unused colList variable

All 66 tests continue to pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…qframework#21/cqframework#18)

- scripts/hapi-fhir-sql-on-fhir/test/run_tests.sql: isolated PostgreSQL
  integration test using a cql_test schema with 17 synthetic FHIR R4 resources;
  covers all 12 views, edge cases (effectivePeriod, medicationReference,
  occurrenceString, doNotPerform), deleted-resource exclusion, and value set
  expansion; always ROLLBACKs for zero side-effects
- packages/elm-to-sql/test/elm-to-sql.test.ts: 36 new US Core 6.1 ViewDefinition
  column contract tests locking down the CQL-critical column set for all 11
  standard views; test count grows from 66 to 102

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cqframework cqframework deleted a comment from asushares-bot Apr 14, 2026
@preston
Copy link
Copy Markdown
Collaborator

preston commented Apr 14, 2026

Could we meet Thursday mid-day or Friday morning for you to do a demo and explain what is going on? 😜

@aks129
Copy link
Copy Markdown
Collaborator Author

aks129 commented Apr 14, 2026

can use my link https://calendar.app.google/MZcQ2Spm1NYNS72p9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants