import type { Organization } from 'fhir/r4'; // (telehealth booking S3, client half) - mirrors // aws/sam/services/api/src/utils/appointmentPolicy.ts. // // The OUTERMOST of telehealth's three gates: does this practice offer video visits at all? (The other // two are per-service - - and per-schedule-block, S4 half.) // // Deliberately shaped like appointmentReminderPolicy.ts, its sibling in this folder, because the server // module it mirrors is deliberately shaped like the reminder one. Keeping the two families parallel is // what makes a drift between plugin and server visible. // // SCOPE, and please keep it: the server file is the home for future appointment policy (booking horizon, // lead time, cancellation window), but today it carries ONE field. An empty policy framework is scope // nobody asked for. export interface AppointmentPolicy { telehealthEnabled: boolean; } /** * `telehealthEnabled: false` is deliberate, and it is the same reasoning as the reminder policy's * `enabled: false`: deploying a feature must not switch it on for every practice. An org that has never * opened this page is not offering video visits. Same posture as S2's absent-extension rule. */ export const DEFAULT_APPOINTMENT_POLICY: AppointmentPolicy = { telehealthEnabled: false, }; // There is no GET /R4/appointment-policy-settings - the org's saved policy travels only on the // Organization resource, as this extension. The server WRITES this exact URL (setAppointmentPolicy in // its own copy of this file); the plugin READS it back here, so the literal MUST match byte for byte. // A drifted character reads as "never saved" forever: the org sets telehealth on, the server stores it, // and every booking surface still sees it off. export const ORG_APPOINTMENT_POLICY_EXTENSION_URL = 'https://akashichealthrecords.com/fhir/StructureDefinition/organization-appointment-policy'; const TELEHEALTH_ENABLED_SUB_URL = 'telehealthEnabled'; /** * Pure reader - mirrors the server's resolveEffectiveAppointmentPolicy exactly (same extension URL, * same child url), so every surface seeds from whatever the org last saved. Falls back to * DEFAULT_APPOINTMENT_POLICY when the org has never saved a policy, same as the server default. * * The `=== true` is not redundant: it fails CLOSED on a non-boolean. The server's validator rejects * those, but a resource written by another path or an older build could still carry one, and a truthy * string reading as ON is a trap this codebase has already been bitten by. */ export function resolveOrgAppointmentPolicy(organization?: Organization | null): AppointmentPolicy { const ext = organization?.extension?.find((e) => e.url === ORG_APPOINTMENT_POLICY_EXTENSION_URL); if (!ext) return { ...DEFAULT_APPOINTMENT_POLICY }; const telehealth = (ext.extension ?? []).find((e) => e.url === TELEHEALTH_ENABLED_SUB_URL); return { telehealthEnabled: telehealth?.valueBoolean === true, }; }