import type { Patient } from "fhir/r4"; export const INTERPRETER_NEEDED_URL = "http://hl7.org/fhir/us/core/StructureDefinition/us-core-interpreter-needed"; const INTERPRETER_ANSWERS: Record = { Y: "Yes", N: "No", UNK: "Unknown", ASKU: "Asked, not answered" }; // Undefined when the record carries no answer, so the row is left out rather than shown as a No. export const interpreterNeededLabel = (patient: Pick | undefined): string | undefined => { const answer = patient?.extension?.find((ext) => ext.url === INTERPRETER_NEEDED_URL); if (typeof answer?.valueBoolean === "boolean") return answer.valueBoolean ? "Yes" : "No"; const code = answer?.valueCode ?? answer?.valueCoding?.code; return code ? INTERPRETER_ANSWERS[code] ?? code : undefined; };