import type { Observation } from 'fhir/r4'; /** How a reading is named to the person who entered it. */ export const readingName = (observation: Observation): string => observation.code?.text ?? observation.code?.coding?.[0]?.display ?? 'reading'; /** * A reading save that stopped part way: the readings saved stand and are named, the one that did not finish is named * with how it ended, and the form sends nothing more - what is saved is checked before anything is added again. */ export const readingsSavedSoFar = (saved: string[], stopped: string, unconfirmed: boolean): string => { const list = saved.map((name) => `the ${name} reading`).join(', '); const lead = `${list.charAt(0).toUpperCase()}${list.slice(1)} ${saved.length === 1 ? 'was' : 'were'} saved.`; const rest = unconfirmed ? `Whether the ${stopped} reading was saved could not be confirmed.` : `The ${stopped} reading could not be saved.`; return `${lead} ${rest} Close this form and check the readings list before adding it again.`; };