From 7b993dc104e237a2cb27416d48d1204b5a77c141 Mon Sep 17 00:00:00 2001 From: Potenz Date: Thu, 11 Sep 2025 01:39:15 +0530 Subject: [PATCH] feat(button) - Add service Button added --- .../src/components/claims/claim-form.tsx | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/apps/Frontend/src/components/claims/claim-form.tsx b/apps/Frontend/src/components/claims/claim-form.tsx index 3842a4a..76e8492 100644 --- a/apps/Frontend/src/components/claims/claim-form.tsx +++ b/apps/Frontend/src/components/claims/claim-form.tsx @@ -399,6 +399,68 @@ export function ClaimForm({ onClose(); }; + // 2nd Button workflow - Only Creates Data, patient, appointmetn, claim, payment, not actually submits claim to MH site. + const handleAddService = async () => { + // 0. Validate required fields + 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 the following field(s): ${missingFields.join(", ")}`, + variant: "destructive", + }); + return; + } + + // 1. Create or update appointment + const appointmentData = { + patientId: patientId, + date: serviceDate, + staffId: staff?.id, + }; + const appointmentId = await onHandleAppointmentSubmit(appointmentData); + + // 2. Update patient + if (patient && typeof patient.id === "number") { + const { id, createdAt, userId, ...sanitizedFields } = patient; + const updatedPatientFields = { + id, + ...sanitizedFields, + insuranceProvider: "MassHealth", + }; + onHandleUpdatePatient(updatedPatientFields); + } else { + toast({ + title: "Error", + description: "Cannot update patient: Missing or invalid patient data", + variant: "destructive", + }); + } + + // 3. Create Claim(if not) + // Filter out empty service lines (empty procedureCode) + const filteredServiceLines = form.serviceLines.filter( + (line) => line.procedureCode.trim() !== "" + ); + const { uploadedFiles, insuranceSiteKey, ...formToCreateClaim } = form; + const createdClaim = await onSubmit({ + ...formToCreateClaim, + serviceLines: filteredServiceLines, + staffId: Number(staff?.id), + patientId: patientId, + insuranceProvider: "MassHealth", + appointmentId: appointmentId!, + }); + + // 4. Close form + onClose(); + }; + return (
@@ -811,6 +873,13 @@ export function ClaimForm({ > MH PreAuth +