import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { insertPatientSchema, InsertPatient, Patient, updatePatientSchema, UpdatePatient } from "@shared/schema"; import { useAuth } from "@/hooks/use-auth"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; interface PatientFormProps { patient?: Patient; extractedInfo?: { firstName: string; lastName: string; dateOfBirth: string; insuranceId: string; }; onSubmit: (data: InsertPatient | UpdatePatient) => void; } export function PatientForm({ patient, extractedInfo, onSubmit }: PatientFormProps) { const { user } = useAuth(); const isEditing = !!patient; const schema = isEditing ? updatePatientSchema : insertPatientSchema.extend({ userId: z.number().optional(), }); // Merge extracted info into default values if available const defaultValues = { firstName: extractedInfo?.firstName || "", lastName: extractedInfo?.lastName || "", dateOfBirth: extractedInfo?.dateOfBirth || "", gender: "", phone: "", email: "", address: "", city: "", zipCode: "", insuranceProvider: "", insuranceId: extractedInfo?.insuranceId || "", groupNumber: "", policyHolder: "", allergies: "", medicalConditions: "", status: "active", userId: user?.id, }; const form = useForm({ resolver: zodResolver(schema), defaultValues: patient || defaultValues, }); const handleSubmit = (data: InsertPatient | UpdatePatient) => { onSubmit(data); }; return (
{/* Personal Information */}

Personal Information

( First Name * )} /> ( Last Name * )} /> ( Date of Birth * )} /> ( Gender * )} />
{/* Contact Information */}

Contact Information

( Phone Number * )} /> ( Email )} /> ( Address )} /> ( City )} /> ( ZIP Code )} />
{/* Insurance Information */}

Insurance Information

( Insurance Provider )} /> ( Insurance ID )} /> ( Group Number )} /> ( Policy Holder (if not self) )} />
{/* Hidden submit button for form validation */}
); }