import { Observation, Reference } from 'fhir/r4'; /** * Who performed an observation, in words, beside the kind of performer the list already shows: the name it was recorded * with, the patient it is about, or that no name was recorded. Never the stored reference, and never a lookup of a * record the viewer was not already shown. */ export const performerLabel = (ref: Reference, observation: Pick): string => { if (ref.display?.trim()) return ref.display.trim(); if (ref.reference && ref.reference === observation.subject?.reference) return 'This patient'; return 'Name not recorded'; }; /** The performers with a readable display, so the shared reference list shows names rather than stored references. */ export const namedPerformers = (observation: Pick): Reference[] | undefined => observation.performer?.map((ref) => ({ ...ref, display: performerLabel(ref, observation) }));