// --------------------------------------------------------------------------------------------- // S1c-c (client half) - the patient's authorization for a collaboration-team referral. // // The server REQUIRES a recorded authorization before it will mint the referral Consent that grants // an invited practitioner access to the patient's chart. Two client actions must therefore carry // one, because they are the two moments the patient acts: // // * approving a referral a practitioner made (PUT /R4/collaboration-team-member, action approve) // * inviting a practitioner themselves (POST.../members, patient-initiated) // // Without it the server answers 400. That is deliberate - approval must not be one silent tap on // something that hands a stranger the whole chart. // // CONTRACT SHARED WITH THE SERVER. `REFERRAL_AUTH_VERSION` must match // `utils/collaborationTeamAuthorization.ts`'s constant in akashic-infrastructure exactly: the server // refuses any other value as stale, on purpose, so that an authorization can only ever be evidence // the patient saw THIS text. If you revise the wording below, bump the version in BOTH repos in the // same change - a bump here alone makes every approval fail, and a bump there alone makes this // screen record agreement to text it never showed. // --------------------------------------------------------------------------------------------- export const REFERRAL_AUTH_VERSION = 1; export type ReferralAuthCaptureMethod = 'self-service' | 'portal-pending' | 'staff-attested'; export interface ReferralAuthorizationRequest { captureMethod: ReferralAuthCaptureMethod; agreedVersion: number; } /** * What the patient is agreeing to, in plain language. Deliberately concrete about the three things * that actually matter to someone deciding: what the practitioner will see, that it is ongoing * rather than one-time, and that it can be taken back. */ export const REFERRAL_AUTH_SUMMARY = [ 'They will be able to view your medical record — including visits, medications, test results, conditions and documents.', 'Access continues until you remove them from this care team.', 'You can remove them at any time, which ends their access.', ] as const; export const REFERRAL_AUTH_HEADLINE = 'Give this practitioner access to your record'; /** * The authorization block to send with an approve or a patient-initiated invite. * * `self-service` is the only capture method a patient's own browser may claim: `staff-attested` * belongs to the in-office endpoint, where the witness is the authenticated practitioner, and * letting the client assert it would let a caller fabricate a witness. The server enforces this too * (it takes the attester from the authenticated caller, never the body) - this just never sends it. */ export const buildReferralAuthorization = (): ReferralAuthorizationRequest => ({ captureMethod: 'self-service', agreedVersion: REFERRAL_AUTH_VERSION, });