Skip to main content
Version: v0.0.3

Function: editCcda()

editCcda(source, options?): CcdaDocument

Re-emit a parsed C-CDA document with sections added or replaced, preserving every unedited section byte-faithfully and (by default) stamping a CDA R2 revision that supersedes the source. See the module overview for the full contract.

Parameters

source

CcdaDocument

A document produced by parseCcda (it must retain its source XML, a hand-constructed document throws NO_SOURCE_DOCUMENT).

options?

EditCcdaOptions = {}

The section edits to apply, the revision behavior, and an optional bring-your-own terminology adapter forwarded to the final re-parse so the edited document flags adapter-rejected codes (SEMANTIC_CODE_INVALID).

Returns

CcdaDocument

A new CcdaDocument, the re-parse of the edited XML. The source is never mutated.

Throws

CcdaEditError when the source has no retained XML, has no structuredBody to edit, violates an add/replace precondition, would drop a SHALL required section, or (when stamping a revision) has no usable ClinicalDocument.id for the RPLC link to name, absent or nullFlavor-marked (SOURCE_MISSING_ID).

Throws

when a section's content violates a builder guard (an invalid timestamp, a resolved problem without a resolution date, …).

Example

import { parseCcda, editCcda } from "@cosyte/ccda";
const doc = parseCcda(xml);
const revised = editCcda(doc, {
sections: [
{
kind: "problems",
content: [{ problem: { code: "38341003", displayName: "Hypertension" }, status: "active" }],
},
],
});
console.log(revised.header.versionNumber); // incremented from the source