import type { Organization } from 'fhir/r4'; /** * Which onboarding track the practice is on, as the server recorded it at founding. * Anything but an explicit receiving answer reads as full, so no practice loses a step. */ export const OPERATING_SCOPE_EXTENSION_URL = 'https://akashichealthrecords.com/fhir/extensions/operating-scope'; export type OperatingScope = 'full' | 'receiving'; export const readOperatingScope = (organization?: Organization | null): OperatingScope => organization?.extension?.find((e) => e.url === OPERATING_SCOPE_EXTENSION_URL)?.valueCode === 'receiving' ? 'receiving' : 'full'; export const withOperatingScope = (organization: Organization, scope: OperatingScope): Organization => ({ ...organization, extension: [ ...(organization.extension ?? []).filter((e) => e.url !== OPERATING_SCOPE_EXTENSION_URL), { url: OPERATING_SCOPE_EXTENSION_URL, valueCode: scope }, ], });