Skip to main content
Version: v0.0.3

Function: parseCcda()

parseCcda(raw, options?): CcdaDocument

Parse a C-CDA XML payload into an immutable CcdaDocument.

Lenient by default, real-world, vendor-quirky documents parse rather than throw, accruing CcdaWarnings on doc.warnings. Only unrecoverable structural problems throw a CcdaParseError (a Tier-3 FatalCode): a declared DTD/external entity, a size/entity/depth limit breach, malformed XML, or a root that is not ClinicalDocument. With { strict: true }, every Tier-2 deviation is escalated to a thrown CcdaParseError instead of a warning.

Parameters

raw

string

The raw C-CDA XML document text.

options?

ParseCcdaOptions = {}

Parse options; see ParseCcdaOptions. Lenient unless strict is set.

Returns

CcdaDocument

The parsed document plus any recovered Tier-2 warnings.

Throws

CcdaParseError on any Tier-3 fatal, or, when options.strict is true, on the first Tier-2 deviation.

Example

import { parseCcda } from "@cosyte/ccda";
const doc = parseCcda(xml);
console.log(doc.documentType, doc.getPatient()?.name?.text);
for (const w of doc.warnings) console.warn(w.code, w.position);