date fixed 2

This commit is contained in:
2025-06-21 10:28:33 +05:30
parent 22c18cbdf4
commit ac98cca194
2 changed files with 61 additions and 36 deletions

View File

@@ -35,6 +35,7 @@ import {
TooltipTrigger, TooltipTrigger,
} from "@/components/ui/tooltip"; } from "@/components/ui/tooltip";
import procedureCodes from "../../assets/data/procedureCodes.json"; import procedureCodes from "../../assets/data/procedureCodes.json";
import exp from "constants";
const PatientSchema = ( const PatientSchema = (
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any> PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
@@ -178,14 +179,32 @@ export function ClaimForm({
}, [staffMembersRaw, staff]); }, [staffMembersRaw, staff]);
// Service date state // Service date state
function parseLocalDate(dateInput: Date | string): Date {
if (dateInput instanceof Date) return dateInput;
const parts = dateInput.split("-");
if (parts.length !== 3) {
throw new Error(`Invalid date format: ${dateInput}`);
}
const year = Number(parts[0]);
const month = Number(parts[1]);
const day = Number(parts[2]);
if (Number.isNaN(year) || Number.isNaN(month) || Number.isNaN(day)) {
throw new Error(`Invalid date parts in date string: ${dateInput}`);
}
return new Date(year, month - 1, day); // month is 0-indexed
}
const [serviceDateValue, setServiceDateValue] = useState<Date>(new Date()); const [serviceDateValue, setServiceDateValue] = useState<Date>(new Date());
const [serviceDate, setServiceDate] = useState<string>( const [serviceDate, setServiceDate] = useState<string>(
new Date().toLocaleDateString("en-CA") // "YYYY-MM-DD" new Date().toLocaleDateString("en-CA") // "YYYY-MM-DD"
); );
useEffect(() => { useEffect(() => {
if (extractedData?.serviceDate) { if (extractedData?.serviceDate) {
const parsed = new Date(extractedData.serviceDate); const parsed = parseLocalDate(extractedData.serviceDate);
const isoFormatted = parsed.toLocaleDateString("en-CA"); const isoFormatted = parsed.toLocaleDateString("en-CA");
setServiceDateValue(parsed); setServiceDateValue(parsed);
setServiceDate(isoFormatted); setServiceDate(isoFormatted);

View File

@@ -9,7 +9,7 @@ import { useAuth } from "@/hooks/use-auth";
import { import {
PatientUncheckedCreateInputObjectSchema, PatientUncheckedCreateInputObjectSchema,
AppointmentUncheckedCreateInputObjectSchema, AppointmentUncheckedCreateInputObjectSchema,
ClaimUncheckedCreateInputObjectSchema ClaimUncheckedCreateInputObjectSchema,
} from "@repo/db/usedSchemas"; } from "@repo/db/usedSchemas";
import { AlertCircle, CheckCircle, Clock, FileCheck } from "lucide-react"; import { AlertCircle, CheckCircle, Clock, FileCheck } from "lucide-react";
import { parse, format } from "date-fns"; import { parse, format } from "date-fns";
@@ -218,13 +218,13 @@ export default function ClaimsPage() {
// selenium pdf download handler // selenium pdf download handler
const handleSeleniumPopup = async (actionType: string) => { const handleSeleniumPopup = async (actionType: string) => {
try { try {
if (!claimRes?.id || !selectedPatient) { if (!claimRes?.id || !selectedPatient) {
throw new Error("Missing claim or patient selection"); throw new Error("Missing claim or patient selection");
} }
const res = await apiRequest("POST", "/api/claims/selenium/fetchpdf", { const res = await apiRequest("POST", "/api/claims/selenium/fetchpdf", {
action: actionType, action: actionType,
patientId:selectedPatient, patientId: selectedPatient,
claimId:claimRes.id claimId: claimRes.id,
}); });
const result = await res.json(); const result = await res.json();
@@ -388,9 +388,11 @@ export default function ClaimsPage() {
}; };
const prefillClaimForm = (patient: Patient) => { const prefillClaimForm = (patient: Patient) => {
const lastAppointment = appointments.find( const patientAppointments = appointments
(a) => a.patientId === patient.id .filter((a) => a.patientId === patient.id)
); .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
const lastAppointment = patientAppointments[0]; // most recent
const dateToUse = lastAppointment const dateToUse = lastAppointment
? parseLocalDate(lastAppointment.date) ? parseLocalDate(lastAppointment.date)
@@ -605,34 +607,38 @@ export default function ClaimsPage() {
</div> </div>
) : patientsWithAppointments.length > 0 ? ( ) : patientsWithAppointments.length > 0 ? (
<div className="divide-y"> <div className="divide-y">
{patientsWithAppointments.map((item: typeof patientsWithAppointments[number]) => ( {patientsWithAppointments.map(
<div (item: (typeof patientsWithAppointments)[number]) => (
key={item.patientId} <div
className="py-4 flex items-center justify-between cursor-pointer hover:bg-gray-50" key={item.patientId}
onClick={() => handleNewClaim(item.patientId)} className="py-4 flex items-center justify-between cursor-pointer hover:bg-gray-50"
> onClick={() => handleNewClaim(item.patientId)}
<div> >
<h3 className="font-medium">{item.patientName}</h3> <div>
<div className="text-sm text-gray-500"> <h3 className="font-medium">{item.patientName}</h3>
<span> <div className="text-sm text-gray-500">
Insurance:{" "} <span>
{getDisplayProvider(item.insuranceProvider)} Insurance:{" "}
</span> {getDisplayProvider(item.insuranceProvider)}
</span>
<span className="mx-2"></span> <span className="mx-2"></span>
<span>ID: {item.insuranceId}</span> <span>ID: {item.insuranceId}</span>
<span className="mx-2"></span> <span className="mx-2"></span>
<span> <span>
Last Visit:{" "} Last Visit:{" "}
{parseLocalDate(item.lastAppointment).toLocaleDateString("en-CA")} {parseLocalDate(
</span> item.lastAppointment
).toLocaleDateString("en-CA")}
</span>
</div>
</div>
<div className="text-primary">
<FileCheck className="h-5 w-5" />
</div> </div>
</div> </div>
<div className="text-primary"> )
<FileCheck className="h-5 w-5" /> )}
</div>
</div>
))}
</div> </div>
) : ( ) : (
<div className="text-center py-8"> <div className="text-center py-8">