claim page , auto fill field working
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
@@ -14,103 +14,145 @@ import { Label } from "@/components/ui/label";
|
||||
import { X, Calendar as CalendarIcon } from "lucide-react";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { Calendar } from "@/components/ui/calendar";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import { PatientUncheckedCreateInputObjectSchema } from "@repo/db/usedSchemas";
|
||||
import {z} from "zod";
|
||||
import { z } from "zod";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { apiRequest } from "@/lib/queryClient";
|
||||
|
||||
const PatientSchema = (PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>).omit({
|
||||
const PatientSchema = (
|
||||
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
|
||||
).omit({
|
||||
appointments: true,
|
||||
});
|
||||
type Patient = z.infer<typeof PatientSchema>;
|
||||
|
||||
interface ClaimFormProps {
|
||||
patientId: number;
|
||||
appointmentId: number;
|
||||
patientName: string;
|
||||
onClose: () => void;
|
||||
patientData?: Patient;
|
||||
interface ServiceLine {
|
||||
procedureCode: string;
|
||||
toothNumber: string;
|
||||
surface: string;
|
||||
quad: string;
|
||||
authNo: string;
|
||||
billedAmount: string;
|
||||
}
|
||||
|
||||
export function ClaimForm({
|
||||
patientId,
|
||||
appointmentId,
|
||||
patientName,
|
||||
interface ClaimFormProps {
|
||||
patientId?: number;
|
||||
extractedData?: Partial<Patient>;
|
||||
onSubmit: (claimData: any) => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export function ClaimForm({
|
||||
patientId,
|
||||
extractedData,
|
||||
onSubmit,
|
||||
onClose,
|
||||
patientData
|
||||
}: ClaimFormProps) {
|
||||
const { toast } = useToast();
|
||||
const [patient, setPatient] = useState<Patient | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [serviceDateValue, setServiceDateValue] = useState<Date>(new Date());
|
||||
const [serviceDate, setServiceDate] = useState<string>(format(new Date(), 'MM/dd/yy'));
|
||||
const [clinicalNotes, setClinicalNotes] = useState<string>('');
|
||||
|
||||
// Fetch patient data if not provided
|
||||
|
||||
// Query patient if patientId provided
|
||||
const { data: fetchedPatient, isLoading, error } = useQuery<Patient>({
|
||||
queryKey: ["/api/patients/", patientId],
|
||||
queryFn: async () => {
|
||||
const res = await apiRequest("GET", `/api/patients/${patientId}`);
|
||||
if (!res.ok) throw new Error("Failed to fetch patient");
|
||||
return res.json();
|
||||
},
|
||||
enabled: !!patientId,
|
||||
});
|
||||
|
||||
// Patient state - initialize from extractedData or null (new patient)
|
||||
const [patient, setPatient] = useState<Patient | null>(
|
||||
extractedData ? ({ ...extractedData } as Patient) : null
|
||||
);
|
||||
|
||||
// Sync fetched patient when available
|
||||
useEffect(() => {
|
||||
if (patientData) {
|
||||
setPatient(patientData);
|
||||
return;
|
||||
if (fetchedPatient) {
|
||||
setPatient(fetchedPatient);
|
||||
}
|
||||
|
||||
const fetchPatient = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await fetch(`/api/patients/${patientId}`);
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch patient data");
|
||||
}
|
||||
const data = await response.json();
|
||||
setPatient(data);
|
||||
} catch (error) {
|
||||
console.error("Error fetching patient:", error);
|
||||
toast({
|
||||
title: "Error",
|
||||
description: "Failed to load patient information",
|
||||
variant: "destructive",
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}, [fetchedPatient]);
|
||||
|
||||
|
||||
// Service date state
|
||||
const [serviceDateValue, setServiceDateValue] = useState<Date>(new Date());
|
||||
const [serviceDate, setServiceDate] = useState<string>(format(new Date(), "MM/dd/yy"));
|
||||
|
||||
// Clinical notes state
|
||||
const [clinicalNotes, setClinicalNotes] = useState<string>("");
|
||||
|
||||
// Doctor selection state
|
||||
const [doctor, setDoctor] = useState("doctor1");
|
||||
|
||||
// Service lines state with one empty default line
|
||||
const [serviceLines, setServiceLines] = useState<ServiceLine[]>([
|
||||
{
|
||||
procedureCode: "",
|
||||
toothNumber: "",
|
||||
surface: "",
|
||||
quad: "",
|
||||
authNo: "",
|
||||
billedAmount: "",
|
||||
},
|
||||
]);
|
||||
|
||||
// Update a field in serviceLines at index
|
||||
const updateServiceLine = (
|
||||
index: number,
|
||||
field: keyof ServiceLine,
|
||||
value: string
|
||||
) => {
|
||||
setServiceLines((prev) => {
|
||||
const updated = [...prev];
|
||||
if (updated[index]) {
|
||||
updated[index][field] = value;
|
||||
}
|
||||
};
|
||||
|
||||
if (patientId) {
|
||||
fetchPatient();
|
||||
}
|
||||
}, [patientId, patientData, toast]);
|
||||
return updated;
|
||||
});
|
||||
};
|
||||
|
||||
// Handle patient field changes (to make inputs controlled and editable)
|
||||
const updatePatientField = (field: keyof Patient, value: any) => {
|
||||
setPatient((prev) => (prev ? { ...prev, [field]: value } : null));
|
||||
};
|
||||
|
||||
|
||||
// Update service date when calendar date changes
|
||||
const onServiceDateChange = (date: Date | undefined) => {
|
||||
if (date) {
|
||||
setServiceDateValue(date);
|
||||
setServiceDate(format(date, 'MM/dd/yy'));
|
||||
setServiceDate(format(date, "MM/dd/yy"));
|
||||
}
|
||||
};
|
||||
|
||||
// Determine patient date of birth format
|
||||
const formatDOB = (dob: string | undefined) => {
|
||||
if (!dob) return '';
|
||||
|
||||
// If already in MM/DD/YYYY format, return as is
|
||||
if (/^\d{2}\/\d{2}\/\d{4}$/.test(dob)) {
|
||||
return dob;
|
||||
}
|
||||
|
||||
// If in YYYY-MM-DD format, convert to MM/DD/YYYY
|
||||
if (/^\d{4}-\d{2}-\d{2}$/.test(dob)) {
|
||||
const [year, month, day] = dob.split('-');
|
||||
return `${month}/${day}/${year}`;
|
||||
}
|
||||
|
||||
return dob;
|
||||
};
|
||||
if (!dob) return "";
|
||||
|
||||
if (/^\d{2}\/\d{2}\/\d{4}$/.test(dob)) return dob; // already MM/DD/YYYY
|
||||
|
||||
if (/^\d{4}-\d{2}-\d{2}/.test(dob)) {
|
||||
const datePart = dob?.split("T")[0]; // safe optional chaining
|
||||
if (!datePart) return "";
|
||||
const [year, month, day] = datePart.split("-");
|
||||
return `${month}/${day}/${year}`;
|
||||
}
|
||||
|
||||
return dob;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4 overflow-y-auto">
|
||||
<Card className="w-full max-w-5xl max-h-[90vh] overflow-y-auto bg-white">
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2 border-b">
|
||||
<CardTitle className="text-xl font-bold">Insurance Claim Form</CardTitle>
|
||||
<CardTitle className="text-xl font-bold">
|
||||
Insurance Claim Form
|
||||
</CardTitle>
|
||||
<Button variant="ghost" size="icon" onClick={onClose}>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
@@ -121,52 +163,56 @@ export function ClaimForm({
|
||||
<div className="grid grid-cols-4 gap-4">
|
||||
<div>
|
||||
<Label htmlFor="memberId">Member ID</Label>
|
||||
<Input
|
||||
id="memberId"
|
||||
value={patient?.insuranceId || ''}
|
||||
disabled={loading}
|
||||
<Input
|
||||
id="memberId"
|
||||
value={patient?.insuranceId || ""}
|
||||
onChange={(e) => updatePatientField("insuranceId", e.target.value)}
|
||||
disabled={isLoading}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="dateOfBirth">Date Of Birth</Label>
|
||||
<Input
|
||||
id="dateOfBirth"
|
||||
value={formatDOB(patient?.dateOfBirth)}
|
||||
disabled={loading}
|
||||
<Input
|
||||
id="dateOfBirth"
|
||||
value={formatDOB(patient?.dateOfBirth)}
|
||||
onChange={(e) => updatePatientField("dateOfBirth", e.target.value)}
|
||||
disabled={isLoading}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="firstName">First Name</Label>
|
||||
<Input
|
||||
id="firstName"
|
||||
value={patient?.firstName || ''}
|
||||
disabled={loading}
|
||||
<Input
|
||||
id="firstName"
|
||||
value={patient?.firstName || ""}
|
||||
onChange={(e) => updatePatientField("firstName", e.target.value)}
|
||||
disabled={isLoading}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="lastName">Last Name</Label>
|
||||
<Input
|
||||
id="lastName"
|
||||
value={patient?.lastName || ''}
|
||||
disabled={loading}
|
||||
<Input
|
||||
id="lastName"
|
||||
value={patient?.lastName || ""}
|
||||
onChange={(e) => updatePatientField("lastName", e.target.value)}
|
||||
disabled={isLoading}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
{/* Clinical Notes Entry */}
|
||||
<div className="mb-4 flex items-center gap-2">
|
||||
<Label htmlFor="clinicalNotes" className="whitespace-nowrap">Clinical Notes:</Label>
|
||||
<Input
|
||||
<Label htmlFor="clinicalNotes" className="whitespace-nowrap">
|
||||
Clinical Notes:
|
||||
</Label>
|
||||
<Input
|
||||
id="clinicalNotes"
|
||||
className="flex-grow"
|
||||
placeholder="Paste clinical notes here"
|
||||
value={clinicalNotes}
|
||||
onChange={(e) => setClinicalNotes(e.target.value)}
|
||||
/>
|
||||
<Button
|
||||
variant="outline"
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
if (clinicalNotes.trim()) {
|
||||
@@ -180,7 +226,7 @@ export function ClaimForm({
|
||||
toast({
|
||||
title: "Empty Input",
|
||||
description: "Please enter clinical notes to extract",
|
||||
variant: "destructive"
|
||||
variant: "destructive",
|
||||
});
|
||||
}
|
||||
}}
|
||||
@@ -191,7 +237,9 @@ export function ClaimForm({
|
||||
|
||||
{/* Service Lines */}
|
||||
<div>
|
||||
<h3 className="text-xl font-semibold mb-2 text-center">Service Lines</h3>
|
||||
<h3 className="text-xl font-semibold mb-2 text-center">
|
||||
Service Lines
|
||||
</h3>
|
||||
<div className="flex justify-end items-center mb-2">
|
||||
<div className="flex gap-2">
|
||||
<Label className="flex items-center">Service Date</Label>
|
||||
@@ -214,8 +262,10 @@ export function ClaimForm({
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<Label className="flex items-center ml-2">Treating Doctor</Label>
|
||||
<Select defaultValue="doctor1">
|
||||
<Label className="flex items-center ml-2">
|
||||
Treating Doctor
|
||||
</Label>
|
||||
<Select value={doctor} onValueChange={setDoctor}>
|
||||
<SelectTrigger className="w-36">
|
||||
<SelectValue placeholder="Select Doctor" />
|
||||
</SelectTrigger>
|
||||
@@ -227,50 +277,45 @@ export function ClaimForm({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-6 gap-4 mb-2">
|
||||
<div>
|
||||
<Label htmlFor="procedureCode1">Procedure Code</Label>
|
||||
<Input id="procedureCode1" placeholder="e.g. D0120" />
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="toothNumber1">Tooth Number</Label>
|
||||
<Input id="toothNumber1" placeholder="e.g. 14" />
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="surface1">Surface</Label>
|
||||
<Input id="surface1" placeholder="e.g. MOD" />
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="quad1">Quad</Label>
|
||||
<Select>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="UR">Upper Right</SelectItem>
|
||||
<SelectItem value="UL">Upper Left</SelectItem>
|
||||
<SelectItem value="LR">Lower Right</SelectItem>
|
||||
<SelectItem value="LL">Lower Left</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="authNo1">Auth No.</Label>
|
||||
<Input id="authNo1" />
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="billedAmount1">Billed Amount</Label>
|
||||
<Input id="billedAmount1" placeholder="$0.00" />
|
||||
</div>
|
||||
<div className="grid grid-cols-6 gap-4 mb-2 font-medium text-sm text-gray-700">
|
||||
<span>Procedure Code</span>
|
||||
<span>Tooth Number</span>
|
||||
<span>Surface</span>
|
||||
<span>Quadrant</span>
|
||||
<span>Auth No.</span>
|
||||
<span>Billed Amount</span>
|
||||
</div>
|
||||
|
||||
{/* Add more service lines - simplified for clarity */}
|
||||
{[2, 3, 4, 5].map(i => (
|
||||
{/* Dynamic Rows */}
|
||||
{serviceLines.map((line, i) => (
|
||||
<div key={i} className="grid grid-cols-6 gap-4 mb-2">
|
||||
<Input placeholder="Procedure Code" />
|
||||
<Input placeholder="Tooth Number" />
|
||||
<Input placeholder="Surface" />
|
||||
<Select>
|
||||
<Input
|
||||
placeholder="e.g. D0120"
|
||||
value={line.procedureCode}
|
||||
onChange={(e) =>
|
||||
updateServiceLine(i, "procedureCode", e.target.value)
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
placeholder="e.g. 14"
|
||||
value={line.toothNumber}
|
||||
onChange={(e) =>
|
||||
updateServiceLine(i, "toothNumber", e.target.value)
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
placeholder="e.g. MOD"
|
||||
value={line.surface}
|
||||
onChange={(e) =>
|
||||
updateServiceLine(i, "surface", e.target.value)
|
||||
}
|
||||
/>
|
||||
<Select
|
||||
value={line.quad}
|
||||
onValueChange={(value) =>
|
||||
updateServiceLine(i, "quad", value)
|
||||
}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select" />
|
||||
</SelectTrigger>
|
||||
@@ -281,10 +326,40 @@ export function ClaimForm({
|
||||
<SelectItem value="LL">Lower Left</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input placeholder="Auth No." />
|
||||
<Input placeholder="$0.00" />
|
||||
<Input
|
||||
placeholder="e.g. 123456"
|
||||
value={line.authNo}
|
||||
onChange={(e) =>
|
||||
updateServiceLine(i, "authNo", e.target.value)
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
placeholder="$0.00"
|
||||
value={line.billedAmount}
|
||||
onChange={(e) =>
|
||||
updateServiceLine(i, "billedAmount", e.target.value)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
setServiceLines([
|
||||
...serviceLines,
|
||||
{
|
||||
procedureCode: "",
|
||||
toothNumber: "",
|
||||
surface: "",
|
||||
quad: "",
|
||||
authNo: "",
|
||||
billedAmount: "",
|
||||
},
|
||||
])
|
||||
}
|
||||
>
|
||||
+ Add Service Line
|
||||
</Button>
|
||||
|
||||
<div className="flex gap-2 mt-4">
|
||||
<Button variant="outline">Child Prophy Codes</Button>
|
||||
@@ -295,7 +370,10 @@ export function ClaimForm({
|
||||
|
||||
{/* File Upload Section */}
|
||||
<div className="mt-4 bg-gray-100 p-3 rounded-md">
|
||||
<p className="text-sm text-gray-500 mb-2">Please note that file types with 4 or more character extensions are not allowed, such as .DOCX, .PPTX, or .XLSX</p>
|
||||
<p className="text-sm text-gray-500 mb-2">
|
||||
Please note that file types with 4 or more character
|
||||
extensions are not allowed, such as .DOCX, .PPTX, or .XLSX
|
||||
</p>
|
||||
<div className="flex justify-between items-center">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label>Select Field:</Label>
|
||||
@@ -304,7 +382,9 @@ export function ClaimForm({
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="supportData">Support Data for Claim</SelectItem>
|
||||
<SelectItem value="supportData">
|
||||
Support Data for Claim
|
||||
</SelectItem>
|
||||
<SelectItem value="xrays">X-Ray Images</SelectItem>
|
||||
<SelectItem value="photos">Clinical Photos</SelectItem>
|
||||
</SelectContent>
|
||||
@@ -317,18 +397,24 @@ export function ClaimForm({
|
||||
|
||||
{/* Insurance Carriers */}
|
||||
<div>
|
||||
<h3 className="text-xl font-semibold mb-4 text-center">Insurance Carriers</h3>
|
||||
<h3 className="text-xl font-semibold mb-4 text-center">
|
||||
Insurance Carriers
|
||||
</h3>
|
||||
<div className="flex justify-between">
|
||||
<Button className="w-32" variant="outline">Delta MA</Button>
|
||||
<Button className="w-32" variant="outline">MH</Button>
|
||||
<Button className="w-32" variant="outline">Others</Button>
|
||||
<Button className="w-32" variant="outline">
|
||||
Delta MA
|
||||
</Button>
|
||||
<Button className="w-32" variant="outline">
|
||||
MH
|
||||
</Button>
|
||||
<Button className="w-32" variant="outline">
|
||||
Others
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user