GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com β€” GitHub - briankfung/fhir-types: Hand-rolled HL7 FHIR R4 TypeScript types, including US Core Patient. Published on npm as @briankfung/fhir-types.

BranchesTags
Open more actions menu

Latest commit

 

History

17 Commits
17 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
node_modules
node_modules
 
 
src
src
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

@briankfung/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 @briankfung/fhir-types

Usage

import type {
  Patient,
  Observation,
  Condition,
  AllergyIntolerance,
  Practitioner,
} from "@briankfung/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:

  • identifier β†’ required, non-empty (1..*)
  • name β†’ required, non-empty (1..*)
  • gender β†’ required (1..1)
  • meta.profile β†’ required, must include the US Core Patient canonical URL

Example:

import type { USCorePatient } from "@briankfung/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 "@briankfung/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

About

Hand-rolled HL7 FHIR R4 TypeScript types, including US Core Patient. Published on npm as @briankfung/fhir-types.

www.npmjs.com/package/@briankfung/fhir-types

Topics

fhirfhir-r4healthcarehl7hl7-fhirinteroperabilitytypescripttypescript-typesus-core

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 β€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800Γ—600. No cookies required.