// A referrals report count opened here: the route and period behind it, classified as the report does. import type { ReferralQueueRow } from '../../../hooks/useReferralQueue'; import { formatDate } from '../../../utils/dateUtils'; import { drillPeriodFrom, withinDrillPeriod, type DrillPeriod } from '../../../utils/reportDrillPeriod'; const ROUTES = { 'inbound-akashic': 'Inbound, from an Akashic practice', 'inbound-external': 'Inbound, external or fax', 'outbound-akashic': 'Outbound, to an Akashic practice', 'outbound-external': 'Outbound, external or fax', } as const; export type ReferralRoute = keyof typeof ROUTES; export interface ReferralDrill extends DrillPeriod { route: ReferralRoute } export const referralDrillFrom = (params: URLSearchParams): ReferralDrill | null => { const route = params.get('route'); const period = drillPeriodFrom(params); if (!route || !(route in ROUTES) || !period) return null; return { route: route as ReferralRoute, ...period }; }; /** On Akashic when the other practice is referenced: the recipient for outbound, the sender for inbound. */ export const routeOf = (row: ReferralQueueRow, direction: 'outbound' | 'inbound'): ReferralRoute => `${direction}-${(direction === 'outbound' ? row.performerReference : row.requesterReference) ? 'akashic' : 'external'}`; export const matchesDrill = (row: ReferralQueueRow, direction: 'outbound' | 'inbound', drill: ReferralDrill): boolean => { return routeOf(row, direction) === drill.route && withinDrillPeriod(row.authoredOn, drill); }; export const describeDrill = (drill: ReferralDrill): string => `${ROUTES[drill.route]}, started ${formatDate(drill.from)} to ${formatDate(drill.to)}`;