import type { Observation } from 'fhir/r4'; import type { EarlierSave } from '../../hooks/useObservationOperation'; const readingOf = (observation: Observation): string => { const name = observation.code?.text ?? observation.code?.coding?.find((coding) => coding.display)?.display; const quantity = observation.valueQuantity; const value = quantity?.value !== undefined ? [quantity.value, quantity.unit].filter((part) => part !== undefined).join(' ') : observation.valueString; return [name, value].filter(Boolean).join(': '); }; const SAYS: Record = { checking: 'Checking an earlier save of a reading…', pending: 'An earlier save of a reading was not finished. Finish it as it was entered, or enter a new reading instead.', unconfirmed: 'This save could not be confirmed. Check it before entering another reading.', unavailable: 'Earlier saves made in this tab could not be read, so one may still be unconfirmed. Check the list before entering another reading.', }; const NOT_FOUND = 'This save could not be found. Check the list before entering another reading.'; /** * An earlier save of this editor that was never confirmed, shown before anything new can be saved. Finishing sends what * the server admitted for it, never what the form now holds; a new reading is only ever a deliberate choice. */ export const EarlierSaveNotice = ({ earlier, onCheck, onFinish, onStartNew }: { earlier?: EarlierSave; onCheck: () => void; onFinish: () => void; onStartNew: () => void; }) => { if (!earlier) return null; if (earlier.kind === 'checking') { return
{SAYS.checking}
; } const notFound = earlier.kind === 'unconfirmed' && earlier.notFound; const shown = earlier.kind === 'pending' && earlier.observation ? readingOf(earlier.observation) : undefined; return (

{notFound ? NOT_FOUND : SAYS[earlier.kind]}

{shown ?

{shown}

: null} {earlier.kind === 'pending' && earlier.withheld ? (

What it holds cannot be shown to you now.

) : null}
{earlier.kind === 'pending' ? ( ) : null} {earlier.kind === 'unconfirmed' && earlier.operationId && !notFound ? ( ) : null}
); };