Skip to main content
Version: v0.0.6

Function: toFhirQuantity()

toFhirQuantity(value, units, ctx?): ConvertResult<FhirComplex>

Convert a parsed HL7 v2 numeric value plus its units to a FHIR Quantity node, fail-safe on the unit. Returns { value: undefined } when the numeric magnitude is absent or non-numeric (a Quantity without a value cannot be safely emitted).

Parameters

value

NM

A parsed @cosyte/hl7 NM (its .raw carries the exact lexical value).

units

CWE

The units component (an OBX-6 CWE); its CWE.1 is the candidate UCUM code.

ctx?

TransformContext = {}

The transform context; used to recognize the UCUM coding system.

Returns

ConvertResult<FhirComplex>

Example

import { toFhirQuantity } from "@cosyte/transform";
const { value } = toFhirQuantity(
{ raw: "5.4", value: 5.4 },
{ identifier: "mg/dL", nameOfCodingSystem: "UCUM" },
);
// value === Quantity { value: 5.4, unit: "mg/dL", system: "http://unitsofmeasure.org", code: "mg/dL" }
void value;