Skip to main content
Version: v0.1.12

@cosyte/fhir

Our FHIR toolkit for Node.js and TypeScript: an R4-first resource model, a JSON and XML codec, and layered validation, with the same one-line ergonomics as the rest of the @cosyte/* parser suite. It is the FHIR member of that suite and mirrors the API shape of @cosyte/hl7, our HL7 v2 parser.

What it is for, in one sentence: read a real-world FHIR resource, model it with correct primitive semantics, and validate it against the profiles you supply, such as US Core, without reading the FHIR specification first.

It is for developers who receive FHIR from servers and EHRs they do not control and need to read it without losing or inventing anything. It is not a FHIR server, a client, a terminology server, or a typed model per resource type; current limits lists what it deliberately leaves out.

Status​

@cosyte/fhir is on the 0.1 line and installs from npm; installation has the command. While the package is below 1.0, a breaking change ships in a minor version and is called out in the changelog. What the package does not do is listed in current limits, which is worth reading before you plan around it.

Start here​

What it does​

Against FHIR R4 (4.0.1), the package can:

  • Read and round-trip a resource through a precision-preserving JSON codec and a zero-dependency XML codec that share one schema-free model. A decimal or integer64 value is kept as its exact lexical text and never routed through a JavaScript number, so a dose or an identifier cannot be silently corrupted. The XML reader refuses any DOCTYPE or non-predefined entity rather than resolving it.
  • Validate across structural, cardinality, and value-domain layers, emitting a value-free OperationOutcome: a finding carries a coded reason and a location, never the value it was raised over.
  • Surface the safety-critical status and negation model: it fails closed on an unknown modifierExtension and does not drop a status, a modifier, or a negation on the paths it reads.
  • Report measured values by their true type with UCUM unit fidelity, never the display string and never converted, validate code systems and binding strength without vendoring any terminology content, validate against caller-supplied US Core or vendor profiles, and evaluate their FHIRPath invariants through a bounded, in-repository expression subset, reporting anything outside that subset as INVARIANT_UNCHECKED rather than passing it.
  • Read Bundles and Bulk Data exports: tell a transaction from a batch without executing either, resolve references inside a Bundle, and stream NDJSON a line at a time.

The quickstart is the shortest way to see the whole flow working.