// What a patient reads for a coded answer from a terminology value set. The value sets answer in their own case and // words ("unmarried", "Interlocutory", "asked but unknown"); a patient reads sentence case, and an answer whose word // says little is explained. Presentation only: the stored system, code and display are never replaced by these // labels, and an answer not mapped here keeps the words it was recorded with. // // Keyed by system and code, never by display, so the same word in another code system is left alone. Distinct // answers stay distinct: unmarried is not never married, unknown is not asked-but-unknown, and an interlocutory // decree is not a final divorce or a legal separation. interface Concept { system?: string; code?: string; display?: string; } // The current and the older address of each code system; a stored coding may carry either. const MARITAL_SYSTEMS = ['http://terminology.hl7.org/CodeSystem/v3-MaritalStatus', 'http://hl7.org/fhir/v3/MaritalStatus']; const NULL_FLAVOR_SYSTEMS = ['http://terminology.hl7.org/CodeSystem/v3-NullFlavor', 'http://hl7.org/fhir/v3/NullFlavor']; // HL7 v3 MaritalStatus (terminology.hl7.org 7.0.0). const MARITAL: Record = { A: 'Annulled', C: 'Common law', D: 'Divorced', I: 'Interim court decree (interlocutory)', L: 'Legally separated', M: 'Married', P: 'Polygamous', S: 'Never married', T: 'Domestic partner', U: 'Unmarried', W: 'Widowed', }; // HL7 v3 NullFlavor (terminology.hl7.org 7.0.1). Only the codes whose meaning is verified are mapped. const NULL_FLAVOR: Record = { UNK: 'Unknown', ASKU: 'Asked, but not known', }; export const codedAnswerLabel = (concept: Concept): string => { const code = concept.code ?? ''; const mapped = MARITAL_SYSTEMS.includes(concept.system ?? '') ? MARITAL[code] : NULL_FLAVOR_SYSTEMS.includes(concept.system ?? '') ? NULL_FLAVOR[code] : undefined; return mapped ?? concept.display ?? code; };