Dynamic Algorithms
src/lib/cases/dynamic-algorithms.ts is the deterministic case-intelligence layer for launch. It turns normalized case signals into explainable scores, ranked risks, optimization metrics, and next-best actions without making external model calls.
Covered Algorithms
- Case health: composes the existing weighted risk-scoring engine into a health/risk outcome.
- Statute risk: uses the sourced SOL catalog to compare stored and derived deadline signals.
- Settlement optimization: models liability-adjusted value, settlement range, target, and demand anchor.
- Lien and disbursement optimization: models fee/cost/lien impact, target reductions, lien savings, and net-to-client.
- Treatment gap detection: detects delayed initial treatment, chronology gaps, and current active-case gaps.
- Deposition contradictions: scores transcript coverage, admissions, contradictions, and follow-up gaps.
- Workload optimization: detects over-capacity staff, under-capacity staff, overdue work, and imbalance.
- Revenue leakage: estimates stale-case, undervalued-settlement, medical-cost, unbilled-work, and receivables leakage.
- Integration reliability: rolls up blocked connectors, attention connectors, backlog, and expiring credentials.
Output Contract
buildDynamicAlgorithmReport(input) returns:
algorithms: one named outcome per algorithm, each withscore,riskScore,level,confidence,summary, and rankedsignals.metrics: domain-specific numeric output for settlement, liens, treatment, deposition, workload, revenue, and integrations.nextBestActions: ranked action queue with category, owner role, due window, evidence, confidence, and optional dollar impact.
Scores are normalized so higher score means healthier/safer and higher riskScore means more urgent.
Product Guidance
- Use this engine as the source of truth for dashboard cards, alerts, command-center panels, and AI review context.
- Keep AI generation separate from this layer. AI may explain or draft from these outputs, but these calculations should remain deterministic and testable.
- Add citations/source spans at the route or AI-envelope layer when actions are shown to attorneys or clients.
- Keep route-specific data fetching outside this file. Pass normalized inputs into the engine so unit tests stay fast.
Verification
Focused coverage lives in src/__tests__/lib/dynamic-algorithms.test.ts.
Run:
npm run test:run -- dynamic-algorithms
npx eslint src/lib/cases/dynamic-algorithms.ts src/__tests__/lib/dynamic-algorithms.test.ts
npm run typecheck