OptionalauditMap of templateId -> pre-created auditRunId. When provided, the worker reuses existing rows instead of creating new ones.
Authenticated user id (auth runs at the trpc middleware layer), or null for
trigger-sourced runs that have no attributable user.
Factory for the question runner, injected by the caller (jobbable). The runner choice is encoded by which job ran — no discriminator is serialized onto the job.
OptionalloggerOptionalsessionWhen set, audit responses produced by this run 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.
OptionaltraceLangSmith trace context. Identifies the modality (manual vs automated) and the source trigger so each run's trace is filterable. Optional — when omitted the run mode is inferred from the run shape (e.g. session-note context implies a session-note validation).
OptionaltreatmentWhen set, scope every template's run to a single treatment episode — the EMR runner's candidate charts are filtered to this episode. Unset for unscoped patient-level reviews.
Multi-template orchestrator. Fans out one
runChartReviewSingleTemplatecall per template underPromise.allSettledso a single template failure does not abort the rest. Constructs the sharedChatOpenAIinstance internally — callers only provide the resolvedChartReviewSettingsplus the supabase client and authenticated user id.Returns the successful audit run ids alongside any per-template errors. Mapping these to a transport-level error (e.g.
TRPCError) is the caller's responsibility.