import type { Reference } from 'fhir/r4'; /** * WHAT TO CALL THE OTHER PARTY WHEN NOBODY CAN NAME THEM - and never their id. * * A resource id is not an answer to a reader. `senderLabel.ts` exists because a clinical message was * attributed to a hex string; this is the same defect on the thread ROW rather than the message, where * `getCounterpartyDisplay` ended `counterpartyId || directDisplay || "Unknown"` and printed the id as * the person's name in the patient's own inbox. * * AND THE ROW STILL HAS TO SAY SOMETHING. Hiding the name is worse than an imperfect one, so this * answers with the role-shaped word the same screen already shows beneath it: honest about what is not * known, and still telling the reader who they are talking to. * * IT LIVES HERE RATHER THAN IN THE PAGE for the reason `counterparty.ts` gives in its own header: the * two counterparty helpers drifted precisely because each surface kept its own copy. Pure and * reference-only, so it is testable without rendering the page. * * @param counterparty the other party's reference, or `undefined` on a pool or visit thread * @param practitionerRoleSummary the caller's role lookup - it already answers "Staff" when a * practitioner's roles cannot be resolved, so this never has to invent a second fallback */ export function counterpartyRoleWord( counterparty: Reference | undefined, practitionerRoleSummary: (practitionerId?: string) => string, ): string { const [resourceType, id] = (counterparty?.reference ?? '').split('/'); if (resourceType === 'Practitioner') { return practitionerRoleSummary(id || undefined); } return resourceType === 'Patient' ? 'Patient' : 'Staff'; }