Skip to content

Getting Started

Installation

Install globally (recommended when using the CLI frequently):

bash
npm install -g babelfhir-ts

Or invoke on-demand without a global install:

bash
npx babelfhir-ts --help

Requirements

Node.js 18+ (ESM support) and an internet connection when downloading packages from remote registries.

Quick Start

Generate code from a local folder that contains FHIR packages:

bash
babelfhir-ts input/ output/

Process a single package archive and write the generated interfaces back into a new .tgz file:

bash
babelfhir-ts hl7.fhir.us.core-8.0.0.tgz us-core-generated.tgz

Download and process a package directly from a registry (defaults to https://packages.simplifier.net):

bash
babelfhir-ts --package hl7.fhir.us.core@8.0.0

Download, process, and install a processed package into your current project:

bash
babelfhir-ts install hl7.fhir.us.core@8.0.0

Using the Generated Code

After generation you can import the emitted classes:

ts
import { USCorePatientClass } from "./output/USCorePatientClass";

const patient = USCorePatientClass.random();
const { errors, warnings } = await patient.validate();

Or use the generated FHIR client to interact with a FHIR server:

ts
import { FhirClient } from "./output/fhir-client";

const client = new FhirClient("https://hapi.fhir.org/baseR4");

// Profile-specific methods generated from your IG
const patient = await client.read().usCorePatient().read("123");
const bundle = await client.read().usCoreCondition().search({ patient: "123" });

// All base resource types for the selected FHIR version are available
const appointment = await client.read().appointment().read("456");

Next Steps

Released under the ISC License.