Skip to main content
v1.2 — R4 · R4B · R5 · R6

fhir-dsl

The TypeScript FHIR toolchain — typed query builder, code generator, FHIRPath, validators, SMART-on-FHIR, terminology, and an MCP bridge.

$npx @fhir-dsl/cli generate --version r4
4
FHIR Versions
R4 · R4B · R5 · R6
10
Workspace Packages
core · runtime · cli · …
70+
FHIRPath Functions
N1 spec coverage
1.6K+
Tests Passing
lint · typecheck · vitest
Walkthrough

See it in action

A short narrated tour of the query builder, generator, and CLI.

Capabilities

The FHIR toolchain, end to end

From StructureDefinitions on the server to the .where() calls in your editor — types, validators, FHIRPath, terminology, SMART, and an MCP bridge.

Type-Safe Queries

Every resource, search parameter, operator, modifier, include, _has, and chained hop is validated at compile time. No malformed FHIR queries at runtime.

Code Generation

Generate TypeScript interfaces, profile schemas, ValueSet enums, and FHIRPath builders from any FHIR version (R4 / R4B / R5 / R6) or any published IG.

Profile-Aware

Query US Core, IPS, or any custom IG with automatic type narrowing. Slicing, typed extensions, and profile cardinality all enforced by the type system.

Standard Schema Validators

Optional zod or zero-dep native validators conforming to Standard Schema V1, with FHIRPath invariants (pat-1, dom-3, …) wired in automatically.

FHIRPath Builder

Type-safe FHIRPath expressions with autocomplete at every step, compilation to FHIRPath strings, and runtime evaluation. 70+ functions across the N1 spec.

SMART on FHIR v2

PKCE-S256, backend-services JWT (RS384 / ES384), patient-launch refresh-token rotation. Lazy-loaded — bearer-only deployments never pay the jose cost.

Terminology Engine

is-a, descendent-of, and regex ValueSet filters with transitive subsumption. Bundled $expand, $validate-code, $lookup, $translate, $subsumes operations.

MCP Server (LLM bridge)

Generated tool surface for any LLM agent, with stdio + streamable HTTP transports, three pluggable auth strategies, write gating, and full audit.

Zero Runtime Overhead

The core DSL has no runtime dependencies beyond @fhir-dsl/types. Dual ESM/CJS. Type safety compiles away to plain objects.

Examples

Fluent API, real FHIR

Search, filter across references, compose transactions, or stream large result sets — every call is fully typed against the FHIR spec.

const result = await fhir
.search("Patient")
.where("family", "eq", "Smith")
.where("birthdate", "ge", "1990-01-01")
.include("general-practitioner")
.sort("birthdate", "desc")
.count(10)
.execute();
// result.data: Patient[] — fully typed
// result.included: Practitioner[]
Workspace

Ten focused packages, one toolchain

Install only what you need. core + runtime get you a typed client; everything else is opt-in.

@fhir-dsl/core
Query builder DSL — search, read, batch, transactions, terminology ops, capability guard.
@fhir-dsl/runtime
HTTP executor with pagination, error handling, bundle resolution, slice helpers.
@fhir-dsl/cli
fhir-gen — generate, capability, validate, scaffold-ig, diff, mcp.
@fhir-dsl/types
Branded FHIR R4/R5 primitives, base datatypes, runtime parsers.
@fhir-dsl/generator
Code generation engine — resources, profiles, slices, typed extensions, layers, IG manifests.
@fhir-dsl/fhirpath
Type-safe FHIRPath expression builder + invariant evaluator.
@fhir-dsl/terminology
CodeSystem hierarchy + ValueSet filter engine (is-a, descendent-of, regex).
@fhir-dsl/smart
SMART on FHIR v2 — PKCE-S256, backend services, scope DSL.
@fhir-dsl/mcp
MCP server — generic FHIR verbs as tools, pluggable auth, audit, stdio + HTTP.
@fhir-dsl/utils
Shared utilities used across the workspace.
Built for

Wherever FHIR meets TypeScript

EHR & FHIR Integrators

Hit US Core, Epic, Cerner, HAPI, or any custom IG with compile-time-checked queries. Profile-aware, slice-aware, no string guessing.

Health-Tech Platforms

Generate types from your tenant's IG, validate every payload at the boundary, and ship a single FHIR client across services with no version drift.

AI & LLM Agents

Expose a FHIR endpoint as an MCP tool surface in one command. Read-only by default, write gating per resource type, full audit, stdio + HTTP transports.

Conformance Authors

Compile FHIRPath invariants, run them against generated Standard Schema validators, and emit OperationOutcome — all from your test suite.

Ready to query FHIR with confidence?

Generate types, spin up a client, and write your first type-safe query in under two minutes.