- apps/Backend/src/queue/: connection, queues, workers, processors - apps/Frontend/src/hooks/use-job-status.ts: WebSocket job progress hook - apps/Frontend/src/lib/socket.ts: shared Socket.IO singleton Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
/**
|
|
* Processors for "claim-submit" and "claim-pre-auth" jobs.
|
|
* Mirrors routes/claims.ts /selenium-claim and /selenium-claim-pre-auth
|
|
*/
|
|
import { storage } from "../../storage";
|
|
import { startPythonJob, pollPythonJob } from "./_shared";
|
|
|
|
export interface ClaimSubmitProcessorInput {
|
|
enrichedPayload: any;
|
|
files: { originalname: string; bufferBase64: string; mimetype: string }[];
|
|
claimId?: number;
|
|
/** "claimsubmit" (default) or "claim-pre-auth" */
|
|
variant?: "claimsubmit" | "claim-pre-auth";
|
|
}
|
|
|
|
export interface ClaimSubmitProcessorResult {
|
|
status: string;
|
|
claimNumber?: string;
|
|
pdf_url?: string;
|
|
[key: string]: any;
|
|
}
|
|
|
|
export async function runClaimSubmitProcessor(
|
|
input: ClaimSubmitProcessorInput
|
|
): Promise<ClaimSubmitProcessorResult> {
|
|
const { enrichedPayload, files, claimId } = input;
|
|
|
|
// Build the same payload shape the Python /claimsubmit endpoint expects
|
|
const pdfs = files
|
|
.filter((f) => f.mimetype === "application/pdf")
|
|
.map(({ originalname, bufferBase64 }) => ({ originalname, bufferBase64 }));
|
|
|
|
const images = files
|
|
.filter((f) => f.mimetype.startsWith("image/"))
|
|
.map(({ originalname, bufferBase64 }) => ({ originalname, bufferBase64 }));
|
|
|
|
const payload = { claim: enrichedPayload, pdfs, images };
|
|
|
|
const endpoint =
|
|
input.variant === "claim-pre-auth" ? "/claim-pre-auth/async" : "/claimsubmit/async";
|
|
|
|
// 1) Start async Python job
|
|
const sid = await startPythonJob(endpoint, payload);
|
|
|
|
// 2) Poll for result
|
|
const result = await pollPythonJob(sid, 10 * 60 * 1000); // claim submit can take up to 10 min
|
|
|
|
// 3) Persist claimNumber if returned
|
|
if (result?.claimNumber && claimId) {
|
|
try {
|
|
await storage.updateClaim(claimId, { claimNumber: result.claimNumber });
|
|
} catch (e) {
|
|
console.error("[claimSubmitProcessor] failed to persist claimNumber:", e);
|
|
}
|
|
}
|
|
|
|
return { ...result, claimId };
|
|
}
|