feat: add Deltains claim submission flow
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.
This commit is contained in:
@@ -98,6 +98,7 @@ interface ClaimFormProps {
|
||||
onHandleForUnitedDHSeleniumPreAuth: (data: ClaimPreAuthData) => void;
|
||||
onHandleForTuftsSCOSeleniumPreAuth: (data: ClaimPreAuthData) => void;
|
||||
onHandleForDDMASeleniumClaim: (data: ClaimFormData) => void;
|
||||
onHandleForDeltainsSeleniumClaim: (data: ClaimFormData) => void;
|
||||
onHandleForUnitedDHSeleniumClaim: (data: ClaimFormData) => void;
|
||||
onHandleForTuftsSCOSeleniumClaim: (data: ClaimFormData) => void;
|
||||
onHandleForUnitedUcardSeleniumClaim: (data: ClaimFormData) => void;
|
||||
@@ -121,6 +122,7 @@ export function ClaimForm({
|
||||
onHandleForUnitedDHSeleniumPreAuth,
|
||||
onHandleForTuftsSCOSeleniumPreAuth,
|
||||
onHandleForDDMASeleniumClaim,
|
||||
onHandleForDeltainsSeleniumClaim,
|
||||
onHandleForUnitedDHSeleniumClaim,
|
||||
onHandleForTuftsSCOSeleniumClaim,
|
||||
onHandleForUnitedUcardSeleniumClaim,
|
||||
@@ -1257,6 +1259,73 @@ export function ClaimForm({
|
||||
onClose();
|
||||
};
|
||||
|
||||
// Deltains Claim: saves to DB then submits via Selenium
|
||||
const handleDeltainsClaim = async (formToUse?: ClaimFormData & { uploadedFiles?: File[] }) => {
|
||||
const f = formToUse ?? form;
|
||||
const missingFields: string[] = [];
|
||||
if (!f.memberId?.trim()) missingFields.push("Member ID");
|
||||
if (!f.dateOfBirth?.trim()) missingFields.push("Date of Birth");
|
||||
if (!patient?.firstName?.trim()) missingFields.push("First Name");
|
||||
if (missingFields.length > 0) {
|
||||
toast({
|
||||
title: "Missing Required Fields",
|
||||
description: `Please fill out the following field(s): ${missingFields.join(", ")}`,
|
||||
variant: "destructive",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const filteredServiceLines = (f.serviceLines || []).filter(
|
||||
(line) => (line.procedureCode ?? "").trim() !== "",
|
||||
);
|
||||
if (filteredServiceLines.length === 0) {
|
||||
toast({
|
||||
title: "No procedure codes",
|
||||
description: "Please add at least one procedure code before submitting the claim.",
|
||||
variant: "destructive",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const appointmentIdToUse = appointmentId ?? null;
|
||||
|
||||
const { uploadedFiles, insuranceSiteKey, npiProvider, ...formToCreateClaim } = f;
|
||||
|
||||
// Upload files to server so we get local filePaths for Selenium
|
||||
const claimFilesMeta: ClaimFileMeta[] = mergeWithExistingAttachments(
|
||||
uploadedFiles?.length ? await uploadAttachmentsToLocalFolder(uploadedFiles) : [],
|
||||
);
|
||||
|
||||
const selectedNpiProviderId = npiProvider?.npiNumber
|
||||
? npiProviders.find((p) => p.npiNumber === npiProvider.npiNumber)?.id ?? null
|
||||
: null;
|
||||
|
||||
const createdClaim = await onSubmit({
|
||||
...formToCreateClaim,
|
||||
serviceLines: filteredServiceLines,
|
||||
staffId: appointmentStaffId ?? Number(staff?.id),
|
||||
patientId,
|
||||
insuranceProvider: "Delta Dental Ins",
|
||||
appointmentId: appointmentIdToUse,
|
||||
claimFiles: claimFilesMeta,
|
||||
...(selectedNpiProviderId ? { npiProviderId: selectedNpiProviderId } : {}),
|
||||
});
|
||||
|
||||
onHandleForDeltainsSeleniumClaim({
|
||||
...f,
|
||||
serviceLines: filteredServiceLines,
|
||||
staffId: appointmentStaffId ?? Number(staff?.id),
|
||||
patientId,
|
||||
insuranceProvider: "Delta Dental Ins",
|
||||
appointmentId: appointmentIdToUse,
|
||||
insuranceSiteKey: "DELTAINS",
|
||||
claimId: createdClaim.id,
|
||||
claimFiles: claimFilesMeta,
|
||||
});
|
||||
|
||||
onClose();
|
||||
};
|
||||
|
||||
// United/DentalHub Claim: saves to DB then submits via Selenium
|
||||
const handleUnitedDHClaim = async (formToUse?: ClaimFormData & { uploadedFiles?: File[] }) => {
|
||||
const f = formToUse ?? form;
|
||||
@@ -1483,6 +1552,8 @@ export function ClaimForm({
|
||||
runWithPriceCheck(handleCCAClaim);
|
||||
} else if (siteKey === "DDMA") {
|
||||
runWithPriceCheck(handleDDMAClaim);
|
||||
} else if (siteKey === "DELTAINS" || siteKey === "DELTA_INS") {
|
||||
runWithPriceCheck(handleDeltainsClaim);
|
||||
} else if (siteKey === "TUFTSSCO" || siteKey === "TUFTS_SCO") {
|
||||
runWithPriceCheck(handleTuftsSCOClaim);
|
||||
} else if (siteKey === "UNITEDSCO" || siteKey === "UNITEDDH" || siteKey === "UNITED_SCO") {
|
||||
@@ -1954,6 +2025,8 @@ export function ClaimForm({
|
||||
handleCCAClaim(pricedForm);
|
||||
} else if (key === "ddma") {
|
||||
handleDDMAClaim(pricedForm);
|
||||
} else if (key === "deltains" || key === "delta_ins") {
|
||||
handleDeltainsClaim(pricedForm);
|
||||
} else if (key === "united_sco" || key === "unitedco" || key === "dentalhub") {
|
||||
handleUnitedDHClaim(pricedForm);
|
||||
} else if (key === "united_ucard" || key === "uniteducard" || key === "ucard") {
|
||||
@@ -2591,6 +2664,14 @@ export function ClaimForm({
|
||||
>
|
||||
Delta MA Claim
|
||||
</Button>
|
||||
<Button
|
||||
className="w-36 bg-indigo-600 hover:bg-indigo-700 text-white"
|
||||
onClick={() => runWithPriceCheck(handleDeltainsClaim)}
|
||||
disabled={!isLicensed}
|
||||
title={!isLicensed ? "License required" : undefined}
|
||||
>
|
||||
Deltains Claim
|
||||
</Button>
|
||||
<Button
|
||||
className="w-44 bg-orange-600 hover:bg-orange-700 text-white"
|
||||
onClick={() => runWithPriceCheck(handleUnitedDHClaim)}
|
||||
|
||||
@@ -136,7 +136,7 @@ function mdyToISO(mdy: string): string {
|
||||
const INSURANCE_TYPE_OPTIONS: { value: string; label: string }[] = [
|
||||
{ value: "mh", label: "MassHealth" },
|
||||
{ value: "ddma", label: "DDMA" },
|
||||
{ value: "delta-ins", label: "Delta Dental" },
|
||||
{ value: "delta-ins", label: "Deltains" },
|
||||
{ value: "united-sco", label: "United SCO" },
|
||||
{ value: "united-ucard", label: "United Ucard" },
|
||||
{ value: "tufts-sco", label: "Tufts SCO" },
|
||||
|
||||
@@ -76,6 +76,10 @@ export default function ClaimsPage() {
|
||||
const [ddmaClaimOtpOpen, setDdmaClaimOtpOpen] = useState(false);
|
||||
const [ddmaClaimOtpSubmitting, setDdmaClaimOtpSubmitting] = useState(false);
|
||||
const ddmaClaimSessionIdRef = useRef<string | null>(null);
|
||||
// Deltains claim OTP modal
|
||||
const [deltainsClaimOtpOpen, setDeltainsClaimOtpOpen] = useState(false);
|
||||
const [deltainsClaimOtpSubmitting, setDeltainsClaimOtpSubmitting] = useState(false);
|
||||
const deltainsClaimSessionIdRef = useRef<string | null>(null);
|
||||
const [unitedDHClaimOtpOpen, setUnitedDHClaimOtpOpen] = useState(false);
|
||||
const [unitedDHClaimOtpSubmitting, setUnitedDHClaimOtpSubmitting] = useState(false);
|
||||
const unitedDHClaimSessionIdRef = useRef<string | null>(null);
|
||||
@@ -645,6 +649,73 @@ export default function ClaimsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
// Deltains claim OTP submit handler
|
||||
const handleDeltainsClaimOtpSubmit = async (otp: string) => {
|
||||
const sessionId = deltainsClaimSessionIdRef.current;
|
||||
if (!sessionId) return;
|
||||
try {
|
||||
setDeltainsClaimOtpSubmitting(true);
|
||||
const resp = await apiRequest("POST", "/api/claims/deltains-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");
|
||||
setDeltainsClaimOtpOpen(false);
|
||||
dispatch(setTaskStatus({ key: "claimSubmit", status: "pending", message: "OTP submitted. Continuing Deltains claim..." }));
|
||||
} catch (err: any) {
|
||||
toast({ title: "Failed to submit OTP", description: err?.message || "Error submitting OTP", variant: "destructive" });
|
||||
} finally {
|
||||
setDeltainsClaimOtpSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Deltains claim selenium handler
|
||||
const handleDeltainsClaimSubmitSelenium = async (data: any) => {
|
||||
try {
|
||||
dispatch(setTaskStatus({ key: "claimSubmit", status: "pending", message: "Submitting Deltains claim..." }));
|
||||
const response = await apiRequest("POST", "/api/claims/deltains-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;
|
||||
deltainsClaimSessionIdRef.current = ev.session_id ?? null;
|
||||
};
|
||||
const onOtpRequired = (ev: any) => {
|
||||
if (String(ev?.jobId) !== String(jobId)) return;
|
||||
if (ev.session_id) deltainsClaimSessionIdRef.current = ev.session_id;
|
||||
setDeltainsClaimOtpOpen(true);
|
||||
dispatch(setTaskStatus({ key: "claimSubmit", status: "pending", message: "OTP required for Deltains. Please enter the code." }));
|
||||
};
|
||||
const onDone = (ev: any) => {
|
||||
if (String(ev?.jobId) !== String(jobId)) return;
|
||||
socket.off("selenium:deltains_claim_started", onSessionStarted);
|
||||
socket.off("selenium:otp_required", onOtpRequired);
|
||||
socket.off("job:update", onDone);
|
||||
setDeltainsClaimOtpOpen(false);
|
||||
deltainsClaimSessionIdRef.current = null;
|
||||
};
|
||||
socket.on("selenium:deltains_claim_started", onSessionStarted);
|
||||
socket.on("selenium:otp_required", onOtpRequired);
|
||||
socket.on("job:update", onDone);
|
||||
|
||||
dispatch(setTaskStatus({ key: "claimSubmit", status: "pending", message: "Deltains claim queued. Awaiting Selenium..." }));
|
||||
toast({ title: "Deltains Claim queued", description: "Selenium is opening the claim form.", variant: "default" });
|
||||
} catch (error: any) {
|
||||
dispatch(setTaskStatus({ key: "claimSubmit", status: "error", message: error.message || "Deltains claim failed" }));
|
||||
toast({ title: "Deltains Claim error", description: error.message || "An error occurred.", variant: "destructive" });
|
||||
}
|
||||
};
|
||||
|
||||
const handleUnitedDHClaimOtpSubmit = async (otp: string) => {
|
||||
const sessionId = unitedDHClaimSessionIdRef.current;
|
||||
if (!sessionId) return;
|
||||
@@ -1358,6 +1429,7 @@ export default function ClaimsPage() {
|
||||
onHandleForCCASeleniumPreAuth={handleCCAPreAuthSubmitSelenium}
|
||||
onHandleForUnitedDHSeleniumPreAuth={handleUnitedDHPreAuthSubmitSelenium}
|
||||
onHandleForDDMASeleniumClaim={handleDDMAClaimSubmitSelenium}
|
||||
onHandleForDeltainsSeleniumClaim={handleDeltainsClaimSubmitSelenium}
|
||||
onHandleForUnitedDHSeleniumClaim={handleUnitedDHClaimSubmitSelenium}
|
||||
onHandleForTuftsSCOSeleniumPreAuth={handleTuftsSCOPreAuthSubmitSelenium}
|
||||
onHandleForTuftsSCOSeleniumClaim={handleTuftsSCOClaimSubmitSelenium}
|
||||
@@ -1417,6 +1489,45 @@ export default function ClaimsPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Deltains Claim OTP Modal */}
|
||||
{deltainsClaimOtpOpen && (
|
||||
<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 — Deltains Claim</h2>
|
||||
<button type="button" onClick={() => setDeltainsClaimOtpOpen(false)} className="text-slate-500 hover:text-slate-800">✕</button>
|
||||
</div>
|
||||
<p className="text-sm text-slate-500 mb-4">
|
||||
The Delta Dental Ins 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()) handleDeltainsClaimOtpSubmit(input.value.trim());
|
||||
}} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<label htmlFor="deltains-claim-otp" className="text-sm font-medium">OTP</label>
|
||||
<input
|
||||
id="deltains-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={() => setDeltainsClaimOtpOpen(false)} disabled={deltainsClaimOtpSubmitting}
|
||||
className="px-4 py-2 text-sm border rounded-md hover:bg-slate-50 disabled:opacity-50">Cancel</button>
|
||||
<button type="submit" disabled={deltainsClaimOtpSubmitting}
|
||||
className="px-4 py-2 text-sm bg-primary text-white rounded-md hover:bg-primary/90 disabled:opacity-50">
|
||||
{deltainsClaimOtpSubmitting ? "Submitting..." : "Submit OTP"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Tufts SCO Claim OTP Modal */}
|
||||
{tuftsSCOClaimOtpOpen && (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40">
|
||||
|
||||
Reference in New Issue
Block a user