import type { PractitionerRole, Schedule } from 'fhir/r4'; import { practitionerIdOfScheduleActor } from './practitionerScheduleUnion'; /** * The clinician a schedule is for: its own Practitioner actor, else the practitioner its PractitionerRole actor is for, * as the desk resolves it. A schedule the app saves with a practitioner chosen names both; one that names only the role * (saved without a practitioner, or seeded) is still that clinician's, and patient booking must find them there too. */ export const schedulePractitionerId = (schedule: Schedule, role?: PractitionerRole | null): string | undefined => practitionerIdOfScheduleActor(schedule) ?? role?.practitioner?.reference?.match(/^Practitioner\/([^/]+)$/)?.[1];