diff --git a/apps/Frontend/src/components/claims/claim-form.tsx b/apps/Frontend/src/components/claims/claim-form.tsx index 4fb83646..b49804e9 100755 --- a/apps/Frontend/src/components/claims/claim-form.tsx +++ b/apps/Frontend/src/components/claims/claim-form.tsx @@ -1090,6 +1090,81 @@ export function ClaimForm({ 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. const handleProceduresVoid = async () => { if (!appointmentId) return; @@ -1687,8 +1762,7 @@ export function ClaimForm({ ) : (
-
)}