Circle V2 API Docs
    Preparing search index...

    Type Alias RunChartReviewSingleTemplateOptions

    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.md for 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.allSettled and persists immediately on success; individual question errors are logged but do not abort the remaining questions.

    When auditQuestionId is provided, only that question is (re-)run and the summary regeneration + markAsComplete are skipped to preserve the existing run's summary — same contract as v1.

    type RunChartReviewSingleTemplateOptions = {
        auditQuestionId?: AuditQuestionId;
        auditRunId?: AuditRunId;
        createdBy: UserId | null;
        createRunner: CreateQuestionRunner;
        logger?: Logger;
        model: ChatOpenAI;
        patientId: PatientId;
        sessionId?: SessionId;
        sessionNoteContext?: string;
        settings: ChartReviewSettings;
        supabase: SupabaseClient<Database>;
        templateId: AuditTemplateId;
        trace?: {
            runMode?: ChartReviewRunMode;
            triggerId?: ChartReviewTriggerId | null;
        };
        treatmentEpisodeId?: string;
    }
    Index

    Properties

    auditQuestionId?: AuditQuestionId

    Re-run only this question; skips summary regen + markAsComplete.

    auditRunId?: AuditRunId

    Existing run to re-run within (idempotent findOrCreate).

    createdBy: UserId | null

    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.

    createRunner: CreateQuestionRunner

    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.

    logger?: Logger
    model: ChatOpenAI

    Injected dependencies — the trpc handler constructs and passes these.

    patientId: PatientId
    sessionId?: SessionId

    When 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.

    sessionNoteContext?: string

    When 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.

    supabase: SupabaseClient<Database>
    templateId: AuditTemplateId
    trace?: {
        runMode?: ChartReviewRunMode;
        triggerId?: ChartReviewTriggerId | null;
    }

    LangSmith trace context — see RunChartReviewOptions["trace"].

    treatmentEpisodeId?: string

    When 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.