Type Alias: ObservationValue
ObservationValue = {
kind:"physicalQuantity";quantity:PQ; } | {code:CD;kind:"coded"; } | {kind:"string";nullFlavor?:string;value:string; } | {kind:"integer";nullFlavor?:string;raw?:string;value?:number; } | {kind:"range";range:IVL_PQ; } | {kind:"unsupported";raw?:string;xsiType?:string; }
A parsed observation value, discriminated on kind. physicalQuantity
carries a UCUM-checked PQ; coded a CD; string a free-text
value; integer a count/score (xsi:type="INT", the type C-CDA prefers for
an assessment-scale score, units are not allowed on an INT); range an
IVL_PQ. unsupported preserves an xsi:type the model does not
specialize (with any raw text) so nothing is ever discarded. integer keeps
value and nullFlavor distinct, a scored INT never collapses into an
unknown one, and vice versa.
integer and string carry a nullFlavor beside their content for the same
reason every v3 datatype does, and integer mirrors PQ exactly: raw is
the verbatim @value token and value the parsed number, so when a
nullFlavor contradicts the score the parser withholds value and keeps
raw (see parsePq). These two arms are parsed inline here rather
than through src/model/types/, so they route through the shared
contradiction check explicitly.
Example
import type { ObservationValue } from "@cosyte/ccda";
function numeric(v: ObservationValue): number | undefined {
if (v.kind === "physicalQuantity") return v.quantity.value;
return v.kind === "integer" ? v.value : undefined;
}