feat: DDMA claim submission with OTP, PDF, claim number extraction
- Add full DDMA claim Selenium flow (steps 1-8): search patient, open member page, create claim, fill form, attach files, next, submit, extract claim number and save confirmation PDF - Add fee schedule price-mismatch dialog for all claim buttons (MH, CCA, DDMA, United, Tufts, Save) with optional price update to JSON - Add OTP modal for DDMA claim when session expires, mirroring eligibility OTP flow - Close Chrome after claim submission via quit_driver() (session preserved in profile) - Move Map Price button between Direct Submission and procedure table, right-aligned above Billed Amount column - Add fee-schedule update-price backend route - Add DDMA claim processor with claimNumber/pdf_url result handling Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
5ceecbeb7f
commit
cd1381e9c6
@@ -33,6 +33,7 @@ import {
|
||||
import ClaimDocumentsUploadMultiple from "@/components/claims/claim-document-upload-modal";
|
||||
import { QK_PATIENTS_BASE } from "@/components/patients/patient-table";
|
||||
import { PdfPreviewModal } from "@/components/insurance-status/pdf-preview-modal";
|
||||
import { socket } from "@/lib/socket";
|
||||
|
||||
export default function ClaimsPage() {
|
||||
const [isClaimFormOpen, setIsClaimFormOpen] = useState(false);
|
||||
@@ -54,6 +55,10 @@ export default function ClaimsPage() {
|
||||
|
||||
// Track pending selenium jobs so we can react to completion via socket
|
||||
const [pendingClaimJobId, setPendingClaimJobId] = useState<string | null>(null);
|
||||
// DDMA claim OTP modal
|
||||
const [ddmaClaimOtpOpen, setDdmaClaimOtpOpen] = useState(false);
|
||||
const [ddmaClaimOtpSubmitting, setDdmaClaimOtpSubmitting] = useState(false);
|
||||
const ddmaClaimSessionIdRef = useRef<string | null>(null);
|
||||
const pendingClaimMeta = useRef<{
|
||||
patientId: number | null;
|
||||
groupKey: "INSURANCE_CLAIM" | "INSURANCE_CLAIM_PREAUTH";
|
||||
@@ -454,6 +459,73 @@ export default function ClaimsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
// DDMA claim OTP submit handler
|
||||
const handleDdmaClaimOtpSubmit = async (otp: string) => {
|
||||
const sessionId = ddmaClaimSessionIdRef.current;
|
||||
if (!sessionId) return;
|
||||
try {
|
||||
setDdmaClaimOtpSubmitting(true);
|
||||
const resp = await apiRequest("POST", "/api/claims/ddma-claim/selenium/submit-otp", {
|
||||
session_id: sessionId,
|
||||
otp,
|
||||
socketId,
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (!resp.ok || data.error) throw new Error(data.error || "Failed to submit OTP");
|
||||
setDdmaClaimOtpOpen(false);
|
||||
dispatch(setTaskStatus({ key: "claimSubmit", status: "pending", message: "OTP submitted. Continuing DDMA claim..." }));
|
||||
} catch (err: any) {
|
||||
toast({ title: "Failed to submit OTP", description: err?.message || "Error submitting OTP", variant: "destructive" });
|
||||
} finally {
|
||||
setDdmaClaimOtpSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
// DDMA claim selenium handler
|
||||
const handleDDMAClaimSubmitSelenium = async (data: any) => {
|
||||
try {
|
||||
dispatch(setTaskStatus({ key: "claimSubmit", status: "pending", message: "Submitting Delta MA claim..." }));
|
||||
const response = await apiRequest("POST", "/api/claims/ddma-claim", {
|
||||
data,
|
||||
socketId,
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.error) throw new Error(result.error);
|
||||
pendingClaimMeta.current = { patientId: selectedPatientId, groupKey: "INSURANCE_CLAIM" };
|
||||
setPendingClaimJobId(result.jobId);
|
||||
|
||||
// Listen for session_id so we can forward OTP if needed
|
||||
const jobId = result.jobId;
|
||||
const onSessionStarted = (ev: any) => {
|
||||
if (String(ev?.jobId) !== String(jobId)) return;
|
||||
ddmaClaimSessionIdRef.current = ev.session_id ?? null;
|
||||
};
|
||||
const onOtpRequired = (ev: any) => {
|
||||
if (String(ev?.jobId) !== String(jobId)) return;
|
||||
if (ev.session_id) ddmaClaimSessionIdRef.current = ev.session_id;
|
||||
setDdmaClaimOtpOpen(true);
|
||||
dispatch(setTaskStatus({ key: "claimSubmit", status: "pending", message: "OTP required for Delta MA. Please enter the code." }));
|
||||
};
|
||||
const onDone = (ev: any) => {
|
||||
if (String(ev?.jobId) !== String(jobId)) return;
|
||||
socket.off("selenium:ddma_claim_started", onSessionStarted);
|
||||
socket.off("selenium:otp_required", onOtpRequired);
|
||||
socket.off("job:update", onDone);
|
||||
setDdmaClaimOtpOpen(false);
|
||||
ddmaClaimSessionIdRef.current = null;
|
||||
};
|
||||
socket.on("selenium:ddma_claim_started", onSessionStarted);
|
||||
socket.on("selenium:otp_required", onOtpRequired);
|
||||
socket.on("job:update", onDone);
|
||||
|
||||
dispatch(setTaskStatus({ key: "claimSubmit", status: "pending", message: "Delta MA claim queued. Awaiting Selenium..." }));
|
||||
toast({ title: "Delta MA Claim queued", description: "Selenium is opening the claim form.", variant: "default" });
|
||||
} catch (error: any) {
|
||||
dispatch(setTaskStatus({ key: "claimSubmit", status: "error", message: error.message || "Delta MA claim failed" }));
|
||||
toast({ title: "Delta MA Claim error", description: error.message || "An error occurred.", variant: "destructive" });
|
||||
}
|
||||
};
|
||||
|
||||
// CCA pre-auth selenium handler
|
||||
const handleCCAPreAuthSubmitSelenium = async (data: any) => {
|
||||
const formData = new FormData();
|
||||
@@ -518,6 +590,7 @@ export default function ClaimsPage() {
|
||||
|
||||
const isPreAuth = groupTitleKey === "INSURANCE_CLAIM_PREAUTH";
|
||||
const preAuthNumber = data.preAuthNumber ?? data.result?.preAuthNumber ?? null;
|
||||
const claimNumberForToast = data.claimNumber ?? null;
|
||||
|
||||
dispatch(
|
||||
setTaskStatus({
|
||||
@@ -525,7 +598,9 @@ export default function ClaimsPage() {
|
||||
status: "success",
|
||||
message: isPreAuth
|
||||
? `PreAuth submitted & PDF saved.${preAuthNumber ? ` PreAuth #: ${preAuthNumber}` : ""}`
|
||||
: "Claim submitted & PDF downloaded successfully.",
|
||||
: claimNumberForToast
|
||||
? `Claim submitted — Claim #: ${claimNumberForToast}`
|
||||
: "Claim submitted & PDF downloaded successfully.",
|
||||
})
|
||||
);
|
||||
|
||||
@@ -535,7 +610,9 @@ export default function ClaimsPage() {
|
||||
? preAuthNumber
|
||||
? `PreAuth Number: ${preAuthNumber} — PDF saved to Documents.`
|
||||
: "PreAuth submitted! PDF saved to Documents page."
|
||||
: "Claim submitted successfully! PDF saved to Documents page.",
|
||||
: claimNumberForToast
|
||||
? `Claim #: ${claimNumberForToast} — PDF saved to Documents.`
|
||||
: "Claim submitted successfully! PDF saved to Documents page.",
|
||||
duration: isPreAuth ? 10000 : 5000,
|
||||
});
|
||||
|
||||
@@ -695,6 +772,7 @@ export default function ClaimsPage() {
|
||||
onHandleForMHSeleniumClaimPreAuth={handleMHClaimPreAuthSubmitSelenium}
|
||||
onHandleForCCASeleniumClaim={handleCCAClaimSubmitSelenium}
|
||||
onHandleForCCASeleniumPreAuth={handleCCAPreAuthSubmitSelenium}
|
||||
onHandleForDDMASeleniumClaim={handleDDMAClaimSubmitSelenium}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -709,6 +787,45 @@ export default function ClaimsPage() {
|
||||
pdfId={previewPdfId}
|
||||
fallbackFilename={previewFallbackFilename}
|
||||
/>
|
||||
|
||||
{/* DDMA Claim OTP Modal */}
|
||||
{ddmaClaimOtpOpen && (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40">
|
||||
<div className="bg-white dark:bg-slate-900 rounded-xl shadow-lg w-full max-w-md p-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h2 className="text-lg font-semibold">Enter OTP — Delta MA Claim</h2>
|
||||
<button type="button" onClick={() => setDdmaClaimOtpOpen(false)} className="text-slate-500 hover:text-slate-800">✕</button>
|
||||
</div>
|
||||
<p className="text-sm text-slate-500 mb-4">
|
||||
The Delta Dental MA portal requires a one-time password (OTP) to continue claim submission.
|
||||
</p>
|
||||
<form onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
const input = (e.currentTarget.elements.namedItem("otp") as HTMLInputElement);
|
||||
if (input?.value.trim()) handleDdmaClaimOtpSubmit(input.value.trim());
|
||||
}} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<label htmlFor="ddma-claim-otp" className="text-sm font-medium">OTP</label>
|
||||
<input
|
||||
id="ddma-claim-otp"
|
||||
name="otp"
|
||||
placeholder="Enter OTP code"
|
||||
autoFocus
|
||||
className="w-full border rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-end gap-3">
|
||||
<button type="button" onClick={() => setDdmaClaimOtpOpen(false)} disabled={ddmaClaimOtpSubmitting}
|
||||
className="px-4 py-2 text-sm border rounded-md hover:bg-slate-50 disabled:opacity-50">Cancel</button>
|
||||
<button type="submit" disabled={ddmaClaimOtpSubmitting}
|
||||
className="px-4 py-2 text-sm bg-primary text-white rounded-md hover:bg-primary/90 disabled:opacity-50">
|
||||
{ddmaClaimOtpSubmitting ? "Submitting..." : "Submit OTP"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user