import type { Organization } from 'fhir/r4'; /** * May this practice's patient portal serve patients?. * * THE OUTAGE THIS EXISTS FOR. `App.tsx` gated the entire patient portal on the `baa-status` * extension of the practice's Organization. then narrowed the UNAUTHENTICATED Organization * read to an allow-list - rightly, because that response was handing a practice's Stripe subscription * and BAA status to anyone who could read its homepage - and `baa-status` was not on it. the field * could no longer ARRIVE, the gate read false for every organization always, and every signed-in * patient at every practice saw *"Patient portal access is currently not available for this * organization."* and nothing else. * * NOTHING WAS MISCONFIGURED. An extension being hidden by default is the property that allow-list * exists to create. What no server-side check could see is that a CLIENT GATE was consuming one *. * Spencer ruled the shape (2026-08-16, option B): the server DERIVES a narrow public boolean from the * BAA and publishes that; the BAA status itself stays private. Do not reintroduce a read of * `baa-status` here - it is deliberately not public, so such a read is false for everyone, silently. * * THIS IS A TRI-STATE AND THE THIRD VALUE IS THE POINT. `undefined` is NOT KNOWN - a response from an * api deploy older than this bundle, which cannot carry a field that did not exist when it shipped. The * caller must treat it as "no answer", never as "no portal": the two repos ship separately (the plugin * as a manual zip ), so a client that reads absence as a refusal * re-creates this exact outage on every version skew. */ export const PATIENT_PORTAL_ENABLED_EXTENSION_URL = 'https://akashichealthrecords.com/fhir/extensions/patient-portal-enabled'; /** * `true` - the practice may serve its portal - `false` - it may not - `undefined` - the server did not * say, so the caller has no answer and must not invent one. * * Reads `valueBoolean` only. The server emits this field for EVERY organization, true or false, so a * value in any other shape is not a lenient case to accommodate - it is a response this system does not * produce, and treating it as an answer would invent one. */ export const patientPortalEnabled = ( // `null` as well as `undefined`: the caller holds a ref that is null before the practice resolves, // and a signature that refused it would push a `?? undefined` onto the call site - noise at exactly // the line whose readability this outage depended on. organization?: Organization | null, ): boolean | undefined => { const value = (organization?.extension ?? []) .find((extension) => extension?.url === PATIENT_PORTAL_ENABLED_EXTENSION_URL) ?.valueBoolean; return typeof value === 'boolean' ? value : undefined; };