feat: add United Ucard claim worker and fix batch-column site-key routing

Adds a "United Ucard Claim" button (claims/preauth insurance form) that
submits through a full Selenium pipeline mirroring the Tufts SCO claim
worker: frontend handler -> backend route/queue processor -> Python
agent, reusing the persistent login/OTP session from the existing
United Ucard eligibility check. Implements the UHC Dental claim wizard
end-to-end (Provider Information, Patient Information search/select,
Claim Information procedures + questions, Upload Documents, Review and
Sign, Submit); the final confirmation-page PDF/claim-number capture is
still a TODO stub pending that page's DOM.

Also wires United Ucard into the AI chatbot's eligibility flow
(insuranceAliases.json, siteKeyToAutoCheck, clarification options), and
fixes a bug where the AI-column batch claim feature silently defaulted
United Ucard patients to MassHealth because batchColumnDeriveSiteKey
had no matching branch and no job-dispatch case for UNITED_UCARD.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-14 23:27:39 -04:00
co-authored by Claude Sonnet 5
parent f30016e674
commit e570a0aa13
15 changed files with 1695 additions and 2 deletions
@@ -100,6 +100,7 @@ interface ClaimFormProps {
onHandleForDDMASeleniumClaim: (data: ClaimFormData) => void;
onHandleForUnitedDHSeleniumClaim: (data: ClaimFormData) => void;
onHandleForTuftsSCOSeleniumClaim: (data: ClaimFormData) => void;
onHandleForUnitedUcardSeleniumClaim: (data: ClaimFormData) => void;
onClose: () => void;
isLicensed?: boolean;
}
@@ -122,6 +123,7 @@ export function ClaimForm({
onHandleForDDMASeleniumClaim,
onHandleForUnitedDHSeleniumClaim,
onHandleForTuftsSCOSeleniumClaim,
onHandleForUnitedUcardSeleniumClaim,
onSubmit,
onClose,
isLicensed = false,
@@ -804,6 +806,7 @@ export function ClaimForm({
if (p.includes("delta ins") || p === "deltains") return "DeltaIns";
if (p.includes("tufts") || p.includes("dentaquest") || p === "tuftssco") return "TuftsSCO";
if ((p.includes("united") && p.includes("sco")) || p === "unitedsco") return "UnitedSCO";
if (p.includes("ucard") || p.includes("onehealthcareid") || p.includes("one healthcare id")) return "UnitedUcard";
if (p.includes("bcbs") || p.includes("blue cross")) return "BCBS";
if (p.includes("united aapr") || p === "unitedaapr") return "UnitedAAPR";
if (p.includes("aetna")) return "Aetna";
@@ -1396,6 +1399,82 @@ export function ClaimForm({
onClose();
};
// United Ucard Claim: saves to DB then submits via Selenium
const handleUnitedUcardClaim = 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;
const claimFilesMeta: ClaimFileMeta[] = mergeWithExistingAttachments(
uploadedFiles?.length ? await uploadAttachmentsToLocalFolder(uploadedFiles) : [],
);
const selectedNpiProviderId = npiProvider?.npiNumber
? npiProviders.find((p) => p.npiNumber === npiProvider.npiNumber)?.id ?? null
: null;
let createdClaim: any;
try {
createdClaim = await onSubmit({
...formToCreateClaim,
serviceLines: filteredServiceLines,
staffId: appointmentStaffId ?? Number(staff?.id),
patientId,
insuranceProvider: "United Ucard",
appointmentId: appointmentIdToUse,
claimFiles: claimFilesMeta,
...(selectedNpiProviderId ? { npiProviderId: selectedNpiProviderId } : {}),
});
} catch (err: any) {
toast({
title: "Failed to save claim",
description: err?.message || "An error occurred saving the claim.",
variant: "destructive",
});
return;
}
onHandleForUnitedUcardSeleniumClaim({
...f,
serviceLines: filteredServiceLines,
staffId: appointmentStaffId ?? Number(staff?.id),
patientId,
insuranceProvider: "United Ucard",
appointmentId: appointmentIdToUse,
insuranceSiteKey: "UNITED_UCARD",
claimId: createdClaim.id,
claimFiles: claimFilesMeta,
});
onClose();
};
const handleClaimAll = () => {
const siteKey = (form.insuranceSiteKey || deriveInsuranceSiteKey(form.insuranceProvider || "")).toUpperCase();
if (siteKey === "MH" || siteKey === "MASSHEALTH") {
@@ -2524,6 +2603,14 @@ export function ClaimForm({
>
Tufts Claim
</Button>
<Button
className="w-40 bg-cyan-600 hover:bg-cyan-700 text-white"
onClick={() => runWithPriceCheck(handleUnitedUcardClaim)}
disabled={!isLicensed}
title={!isLicensed ? "License required" : undefined}
>
United Ucard Claim
</Button>
<Button
className="w-36 bg-emerald-600 hover:bg-emerald-700 text-white"
onClick={() => runWithPriceCheck(handleClaimSaved)}
@@ -138,6 +138,7 @@ const INSURANCE_TYPE_OPTIONS: { value: string; label: string }[] = [
{ value: "ddma", label: "DDMA" },
{ value: "delta-ins", label: "Delta Dental" },
{ value: "united-sco", label: "United SCO" },
{ value: "united-ucard", label: "United Ucard" },
{ value: "tufts-sco", label: "Tufts SCO" },
{ value: "cca", label: "CCA" },
];
+108
View File
@@ -85,6 +85,9 @@ export default function ClaimsPage() {
const [tuftsSCOClaimOtpOpen, setTuftsSCOClaimOtpOpen] = useState(false);
const [tuftsSCOClaimOtpSubmitting, setTuftsSCOClaimOtpSubmitting] = useState(false);
const tuftsSCOClaimSessionIdRef = useRef<string | null>(null);
const [unitedUcardClaimOtpOpen, setUnitedUcardClaimOtpOpen] = useState(false);
const [unitedUcardClaimOtpSubmitting, setUnitedUcardClaimOtpSubmitting] = useState(false);
const unitedUcardClaimSessionIdRef = useRef<string | null>(null);
const [tuftsSCOPreAuthOtpOpen, setTuftsSCOPreAuthOtpOpen] = useState(false);
const [tuftsSCOPreAuthOtpSubmitting, setTuftsSCOPreAuthOtpSubmitting] = useState(false);
const tuftsSCOPreAuthSessionIdRef = useRef<string | null>(null);
@@ -902,6 +905,71 @@ export default function ClaimsPage() {
}
};
const handleUnitedUcardClaimOtpSubmit = async (otp: string) => {
const sessionId = unitedUcardClaimSessionIdRef.current;
if (!sessionId) return;
try {
setUnitedUcardClaimOtpSubmitting(true);
const resp = await apiRequest("POST", "/api/claims/uniteducard-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");
setUnitedUcardClaimOtpOpen(false);
dispatch(setTaskStatus({ key: "claimSubmit", status: "pending", message: "OTP submitted. Continuing United Ucard claim..." }));
} catch (err: any) {
toast({ title: "Failed to submit OTP", description: err?.message || "Error submitting OTP", variant: "destructive" });
} finally {
setUnitedUcardClaimOtpSubmitting(false);
}
};
// United Ucard claim selenium handler
const handleUnitedUcardClaimSubmitSelenium = async (data: any) => {
try {
dispatch(setTaskStatus({ key: "claimSubmit", status: "pending", message: "Submitting United Ucard claim..." }));
const response = await apiRequest("POST", "/api/claims/uniteducard-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);
const jobId = result.jobId;
const onSessionStarted = (ev: any) => {
if (String(ev?.jobId) !== String(jobId)) return;
unitedUcardClaimSessionIdRef.current = ev.session_id ?? null;
};
const onOtpRequired = (ev: any) => {
if (String(ev?.jobId) !== String(jobId)) return;
if (ev.session_id) unitedUcardClaimSessionIdRef.current = ev.session_id;
setUnitedUcardClaimOtpOpen(true);
dispatch(setTaskStatus({ key: "claimSubmit", status: "pending", message: "OTP required for United Ucard. Please enter the code." }));
};
const onDone = (ev: any) => {
if (String(ev?.jobId) !== String(jobId)) return;
socket.off("selenium:uniteducard_claim_started", onSessionStarted);
socket.off("selenium:otp_required", onOtpRequired);
socket.off("job:update", onDone);
setUnitedUcardClaimOtpOpen(false);
unitedUcardClaimSessionIdRef.current = null;
};
socket.on("selenium:uniteducard_claim_started", onSessionStarted);
socket.on("selenium:otp_required", onOtpRequired);
socket.on("job:update", onDone);
dispatch(setTaskStatus({ key: "claimSubmit", status: "pending", message: "United Ucard claim queued. Awaiting Selenium..." }));
toast({ title: "United Ucard Claim queued", description: "Selenium is opening the claim form.", variant: "default" });
} catch (error: any) {
dispatch(setTaskStatus({ key: "claimSubmit", status: "error", message: error.message || "United Ucard claim failed" }));
toast({ title: "United Ucard Claim error", description: error.message || "An error occurred.", variant: "destructive" });
}
};
// CCA pre-auth selenium handler
const handleCCAPreAuthSubmitSelenium = async (data: any) => {
const formData = new FormData();
@@ -1293,6 +1361,7 @@ export default function ClaimsPage() {
onHandleForUnitedDHSeleniumClaim={handleUnitedDHClaimSubmitSelenium}
onHandleForTuftsSCOSeleniumPreAuth={handleTuftsSCOPreAuthSubmitSelenium}
onHandleForTuftsSCOSeleniumClaim={handleTuftsSCOClaimSubmitSelenium}
onHandleForUnitedUcardSeleniumClaim={handleUnitedUcardClaimSubmitSelenium}
isLicensed={isLicensed}
/>
)}
@@ -1387,6 +1456,45 @@ export default function ClaimsPage() {
</div>
)}
{/* United Ucard Claim OTP Modal */}
{unitedUcardClaimOtpOpen && (
<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 — United Ucard Claim</h2>
<button type="button" onClick={() => setUnitedUcardClaimOtpOpen(false)} className="text-slate-500 hover:text-slate-800">✕</button>
</div>
<p className="text-sm text-slate-500 mb-4">
The United Ucard (UHC Dental) 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()) handleUnitedUcardClaimOtpSubmit(input.value.trim());
}} className="space-y-4">
<div className="space-y-2">
<label htmlFor="uniteducard-claim-otp" className="text-sm font-medium">OTP</label>
<input
id="uniteducard-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={() => setUnitedUcardClaimOtpOpen(false)} disabled={unitedUcardClaimOtpSubmitting}
className="px-4 py-2 text-sm border rounded-md hover:bg-slate-50 disabled:opacity-50">Cancel</button>
<button type="submit" disabled={unitedUcardClaimOtpSubmitting}
className="px-4 py-2 text-sm bg-primary text-white rounded-md hover:bg-primary/90 disabled:opacity-50">
{unitedUcardClaimOtpSubmitting ? "Submitting..." : "Submit OTP"}
</button>
</div>
</form>
</div>
</div>
)}
{/* United/DentalHub PreAuth OTP Modal */}
{unitedDHPreAuthOtpOpen && (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40">