Function: parseSn()
parseSn(
rep,enc):SN|undefined
Parse an HL7 v2 SN repetition into a structured SN, or undefined when the
field carries no usable structured-numeric content (empty, or so malformed
that no comparator, number, or separator can be recovered). Components are
returned verbatim (already decoded by the tokenizer); num1/num2 use strict Number() parsing.
Fail-safe: a non-operator value in the comparator slot (SN.1) is dropped
rather than surfaced as a relation, and a non-numeric SN.2/SN.4 becomes
undefined: the parser never emits a confident wrong comparator or number.
Parameters
rep
enc
Returns
SN | undefined
Example
import { parseSn, DEFAULT_ENCODING_CHARACTERS } from "@cosyte/hl7";
const rep = { components: [
{ subcomponents: [">"] },
{ subcomponents: ["90"] },
] };
const sn = parseSn(rep, DEFAULT_ENCODING_CHARACTERS);
console.log(sn?.comparator, sn?.num1); // ">" 90