/** * WHO WROTE THIS MESSAGE, and never a raw identifier. * * - WHAT A CLINICIAN ACTUALLY SAW. Great River, the practitioner workspace, * Messages Collaboration Teams Test Team, 2026-08-23: * * cb68ee44-4c9e-4147-98a1-1480675cf278 8:49 AM * Dr Whitfield here - I have accepted the referral and can see the record now... * * The only reason anybody could tell who wrote it is that the human typed their own name into the * message body. The interface attributed a clinical collaboration message to a hex string. * * THE CAUSE WAS A FALLBACK ORDER, NOT A MISSING FEATURE: * * communication.sender?.display || senderReference.split("/")[1] || "Participant" * * The middle term is the defect, and the code already had a better answer one term to its right - * `"Participant"` could essentially never run, because a reference always has an id. * * AND THE FIX IS NOT TO HIDE THE SENDER LINE. An unattributed message in a clinical thread is worse * than an ugly one; the card says so outright. */ /** * A reference's id, when the reference has one. * * Exported for the guard below rather than for callers - a label must never be built from this. */ const referenceId = (reference: string): string => reference.split('/')[1] ?? ''; /** * DOES THIS LOOK LIKE AN IDENTIFIER RATHER THAN A PERSON? * * SHAPE, NOT PROVENANCE. A denormalised `display` is written by whoever sent the message, and a writer * that stamped an id into it produces exactly the string this card is about - so trusting `display` * merely because it exists is what let this through. The label is judged on what it looks like. * * Catches a UUID, a bare hex blob, and any single token with no letters - the shapes an id takes here. */ export const looksLikeAnIdentifier = (value: string): boolean => { const trimmed = value.trim(); if (!trimmed) return true; if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(trimmed)) return true; if (/^[0-9a-f]{16,}$/i.test(trimmed)) return true; /* * A LONG SINGLE TOKEN WITH NO VOWEL - and the length bound is not decoration. * * A first draft flagged any vowel-less token with no space, and its own control caught it: **`Ng` is * a real surname**, and the rule would have replaced a colleague's name with "Participant". That is * the same defect this file exists to fix, wearing the opposite face - and worse, because a wrong * name is quieter than an obvious id. * * 12 characters is far beyond any surname and far below the ids actually seen here. When in * doubt this must fall on the side of PRINTING what it was given: an ugly label is recoverable, a * silently withheld identity is not. */ return !trimmed.includes(' ') && trimmed.length >= 12 && !/[aeiouy]/i.test(trimmed); }; export interface SenderLabelInput { /** What the writer denormalised onto the message, if anything. */ display?: string; /** The sender reference, e.g. `Practitioner/abc`. */ reference?: string; /** Names resolved from the team roster, keyed by reference. The server's answer, not a second one. */ rosterNames?: Record; } /** * The label to render for a message author. * * THE ROSTER IS CONSULTED BEFORE GIVING UP, and it is the SERVER's answer rather than a second * resolution path - the collaboration-team read now returns a `displayName` for every practitioner * member, so the name is already in hand. Two resolution paths for one fact is how they drift; that is * the Captain's steer on this card and the reason this does not fetch anything. * * AND IT NEVER RETURNS AN ID. When nothing resolves, the reader gets a role-shaped word - honest about * what is not known, and still attributing the message to somebody. */ export const senderLabel = ({ display, reference, rosterNames }: SenderLabelInput): string => { const stamped = (display ?? '').trim(); if (stamped && !looksLikeAnIdentifier(stamped)) return stamped; const fromRoster = (rosterNames ?? {})[(reference ?? '').trim()]?.trim(); if (fromRoster && !looksLikeAnIdentifier(fromRoster)) return fromRoster; return 'Participant'; }; export { referenceId };