From ebd5f514be7bcebf524bbb6d1b800f065fad4449 Mon Sep 17 00:00:00 2001 From: Vishnu Date: Fri, 30 May 2025 18:32:23 +0530 Subject: [PATCH] appointment creation done, claim form raw done --- .../src/components/claims/claim-form.tsx | 47 ++++++++++------ apps/Frontend/src/pages/appointments-page.tsx | 56 ++++++++----------- packages/db/prisma/schema.prisma | 2 +- 3 files changed, 54 insertions(+), 51 deletions(-) diff --git a/apps/Frontend/src/components/claims/claim-form.tsx b/apps/Frontend/src/components/claims/claim-form.tsx index 176ff40..8a86503 100644 --- a/apps/Frontend/src/components/claims/claim-form.tsx +++ b/apps/Frontend/src/components/claims/claim-form.tsx @@ -19,7 +19,10 @@ import { PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; -import { PatientUncheckedCreateInputObjectSchema, AppointmentUncheckedCreateInputObjectSchema} from "@repo/db/usedSchemas"; +import { + PatientUncheckedCreateInputObjectSchema, + AppointmentUncheckedCreateInputObjectSchema, +} from "@repo/db/usedSchemas"; import { z } from "zod"; import { useQuery } from "@tanstack/react-query"; import { apiRequest } from "@/lib/queryClient"; @@ -32,7 +35,6 @@ const PatientSchema = ( }); type Patient = z.infer; - //creating types out of schema auto generated. type Appointment = z.infer; @@ -55,7 +57,6 @@ const updateAppointmentSchema = ( .partial(); type UpdateAppointment = z.infer; - interface ServiceLine { procedure_code: string; procedure_date: string; @@ -69,7 +70,9 @@ interface ClaimFormProps { patientId?: number; extractedData?: Partial; onSubmit: (claimData: any) => void; - onHandleAppointmentSubmit: (appointmentData: InsertAppointment | UpdateAppointment) => void; + onHandleAppointmentSubmit: ( + appointmentData: InsertAppointment | UpdateAppointment + ) => void; onClose: () => void; } @@ -126,6 +129,12 @@ export function ClaimForm({ return res.json(); }, }); + useEffect(() => { + if (staffMembersRaw.length > 0 && !staff) { + const firstStaff = staffMembersRaw[0]; + if (firstStaff) setStaff(firstStaff); + } + }, [staffMembersRaw, staff]); // Service date state const [serviceDateValue, setServiceDateValue] = useState(new Date()); @@ -147,10 +156,9 @@ export function ClaimForm({ // used in submit button to send correct date. function convertToISODate(mmddyyyy: string): string { - const [month, day, year] = mmddyyyy.split("/"); - return `${year}-${month?.padStart(2, "0")}-${day?.padStart(2, "0")}`; -} - + const [month, day, year] = mmddyyyy.split("/"); + return `${year}-${month?.padStart(2, "0")}-${day?.padStart(2, "0")}`; + } // Remarks state const [remarks, setRemarks] = useState(""); @@ -363,8 +371,11 @@ export function ClaimForm({ }} > - + + {staffMembersRaw.map((member) => ( @@ -526,14 +537,18 @@ export function ClaimForm({ className="w-32" variant="outline" onClick={() => { - const appointmentData = { - patientId: patientId, - date: convertToISODate(serviceDate), - staffId:staff?.id, - }; + const appointmentData = { + patientId: patientId, + date: convertToISODate(serviceDate), + staffId: staff?.id, + }; - // 1. Create or update appointment - onHandleAppointmentSubmit(appointmentData);}} + // 1. Create or update appointment + onHandleAppointmentSubmit(appointmentData); + + // close form + onClose(); + }} > Delta MA diff --git a/apps/Frontend/src/pages/appointments-page.tsx b/apps/Frontend/src/pages/appointments-page.tsx index 9aa6ac0..862ab74 100644 --- a/apps/Frontend/src/pages/appointments-page.tsx +++ b/apps/Frontend/src/pages/appointments-page.tsx @@ -85,7 +85,7 @@ interface ScheduledAppointment { id?: number; patientId: number; patientName: string; - staffId: string; + staffId: number; date: string | Date; startTime: string | Date; endTime: string | Date; @@ -190,7 +190,7 @@ export default function AppointmentsPage() { // Handle creating a new appointment at a specific time slot and for a specific staff member const handleCreateAppointmentAtSlot = ( timeSlot: TimeSlot, - staffId: string + staffId: number ) => { // Calculate end time (30 minutes after start time) const startHour = parseInt(timeSlot.time.split(":")[0] as string); @@ -202,7 +202,7 @@ export default function AppointmentsPage() { const endTime = `${endDate.getHours().toString().padStart(2, "0")}:${endDate.getMinutes().toString().padStart(2, "0")}`; // Find staff member - const staff = staffMembers.find((s) => s.id === staffId); + const staff = staffMembers.find((s) => Number(s.id) === Number(staffId)); // Pre-fill appointment form with default values const newAppointment = { @@ -259,7 +259,7 @@ export default function AppointmentsPage() { timeSlots.find((slot) => slot.time === "09:00") || timeSlots[0]; // Open appointment modal with prefilled patient - handleCreateAppointmentAtSlot(defaultTimeSlot!, staffId); + handleCreateAppointmentAtSlot(defaultTimeSlot!, Number(staffId)); // Pre-select the patient in the appointment form const patientData = { @@ -280,7 +280,6 @@ export default function AppointmentsPage() { } } } - // eslint-disable-next-line react-hooks/exhaustive-deps }, [patients, user, location]); // Create appointment mutation @@ -479,28 +478,17 @@ export default function AppointmentsPage() { ? `${patient.firstName} ${patient.lastName}` : "Unknown Patient"; - // Try to determine the staff from the notes or title - let staffId = "doctor1"; // Default to first doctor if we can't determine + let staffId: number; - // Check notes first - if (apt.notes) { - // Look for "Appointment with Dr. X" or similar patterns - for (const staff of staffMembers) { - if (apt.notes.includes(staff.name)) { - staffId = staff.id; - break; - } - } - } - - // If no match in notes, check title - if (staffId === "doctor1" && apt.title) { - for (const staff of staffMembers) { - if (apt.title.includes(staff.name)) { - staffId = staff.id; - break; - } - } + if ( + staffMembers && + staffMembers.length > 0 && + staffMembers[0] !== undefined && + staffMembers[0].id !== undefined + ) { + staffId = Number(apt.staffId); + } else { + staffId = 1; } const processed = { @@ -515,7 +503,7 @@ export default function AppointmentsPage() { }); // Check if appointment exists at a specific time slot and staff - const getAppointmentAtSlot = (timeSlot: TimeSlot, staffId: string) => { + const getAppointmentAtSlot = (timeSlot: TimeSlot, staffId: number) => { if (processedAppointments.length === 0) { return undefined; } @@ -552,7 +540,7 @@ export default function AppointmentsPage() { const handleMoveAppointment = ( appointmentId: number, newTimeSlot: TimeSlot, - newStaffId: string + newStaffId: number ) => { const appointment = appointments.find((a) => a.id === appointmentId); if (!appointment) return; @@ -567,7 +555,7 @@ export default function AppointmentsPage() { const endTime = `${endDate.getHours().toString().padStart(2, "0")}:${endDate.getMinutes().toString().padStart(2, "0")}`; // Find staff member - const staff = staffMembers.find((s) => s.id === newStaffId); + const staff = staffMembers.find((s) => Number(s.id) === newStaffId); // Update appointment data const { id, createdAt, ...sanitizedAppointment } = appointment; @@ -653,7 +641,7 @@ export default function AppointmentsPage() { staff, }: { timeSlot: TimeSlot; - staffId: string; + staffId: number; appointment: ScheduledAppointment | undefined; staff: Staff; }) { @@ -851,10 +839,10 @@ export default function AppointmentsPage() { @@ -924,7 +912,7 @@ export default function AppointmentsPage() { { processedAppointments.filter( (apt) => - staffMembers.find((s) => s.id === apt.staffId) + staffMembers.find((s) => Number(s.id) === apt.staffId) ?.role === "doctor" ).length } @@ -938,7 +926,7 @@ export default function AppointmentsPage() { { processedAppointments.filter( (apt) => - staffMembers.find((s) => s.id === apt.staffId) + staffMembers.find((s) => Number(s.id) === apt.staffId) ?.role === "hygienist" ).length } diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index 56d4e81..c7eacc1 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -57,7 +57,7 @@ model Appointment { id Int @id @default(autoincrement()) patientId Int userId Int - staffId Int? // Optional: Appointment may or may not have staff assigned + staffId Int title String date DateTime @db.Date startTime String // Store time as "hh:mm"