Circle V2 API Docs
    Preparing search index...
    formTemplatesRouter: BuiltRouter<
        {
            ctx: TRPCContext;
            errorShape: DefaultErrorShape;
            meta: object;
            transformer: false;
        },
        DecorateCreateRouterOptions<
            {
                create: MutationProcedure<
                    {
                        input: { fileName: string; storageKey: string };
                        meta: object;
                        output: { id: FormId };
                    },
                >;
                createUploadTarget: MutationProcedure<
                    {
                        input: { fileName: string; sizeBytes: number };
                        meta: object;
                        output: { bucket: string; config: StorageCredentials; key: string };
                    },
                >;
                delete: MutationProcedure<
                    { input: { formId: string }; meta: object; output: { id: FormId } },
                >;
                detect: MutationProcedure<
                    {
                        input: { formId: string };
                        meta: object;
                        output: TemplateDetection;
                    },
                >;
                detectWithExtend: MutationProcedure<
                    {
                        input: { formId: string };
                        meta: object;
                        output: { runId: string };
                    },
                >;
                get: QueryProcedure<
                    {
                        input: { formId: string };
                        meta: object;
                        output: {
                            annotationCount: number;
                            context: string | null;
                            createdAt: DbDate;
                            createdBy: UserId | null;
                            defaultFontSize: string | null;
                            fileName: string | null;
                            fileUrl: string | null;
                            id: FormId;
                            orgId: number & { __brand: "EntityId" } | null;
                            requiredContactTypes: FormTemplateRequiredContactType[];
                            shareWithOrg: boolean;
                            updatedAt: DbDate | null;
                        };
                    },
                >;
                getDetection: QueryProcedure<
                    {
                        input: { formId: string };
                        meta: object;
                        output: TemplateDetection;
                    },
                >;
                getDocument: QueryProcedure<
                    {
                        input: { formId: string };
                        meta: object;
                        output: { documentUrl: string };
                    },
                >;
                getExtendDetection: QueryProcedure<
                    {
                        input: { formId: string; runId: string };
                        meta: object;
                        output: ExtendDetectionState;
                    },
                >;
                getFields: QueryProcedure<
                    {
                        input: { formId: string };
                        meta: object;
                        output: {
                            conditionalRules: {
                                description: string;
                                id: string;
                                kind: "unknown" | "reveals" | "requires" | "one-of";
                                sourceAnnotationId: string;
                                targetAnnotationId: string;
                            }[];
                            fields: FormTemplateField[];
                            formId: FormId;
                            requiredContactTypes: FormTemplateRequiredContactType[];
                        };
                    },
                >;
                list: QueryProcedure<
                    {
                        input: { cursor?: number; limit?: number; offset?: number };
                        meta: object;
                        output: PaginatedResponse<
                            {
                                annotationCount: number;
                                context: string
                                | null;
                                createdAt: DbDate;
                                createdBy: UserId | null;
                                defaultFontSize: string | null;
                                fileName: string | null;
                                fileUrl: string | null;
                                id: FormId;
                                orgId: number & { __brand: "EntityId" } | null;
                                permissions: FormTemplateRowPermissions;
                                requiredContactTypes: FormTemplateRequiredContactType[];
                                shareWithOrg: boolean;
                                updatedAt: DbDate | null;
                            },
                        >;
                    },
                >;
                rename: MutationProcedure<
                    {
                        input: { fileName: string; formId: string };
                        meta: object;
                        output: { fileName: string | null; id: FormId };
                    },
                >;
                setOrgSharing: MutationProcedure<
                    {
                        input: { formId: string; shareWithOrg: boolean };
                        meta: object;
                        output: { id: FormId; shareWithOrg: boolean };
                    },
                >;
                testFill: MutationProcedure<
                    {
                        input: {
                            annotationIds?: string[];
                            chosenContacts?: Record<string, string>;
                            formId: string;
                            includeEmr?: boolean;
                            maxAiFields?: number;
                            patientId: string;
                            renderAnswers?: {
                                annotationId: string;
                                value: { kind: ...; values: ... } | { kind: ...; subfields: ... };
                            }[];
                            renderPdf?: boolean;
                            selectedDocumentIds?: string[];
                            selectedSessionIds?: string[];
                            treatmentEpisodeId?: string;
                        };
                        meta: object;
                        output: {
                            aiFieldCount: number;
                            aiFieldIds: string[];
                            aiFieldsAnswered: number;
                            chunkSize: number;
                            degradations: DegradationSummaryEntry[];
                            deterministicAnswerCount: number;
                            fields: DryRunFormFillField[];
                            formId: FormId;
                            patientId: PatientId;
                            pdf: { byteLength: number; dataUrl: string; fileName: string }
                            | null;
                            pdfOmittedReason: "too_large" | "not_requested" | null;
                            skippedFieldIds: string[];
                            truncated: boolean;
                            undrawnCount: number;
                            unpositionedCount: number;
                        };
                    },
                >;
                update: MutationProcedure<
                    {
                        input: {
                            annotations: {
                                contactLink?: { contactTypeId: string; fieldId: string }
                                | null;
                                coordinates: {
                                    height: number;
                                    id?: (...) | (...);
                                    page: number;
                                    value?: (...) | (...) | (...);
                                    width: number;
                                    x: number;
                                    y: number;
                                }[];
                                generatedByAi?: boolean;
                                id?: string;
                                isExclusive?: boolean
                                | null;
                                prompt: string | null;
                                type: "ai_prompt" | "checkbox" | "text" | "contact";
                            }[];
                            context?: string
                            | null;
                            defaultFontSize?: number | null;
                            formId: string;
                        };
                        meta: object;
                        output: SavedTemplate;
                    },
                >;
                updateConditionalRules: MutationProcedure<
                    {
                        input: {
                            formId: string;
                            rules: {
                                description: string;
                                id: string;
                                kind: "unknown"
                                | "reveals"
                                | "requires"
                                | "one-of";
                                sourceAnnotationId: string;
                                targetAnnotationId: string;
                            }[];
                        };
                        meta: object;
                        output: {
                            formId: FormId;
                            rules: {
                                description: string;
                                id: string;
                                kind: "unknown"
                                | "reveals"
                                | "requires"
                                | "one-of";
                                sourceAnnotationId: string;
                                targetAnnotationId: string;
                            }[];
                        };
                    },
                >;
            },
        >,
    > = ...

    Every procedure carries the formFillingEnabled org setting AND the formGenV2TemplatingFlow flag, then a resource gate: canAccessFormTemplate for reads that name a form, canEditFormTemplate for writes, the narrower canDeleteFormTemplate for delete. list, createUploadTarget and create name no existing form, so ctx.user scopes them. testFill reads a PATIENT's chart, so it carries canAccessPatient rather than a template gate. detectWithExtend and getExtendDetection are both EDIT-gated: they are one action, and the run is vendor state only its starter should read.