Skip to main content
Version: v0.0.3

Function: extractStructuredSig()

extractStructuredSig(medEl, path, warnings): StructuredSig | undefined

Decode a structured SCRIPT <Sig> element into a StructuredSig, or return undefined when no <Sig> is present under medEl.

Lenient and lossy by construction: every component is read independently and tagged with its provenance; unrecoverable ambiguity downgrades a field to "absent" and warns rather than guessing. The free-text <SigText> is always preserved verbatim. Raises "../common/warnings".SCRIPT_WARNING_CODES.SIG_STRUCTURED_LOSSY once when any structured component is decoded.

Parameters

medEl

XmlElement

The <MedicationPrescribed> (or equivalent) element.

path

string

XPath-style location of medEl (for warning context).

warnings

NcpdpScriptWarning[]

Sink that collects non-fatal warnings.

Returns

StructuredSig | undefined

A frozen StructuredSig, or undefined when no <Sig> exists.

Example

const warnings: NcpdpScriptWarning[] = [];
const sig = extractStructuredSig(medEl, "/Message/Body/NewRx/MedicationPrescribed", warnings);
sig?.sigText; // verbatim free text: the source of truth
sig?.route.code?.system; // "SNOMED" when the route was coded