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,
} from "@/components/ui/tooltip";
import procedureCodes from "../../assets/data/procedureCodes.json";
import exp from "constants";
const PatientSchema = (
PatientUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
@@ -178,14 +179,32 @@ export function ClaimForm({
}, [staffMembersRaw, staff]);
// 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 [serviceDate, setServiceDate] = useState<string>(
new Date().toLocaleDateString("en-CA") // "YYYY-MM-DD"
);
useEffect(() => {
if (extractedData?.serviceDate) {
const parsed = new Date(extractedData.serviceDate);
const parsed = parseLocalDate(extractedData.serviceDate);
const isoFormatted = parsed.toLocaleDateString("en-CA");
setServiceDateValue(parsed);
setServiceDate(isoFormatted);

View File

@@ -9,7 +9,7 @@ import { useAuth } from "@/hooks/use-auth";
import {
PatientUncheckedCreateInputObjectSchema,
AppointmentUncheckedCreateInputObjectSchema,
ClaimUncheckedCreateInputObjectSchema
ClaimUncheckedCreateInputObjectSchema,
} from "@repo/db/usedSchemas";
import { AlertCircle, CheckCircle, Clock, FileCheck } from "lucide-react";
import { parse, format } from "date-fns";
@@ -224,7 +224,7 @@ export default function ClaimsPage() {
const res = await apiRequest("POST", "/api/claims/selenium/fetchpdf", {
action: actionType,
patientId: selectedPatient,
claimId:claimRes.id
claimId: claimRes.id,
});
const result = await res.json();
@@ -388,9 +388,11 @@ export default function ClaimsPage() {
};
const prefillClaimForm = (patient: Patient) => {
const lastAppointment = appointments.find(
(a) => a.patientId === patient.id
);
const patientAppointments = appointments
.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
? parseLocalDate(lastAppointment.date)
@@ -605,7 +607,8 @@ export default function ClaimsPage() {
</div>
) : patientsWithAppointments.length > 0 ? (
<div className="divide-y">
{patientsWithAppointments.map((item: typeof patientsWithAppointments[number]) => (
{patientsWithAppointments.map(
(item: (typeof patientsWithAppointments)[number]) => (
<div
key={item.patientId}
className="py-4 flex items-center justify-between cursor-pointer hover:bg-gray-50"
@@ -624,7 +627,9 @@ export default function ClaimsPage() {
<span className="mx-2"></span>
<span>
Last Visit:{" "}
{parseLocalDate(item.lastAppointment).toLocaleDateString("en-CA")}
{parseLocalDate(
item.lastAppointment
).toLocaleDateString("en-CA")}
</span>
</div>
</div>
@@ -632,7 +637,8 @@ export default function ClaimsPage() {
<FileCheck className="h-5 w-5" />
</div>
</div>
))}
)
)}
</div>
) : (
<div className="text-center py-8">