src/ccda
@cosyte/synth/ccda: the C-CDA generation surface, exposed as its own subpath so importing the
package root does not pull @cosyte/ccda. This is the lazy, per-format boundary: a consumer
who only needs C-CDA fixtures imports @cosyte/synth/ccda; one who needs only the core primitives
never loads a parser.
@cosyte/ccda is an optional peer dependency, present only for this subpath.
This subpath ships spec-clean C-CDA document generation via @cosyte/ccda's
buildCcda: a CCD (generateCcd) and a Referral Note (generateReferralNote), each built
through the parser's own emitter so it round-trips through parseCcda with zero warnings, and each
drawing every identity value from the synthetic-safety providers.
Interfaces
CcdaCorpusOptions
Options for ccdaCorpus.
Properties
count?
readonlyoptionalcount?:number
How many documents to generate. Defaults to 1.
mix?
readonlyoptionalmix?: readonlyCcdaDocumentType[]
The document types to cycle through. Defaults to one CCD + one Referral Note.
seed
readonlyseed:number
The seed for the whole corpus (deterministic).
CcdaPatientIdentity
A synthetic C-CDA patient identity: the values threaded into a document's recordTarget.
Properties
mrn
readonlymrn:SyntheticIdentifier
The medical-record identifier, scoped to the synthetic assigning authority.
patient
readonlypatient:BuildCcdaPatient
The BuildCcdaPatient @cosyte/ccda consumes for the single recordTarget.
person
readonlyperson:SyntheticName
The name from the shipped fake-name pool (also used to compose synthetic narrative/email).
CcdaQuirkCorpusOptions
Options for ccdaQuirkCorpus.
Properties
count?
readonlyoptionalcount?:number
How many quirk artifacts to generate. Defaults to the number of quirks.
documentType?
readonlyoptionaldocumentType?:CcdaDocumentType
The base document type each quirk is injected into. Defaults to "ccd".
profile?
readonlyoptionalprofile?:SynthProfile
A SynthProfile whose quirks drive the corpus (validated). Takes precedence over quirks.
quirks?
readonlyoptionalquirks?: readonlyCcdaQuirkName[]
The quirk names to cycle through. Defaults to every C-CDA quirk. Validated; unsupported ⇒ fatal.
seed
readonlyseed:number
The seed for the whole corpus (deterministic).
GenerateCcdaOptions
Options common to every C-CDA generator.
Properties
documentType?
readonlyoptionaldocumentType?:CcdaDocumentType
The document type to emit. Defaults to "ccd".
seed?
readonlyoptionalseed?:number
The seed (deterministic: same seed yields a byte-identical document). Defaults to 0.
GenerateCcdaQuirkOptions
Options for generateCcdaQuirk.
Properties
documentType?
readonlyoptionaldocumentType?:CcdaDocumentType
The spec-clean base document type. Defaults to "ccd".
quirk
readonlyquirk:CcdaQuirkName
The quirk to inject. Required.
seed?
readonlyoptionalseed?:number
The seed: the same seed + quirk yields a byte-identical document. Defaults to 0.
RoundTripResult
The verdict of one round-trip through @cosyte/ccda.
Properties
byteStable
readonlybyteStable:boolean
Whether re-serializing the re-parsed document is byte-identical to content.
content
readonlycontent:string
The serialized C-CDA XML (the builder/serializer's own conservative emit).
specClean
readonlyspecClean:boolean
true iff the artifact is spec-clean: zero warnings and byte-stable.
warnings
readonlywarnings: readonlystring[]
The warning codes the parser emitted on re-parse. Empty ⇒ spec-clean.
Type Aliases
CcdaCorpusKind
CcdaCorpusKind =
CcdaDocumentType
Every C-CDA document kind ccdaCorpus generates: the documentType used as the corpus kind.
CcdaDocumentType
CcdaDocumentType =
"ccd"|"referralNote"
The C-CDA document type a generator emits: the two buildCcda supports.
CcdaQuirkName
CcdaQuirkName =
"template-extension-absent"|"deprecated-loinc"|"deprecated-code-system"
Every C-CDA quirk this package ships.
Variables
ALLERGENS
constALLERGENS: readonlyCodeConcept[] =EXAMPLE_ALLERGENS
RxNorm / SNOMED CT allergen example codes (Allergies).
ALLERGY_REACTIONS
constALLERGY_REACTIONS: readonlyCodeConcept[] =EXAMPLE_ALLERGY_MANIFESTATIONS
SNOMED CT allergy-reaction manifestation example codes.
CCDA_QUIRKS
constCCDA_QUIRKS:Readonly<Record<CcdaQuirkName,QuirkDescriptor>>
The C-CDA quirk registry: each recipe bound to the exact @cosyte/ccda warning code it targets.
ccdaQuirkProfile
constccdaQuirkProfile:SynthProfile
A ready-made SynthProfile requesting every built-in C-CDA quirk.
LAB_RESULTS
constLAB_RESULTS: readonlyQuantConcept[] =EXAMPLE_LAB_OBSERVATIONS
LOINC laboratory-result example codes with UCUM units + value bands (Results members).
MEDICATIONS
constMEDICATIONS: readonlyCodeConcept[] =EXAMPLE_MEDICATIONS
RxNorm medication example codes (Medications).
PROBLEMS
constPROBLEMS: readonlyCodeConcept[] =EXAMPLE_CONDITIONS
SNOMED CT problem/condition example codes (Problems / Past Medical History).
PROCEDURES
constPROCEDURES: readonlyCodeConcept[] =EXAMPLE_PROCEDURES
SNOMED CT procedure example codes (Procedures).
RESULT_PANELS
constRESULT_PANELS: readonlyCodeConcept[] =EXAMPLE_DIAGNOSTIC_REPORTS
LOINC panel example codes (the Result Organizer code).
ROUTES
constROUTES: readonlyBuildCode[]
NCI Thesaurus administration-route example codes (Medications / Immunizations route). Public NCI
concept ids used as structural fillers.
SMOKING_STATUSES
constSMOKING_STATUSES: readonlyBuildCode[]
SNOMED CT Current Smoking Status value-set example codes (Social History). Public SNOMED CT
identifiers used as structural fillers; @cosyte/synth bundles no SNOMED content.
VACCINES
constVACCINES: readonlyCodeConcept[] =EXAMPLE_VACCINES
CVX vaccine example codes (Immunizations).
VITAL_SIGNS
constVITAL_SIGNS: readonlyQuantConcept[] =EXAMPLE_VITAL_SIGNS
LOINC vital-sign example codes with UCUM units + value bands (Vital Signs members).
Functions
ccdaCorpus()
ccdaCorpus(
options):Corpus
Build a reproducible Corpus of spec-clean C-CDA documents. Each document is generated from a
distinct sub-seed derived from the corpus seed (so the set is deterministic) and round-tripped through
@cosyte/ccda; the per-artifact warnings record the parser's verdict (empty ⇒ spec-clean).
Parameters
options
Seed, count, and the document mix. See CcdaCorpusOptions.
Returns
A deep-frozen Corpus.
Example
import { ccdaCorpus } from "@cosyte/synth/ccda";
const corpus = ccdaCorpus({ seed: 42, count: 4 });
corpus.artifacts.every((a) => a.warnings.length === 0); // true, spec-clean
ccdaPatientIdentity()
ccdaPatientIdentity(
rng):CcdaPatientIdentity
Mint a complete synthetic CcdaPatientIdentity. Every value comes from a synthetic-safety
provider, no code path here can return a real identifier. The MRN is scoped to the
synthetic assigning-authority OID (mrnRoot), so it is non-colliding by namespace, not by value.
Parameters
rng
The seeded generator.
Returns
A synthetic CcdaPatientIdentity.
Example
import { createRng } from "@cosyte/synth";
import { ccdaPatientIdentity } from "@cosyte/synth/ccda";
// const { patient } = ccdaPatientIdentity(createRng(1));
ccdaQuirkCorpus()
ccdaQuirkCorpus(
options):Corpus
Build a reproducible Corpus of C-CDA quirk artifacts. Each artifact's warnings record the
intended code for its quirk; the manifest lists the applied quirk names.
Parameters
options
Seed, count, and the quirk selection. See CcdaQuirkCorpusOptions.
Returns
A deep-frozen Corpus.
Example
import { ccdaQuirkCorpus } from "@cosyte/synth/ccda";
ccdaQuirkCorpus({ seed: 42 }).manifest.quirks; // the applied quirk names
ccdaQuirkRoundTrip()
ccdaQuirkRoundTrip(
artifact):QuirkRoundTripResult
Round-trip a C-CDA quirk artifact through @cosyte/ccda and report the intended-warning verdict: a bare
parse must produce exactly the intended code, and the matching public profile
must re-badge it to PROFILE_QUIRK_APPLIED.
Parameters
artifact
The quirk artifact (from generateCcdaQuirk).
Returns
The QuirkRoundTripResult.
Example
import { generateCcdaQuirk, ccdaQuirkRoundTrip } from "@cosyte/synth/ccda";
ccdaQuirkRoundTrip(generateCcdaQuirk({ seed: 1, quirk: "deprecated-loinc" })).intendedWarningHeld;
generateCcd()
generateCcd(
options?):CcdaDocument
Generate a spec-clean synthetic Continuity of Care Document (CCD).
Parameters
options?
Omit<GenerateCcdaOptions, "documentType"> = {}
Seed (deterministic). See GenerateCcdaOptions.
Returns
CcdaDocument
The CcdaDocument.
Example
import { generateCcd, roundTrip } from "@cosyte/synth/ccda";
roundTrip(generateCcd({ seed: 1 })).specClean; // true
generateCcda()
generateCcda(
options?):CcdaDocument
Generate a spec-clean synthetic C-CDA document (CCD by default, or Referral Note), built through
@cosyte/ccda's buildCcda. The returned CcdaDocument round-trips through parseCcda with
zero warnings, and the same seed yields a byte-identical document.
Parameters
options?
GenerateCcdaOptions = {}
Seed and document type. See GenerateCcdaOptions.
Returns
CcdaDocument
The @cosyte/ccda CcdaDocument (serialize via serializeCcda(doc) or doc.toString()).
Example
import { generateCcda } from "@cosyte/synth/ccda";
import { serializeCcda } from "@cosyte/ccda";
const xml = serializeCcda(generateCcda({ seed: 42 }));
generateCcdaQuirk()
generateCcdaQuirk(
options):QuirkArtifact
Generate one C-CDA quirk artifact: a spec-clean document (built through @cosyte/ccda's
buildCcda) with the requested vendor deviation injected post-serialize. Deterministic in seed +
quirk + documentType.
Parameters
options
Seed, quirk, and base document type. See GenerateCcdaQuirkOptions.
Returns
The QuirkArtifact: its content round-trips to intendedWarnings exactly.
Throws
SynthError SYNTH_UNSUPPORTED_QUIRK if quirk is not a supported C-CDA quirk.
Throws
Error if the base document does not contain the structural anchor the quirk targets.
Example
import { generateCcdaQuirk, ccdaQuirkRoundTrip } from "@cosyte/synth/ccda";
const rt = ccdaQuirkRoundTrip(generateCcdaQuirk({ seed: 1, quirk: "deprecated-loinc" }));
rt.withProfile?.tolerated; // true, `smartScorecard` re-badges DEPRECATED_LOINC
generateReferralNote()
generateReferralNote(
options?):CcdaDocument
Generate a spec-clean synthetic Referral Note: the second document type buildCcda supports,
with its own US Realm Header specialization and Reason-for-Referral / Assessment narrative sections.
Parameters
options?
Omit<GenerateCcdaOptions, "documentType"> = {}
Seed (deterministic). See GenerateCcdaOptions.
Returns
CcdaDocument
The CcdaDocument.
Example
import { generateReferralNote } from "@cosyte/synth/ccda";
generateReferralNote({ seed: 1 }).documentType; // "referralNote"
injectCcdaQuirk()
injectCcdaQuirk(
quirk,cleanXml):string
Apply a C-CDA quirk transform to a spec-clean document, or fail closed. Refuses to return a document that does not carry the intended deviation (a quirk whose structural anchor is absent): a fixture that silently lost its quirk would test the wrong thing.
Parameters
quirk
The quirk to inject.
cleanXml
string
The spec-clean C-CDA XML.
Returns
string
The quirked XML.
Throws
SynthError SYNTH_UNSUPPORTED_QUIRK when quirk is not a supported C-CDA quirk.
Throws
SynthError SYNTH_QUIRK_ANCHOR_ABSENT when the quirk found no structural anchor to mutate.
Example
import { injectCcdaQuirk } from "@cosyte/synth/ccda";
injectCcdaQuirk("template-extension-absent", cleanXml);
quantityFor()
quantityFor(
rng,concept):BuildQuantity
Draw a synthetic-but-structurally-sane BuildQuantity for a quantitative concept: a value in the concept's plausible band (from the seeded generator, so reproducible) rendered to the concept's decimal precision, with its UCUM unit. The value implies no real measurement.
Parameters
rng
The seeded generator.
concept
The quantitative concept (LOINC code + UCUM unit + value band).
Returns
BuildQuantity
A BuildQuantity ({ value, unit }) for the C-CDA builder.
Example
import { createRng } from "@cosyte/synth";
import { quantityFor, LAB_RESULTS } from "@cosyte/synth/ccda";
// quantityFor(createRng(1), LAB_RESULTS[0]);
roundTrip()
roundTrip(
doc):RoundTripResult
Round-trip a generated @cosyte/ccda CcdaDocument through serialize → parse → serialize and report
the verdict. A spec-clean document re-parses with zero warnings and re-serializes byte-identically.
Parameters
doc
CcdaDocument
The document to check (typically from ./ccd.generateCcd).
Returns
The RoundTripResult.
Example
import { generateCcd, roundTrip } from "@cosyte/synth/ccda";
const { specClean, warnings } = roundTrip(generateCcd({ seed: 1 }));
// specClean === true, warnings.length === 0
toBuildCode()
toBuildCode(
concept):BuildCode
Adapt a FHIR CodeConcept to a @cosyte/ccda BuildCode, resolving its system URI to
the matching OID. The codeSystem is always set explicitly (never left to a per-slot default), so a
SNOMED allergen or a LOINC panel carries the right OID regardless of which builder slot consumes it.
Parameters
concept
The FHIR-shaped { system, code, display } concept.
Returns
BuildCode
The @cosyte/ccda BuildCode.
Throws
SynthError SYNTH_UNMAPPED_CODE_SYSTEM when the concept's system URI has no known OID
mapping. The refusal does not quote the URI: concept is caller-supplied.
Example
import { toBuildCode } from "@cosyte/synth/ccda";
// toBuildCode({ system: "http://snomed.info/sct", code: "59621000", display: "Essential hypertension" });