feat: add Claim Saved button and use patient insurance provider

- Replace Others button with Claim Saved (blue MH, green Claim Saved)
- Claim Saved saves full claim to DB using patient's insuranceProvider
- No Selenium triggered — works like a real claim for payment/report tracking

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gitead
2026-05-17 10:01:21 -04:00
parent e34140c2b1
commit 208ccf3549

View File

@@ -1090,6 +1090,81 @@ export function ClaimForm({
await handleProceduresSave(); await handleProceduresSave();
}; };
// Saves claim to DB with all info (member ID, DOB, service date, provider, CDT codes, NPI).
// No Selenium action — works like a real MassHealth claim for payment/report tracking.
const handleClaimSaved = async () => {
const missingFields: string[] = [];
if (!form.memberId?.trim()) missingFields.push("Member ID");
if (!form.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: ${missingFields.join(", ")}`,
variant: "destructive",
});
return;
}
const filteredServiceLines = form.serviceLines.filter(
(line) => (line.procedureCode ?? "").trim() !== "",
);
if (filteredServiceLines.length === 0) {
toast({
title: "No procedure codes",
description: "Please add at least one procedure code before saving.",
variant: "destructive",
});
return;
}
let appointmentIdToUse = appointmentId;
if (appointmentIdToUse == null) {
const created = await onHandleAppointmentSubmit({
patientId: patientId,
date: serviceDate,
staffId: appointmentStaffId ?? staff?.id,
});
if (typeof created === "number" && created > 0) {
appointmentIdToUse = created;
} else if (created && typeof (created as any).id === "number") {
appointmentIdToUse = (created as any).id;
}
}
const { uploadedFiles, insuranceSiteKey, npiProvider, ...formToCreateClaim } = form;
const claimFilesMeta: ClaimFileMeta[] = uploadedFiles?.length
? await uploadAttachmentsToLocalFolder(uploadedFiles)
: [];
const selectedNpiProviderId = npiProvider?.npiNumber
? npiProviders.find((p) => p.npiNumber === npiProvider.npiNumber)?.id ?? null
: null;
try {
await onSubmit({
...formToCreateClaim,
serviceLines: filteredServiceLines,
staffId: appointmentStaffId ?? Number(staff?.id),
patientId: patientId,
insuranceProvider: patient?.insuranceProvider || "MassHealth",
appointmentId: appointmentIdToUse!,
claimFiles: claimFilesMeta,
...(selectedNpiProviderId ? { npiProviderId: selectedNpiProviderId } : {}),
});
toast({ title: "Claim Saved", description: "Claim saved to database successfully." });
onClose();
} catch (err: any) {
toast({
title: "Save failed",
description: err?.message ?? "Failed to save claim.",
variant: "destructive",
});
}
};
// Marks the claim for this appointment as VOID so batch-column will always skip it. // Marks the claim for this appointment as VOID so batch-column will always skip it.
const handleProceduresVoid = async () => { const handleProceduresVoid = async () => {
if (!appointmentId) return; if (!appointmentId) return;
@@ -1687,8 +1762,7 @@ export function ClaimForm({
) : ( ) : (
<div className="flex justify-between"> <div className="flex justify-between">
<Button <Button
className="w-32" className="w-32 bg-blue-600 hover:bg-blue-700 text-white"
variant="secondary"
onClick={() => handleMHSubmit()} onClick={() => handleMHSubmit()}
> >
MH MH
@@ -1703,8 +1777,11 @@ export function ClaimForm({
<Button className="w-32" variant="outline"> <Button className="w-32" variant="outline">
Delta MA Delta MA
</Button> </Button>
<Button className="w-32" variant="outline"> <Button
Others className="w-36 bg-emerald-600 hover:bg-emerald-700 text-white"
onClick={handleClaimSaved}
>
Claim Saved
</Button> </Button>
</div> </div>
)} )}