Skip to main content
Version: v0.0.3

Function: renderText()

renderText(input, enc?, opts?): RenderedText

Render an HL7 v2 escape/formatting-bearing string into a normalized display model (plain text + highlight-aware runs). A read projection: it never mutates the underlying field, and it never fabricates: an escape it cannot render is preserved as literal characters and flagged in RenderedText.unrenderedSequences.

input is the field's escape-bearing text. Pass the wire form (e.g. Field.text, byte-verbatim for parsed content) for the most faithful result: a wire \E\H\E\ (an escaped literal backslash-H-backslash) then renders as the three literal characters \H, never as a highlight. Passing an already-decoded Field.value also works: its \.br\ is already a newline (rendered as one line break) and its \H/formatting sentinels are still recognized.

Never throws for any input.

Parameters

input

string

the escape-bearing field text to render.

enc?

EncodingCharacters = DEFAULT_ENCODING_CHARACTERS

the message's encoding characters (for \F\/\S/… targets); defaults to the HL7 standard |^~\&.

opts?

RenderTextOptions

see RenderTextOptions.

Returns

RenderedText

the normalized RenderedText.

Example

import { renderText } from "@cosyte/hl7";

const r = renderText("Specimen received.\\.br\\Gross exam \\H\\normal\\N\\.");
r.text;
// "Specimen received.\nGross exam normal."
r.runs;
// [ { text: "Specimen received.\nGross exam ", highlighted: false },
// { text: "normal", highlighted: true },
// { text: ".", highlighted: false } ]
r.unrenderedSequences; // []