Function: parseCd()
parseCd(
el,ctx):CD|undefined
Parse a CD/CE element into a typed CD. Returns undefined when
the element is absent. Resolves a child <originalText> to its trimmed text
and parses each <translation> recursively (translations of a translation
are ignored, C-CDA does not nest them). Never throws.
A @nullFlavor declared beside a populated @code emits
CONTRADICTORY_NULL_FLAVOR: the element says both "this concept is unknown"
and "this concept is X". Only @code counts as the contradicting assertion.
A nullFlavor beside originalText, a <translation>, a displayName or a
bare @codeSystem is the documented C-CDA idiom for "not codable in the
bound value set, here is the source text or an alternate coding", which is
coherent rather than contradictory and stays silent.
Unlike PQ/TS, the code is kept: it is the document's own text
rather than a reading this parser manufactured, and there is no verbatim copy
to fall back on, so withholding it would delete what the document said. See
parsePq for the full argument.
Parameters
el
any
ctx
Returns
CD | undefined
Example
import { parseCd } from "@cosyte/ccda";
const code = parseCd(codeEl, { emit: () => {} });
console.log(code?.code, code?.displayName);