lib/pipeline/prioritize.ts and is fully covered by regression tests.
Appeal deadline calculation
The deadline is calculated from the remittance’snotice_date using two constants that model the Medicare Part A/B redetermination window:
The formula in plain terms:
noticeDate is an ISO calendar date string (e.g. "2025-03-01"). The function returns the deadline as an ISO calendar date string. All arithmetic is performed in UTC to avoid daylight-saving edge cases.
The deadline is a conservative approximation for triage and queue-ordering purposes. Actual payer-specific deadlines — including Medicare Advantage, Medicaid, and commercial payer rules — vary significantly and must be verified by the billing team before acting on any line.
Urgency score
Urgency is a0–1 value that increases as the deadline approaches. It is calculated using the URGENCY_SCALE_DAYS constant (125), which equals the total presumed window from notice date to deadline.
Formula:
daysRemaining is the number of calendar days from today to the deadline.
- A line with 125 or more days remaining → urgency
0.0(no time pressure) - A line with 0 days remaining → urgency
1.0(at the deadline) - A line past the deadline → urgency clamped to
1.0 - A line with 62 days remaining → urgency ≈
0.50
Priority score
The priority score combines three signals: how much money is at stake, how likely recovery is, and how urgently the deadline is approaching. Formula:
A high-value line with a strong recovery probability and an approaching deadline rises to the top of the queue. A low-value line that is unlikely to recover, even with an urgent deadline, scores lower.
Sort order
prioritize() returns lines in the following order:
1
Sort by deadline ascending
Lines with the soonest deadline appear first. A line due in 10 days always precedes a line due in 60 days, regardless of dollar value.
2
Sort by priority score descending within the same deadline date
Among lines sharing the same deadline date, higher
priority_score wins. This surfaces the most financially valuable, highest-probability-of-recovery lines within each deadline bucket.prioritize() function
The full function signature and sort logic from lib/pipeline/prioritize.ts:
PrioritizeInput is { line: AdjustmentLine; triage: DenialTriage }. The output is an array of PrioritizedLine objects, each carrying the original line and triage data alongside the three computed values (deadline, urgency, priority_score).
The deadline calculation is a conservative approximation for triage purposes. Actual payer-specific deadlines must be verified by the billing team before acting on any denial.