import type { PractitionerRole, Schedule } from 'fhir/r4'; import { isClinicianEnabled } from '../clinicianEnabled'; import { practitionerIdOfRole, seatCapacityAdmits, type SeatStanding } from '../seatStanding'; /** * Can this schedule's owner be booked to perform a service? * * WHAT WAS ACTUALLY DECIDING IT BEFORE: nothing about the person. The whole eligibility test was * "does this schedule list this service?", so somebody became bookable the moment a clinical service * was attached to their schedule - and the product accepted it end to end: offered, selected, written, * never refused. On staging a receptionist's schedule carried `Consultation`, and because it was the * only match the booking dialog filled it in by itself. * * Spencer, 2026-08-27: *"How can a receptionist be a practitioner that can be booked? Answer is they * can't! How did this happen"* * * THE SEAT IS THE FACT, SO IT IS WHAT THIS USES. `clinician-enabled` already exists, already fails * closed, and is already what decides whether somebody may hold the practitioner workspace at all. It * was read by campaign targeting, the seat card, the screen that grants it and five pieces of billing * machinery - and by no booking path anywhere. * * NOT BY ROLE NAME OR CODE. 161 of 204 role codings on staging are not our own vocabulary, so a * name-based filter hides real clinicians - the lesson already paid for. * * A SCHEDULE WITH NO ROLE IS REFUSED, and that is a deliberate choice rather than an oversight. It has * no seat to show, and the seat's own rule is that an absent flag is not enabled - "load-bearing: it is * what makes this a gate rather than a suggestion". Failing open here would leave the hole exactly as it * was: attach a service to a role-less schedule and the person is bookable again. * * AND THE HONEST LIMIT: this gates the PERSON, not the SERVICE. Every service in the catalogue today * is clinical, so refusing a non-clinician is right for all of them. If a genuinely non-clinical service * is ever added - an interpreter slot, forms help, the things a front desk legitimately books - this * will refuse it too, and at that point the gate needs the other half: which services require a seat. * There is no marker for that on `HealthcareService` today, which is why it is not read here. */ export const canBeBookedAsClinician = ( schedule: Schedule, role: PractitionerRole | undefined, seat: SeatStanding | null, ): boolean => Boolean(schedule.id) && isClinicianEnabled(role) && seatCapacityAdmits(practitionerIdOfRole(role), seat);