The boundaries of reading, building and editing
Mis-reading a dose, an allergy, a code system or a patient identifier can cause real clinical harm, so this page explains each boundary of the parser, the builder and the editor: where it sits, why, and what a document that reaches it reads back as. Most of them are documented boundaries, not bugs: the lenient parser is built never to silently drop or garble data, and where a boundary applies, the raw value is preserved (often with a warning) and is simply not decoded further. Where a value does still go missing from the model with no warning, this page names the case.
The known limitations page lists the same boundaries in brief, with the tables of what each part covers, and the warning and error codes page gives the meaning of every code named here. Depth tracks the code, and never leads it: where a boundary is genuinely open, this page says so instead of resolving it in your favor.
Reading a document
-
All twelve document types are recognized; fourteen entry families are decoded.
parseCcdaresolves every C-CDA R2.1 US Realm document type from the roottemplateId, and reads a document that carries only the Patient Generated Document header aspatientGeneratedDocument. Problems, Medications, Allergies, Results, Vital Signs, Immunizations, Procedures, Encounters, Social-History smoking status, Plan of Treatment, Functional Status, Mental Status, Family History, and Past Medical History decode to structured entries. Every other section is framed and its narrative retained, but its entries are not modeled, and recognition of those sections has three outcomes. A catalog section matched on itstemplateId(Advance Directives, Medical Equipment, Payers, Instructions, Nutrition, Goals, Interventions, and the rest) gets a stablekeyand no warning. A catalog section matched only by its LOINC code also gets itskey, but raisesSECTION_MATCHED_BY_LOINC_FALLBACK; Reason for Visit and Chief Complaint carry no recognizedtemplateIdat all, so they always take this path. A section the catalog does not recognize (a Procedure Note's Complications Section among them) reads back withkey: undefinedand raisesUNKNOWN_SECTION_CODE, or, if it carries no sectioncodeto match on, silently. None of the three drops anything: the narrative and the raw structure are preserved, and the document still re-serializes faithfully. Five sections the builder writes are the exception to the third outcome: a section carrying the root of Hospital Course (1.3.6.1.4.1.19376.1.5.3.1.3.5), General Status (2.16.840.1.113883.10.20.2.5), Physical Exam (2.16.840.1.113883.10.20.2.10), Review of Systems (1.3.6.1.4.1.19376.1.5.3.1.3.18) or Chief Complaint and Reason for Visit (2.16.840.1.113883.10.20.22.2.13), and matching nothing in the catalog, gets its key (hospitalCourse,generalStatus,physicalExam,reviewOfSystems,chiefComplaintAndReasonForVisit) and no warning. Each is matched by its root only, never by its LOINC code, so a section carrying the code without the root still raisesUNKNOWN_SECTION_CODE. -
An entry another subject governs is withheld, not attributed. CDA R2 makes
Section.subjectthe "primary target of the entries recorded in a section" and C-CDA admits the same override on a clinical statement, so a document can carry a relative's or a donor's statement inside the patient's document. Wherever a<subject>governs a top-level<entry>(its own, one on a statement nested inside it, or one on an enclosing section) that WHOLE entry is withheld from every read path documented as the record target's own data, andSUBJECT_CONTEXT_OVERRIDEis raised once for it, naming the entry's bounded locus. The warning is safety-critical, so no profile can quiet it, and in strict mode it throws like any other. Presence is the trigger: nothing the declaration names is compared with the patient, so a document that redundantly restates the patient as an entry subject loses those entries too, which is the safe direction of that error. Two things are deliberately unaffected: the entry re-serializes byte for byte throughtoString()(the only way to reach it), andgetFamilyHistory()returns what it always did, because a Family History Organizer's own<subject>slot is that template's mechanism for naming the relative rather than a context override. -
Code checks are recognition, not membership, unless you supply an adapter.
checkCodeSlot/checkLoincDeprecationverify that a code's system is the one expected for its slot (and flag deprecated or unexpected systems); on their own they do not verify that a code is a real, active member of SNOMED CT / RxNorm / LOINC. That tier needs a licensed terminology service, so it is bring-your-own: pass aTerminologyAdaptertoparseCcdaorbuildCcdaand it is consulted at the five recognized coded slots (problem,medication,allergen,route,vaccine). A code the adapter rejects is surfaced verbatim and flaggedSEMANTIC_CODE_INVALID, never rewritten to a "corrected" value; an adapter returningundefinedhas no opinion and produces no warning. With no adapter, behavior is recognition-only. A value at one of those slots that asserts a@codewith no@codeSystemis flaggedMISSING_CODE_SYSTEMand is never handed to your adapter (which validates a system + code pair): the parser flags it rather than inferring a system, because a code without its system is not a code. The mirror shape, a slot that is present but asserts no usable@codeand declares no@nullFlavor, is flaggedMISSING_CODE_VALUE. AnullFlavor-only value stays silent (a complete statement of "unknown"), and so does an absent element, there is nothing to judge. Those five slots are the whole of it, so read a silent document carefully. Every other coded value is never handed to your adapter and therefore can never raiseSEMANTIC_CODE_INVALID: the Results and Vital Signs LOINC codes, the procedure, encounter, and family-history codes, the planned-item codes for the five variants whosecodeis the planned act (the other two are exceptions: a planned medication'scodeis the drug and a planned immunization's is the vaccine, so those are checked at themedicationandvaccineslots like any other), the smoking-status, functional-status, and mental-status observation values, the allergy propensity type, and the reaction, severity, and criticality observations. Within the five, the checks apply to the slot's primary coding; alternate codings carried in<translation>are preserved and re-serialized but are not themselves slot-checked. A clean run means the five checked slots passed, not that the document's terminology was verified. -
A
nullFlavorbeside a value is a contradiction, and the parser resolves it against the number.<doseQuantity nullFlavor="UNK" value="10" unit="mg"/>asserts both "unknown" and "10 mg". Every v3 datatype flags thisCONTRADICTORY_NULL_FLAVOR(safety-critical, so no profile can quiet it), including theINTandSTarms of an observation<value>, and onPQ,TS, and anintegerobservation value the derived reading is withheld:dose.valueisundefined, whiledose.raw("10"),dose.unitanddose.nullFlavorare all preserved. If you were reading.valueand now seeundefined, that is the fix, and the document is telling you the value is unknown. OnCD,II,ST,ED, andBLthe field is the document's own text with no verbatim copy behind it, so it is kept and the warning is the signal, readdoc.warnings. Metadata beside anullFlavor(a@unitwith no@value, an@rootwith no@extension, aCD'soriginalText/<translation>) is coherent, not contradictory, and stays silent, and anullFlavor-only coded slot is still checked for a wrong or deprecated@codeSystem. -
getMrn()withholds on anullFlavor-marked<id>. If you were getting an MRN and now getundefined, the firstpatientRole/iddeclared itself unknown. That is the one place this model manufactures an identifier out of anII:pickMrnselects one id from a list and flattens it to a bare string with the marking gone, so the selection declines while the datatype keeps everything. It does not fall through to the next<id>: nothing in a C-CDA rankspatientRole/identries, so the second one is whatever the sender listed second, often a member number, an account number, or the SSN. Readdoc.getPatient()?.identifiersfor the verbatimextensionwith itsnullFlavorbeside it, and branch onrootyourself if you know your assigning authority's OIDs. The other identity slots (documentid,setId,parentDocument/id, entry-level ids) are unchanged and still report the document verbatim;templateIdis the stated exception, a null-marked one still resolves the document type, deliberately, since it asserts a document shape rather than a person. On the emit side,editCcdarefuses to stamp anRPLCrevision from a null-markedClinicalDocument.id(CcdaEditErrorSOURCE_MISSING_ID), because copyingroot/extensioninto theparentDocumentwould drop the marking. -
A medication or vaccine product is read from either
ManufacturedProductarm.manufacturedMaterialis silent;manufacturedLabeledDrugis read too and flaggedMEDICATION_PRODUCT_ARM_UNEXPECTED. That one is tolerable by a profile, and the reason is conditional rather than absolute: wherever it fires alone a<code>element was selected and read exactly as a single-arm document's would have been, and wherever no product identity comes back it is not alone, becauseMEDICATION_PRODUCT_ARM_CONFLICT(the arms disagreed),MISSING_PRODUCT_CODE(no arm carried a<code>at all, which is what a name-onlyLabeledDrugproduces) orMISSING_CODE_VALUE(an element was selected and asserts neither a symbol nor anullFlavor) fires beside it, and all three are safety-critical and unquietable by a profile. The third was missing from this list until0.0.3: it covered the shapes where selection failed, not every shape where identity is absent. So tolerating the presence warning can never buy silence about an absent or withheld drug. No arm yielding a code isMISSING_PRODUCT_CODEand is safety-critical, because dose, route, and timing all survive a missing consumable and would otherwise make the record read as a complete medication with no drug. Both apply at every consumable call site: a performed Medication Activity, an Immunization Activity, a Planned Medication Activity, and a Planned Immunization Activity. A document whose arms name different products drawsMEDICATION_PRODUCT_ARM_CONFLICT(safety-critical) and no product code is selected at all: two drugs on one medication is a contradictory document, nothing in it ranks the arms, and picking one would be the parser inventing an answer. That covers both arms of the choice and a repeated arm of one kind (two siblingmanufacturedMaterials naming different drugs is the same silent pick). Ifmed.drugisundefinedand you see this code, readdoc.toString(), every arm survives serialization byte-for-byte.MISSING_PRODUCT_CODEis suppressed behind it because "no arm yielded a code" would be false, and so are the code-system checks, since there is no code to check, which is why the conflict warning is safety-critical. Arms naming the same product are redundant rather than contradictory, so the material arm is read as before. An arm asserting no symbol at all (anullFlavor-only<code>with no<translation>, or no<code>) names no product and never conflicts with one that does, so whichever arm names the drug is read. -
An arm that asserts no
@codenames what its<translation>alternates name. If you have anullFlavor="OTH"arm whose<translation>carries the real RxNorm code, that arm now names a drug: where it disagrees with the other arm you will getMEDICATION_PRODUCT_ARM_CONFLICTandmed.drug === undefinedwhere you previously got the other arm's code in silence. The translations are a fallback, never an addition, so two arms that both assert a@codeare compared on those and nothing else, exactly as before. That direction is deliberate: a translation the two arms happen to share is routinely coarser than either primary (an RxNorm ingredient, a local formulary id, an NDC spanning presentations), so counting it would let two arms naming two strengths of one drug agree, and one strength would be handed back. Reading translations can only make the warning fire more, never less. Selection is separate and unchanged: the element handed to the code-system and terminology checks is still chosen on the primary@code, and a coding is never lifted out of a<translation>to stand in as the product, because translations are preserved but not slot-checked. Where BOTH arms fall back to translations, sharing one coding is not always enough to agree: that is the one pairing where a shared coarser coding can still hold together two arms naming two products, so they also conflict when each names a coding the other does not and two of those unshared codings are in the same code system under different symbols. An arm that merely offers an extra alternate the other stayed quiet about (an NDC beside the RxNorm concept both share) is elaborating its own concept, not denying the other's, and is not a conflict; codings in different code systems are never compared, because that is terminology work. That last test is a parser's reading rather than something the document asserts, and it deliberately over-fires: two NDC package codes can describe one drug, and an RxNorm branded drug and its clinical equivalent are one product at two granularities, but telling those apart is the terminology work above. Over-firing costs a withheld product beside a loud code; under-firing costs one of two strengths handed back in silence. On the newly-refused shapesmed.drugisundefinedwith the conflict code beside it. If the two fallback arms were the only ones you previously got the first arm'snullFlavorCDand that arm's translations, andmed.drug?.codewasundefinedeither way. If a third arm asserts a primary the two fallback arms disagree behind, you previously got that arm's fully codedCD, so a code you were reading does go away: the document names one product in a primary and two others in translations, and the parser now declines to pick. Readdoc.toString()for every arm verbatim. -
A product named only in a
<translation>now says so (MEDICATION_PRODUCT_CODE_TRANSLATION_ONLY, safety-critical). If no arm asserts a primary@codeand one of them carries the real coding in a<translation>, you get this code andmed.drug?.code === undefined. That is not a change of reading, it is the same reading with the silence removed. Where to find the coding depends on which arm holds it, and the warning's message andpositiontell you. Only one arm ever becomesmed.drug: when that is the arm carrying the translation, searchmed.drug?.translationfor it, beside thenullFlavorthe document wrote; do not just read[0], since a<code>may carry several<translation>s and the first can benullFlavor-marked or in a code system you did not want. When it is not (two arms, neither asserting a primary, the translation on the one that was not selected),med.drugis the other arm'sCDand no product-naming coding is on it, so readdoc.toString(), which re-emits every arm byte-for-byte. No profile may quiet it: on thenullFlavor-marked idiom nothing else fires at all (MISSING_PRODUCT_CODEwould be false, an arm did carry a<code>, and the code-system checks are silent by design on a slot whose only assertion is anullFlavor), and on the variant that asserts neither a symbol nor anullFlavorthe companion isMISSING_CODE_VALUE, which is itself safety-critical, at every consumable call site alike: a performed medication, an immunization, a planned medication's drug, and a planned vaccination's vaccine (see the Plan of Treatment bullet below). BehindMEDICATION_PRODUCT_ARM_CONFLICTit stands down, the same wayMISSING_PRODUCT_CODEdoes. Its precondition is about each arm's LEAD<code>, not the arm: selection reads the first<code>on an arm and no other, so an arm whose second<code>asserts a primary is still a slot with no selected product and still draws this code, withMEDICATION_PRODUCT_CODE_REPEATEDbeside it. The message said "no arm asserts a primary@code" and called the translation the only place the product was named until0.0.3; both were false on precisely that shape. -
A repeated arm is reported even when the repeats agree (
MEDICATION_PRODUCT_ARM_REPEATED).ManufacturedProductmodels a choice of one participant, so twomanufacturedMaterials (or twomanufacturedLabeledDrugs) is outside the model whatever they say. Disagreeing repeats are still refused; agreeing repeats used to be reduced to one silently, so a document asserting the same product three times looked exactly like one asserting it once. It is keyed to the arms rather than to their codings, so an arm with no<code>counts, and it is tolerable by a profile: where it fires alone a<code>was selected and read exactly as any single-arm document's would be, and each state where that would not be enough carries an unquietable companion (MEDICATION_PRODUCT_ARM_CONFLICT,MISSING_PRODUCT_CODE,MEDICATION_PRODUCT_CODE_TRANSLATION_ONLY, orMISSING_CODE_VALUEwhere the selected<code>asserts neither a symbol nor anullFlavor, which is exactly what two empty-<code/>material arms produce). That fourth one was missing from this list until0.0.3. -
A repeated
<code>on ONE arm is reported too, and its second<code>is no longer dropped from the comparison (MEDICATION_PRODUCT_CODE_REPEATED, safety-critical).Material.codeandLabeledDrug.codeare each at most one in CDA R2, and only the first was ever read, so an arm writing an RxNorm code for Lisinopril and a second one for Aspirin handed back Lisinopril and said nothing at all. Every<code>on every arm now reaches the comparison, so that document raisesMEDICATION_PRODUCT_ARM_CONFLICTandmed.drugisundefined. This code is reported per arm, and itspositionnames which arm carries the repeat, so two offending arms give you two warnings at two places rather than one that points at only one of them. What you read does not change: selection still takes each arm's first<code>and nothing else, deliberately, because a newly-visible sibling sits earlier in document order and would displace an equally-symboled but richer coding, takingCODE_NARRATIVE_MISMATCH,MISSING_CODE_VALUE, or a<translation>list with it in exchange for a symbol that was already identical. No profile can quiet this one, and that is why: on the shape where the arm's first<code>asserts anullFlavorand its sibling names the drug,med.drug?.codeisundefinedover a document that names the drug one element along, nothing else fires, and this is the only signal. Readdoc.toString()for the sibling verbatim. On a benign identical repeat it costs you a warning over a document that lost nothing; that over-fire is the price of not letting what the codings say decide whether the cardinality gets named at all. -
A Planned Medication Activity's
codeis the drug, not thesubstanceAdministration's own<code>. If you readgetPlannedItems()and amedicationActivityentry came back with a code that is not a drug (a SNOMED CT "Administration of drug or medicament", say) you were on0.0.2or earlier: the direct<code>was preferred whenever it was present, and only a planned medication without one ever read itsconsumable. CDA R2 makesSubstanceAdministration.codeanActSubstanceAdministrationCode, the kind of administration act, while the substance participates throughconsumable/manufacturedProduct, so that code was never a drug and reading it into the drug slot short-circuited the entire product path. Every product warning on this page was unreachable on that variant,MEDICATION_PRODUCT_ARM_CONFLICTabove all, so a planned medication whose twomanufacturedProductarms named two different drugs was reported with no warning of any kind, on the section that says what a patient is about to be given.CODE_NARRATIVE_MISMATCHwas reachable but useless there, comparing an act type's label against a narrative that names a drug, so it fired on well-formed documents and stayed quiet about the structured drug contradicting the narrative. All of that is fixed in0.0.3. The act<code>is not on the model for this variant, as it is not for a performed Medication Activity or an Immunization Activity; readdoc.toString()if you need it. The code-system and terminology checks reach it too, as of0.0.3. Because thatcodeis the drug, it is checked against themedicationbinding exactly as a performed Medication Activity'sdrugis, soMISSING_CODE_VALUE,MISSING_CODE_SYSTEM,UNEXPECTED_CODE_SYSTEM, and (with aTerminologyAdapter)SEMANTIC_CODE_INVALIDfire on a planned drug, code for code with its performed twin. On0.0.2and earlier none of them could: a planned drug asserting a@codewith no@codeSystem, an empty<code/>, or an OID outside RxNorm/NDC came back read and unremarked.DEPRECATED_CODE_SYSTEMis the one that does not apply, and it does not apply to a performed drug either: themedicationbinding declares no deprecated systems, so an ICD-9-CM OID on a drug isUNEXPECTED_CODE_SYSTEMin both places. What that changed for the tolerable product codes.MEDICATION_PRODUCT_ARM_UNEXPECTEDandMEDICATION_PRODUCT_ARM_REPEATEDare profile-tolerable, and their tolerability rests on an unquietable companion firing wherever no<code>was selected and read normally. On the empty-<code>shape that companion isMISSING_CODE_VALUE, which could not fire here, so on0.0.2a planned medication whose single arm was<manufacturedLabeledDrug><code/></manufacturedLabeledDrug>had no drug identity at all and drewMEDICATION_PRODUCT_ARM_UNEXPECTEDalone, and two empty-<code/>material arms drewMEDICATION_PRODUCT_ARM_REPEATEDalone. Apply a vendor profile, filter the expected noise as this documentation elsewhere suggests, and that document reached you silent. Both shapes now carryMISSING_CODE_VALUE, which no profile can quiet. The other five planned kinds are still not slot-checked. That is a choice, and it used to be stated as a necessity ("binding them would mean inventing a value set"), which is true only of the system checks:MISSING_CODE_VALUEandMISSING_CODE_SYSTEMare raised before any binding is read, so they could be raised on an act-coded planned<code>without citing a value set. They are not, deliberately, and changing that would be its own decision. So do not treat a quietgetPlannedItems()as a checked one: testitem.code?.code, notitem.code. -
A Planned Immunization Activity used to vanish entirely, and that was the sharpest form of this family. On
0.0.2and earlier a Plan of Treatment entry carrying the Planned Immunization Activity template (…22.4.120) matched nothing:getPlannedItems()returned no item for it at all and raised no warning, so reading that list to answer "what is this patient scheduled to receive" gave you a clean, warning-free answer with a scheduled vaccination missing from it. There was noundefinedto test for and no code to filter on, and the document round-tripped byte-for-byte throughserializeCcda, so nothing looked wrong. As of0.0.3it comes back askind: "immunizationActivity", and, exactly like a planned medication, itscodeis the product from theconsumablerather than thesubstanceAdministration's own<code>, so every product warning on this page applies to it. It is slot-checked against thevaccinebinding, which is CVX only: an NDC-coded planned vaccine drawsUNEXPECTED_CODE_SYSTEMwhere an NDC-coded planned drug does not, because each variant matches its own performed twin rather than the other variant. If you kept a workaround that read these entries out ofdoc.toString(), you can drop it. WhatgetPlannedItems()returns is still not everything a Plan of Treatment section can hold: the section admits eleven entry templates and this returns seven. The four it does not return are Instruction (…22.4.20), Handoff Communication Participants (…22.4.141), Nutrition Recommendation (…22.4.130) and Goal Observation (…22.4.121); a Goal Observation ismoodCode="GOL", which this parser calls neither performed nor planned. Their narrative and structure are preserved and they re-serialize faithfully, and they are still not planned items. Three of the four are no longer silent: Instruction, Handoff Communication Participants, and Nutrition Recommendation each drawPLAN_ENTRY_NOT_MODELEDwhere planned items are read, once per matching root, so a consumer has a code to filter on instead of an entry that vanishes in the places the report covers. Reporting is not modeling: nothing about the returned list changed. A direct entry is reported in two sections, Plan of Treatment and the Interventions Section (V3) (…21.2.3, which admits a Handoff as a direct entry in as many words, CONF:1198-32402 / 1198-32403). That citation is V3's, while the matching is this library's usual section recognition and so is wider: templateId root first, LOINC62387-6as the fallback, no@extensioncheck. An Instruction in the Instructions Section (…22.2.45), where it is that section's own required entry, still draws nothing. The nested half is reported wherever the Planned Intervention Act sits. That scope is a bound this library chose, not a catalog of which sections C-CDA admits these templates in: they appear in more places than it covers, and an occurrence outside it is still dropped in silence. Two such places are measured and pinned: a Handoff nested in an Intervention Act (…22.4.131) is silent because that act is not a container this library descends into, and a direct entry of a section this catalog recognizes as nothing is silent because there is no key to match. A Goal Observation is reported too, with the same code and its own wording, wherever it is a section's direct entry (a Goals section, a Plan of Treatment section, or any other). It is still not modeled: no accessor returns it. -
A planned entry nested in a Planned Intervention Act was dropped in silence, for all seven kinds (fixed in
0.0.3).getPlannedItems()used to read an<entry>'s own act and go no deeper, so a planned flu shot or drug order hanging off a Planned Intervention Act (…22.4.146, the act that groups the interventions planned toward a goal) came back as no item and no warning, round-tripping byte-for-byte. That was the same silence as the missing Planned Immunization Activity, one markup layer in and across all seven templates. Those entries are now returned, and they read exactly as the same act reads as a direct<entry>: samekind, samecode, same slot check, same product warnings. If you kept a workaround that read intervention components out ofdoc.toString(), you can drop it. Three bounds still apply. A pointer is never followed: the container'stypeCode="RSON"relationship holds an Entry Reference (…22.4.122) naming a goal recorded elsewhere, and that is stepped over rather than resolved. It is the only container descended into, and C-CDA has others, so nesting is not solved in general. A Nutrition Recommendation (…22.4.130) inline-holds six of the seven planned templates, and an Intervention Act (…22.4.131) inline-holds a Planned Intervention Act; a planned entry in either still comes back as nothing, exactly as it did before. What changed is only that the Nutrition Recommendation container now drawsPLAN_ENTRY_NOT_MODELED(it is one of the three named above); what it holds is still not reached, and the Intervention Act is still silent end to end. Readdoc.toString()if your senders nest that way. A returned item does not say whether it was direct or nested, either: the intervention itself is not modeled, so the grouping toward the goal is available only fromdoc.toString(). -
UCUM validation is grammatical, on a curated atom subset. The validator checks well-formed UCUM against the prefixes/atoms that appear in lab Results and Vital Signs, not the full UCUM registry. A valid-but-uncurated atom may read as
NON_UCUM_UNIT; the raw unit is always preserved. It does not convert or dimension-check units. -
nonXMLBodybase64 is left inert. An Unstructured Document's wrapped payload is exposed but never decoded: decoding an arbitrary embedded blob is a needless attack surface and a PHI decision the caller owns. -
One attribute under two prefixes of one namespace is refused, not halved. Namespaces in XML 1.0 (section 6.3) makes an element not well formed when two of its attributes share a local name and their prefixes are bound to the same namespace:
xsi:type="CD"besidet:type="PQ"withtalso bound to the XML Schema instance namespace, declared on the element or above it. The DOM library under the parser keeps the later of the two and drops the earlier with no error, so up to this release such a document was read with one value missing and nothing said.parseCcdaandparseSecureXmlnow throwNOT_WELL_FORMED_XMLfor it, like any other text that is not XML. One local name in two different namespaces, or an unprefixed attribute beside a prefixed one, is allowed and read as before. -
Line endings are read as XML 1.0 reads them. A carriage return followed by a line feed, and a carriage return on its own, each become one line feed (section 2.11). Nothing else is rewritten: NEL (U+0085), LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR (U+2029) are line breaks only in XML 1.1, so in text, attribute values, comments, CDATA sections and processing instructions they are kept as they were written. Up to this release the parser turned each of them into a line feed (and, in an attribute value, a space) without a warning. XML 1.0 does not read them as white space, so one between the parts of a tag, in an end tag, in a processing instruction's target or the XML declaration, or outside the root element makes the text not well formed:
parseCcdaandparseSecureXmlthrowNOT_WELL_FORMED_XMLfor it, as libxml2 does. -
Markup holds only XML 1.0's white space and name characters. The same refusal covers every character outside ASCII that XML 1.0 allows in a document but neither as white space (production [3]: space, tab, line feed, carriage return) nor in a name (production [4a]): U+0080 to U+00BF but the middle dot U+00B7, U+00D7, U+00F7, U+037E, U+2000 to U+200B, U+200E to U+203E, U+2041 to U+206F, U+2190 to U+2BFF, U+2FF0 to U+3000, U+E000 to U+F8FF, U+FDD0 to U+FDEF and U+F0000 to U+10FFFF. The list is derived from those productions and checked against them at every code point. Among them are the no-break space (U+00A0), the other Unicode spaces and the private use characters. Text, attribute values, comments, CDATA sections and processing instruction data keep them as they were written. Up to this release the DOM library under the parser read U+0080 inside a tag as white space, and read a tag holding most of the others as plain text,
<and all, so an element could gain a wrong attribute split or turn into narrative text without a warning. -
Vendor profiles only quiet benign noise.
parseCcda(xml, { profile })(or a process default viasetDefaultCcdaProfile) applies aCcdaProfilethat downgrades the non-safety-critical deviations it expects toPROFILE_QUIRK_APPLIED(flaggedexpected, carrying the originaltoleratedCode). It never drops a warning and never touches an extracted value. A profile cannot tolerate a safety-critical warning (dose, unit, allergen, identity, wrong or missing code system, malformed datetime, …);defineCcdaProfile()throws if you try. Built-ins:ccdaProfiles.smartScorecard(deprecated terminology) andccdaProfiles.legacyR11(R1.1-origin structural tolerance), each with cited provenance, plusccdaProfiles.default, which tolerates nothing and is identical to passing no profile at all. There is no named per-vendor profile: one is added only when a real, de-identified document from that vendor grounds the quirk, never from an invented one. -
The required-section (SHALL) table is conservative, and every type reports how far it was verified. It asserts only unconditional, in-catalog, high-confidence SHALL constraints; it omits choice constraints (
SHALL contain A OR B), SHOULD/MAY sections, SHALL sections outside the recognized catalog, and four SHALL sections it recognizes by root but does not assert (Hospital Course, General Status, Physical Exam, Review of Systems, reasonassertion-would-tighten-parse).requiredSectionStatus(documentType)returns the asserted keys with averificationstate, so an empty set is never ambiguous:traced-completefor CCD and Care Plan: every SHALL section the source names for those two is in this parser's catalog and is asserted, sostatus.unassertedis empty because there is nothing left over. The Patient Generated Document header reports it too: its source names no section at all.traced-partialfor the other nine structured types. Their SHALL sections were read off the normative C-CDA R2.1 source, and one or more of them cannot be asserted. Consultation Note asserts History of Present Illness (CONF:1198-28907), Allergies (-28911), and Problems (-28929), each scoped to the R2.1 stamp its constraint carries. Progress Note, Procedure Note, Operative Note, and Diagnostic Imaging Report assert nothing, and that is a traced result rather than an unread table: every SHALL section their templates name is either outside this parser's recognized catalog (Complications, Procedure Description, Anesthesia, Findings (DIR) and the rest) or a choice. Each one is listed by name instatus.unassertedwith the reason.not-applicablefor Unstructured Document: its component SHALL be anonXMLBody(CONF:1198-31086), so it carries no section to require and none can be missing.untracedis reported by no recognized type. It stays in the vocabulary as the honest state for a type whose obligation has not been read.
Every status also names the artifact its obligation was read from and that artifact's own revision date (
status.source), so a reader holding a later revision can tell the table is stale without re-deriving it.This under-warns rather than over-warns: a document of a
traced-partialtype that is missing a section its type requires can still parse clean, with noREQUIRED_SECTION_MISSING. Read an empty asserted set through its state, never as "this type has no requirements," and do not treat a quiet parse as a conformance result.import {requiredSectionKeys,requiredSectionStatus,requiredSectionStatuses,DOCUMENT_TYPES,} from "@cosyte/ccda";DOCUMENT_TYPES.length; // => 13requiredSectionStatuses().length; // => 13requiredSectionStatuses().filter((s) => s.verification === "untraced").length; // => 0const consult = requiredSectionStatus("consultationNote");consult.verification; // => "traced-partial"consult.keys.join(","); // => "historyOfPresentIllness,allergies,problems"consult.traced[0]?.conformanceId; // => "CONF:1198-28907"consult.unasserted[0]?.reason; // => "not-unconditionally-required"// An empty asserted set, two different readings, two different values.requiredSectionStatus("operativeNote").keys.length; // => 0requiredSectionStatus("operativeNote").verification; // => "traced-partial"requiredSectionStatus("operativeNote").unasserted[0]?.reason; // => "outside-section-catalog"requiredSectionStatus("unstructuredDocument").verification; // => "not-applicable"requiredSectionStatus("ccd").verification; // => "traced-complete"// A Discharge Summary requires a Plan of Treatment section and does NOT require// a Discharge Medications section: the source states that one as a SHOULD.requiredSectionKeys("dischargeSummary").includes("planOfTreatment"); // => truerequiredSectionKeys("dischargeSummary").includes("dischargeMedications"); // => falserequiredSectionStatus("dischargeSummary").source?.revision; // => "2025-09-08"// Hospital Course is recognized when present but not asserted, and says why.requiredSectionKeys("dischargeSummary").includes("hospitalCourse"); // => falserequiredSectionStatus("dischargeSummary").unasserted[0]?.reason; // => "assertion-would-tighten-parse"
Building a document
buildCcdaemits six of the twelve document types. A CCD (the default), a Referral Note (documentType: "referralNote"), an inpatient Discharge Summary (documentType: "dischargeSummary"), a Progress Note ("progressNote"), a History and Physical ("historyAndPhysical") and a Consultation Note ("consultationNote"). Any other value throws aTypeErrorrather than emitting something that merely resembles the type you asked for. The other six types (Procedure Note, Operative Note, Care Plan, Diagnostic Imaging Report, Unstructured Document, Transfer Summary) are not implemented. Only an omitted (undefined)documentTypemeans a CCD:null, and any value that is not a string, is refused.- A clean build of any of the six types reparses with zero warnings. A Discharge Summary's
SHALL set includes the Hospital Course Section (
1.3.6.1.4.1.19376.1.5.3.1.3.5, LOINC8648-8), an IHE PCC template the parser recognizes by its root, sofindSection("hospitalCourse")resolves. The parser does not assert it as required, though: a reparse of a Discharge Summary that lacks it does not report it missing. The conformance run in our repository (pnpm conformance) is the check on its presence. The same holds for the History and Physical's General Status (2.16.840.1.113883.10.20.2.5), Physical Exam (2.16.840.1.113883.10.20.2.10) and Review of Systems (1.3.6.1.4.1.19376.1.5.3.1.3.18) sections, and for the Chief Complaint and Reason for Visit section (2.16.840.1.113883.10.20.22.2.13) the builder writes for its chief-complaint choice: each is recognized by its root (findSection("physicalExam")resolves), and none is asserted. A third-party document carrying one of these four sections no longer drawsUNKNOWN_SECTION_CODEfor it. - Content you supply is emitted or refused, never dropped. A Discharge Summary emits the
problemsandmedicationsyou hand it, the medications in the Medications Section (it never emits the Discharge Medications Section, which would assert they are discharge medications).hospitalCourseanddischargeDiagnosesthrow aTypeErroron every type but a Discharge Summary,encompassingEncounterthrows on a CCD or a Referral Note,assessmentthrows on a Discharge Summary,reasonForReferralthrows on a Discharge Summary, a Progress Note or a History and Physical, and the five office-visit narratives (historyOfPresentIllness,chiefComplaintAndReasonForVisit,reviewOfSystems,physicalExam,generalStatus) throw on a CCD, a Referral Note or a Discharge Summary. A CCD still ignoresassessmentandreasonForReferral, as it always has. - A Discharge Summary's encounter frame is never guessed.
componentOf/encompassingEncounteris always emitted for that type, because its template requires it, and each slot the caller did not supply throughencompassingEncounter(either period bound, the discharge disposition) is emittednullFlavor="UNK"and reparses as absent. None of the three is ever derived from the documenteffectiveTimeor from adocumentationOfservice event. - The office-visit types carry the header slots their rules require, and nothing is guessed.
A Progress Note, a History and Physical and a Consultation Note each carry the
componentOf/encompassingEncounterframe their templates require, with an encounteridand aneffectiveTimewhoselowis the period start you supply ornullFlavor="UNK". Their rules do not require ahighor a discharge disposition, so each is written only when you supply it. A Progress Note's encounter also carries thelocation/healthCareFacilityits rule requires (CONF:1198-30879), and a Consultation Note carries theinFulfillmentOf/orderits rule requires (CONF:1198-8382); both of those ids arenullFlavor="UNK", because the builder takes no facility or order input and an invented identifier would name a place or a request that does not exist. None of the three emitsdocumentationOf, which their rules do not require. - Which sections a build can carry. For a CCD, its six SHALL sections are always emitted, as
spec-clean empty
nullFlavor="NI"sections when you supply no content: Problems, Allergies, Medications, Results, Vital Signs, and Social History (smoking status). Immunizations, Procedures, Encounters, Functional Status, Mental Status, Past Medical History, Plan of Treatment, and Family History are emitted only when populated, so an empty one is never fabricated. A Referral Note instead always emits Problems, Allergies, Medications, Reason for Referral, Assessment, and Plan of Treatment, and demotes Results, Vital Signs, and Social History to populated-only. A Discharge Summary always emits Allergies, Hospital Course, Discharge Diagnosis, and Plan of Treatment, and forces nothing else: neither Problems nor Medications is in its SHALL set, so both are populated-only there. A Progress Note always emits Assessment and Plan of Treatment, its one section obligation being that choice (CONF:1198-30657). A History and Physical always emits its ten SHALL sections (Allergies, Family History, General Status, Past Medical History, Medications, Physical Exam, Results, Review of Systems, Social History, Vital Signs) plus Chief Complaint and Reason for Visit, Assessment, and Plan of Treatment for its two choices. A Consultation Note always emits History of Present Illness, Allergies, Problems, Reason for Referral, Assessment, and Plan of Treatment. Each narrative it requires and you leave out is an emptynullFlavor="NI"section, and a Progress Note or Consultation Note emits a narrative it does not require only when you supply it. Each type meets an Assessment/Plan choice with the separate Assessment and Plan of Treatment sections; the combined Assessment and Plan Section cannot be built. Any C-CDA section outside these sets cannot be built. - Every coded value that reaches the narrative needs a
displayName, and a missing one is refused. Each populated section regenerates its<text>narrative from the sameBuildCode.displayNamethe coded entry carries, and links the two with a<reference>, so the narrative is the attested restatement a clinician reads.displayNameis a required field, but the package ships JavaScript and validates at runtime, sobuildCcda(andeditCcda, which writes through the same emitter) throws aTypeErrornaming the field path when the label is absent, empty, or not a string, and the same when the code itself is missing ornull. An optional coded value with a fallback (a smoking status, a functional or mental finding, a family relationship or condition) set tonullreads as absent, the same as leaving it out. It does not substitute a placeholder: any confident stand-in is a sentence the entry does not support. Until0.0.11inclusive the allergy slot substituted "No known allergies", so an allergy asserted positively could carry a narrative byte-identical to the negated no-known-allergies form, and seven other slots wrote the literal stringundefined. ABuildCodethat reaches only the entry (an allergytype, a resultinterpretation, a medicationroute) is not covered:@displayNameis optional on a v3CD, so omitting the attribute states nothing false. - Every entry carries the
effectiveTimeits template requires. The caller's time when supplied, elsenullFlavor="UNK": the SHALL cardinality is satisfied without a fabricated clinical timestamp, and the parser reads that back as absent, never as a realDate. <translation>alternates are emitted only at the recognized coded slots. If your adapter implements the optionaltranslate,buildCcdaemits each returned coding as a spec-clean CDA R2<translation>beside the primary code, never replacing it. The wired slots are the problem value, the allergen, the medication drug and route, and the vaccine and route. The Results and Vital Signs LOINC codes, the reaction/severity/criticality observations, and the procedure, encounter, planned-item, and family-history codes are not wired. An adapter withouttranslate, or one returning no matches, leaves the output byte-identical: an unmapped code never produces a guessed alternate.- A built document is validated against the normative artifacts, and the result is published.
The conformance run in our repository (
pnpm conformance) fetches the C-CDA R2.1 Schematron, its vocabulary file, and the CDA R2 XML schema from pinned immutable references, validates every documentbuildCcdaemits against the schema and then the Schematron's error-severity phase, and writesdocumentation/conformance-report.md. The measured set is one document per optional section as well as a minimal and a populated document per document type, so a green run is not a green run over a subset of what the builder can emit. The current result is zero error-severity results. What that does and does not tell you, stated here rather than left to be assumed. It covers the six document types the builder emits and says nothing about the other six, which it does not emit. It covers the error-severity phase; the warning phase is not run. It checks value-set membership only where the Schematron's own vocabulary file checks it, so it is not a terminology verification. It is an assessment against a published artifact, not a certification, and no accredited body has reviewed it. If your pipeline requires a validation of record, run your own validator over the output. - A Functional Status Organizer you asked for is missing, and the document says why. Its R2.1
template SHALL contain a Self-Care Activities (ADL and IADL) observation as well as a Functional
Status Observation. Supply
selfCareActivitieson the organizer and it is written with its categorization code andeffectiveTime; supply none and the findings are written as standalone Functional Status Observations (all present, all read back unchanged) and the returned document carriesMISSING_SELF_CARE_ACTIVITY. The builder writes neither a fabricated activity nor an organizer claiming a template it does not satisfy. serializeCcda/toString()need a parsed or built document.buildCcdareturns the parse of the XML it just emitted, so a built document serializes. A hand-constructedCcdaDocumentretains no source XML and throws.
Editing a document
editCcdaadds or replaces a whole section, across twelve section kinds.problems,allergies,medications,results,vitalSigns,immunizations,procedures,encounters,socialHistory,pastMedicalHistory,planOfTreatment, andfamilyHistory. Functional Status and Mental Status are buildable but not editable: each is assembled from three separate content lists, which the single-list edit shape does not fit. The Referral Note's narrative-only Assessment and Reason for Referral sections are likewise not editable.- No entry-level append, and no section removal. Adding one problem to an existing Problems
section means a
replacecarrying the full entry set, which rebuilds that section from your typed input: anything in the original section you do not carry over, including detail this library does not model, is absent from the result. Every section you did not target is still carried through byte-for-byte. A true append that byte-preserves a section's other entries needs a lossless read-model that does not exist yet, and there is no way to remove a section at all. RPLConly. An edit stamps a CDA R2 replacement revision (relatedDocument typeCode="RPLC"plussetId/versionNumber), or no revision at all withrevision: false. TheAPND(append) andXFRM(transform) document relationships are not emitted.- An edit needs a parsed source, and a section edit needs a
structuredBody. A hand-constructed document throwsCcdaEditError(NO_SOURCE_DOCUMENT), and so does any value that is not aCcdaDocument, such as a plain object or the XML text itself. A document with nostructuredBody, such as an Unstructured Document, throwsNO_STRUCTURED_BODYonly when you actually pass a section edit: with nosections,editCcdajust stamps the revision and returns, so a revision-only edit of an Unstructured Document succeeds. A revision of a source carrying noClinicalDocument.idthrowsSOURCE_MISSING_IDrather than inventing the id theRPLClink has to name, and an edit that would drop a SHALL required section throwsREQUIRED_SECTION_MISSINGinstead of emitting a non-conformant document. - On this path the terminology adapter validates but does not translate.
editCcdaforwards a supplied adapter to its final re-parse, so a rejected code in the edited document is still flaggedSEMANTIC_CODE_INVALID. It does not emit<translation>alternates into the section it rebuilds; onlybuildCcdadoes that.
Related
- Known limitations, the same boundaries as a list and tables.
- Warning and error codes, every code this page names.
- Check required sections, which applies the required-section status described above.
- Apply a vendor profile, which applies what a profile may and may not tolerate.
- Check codes with your terminology, which applies the five coded slots.