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

@ufbfung/fhir-types

v0.0.4

Published

Minimal HL7 FHIR R4 TypeScript types (hand-rolled MVP).

Readme

@ufbfung/fhir-types

Minimal, hand-rolled HL7 FHIR R4 TypeScript types.

This package intentionally starts small and dependency-free, focusing on a clean, ergonomic type surface that can grow incrementally over time. The long-term goal is to support optional, transparent code generation — without sacrificing readability or control.

📓 See CHANGELOG.md for release notes and version history.


Installation

npm install @ufbfung/fhir-types

Usage

import type {
  Patient,
  Observation,
  Condition,
  AllergyIntolerance,
  Practitioner,
} from "@ufbfung/fhir-types";

const patient: Patient = {
  resourceType: "Patient",
  id: "123",
};

const observation: Observation = {
  resourceType: "Observation",
  status: "final",
  code: { text: "Heart rate" },
  valueQuantity: { value: 72, unit: "beats/min" },
};

All resources use resourceType as a discriminant, making them safe and ergonomic to use in unions, type guards, and switch statements.


Supported Resources

This package is intentionally constrained. Only explicitly supported resources are exported and included in the public API.

Currently supported:

  • Patient
  • Observation
  • Condition
  • AllergyIntolerance
  • Practitioner

These are also exposed via:

  • SUPPORTED_RESOURCE_TYPES
  • SupportedResourceType
  • SupportedResource
  • Runtime guards:
    • isSupportedResourceType
    • isSupportedResource
    • assertSupportedResource

This design allows downstream systems (e.g. FHIR servers, validators, ingestion pipelines) to fail fast when encountering unsupported resource types.


Profile-Aware Types (US Core)

In addition to base FHIR R4 resources, this package includes profile-aware types for common U.S. implementation guides.

US Core Patient

The package provides a strict USCorePatient type aligned with US Core Patient (STU6.1).

This type enforces key cardinality constraints at compile time:

  • identifierrequired, non-empty (1..*)
  • namerequired, non-empty (1..*)
  • genderrequired (1..1)
  • meta.profilerequired, must include the US Core Patient canonical URL

Example:

import type { USCorePatient } from "@ufbfung/fhir-types";

const patient: USCorePatient = {
  resourceType: "Patient",
  meta: {
    profile: ["http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"],
  },
  identifier: [{ system: "urn:mrn", value: "12345" }],
  name: [{ family: "Doe", given: ["Jane"] }],
  gender: "female",
};

If any required fields are missing, TypeScript will fail at author time — similar to how SUSHI validates FHIR instances against profiles.


Draft Construction Pattern

To support ergonomic, incremental object construction, a DraftUSCorePatient type is also provided.

This pattern allows developers to build partial objects and then explicitly confirm conformance when ready.

import type {
  DraftUSCorePatient,
  USCorePatient,
} from "@ufbfung/fhir-types";

const draft: DraftUSCorePatient = {
  resourceType: "Patient",
};

draft.identifier = [{ value: "12345" }];
draft.name = [{ family: "Doe", given: ["Jane"] }];
draft.gender = "female";
draft.meta = {
  profile: ["http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"],
};

const finalPatient = draft as USCorePatient;

Future versions may optionally replace this assertion with runtime validation.


Shared Datatypes

A minimal but practical set of common FHIR datatypes is included, aligned with the FHIR specification:

  • CodeableConcept
  • Coding
  • Identifier
  • HumanName
  • Reference
  • Quantity
  • Period
  • Extension
  • Element
  • Primitive wrappers (e.g. FhirString, FhirDate, etc.)

These datatypes are reused across all supported resources.


Design Principles

  • Types-first, runtime-light
  • No required runtime dependencies
  • Incremental growth over full spec coverage
  • Clear, auditable type definitions
  • Generator-friendly file structure
  • Explicitly scoped support
  • Static enforcement of simple profile constraints (cardinality + profile identity)

This is not a full FHIR SDK. It is a deliberately minimal foundation designed to grow alongside real usage, not ahead of it.


Roadmap (High-Level)

Planned or considered additions:

  • More core R4 resources
  • AnySupportedResource discriminated unions
  • Explicit supported-version metadata
  • Optional schema-driven generator
  • Additional profile / Implementation Guide–aware types (e.g. US Core)
  • Optional future runtime validators (e.g. invariants, slicing) layered on top

Breaking changes will be versioned conservatively.


FHIR Version

  • HL7 FHIR R4 (4.0.1)

License

MIT