Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FHIR Sample Data Generator

A simple, maintainable TypeScript library for generating realistic FHIR R4 sample data using type-safe, tree-shakeable FHIR types generated by @atomic-ehr/codegen.

Features

  • 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

Generated Resources

  • Patient - Demographics and administrative information
  • Encounter - Healthcare interactions between patient and providers
  • Observation - Vital signs and laboratory values
  • Appointment - Scheduled healthcare appointments

Installation

bun install
bun run gen:types  # Generate FHIR types

Usage

Individual Generators

import { 
  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);

Complete Patient Record

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 resources

Demo

bun run demo

Configuration

The 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.

Architecture

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages