Skip to main content
Version: v0.0.3

Interface: TerminologyAdapter

The bring-your-own terminology contract a consumer supplies to parseCcda (via ParseCcdaOptions.terminology) or buildCcda (via BuildCcdaOptions.terminology). @cosyte/ccda never implements or imports one, it only calls the one you supply, and only where a coded value carries both a code and a system.

validateCode is the one method the parser consumes. For each recognized coded slot (problem, medication, allergen, route, vaccine), the parser calls validateCode and, on a result: false, emits SEMANTIC_CODE_INVALID with the code preserved verbatim, it never rewrites the value. Returning undefined means the adapter has no opinion (e.g. the system is outside its coverage); the parser then stays silent and falls back to recognize-only, so an adapter that only covers some systems adds no noise for the rest.

translate is consumed on build and optional. buildCcda calls it at each clinical coded slot and emits any returned coding as a <translation> alternate beside the primary code (never a substitution), see CodeTranslationResult.

Example

import { parseCcda, type TerminologyAdapter } from "@cosyte/ccda";

// A tiny BYO adapter, ccda imports no terminology library; you supply one.
const adapter: TerminologyAdapter = {
validateCode: (coding) =>
coding.system === "2.16.840.1.113883.6.96"
? { result: mySnomedService.has(coding.code) }
: undefined, // no opinion on other systems
};

const doc = parseCcda(xml, { terminology: adapter });
// A structurally-valid but non-member SNOMED code now carries SEMANTIC_CODE_INVALID.

Properties

translate?

readonly optional translate?: (coding) => CodeTranslationResult | undefined

Translate coding through the consumer's map, returning declared targets verbatim (empty ⇒ unmapped, never fabricated). buildCcda emits each returned coding as a <translation> alternate beside the primary code, never a substitution. Optional, a validation-only adapter may omit it, and its absence yields byte-identical output.

Parameters

coding

TerminologyCoding

Returns

CodeTranslationResult | undefined


validateCode

readonly validateCode: (coding) => CodeValidationResult | undefined

Validate that coding is a real member of its code system. Return { result: true } when it is, { result: false } when it is not, or undefined when the adapter cannot judge (the system is out of its scope), undefined produces no warning and no change.

Parameters

coding

TerminologyCoding

Returns

CodeValidationResult | undefined