feat: improve CCA preauth cell filling, implants category, preauth no recording
- Selenium: bulletproof Wait→Click→Clear→Type→Verify for tooth, billed amt cells - Selenium: fix billed amt to click td[23] (correct column) to trigger edit mode - Selenium: skip tentative date (auto-filled by page after tooth entry) - Frontend: add Implants category with Implant/Abut/Crown, Fixture, Abutment, Crown buttons (D6010/D6057/D6058) - Frontend: pdf-preview-modal renders PNG screenshots as <img> instead of PDF iframe - Backend: CCA preauth route creates claim record if none exists - Backend: CCA preauth processor saves authNumber into claimNumber column after submission Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
121
apps/Backend/src/routes/insuranceStatusCCAPreAuth.ts
Normal file
121
apps/Backend/src/routes/insuranceStatusCCAPreAuth.ts
Normal file
@@ -0,0 +1,121 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { storage } from "../storage";
|
||||
import { enqueueSeleniumJob } from "../queue/jobRunner";
|
||||
import multer from "multer";
|
||||
|
||||
const router = Router();
|
||||
const upload = multer({ storage: multer.memoryStorage() });
|
||||
|
||||
/**
|
||||
* POST /cca-preauth
|
||||
*
|
||||
* Enqueues a CCA pre-authorization submission job.
|
||||
* Accepts multipart/form-data with optional pdfs/images attachments.
|
||||
*
|
||||
* Body fields:
|
||||
* data — JSON string with preauth payload (memberId, dateOfBirth, serviceDate,
|
||||
* serviceLines, patientName, etc.)
|
||||
* socketId — socket.io client id
|
||||
* claimId — existing claim DB id (optional)
|
||||
*/
|
||||
router.post(
|
||||
"/cca-preauth",
|
||||
upload.fields([
|
||||
{ name: "pdfs", maxCount: 10 },
|
||||
{ name: "images", maxCount: 10 },
|
||||
]),
|
||||
async (req: Request, res: Response): Promise<any> => {
|
||||
if (!req.user?.id) {
|
||||
return res.status(401).json({ error: "Unauthorized: user info missing" });
|
||||
}
|
||||
|
||||
try {
|
||||
const claimData =
|
||||
typeof req.body.data === "string"
|
||||
? JSON.parse(req.body.data)
|
||||
: req.body.data ?? {};
|
||||
|
||||
const pdfs =
|
||||
(req.files as Record<string, Express.Multer.File[]>)?.pdfs ?? [];
|
||||
const images =
|
||||
(req.files as Record<string, Express.Multer.File[]>)?.images ?? [];
|
||||
|
||||
const credentials = await storage.getInsuranceCredentialByUserAndSiteKey(
|
||||
req.user.id,
|
||||
"CCA"
|
||||
);
|
||||
if (!credentials) {
|
||||
return res.status(404).json({
|
||||
error: "No CCA credentials found. Please add them on the Settings page.",
|
||||
});
|
||||
}
|
||||
|
||||
const filesForQueue = [...pdfs, ...images].map((f) => ({
|
||||
originalname: f.originalname,
|
||||
bufferBase64: f.buffer.toString("base64"),
|
||||
mimetype: f.mimetype,
|
||||
}));
|
||||
|
||||
const enrichedPayload = {
|
||||
claim: {
|
||||
...claimData,
|
||||
cca_username: credentials.username,
|
||||
cca_password: credentials.password,
|
||||
},
|
||||
files: filesForQueue,
|
||||
};
|
||||
|
||||
const socketId: string | undefined = req.body.socketId;
|
||||
let claimId: number | undefined = claimData.claimId
|
||||
? Number(claimData.claimId)
|
||||
: undefined;
|
||||
|
||||
// Create a PREAUTH claim record so authNumber can be stored in claimNumber column
|
||||
if (!claimId && claimData.patientId) {
|
||||
try {
|
||||
const serviceDate = claimData.serviceDate
|
||||
? new Date(claimData.serviceDate)
|
||||
: new Date();
|
||||
const dob = claimData.dateOfBirth
|
||||
? new Date(claimData.dateOfBirth)
|
||||
: new Date("2000-01-01");
|
||||
const record = await storage.createClaim({
|
||||
patientId: Number(claimData.patientId),
|
||||
appointmentId: claimData.appointmentId ? Number(claimData.appointmentId) : null,
|
||||
userId: req.user.id,
|
||||
staffId: Number(claimData.staffId) || 1,
|
||||
patientName: claimData.patientName || "",
|
||||
memberId: claimData.memberId || "",
|
||||
dateOfBirth: dob,
|
||||
remarks: claimData.remarks || "",
|
||||
missingTeethStatus: claimData.missingTeethStatus || "No_missing",
|
||||
serviceDate,
|
||||
insuranceProvider: "CCA",
|
||||
status: "PREAUTH",
|
||||
} as any);
|
||||
claimId = record.id;
|
||||
console.log(`[cca-preauth route] created claim record id=${claimId}`);
|
||||
} catch (e: any) {
|
||||
console.error("[cca-preauth route] failed to create claim record:", e?.message);
|
||||
}
|
||||
}
|
||||
|
||||
const jobId = enqueueSeleniumJob({
|
||||
jobType: "cca-preauth-submit",
|
||||
userId: req.user.id,
|
||||
socketId,
|
||||
enrichedPayload,
|
||||
claimId,
|
||||
});
|
||||
|
||||
return res.json({ status: "queued", jobId });
|
||||
} catch (err: any) {
|
||||
console.error("[cca-preauth route] error:", err);
|
||||
return res.status(500).json({
|
||||
error: err.message || "Failed to enqueue CCA preauth job",
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user