From e793c43f111db5cb2202adb9688af0f85105906d Mon Sep 17 00:00:00 2001 From: Potenz Date: Tue, 1 Jul 2025 10:07:36 +0530 Subject: [PATCH] claimId fixed --- .../src/components/claims/claim-form.tsx | 26 +++++++++++-------- apps/Frontend/src/pages/claims-page.tsx | 24 ++++++++--------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/apps/Frontend/src/components/claims/claim-form.tsx b/apps/Frontend/src/components/claims/claim-form.tsx index 6f672ea..7563192 100644 --- a/apps/Frontend/src/components/claims/claim-form.tsx +++ b/apps/Frontend/src/components/claims/claim-form.tsx @@ -8,7 +8,6 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; -import { format, parse } from "date-fns"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { X, Calendar as CalendarIcon, HelpCircle } from "lucide-react"; @@ -22,6 +21,7 @@ import { import { PatientUncheckedCreateInputObjectSchema, AppointmentUncheckedCreateInputObjectSchema, + ClaimUncheckedCreateInputObjectSchema, } from "@repo/db/usedSchemas"; import { z } from "zod"; import { useQuery } from "@tanstack/react-query"; @@ -35,7 +35,6 @@ import { TooltipTrigger, } from "@/components/ui/tooltip"; import procedureCodes from "../../assets/data/procedureCodes.json"; -import exp from "constants"; const PatientSchema = ( PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject @@ -78,6 +77,9 @@ const updateAppointmentSchema = ( .partial(); type UpdateAppointment = z.infer; +type Claim = z.infer; + + interface ServiceLine { procedureCode: string; procedureDate: string; // YYYY-MM-DD @@ -101,12 +103,13 @@ interface ClaimFormData { insuranceSiteKey?: string; status: string; // default "pending" serviceLines: ServiceLine[]; + claimId?: number; } interface ClaimFormProps { patientId: number; extractedData?: Partial; - onSubmit: (data: ClaimFormData) => void; + onSubmit: (data: ClaimFormData) => Promise; onHandleAppointmentSubmit: ( appointmentData: InsertAppointment | UpdateAppointment ) => void; @@ -413,14 +416,14 @@ export function ClaimForm({ ); const { uploadedFiles, insuranceSiteKey, ...formToCreateClaim } = form; - onSubmit({ - ...formToCreateClaim, - serviceLines: filteredServiceLines, - staffId: Number(staff?.id), - patientId: patientId, - insuranceProvider: "MassHealth", - appointmentId: appointmentId!, - }); + const createdClaim = await onSubmit({ + ...formToCreateClaim, + serviceLines: filteredServiceLines, + staffId: Number(staff?.id), + patientId: patientId, + insuranceProvider: "MassHealth", + appointmentId: appointmentId!, + }); // 4. sending form data to selenium service onHandleForSelenium({ @@ -431,6 +434,7 @@ export function ClaimForm({ insuranceProvider: "Mass Health", appointmentId: appointmentId!, insuranceSiteKey: "MH", + claimId: createdClaim.id, }); // 4. Close form onClose(); diff --git a/apps/Frontend/src/pages/claims-page.tsx b/apps/Frontend/src/pages/claims-page.tsx index a167547..3420ee0 100644 --- a/apps/Frontend/src/pages/claims-page.tsx +++ b/apps/Frontend/src/pages/claims-page.tsx @@ -85,7 +85,6 @@ export default function ClaimsPage() { patientId: null, serviceDate: "", }); - const [claimRes, setClaimRes] = useState(null); // Fetch patients const { data: patients = [], isLoading: isLoadingPatients } = useQuery< @@ -305,11 +304,9 @@ export default function ClaimsPage() { const res = await apiRequest("POST", "/api/claims/", claimData); return res.json(); }, - onSuccess: (data) => { - console.log(data) - setClaimRes(data); + onSuccess: () => { toast({ - title: "Claim submitted successfully", + title: "Claim created successfully", variant: "default", }); }, @@ -322,6 +319,12 @@ export default function ClaimsPage() { }, }); + function handleClaimSubmit(claimData: any): Promise { + return createClaimMutation.mutateAsync(claimData).then((data) => { + return data; + }); + } + const [location] = useLocation(); // gets path, e.g. "/claims" const { name, memberId, dob } = useMemo(() => { @@ -425,9 +428,6 @@ export default function ClaimsPage() { } }, [memberId, dob]); - function handleClaimSubmit(claimData: any) { - createClaimMutation.mutate(claimData); - } const getDisplayProvider = (provider: string) => { const insuranceMap: Record = { @@ -553,8 +553,8 @@ export default function ClaimsPage() { // selenium pdf download handler const handleSeleniumPdfDownload = async (data: any) => { try { - if (!claimRes?.id) { - throw new Error("Missing claimId2s"); + if (!data.claimId) { + throw new Error("Missing claimId in handleSeleniumPdfDownload"); } if (!selectedPatient) { throw new Error("Missing patientId"); @@ -569,8 +569,8 @@ export default function ClaimsPage() { const res = await apiRequest("POST", "/api/claims/selenium/fetchpdf", { patientId: selectedPatient, - claimId: claimRes.id, - pdf_url: data["pdf_url"], + claimId: data.claimId, + pdf_url: data.pdf_url, }); const result = await res.json(); if (result.error) throw new Error(result.error);