// An Orders & results report count opened here: the service and period behind it, dated as the report dates it. import type { DiagnosticOrderQueueRow } from '../../../hooks/useDiagnosticOrderQueue'; import { formatDate } from '../../../utils/dateUtils'; import { drillPeriodFrom, withinDrillPeriod, type DrillPeriod } from '../../../utils/reportDrillPeriod'; const SERVICES = { laboratory: 'Laboratory orders', imaging: 'Imaging orders', } as const; export type DiagnosticService = keyof typeof SERVICES; export interface DiagnosticDrill extends DrillPeriod { kind: DiagnosticService } export const diagnosticDrillFrom = (params: URLSearchParams): DiagnosticDrill | null => { const kind = params.get('kind'); const period = drillPeriodFrom(params); if (!kind || !(kind in SERVICES) || !period) return null; return { kind: kind as DiagnosticService, ...period }; }; export const matchesDrill = (row: DiagnosticOrderQueueRow, drill: DiagnosticDrill): boolean => { return row.kind === drill.kind && withinDrillPeriod(row.authoredOn, drill); }; export const describeDrill = (drill: DiagnosticDrill): string => `${SERVICES[drill.kind]} placed ${formatDate(drill.from)} to ${formatDate(drill.to)}`;