/** * - WHY A PRACTICE IS NOT GOING TO SEE THIS PATIENT. * * Spencer ruled (b) on 2026-08-24: the coordinator closes an unservable referral with a reason, and * the SENDING practice sees that reason. The argument is about the patient rather than tidiness - * *"they declined"* and *"we sent it to the wrong place"* lead the sender to do completely different * things for somebody who still needs care. * * A FIXED LIST, AND THE CODES MUST MATCH THE SERVER'S EXACTLY. This value crosses an organization * boundary: written here, read by the practice that sent the referral. Free text is a disclosure * surface and *"declined because..."* is arguably clinical - far easier to add later than to take back. * `utils/referralClosureReason.ts` in the api repo is the other half; the server refuses anything * off this list, so a drift here is a 400 rather than a silent wrong value. */ export const REFERRAL_CLOSURE_REASONS = { DECLINED_BY_PATIENT: 'declined-by-patient', DUPLICATE: 'duplicate', NOT_A_SERVICE_WE_OFFER: 'not-a-service-we-offer', UNABLE_TO_REACH_PATIENT: 'unable-to-reach-patient', } as const; export type ReferralClosureReason = (typeof REFERRAL_CLOSURE_REASONS)[keyof typeof REFERRAL_CLOSURE_REASONS]; /** * What a coordinator picks from, in the words they would use. * * ORDERED BY HOW OFTEN A FRONT DESK WILL REACH FOR IT, not alphabetically - "could not reach them" and * "they declined" are the everyday outcomes; a duplicate or a wrong-specialty referral is rarer. * THE LABEL IS OURS AND THE CODE IS THE CONTRACT. Rewording a label is safe; changing a code is a * cross-organization vocabulary change and needs the server in the same commit. */ export const REFERRAL_CLOSURE_REASON_LABELS: Record = { [REFERRAL_CLOSURE_REASONS.UNABLE_TO_REACH_PATIENT]: 'We could not reach the patient', [REFERRAL_CLOSURE_REASONS.DECLINED_BY_PATIENT]: 'The patient declined', [REFERRAL_CLOSURE_REASONS.NOT_A_SERVICE_WE_OFFER]: 'Not a service we offer', [REFERRAL_CLOSURE_REASONS.DUPLICATE]: 'Duplicate of another referral', }; /** * The order the choices are offered in. * * Derived from the label map rather than written twice - a second list is one that silently loses an * option the day somebody adds one. */ export const REFERRAL_CLOSURE_REASON_CHOICES = Object.keys( REFERRAL_CLOSURE_REASON_LABELS, ) as ReferralClosureReason[]; /** * What the SENDING practice reads on a closed referral. * * Falls back to the raw code rather than to "Closed" or an empty string: an unrecognised code means * the other side is running a newer vocabulary than we are, and showing the code is honest and still * actionable. Swallowing it would tell a sender the referral ended for no reason. */ export const referralClosureReasonLabel = (reason?: string): string | undefined => { if (!reason) return undefined; return REFERRAL_CLOSURE_REASON_LABELS[reason as ReferralClosureReason] ?? reason; };