diff --git a/apps/Frontend/src/components/patients/patient-table.tsx b/apps/Frontend/src/components/patients/patient-table.tsx index 1bca632..c59d6c9 100644 --- a/apps/Frontend/src/components/patients/patient-table.tsx +++ b/apps/Frontend/src/components/patients/patient-table.tsx @@ -68,7 +68,7 @@ interface PatientTableProps { allowView?: boolean; allowDelete?: boolean; allowCheckbox?: boolean; - onSelectPatient?: (patient: Patient) => void; + onSelectPatient?: (patient: Patient | null) => void; } export function PatientTable({ @@ -107,8 +107,8 @@ export function PatientTable({ const newSelectedId = isSelected ? null : patient.id; setSelectedPatientId(newSelectedId); - if (!isSelected && onSelectPatient) { - onSelectPatient(patient); + if (onSelectPatient) { + onSelectPatient(isSelected ? null : patient); } }; diff --git a/apps/Frontend/src/pages/insurance-eligibility-page.tsx b/apps/Frontend/src/pages/insurance-eligibility-page.tsx index 1e12bab..9fba52d 100644 --- a/apps/Frontend/src/pages/insurance-eligibility-page.tsx +++ b/apps/Frontend/src/pages/insurance-eligibility-page.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useMutation } from "@tanstack/react-query"; import { TopAppBar } from "@/components/layout/top-app-bar"; import { Sidebar } from "@/components/layout/sidebar"; @@ -12,12 +12,20 @@ import { CardTitle, } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; -import { CheckCircle } from "lucide-react"; +import { CalendarIcon, CheckCircle } from "lucide-react"; import { PatientUncheckedCreateInputObjectSchema } from "@repo/db/usedSchemas"; import { useAuth } from "@/hooks/use-auth"; import { useToast } from "@/hooks/use-toast"; import { z } from "zod"; import { PatientTable } from "@/components/patients/patient-table"; +import { format } from "date-fns"; +import { Calendar } from "@/components/ui/calendar"; +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover"; +import { cn } from "@/lib/utils"; const PatientSchema = ( PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject @@ -28,6 +36,8 @@ type Patient = z.infer; export default function InsuranceEligibilityPage() { const { user } = useAuth(); + const { toast } = useToast(); + const [selectedPatient, setSelectedPatient] = useState(null); const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); @@ -37,18 +47,29 @@ export default function InsuranceEligibilityPage() { // Insurance eligibility check form fields const [memberId, setMemberId] = useState(""); - const [dateOfBirth, setDateOfBirth] = useState(""); + const [dateOfBirth, setDateOfBirth] = useState(); const [firstName, setFirstName] = useState(""); const [lastName, setLastName] = useState(""); - // Selected patient for insurance check - const [selectedPatientId, setSelectedPatientId] = useState( - null - ); + // Populate fields from selected patient + useEffect(() => { + if (selectedPatient) { + setMemberId(selectedPatient.insuranceId ?? ""); + setFirstName(selectedPatient.firstName ?? ""); + setLastName(selectedPatient.lastName ?? ""); + + const dob = selectedPatient.dateOfBirth + ? new Date(selectedPatient.dateOfBirth) + : undefined; + setDateOfBirth(dob); + } else { + setMemberId(""); + setFirstName(""); + setLastName(""); + setDateOfBirth(undefined); + } +}, [selectedPatient]); - // Insurance automation states - const [selectedProvider, setSelectedProvider] = useState(""); - const { toast } = useToast(); // Insurance eligibility check mutation const checkInsuranceMutation = useMutation({ @@ -93,18 +114,16 @@ export default function InsuranceEligibilityPage() { }); // Handle insurance provider button clicks - const handleProviderClick = (providerName: string) => { - if (!selectedPatientId) { - toast({ - title: "No Patient Selected", - description: - "Please select a patient first by checking the box next to their name.", - variant: "destructive", - }); - return; - } - - setSelectedProvider(providerName); + const handleMHButton= () => { + if (!memberId || !dateOfBirth || !firstName) { + toast({ + title: "Missing Fields", + description: + "Please fill in all the required fields: Member ID, Date of Birth, First Name.", + variant: "destructive", + }); + return; + } }; return ( @@ -135,7 +154,7 @@ export default function InsuranceEligibilityPage() { Check Insurance Eligibility -
+
setMemberId(e.target.value)} />
+
- - setDateOfBirth(e.target.value)} - /> + + + + + + + date > new Date()} + /> + +
+
+