checkpoint claimpage

This commit is contained in:
2025-07-28 14:40:01 +05:30
parent af1b0f8d70
commit d9ce19df80
3 changed files with 167 additions and 236 deletions

View File

@@ -108,7 +108,6 @@ interface ClaimFormData {
interface ClaimFormProps {
patientId: number;
extractedData?: Partial<Patient>;
onSubmit: (data: ClaimFormData) => Promise<Claim>;
onHandleAppointmentSubmit: (
appointmentData: InsertAppointment | UpdateAppointment
@@ -123,7 +122,6 @@ type Staff = z.infer<typeof StaffUncheckedCreateInputObjectSchema>;
export function ClaimForm({
patientId,
extractedData,
onHandleAppointmentSubmit,
onHandleUpdatePatient,
onHandleForMHSelenium,
@@ -133,10 +131,7 @@ export function ClaimForm({
const { toast } = useToast();
const { user } = useAuth();
// Patient state - initialize from extractedData (if given ) or null (new patient)
const [patient, setPatient] = useState<Patient | null>(
extractedData ? ({ ...extractedData } as Patient) : null
);
const [patient, setPatient] = useState<Patient | null>(null);
// Query patient based on given patient id
const {
@@ -185,14 +180,6 @@ export function ClaimForm({
const [serviceDate, setServiceDate] = useState<string>(
formatLocalDate(new Date())
);
useEffect(() => {
if (extractedData?.serviceDate) {
const parsed = parseLocalDate(extractedData.serviceDate);
const isoFormatted = formatLocalDate(parsed);
setServiceDateValue(parsed);
setServiceDate(isoFormatted);
}
}, [extractedData]);
// Update service date when calendar date changes
const onServiceDateChange = (date: Date | undefined) => {
@@ -219,7 +206,7 @@ export function ClaimForm({
});
}, [serviceDate]);
// Determine patient date of birth format
// Determine patient date of birth format - required as date extracted from pdfs has different format.
const formatDOB = (dob: string | undefined) => {
if (!dob) return "";
if (/^\d{2}\/\d{2}\/\d{4}$/.test(dob)) return dob; // already MM/DD/YYYY

View File

@@ -31,6 +31,7 @@ import { CalendarIcon } from "lucide-react";
import { format } from "date-fns";
import { Button } from "../ui/button";
import { cn } from "@/lib/utils";
import { formatLocalDate, parseLocalDate } from "@/utils/dateUtils";
const PatientSchema = (
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
@@ -94,7 +95,7 @@ export const PatientForm = forwardRef<PatientFormRef, PatientFormProps>(
return {
...sanitizedPatient,
dateOfBirth: patient.dateOfBirth
? new Date(patient.dateOfBirth).toISOString().split("T")[0]
? formatLocalDate(new Date(patient.dateOfBirth))
: "",
};
}
@@ -146,7 +147,7 @@ export const PatientForm = forwardRef<PatientFormRef, PatientFormProps>(
const resetValues: Partial<Patient> = {
...sanitizedPatient,
dateOfBirth: patient.dateOfBirth
? new Date(patient.dateOfBirth).toISOString().split("T")[0]
? formatLocalDate(new Date(patient.dateOfBirth))
: "",
};
form.reset(resetValues);
@@ -218,7 +219,7 @@ export const PatientForm = forwardRef<PatientFormRef, PatientFormProps>(
)}
>
{field.value ? (
format(field.value, "PPP")
format(parseLocalDate(field.value), "PPP")
) : (
<span>Pick a date</span>
)}
@@ -229,10 +230,14 @@ export const PatientForm = forwardRef<PatientFormRef, PatientFormProps>(
<PopoverContent className="w-auto p-4">
<Calendar
mode="single"
selected={field.value}
selected={
field.value
? parseLocalDate(field.value)
: undefined
}
onSelect={(date) => {
if (date) {
const localDate = format(date, "yyyy-MM-dd");
const localDate = formatLocalDate(date); // keep yyyy-MM-dd
field.onChange(localDate);
}
}}