npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@reasonhealth/fhir-zod

v1.0.4

Published

Zod schemas for FHIR R4, R4B, R5

Downloads

625

Readme

@reasonhealth/fhir-zod

npm

Zod schemas for FHIR R4, R4B, and R5. Generated from official FHIR StructureDefinition packages via @reasonhealth/fhir-ts-codegen.

Installation

npm install @reasonhealth/fhir-zod zod
# or
bun add @reasonhealth/fhir-zod zod

Pair with @types/fhir for ambient TypeScript types if you need them alongside runtime validation:

npm install --save-dev @types/fhir

Usage

import { PatientSchema, BundleSchema } from '@reasonhealth/fhir-zod/r4'

// Parse and validate (throws ZodError on failure)
const patient = PatientSchema.parse(rawJson)

// Safe parse (no throw)
const result = PatientSchema.safeParse(rawJson)
if (result.success) {
  console.log(result.data.resourceType) // 'Patient'
}

// Infer types directly from the schema
import type { z } from 'zod'
import { PatientSchema } from '@reasonhealth/fhir-zod/r4'
type Patient = z.infer<typeof PatientSchema>

Available entry points

| Import | FHIR Version | |--------|-------------| | @reasonhealth/fhir-zod/r4 | FHIR R4 (4.0.1) | | @reasonhealth/fhir-zod/r4b | FHIR R4B (4.3.0) | | @reasonhealth/fhir-zod/r5 | FHIR R5 (5.0.0) |

Every schema file exports:

  • A *Schema constant for each FHIR type (e.g. PatientSchema, BundleSchema)
  • An inferred TypeScript type for each schema (e.g. type Patient = z.infer<typeof PatientSchema>)

Examples

Safe parse with error handling

import { ObservationSchema } from '@reasonhealth/fhir-zod/r4'

const result = ObservationSchema.safeParse(raw)
if (!result.success) {
  console.error('Invalid Observation:', result.error.flatten())
} else {
  console.log('Status:', result.data.status)
}

Infer types from schemas

import { z } from 'zod'
import { PatientSchema, BundleSchema } from '@reasonhealth/fhir-zod/r4'

type Patient = z.infer<typeof PatientSchema>
type Bundle  = z.infer<typeof BundleSchema>

Using with @types/fhir

@types/fhir provides ambient namespace types (fhir4.Patient, etc.). Build a type-guard that bridges the two:

import { PatientSchema } from '@reasonhealth/fhir-zod/r4'

function isPatient(resource: fhir4.Resource): resource is fhir4.Patient {
  return PatientSchema.safeParse(resource).success
}

Bundle unpacking

import { BundleSchema, PatientSchema } from '@reasonhealth/fhir-zod/r4'

const bundle = BundleSchema.parse(raw)
const patients = (bundle.entry ?? [])
  .map(e => e.resource)
  .filter(r => r?.resourceType === 'Patient')
  .map(r => PatientSchema.parse(r))

Discriminated union

import { z } from 'zod'
import { PatientSchema, PractitionerSchema, OrganizationSchema } from '@reasonhealth/fhir-zod/r4'

const SubjectSchema = z.discriminatedUnion('resourceType', [
  PatientSchema,
  PractitionerSchema,
  OrganizationSchema,
])

type Subject = z.infer<typeof SubjectSchema>

Extend or restrict for profiles

import { PatientSchema } from '@reasonhealth/fhir-zod/r4'

const PatientSummarySchema = PatientSchema.pick({ id: true, name: true, birthDate: true })

const IdentifiedPatientSchema = PatientSchema.extend({
  id: PatientSchema.shape.id.unwrap(), // make id required
})

What's generated

Notable schema features:

  • BackboneElements use BackboneElementSchema.extend({}) for clean inheritance
  • Choice types (value[x]) expand to individual optional fields
  • Primitive shadow fields (_birthDate) included for FHIR primitive extensions
  • Inline enums for required-strength bindings (z.enum(['male', 'female', 'other', 'unknown']))
  • resourceType as z.literal('Patient') for discriminated union support
  • Circular references (e.g. Questionnaire.item.item, ValueSet.compose) handled with z.lazy()
  • Schemas emitted in topological order to minimise forward references

Regenerating

bun run generate

Requires @reasonhealth/fhir-ts-codegen to be available (installed via workspace). FHIR packages are downloaded automatically on first run and cached in .fhir-cache/.

Supported By

This project is proudly supported by Vermonster / ReasonHealth.