OptionalauditRe-run only this question; skips summary regen + markAsComplete.
OptionalauditExisting run to re-run within (idempotent findOrCreate).
Authenticated user id (auth runs at the trpc middleware layer), or null for
trigger-sourced runs that have no attributable user. Doubles as the
triggering user's Supabase auth uuid in the trace metadata.
Factory for the question runner. Injected by the caller (jobbable) so the runner choice is encoded by which job ran — no discriminator is serialized and this pipeline stays runner-agnostic.
OptionalloggerInjected dependencies — the trpc handler constructs and passes these.
OptionalsessionWhen set, persisted audit responses are stamped with this sessionId so
the session-note chart-review badge can surface them via
auditRunsRepo.listIdsBySessionId. Omit for patient-level reviews.
OptionalsessionWhen set, the run uses ONLY this (already HTML-cleaned) session-note text as the AI context, bypassing EMR/patient_charts and Pinecone retrieval. Set by the session-note trigger path; unset for patient-level reviews.
Pre-resolved settings — see ./settings.ts.
OptionaltraceLangSmith trace context — see RunChartReviewOptions["trace"].
OptionaltreatmentWhen set, scope this run to a single treatment episode: the EMR runner's candidate charts are filtered to this episode so charts from other episodes (and unassigned charts) are never reviewed. Unset for unscoped patient-level reviews.
In-process port of
circlehealthai-web/app/api/chart-review/run-v2/route.ts. The HTTP boundary, Supabase admin client construction, ChatOpenAI construction, LaunchDarkly resolution, and auth checks are all stripped — those become concerns of the trpc handler that calls this function.See
packages/legacy/src/chart-review/run-v2/lib/README.mdfor the porting policy of the inner pipeline.Throws on patient/case/template not found, on missing/empty questions, and on persistence failures. The trpc handler is responsible for mapping those to
TRPCErrors. On any throw, this function best-effort-marks the audit run as failed before rethrowing.Per-question failure semantics are preserved verbatim from v1: each question runs under
Promise.allSettledand persists immediately on success; individual question errors are logged but do not abort the remaining questions.When
auditQuestionIdis provided, only that question is (re-)run and the summary regeneration +markAsCompleteare skipped to preserve the existing run's summary — same contract as v1.