A simple, maintainable TypeScript library for generating realistic FHIR R4 sample data using type-safe, tree-shakeable FHIR types generated by @atomic-ehr/codegen.
- ✅ Type-safe: Generated using official FHIR R4 types
- 🌲 Tree-shakeable: Only import what you need
- 🎯 Simple API: Clean, focused generator functions
- 📊 Realistic data: Uses faker.js for realistic healthcare data
- 🏥 FHIR Compliant: Uses official FHIR value sets for status codes
- 🔧 Maintainable: Simple, readable code without over-engineering
- Patient - Demographics and administrative information
- Encounter - Healthcare interactions between patient and providers
- Observation - Vital signs and laboratory values
- Appointment - Scheduled healthcare appointments
bun install
bun run gen:types # Generate FHIR typesimport {
createPatient,
createEncounter,
createObservation,
createAppointment
} from './index.js';
// Generate a patient
const patient = createPatient();
// Generate an encounter for a patient
const encounter = createEncounter(patient.identifier?.[0]?.value || 'patient-id');
// Generate vital signs observation
const vitals = createObservation(patient, encounter, 'vital-sign');
// Generate lab observation
const lab = createObservation(patient, encounter, 'lab');
// Generate appointment
const appointment = createAppointment(patient);import { createPatientRecord } from './index.js';
// Generate a complete patient record with related data
const record = createPatientRecord();
console.log(record.patient); // Patient resource
console.log(record.encounter); // Encounter resource
console.log(record.appointment); // Appointment resource
console.log(record.observations); // Array of Observation resourcesbun run demoThe FHIR types are generated using atomic-codegen.config.js:
- Tree-shaking: Only Patient, Encounter, Observation, and Appointment types are included
- Output: Types are generated in
./src/fhir/types/ - Source: FHIR R4 Core specification (
hl7.fhir.r4.core@4.0.1)
To add more FHIR resources, update the treeshake array in the config and run bun run gen:types.
src/
├── fhir/types/ # Generated FHIR types (tree-shakeable)
├── types/fhir-values.ts # Official FHIR value sets and enums
└── generators/ # Simple generator functions
├── patient.ts # Patient generator
├── encounter.ts # Encounter generator
├── observation.ts # Observation generator
└── appointment.ts # Appointment generator
Each generator uses official FHIR value sets instead of hardcoded values, ensuring compliance with FHIR specifications.