Skip to main content
Version: v0.0.4

Function: parseNm()

parseNm(rep, _enc): NM

Parse an HL7 v2 NM repetition into { raw, value }. Uses Number(raw) for strict numeric parsing: trailing non-numeric characters produce NaN, normalized to undefined. Empty raw also produces undefined.

Number("") is 0 in JS: which is the wrong answer for an empty HL7 numeric field. The explicit empty-string check below returns { raw: "", value: undefined } so empty inputs match missing inputs.

Parameters

rep

RawRepetition

_enc

EncodingCharacters

Returns

NM

Example

import { parseNm, DEFAULT_ENCODING_CHARACTERS } from "@cosyte/hl7";
const rep = { components: [{ subcomponents: ["120.5"] }] };
const nm = parseNm(rep, DEFAULT_ENCODING_CHARACTERS);
console.log(nm.value); // 120.5