Adds a full "Deltains Claim" button next to Delta MA Claim, mirroring the DDMA claim flow across frontend, backend queue/routes, and a new Selenium worker. Reuses the existing Deltains eligibility login/OTP code and was iteratively wired against the live portal (patient roster search, per-service-line fields, tooth number/surface selects, review and submit). Also fixes chatbot/insurance-alias carrier recognition so "deltains" resolves correctly instead of falling back to MassHealth.
104 lines
3.2 KiB
TypeScript
104 lines
3.2 KiB
TypeScript
import { Router, Request, Response } from "express";
|
|
import { storage } from "../storage";
|
|
import { enqueueSeleniumJob } from "../queue/jobRunner";
|
|
import { forwardOtpToSeleniumDeltainsClaimAgent } from "../services/seleniumDeltainsClaimClient";
|
|
import { io } from "../socket";
|
|
|
|
const router = Router();
|
|
|
|
/**
|
|
* POST /deltains-claim
|
|
*
|
|
* Enqueues a Delta Dental Ins claim submission job.
|
|
*
|
|
* Body fields (JSON):
|
|
* data — claim payload (memberId, dateOfBirth, serviceDate, serviceLines, patientName, etc.)
|
|
* socketId — socket.io client id
|
|
* claimId — existing claim DB id (optional)
|
|
*
|
|
* Response: { status: "queued", jobId: "…" }
|
|
*/
|
|
router.post("/deltains-claim", 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 ?? req.body ?? {};
|
|
|
|
// Fetch Deltains credentials
|
|
const credentials = await storage.getInsuranceCredentialByUserAndSiteKey(
|
|
req.user.id,
|
|
"DELTAINS"
|
|
);
|
|
if (!credentials) {
|
|
return res.status(404).json({
|
|
error: "No Delta Dental Ins credentials found. Please add them on the Settings page.",
|
|
});
|
|
}
|
|
|
|
// Use provider from the claim form if set; fall back to Provider #1 (default)
|
|
const npiProviders = await storage.getNpiProvidersByUser(req.user.id);
|
|
const primaryProvider = npiProviders[0];
|
|
const providerName =
|
|
(claimData.npiProvider?.providerName as string | undefined)?.trim() ||
|
|
primaryProvider?.providerName ||
|
|
"";
|
|
|
|
const enrichedPayload = {
|
|
claim: {
|
|
...claimData,
|
|
deltainsUsername: credentials.username,
|
|
deltainsPassword: credentials.password,
|
|
providerName,
|
|
},
|
|
};
|
|
|
|
const socketId: string | undefined = req.body.socketId;
|
|
const claimId: number | undefined = claimData.claimId
|
|
? Number(claimData.claimId)
|
|
: undefined;
|
|
|
|
const jobId = enqueueSeleniumJob({
|
|
jobType: "deltains-claim-submit",
|
|
userId: req.user.id,
|
|
socketId,
|
|
enrichedPayload,
|
|
claimId,
|
|
});
|
|
|
|
return res.json({ status: "queued", jobId });
|
|
} catch (err: any) {
|
|
console.error("[deltains-claim route] error:", err);
|
|
return res.status(500).json({
|
|
error: err.message || "Failed to enqueue Deltains claim job",
|
|
});
|
|
}
|
|
});
|
|
|
|
/**
|
|
* POST /claims/deltains-claim/selenium/submit-otp
|
|
* Body: { session_id, otp, socketId? }
|
|
*/
|
|
router.post("/deltains-claim/selenium/submit-otp", async (req: Request, res: Response): Promise<any> => {
|
|
const { session_id: sessionId, otp, socketId } = req.body;
|
|
if (!sessionId || !otp) {
|
|
return res.status(400).json({ error: "session_id and otp are required" });
|
|
}
|
|
try {
|
|
const r = await forwardOtpToSeleniumDeltainsClaimAgent(sessionId, otp);
|
|
if (socketId && io) {
|
|
io.to(socketId).emit("selenium:otp_submitted", { session_id: sessionId });
|
|
}
|
|
return res.json(r);
|
|
} catch (err: any) {
|
|
console.error("[deltains-claim] submit-otp failed:", err?.message);
|
|
return res.status(500).json({ error: err?.message || "Failed to forward OTP" });
|
|
}
|
|
});
|
|
|
|
export default router;
|