diff --git a/apps/Backend/src/routes/insuranceStatus.ts b/apps/Backend/src/routes/insuranceStatus.ts index 546aad8..6aee98c 100644 --- a/apps/Backend/src/routes/insuranceStatus.ts +++ b/apps/Backend/src/routes/insuranceStatus.ts @@ -647,9 +647,23 @@ router.post( // Update patient status based on seleniumResult.eligibility const newStatus = seleniumResult?.eligibility === "Y" ? "ACTIVE" : "INACTIVE"; + + // 1. updating patient await storage.updatePatient(updatedPatient.id, { status: newStatus }); resultItem.patientUpdateStatus = `Patient status updated to ${newStatus}`; + // 2. updating appointment status - for aptmnt page + try { + await storage.updateAppointment(Number(apt.id), { + eligibilityStatus: newStatus, + }); + resultItem.appointmentUpdateStatus = `Appointment eligibility set to ${newStatus}`; + } catch (apptUpdateErr: any) { + resultItem.warning = + (resultItem.warning ? resultItem.warning + " | " : "") + + `Failed to update appointment eligibility: ${apptUpdateErr?.message ?? String(apptUpdateErr)}`; + } + // If PDF exists, upload to PdfGroup (ELIGIBILITY_STATUS) if ( seleniumResult?.pdf_path && diff --git a/apps/Frontend/src/pages/appointments-page.tsx b/apps/Frontend/src/pages/appointments-page.tsx index 946d637..767a5e9 100644 --- a/apps/Frontend/src/pages/appointments-page.tsx +++ b/apps/Frontend/src/pages/appointments-page.tsx @@ -71,7 +71,7 @@ interface ScheduledAppointment { id?: number; patientId: number; patientName: string; - patientStatus: PatientStatus; + eligibilityStatus: PatientStatus; staffId: number; date: string | Date; startTime: string | Date; @@ -403,10 +403,12 @@ export default function AppointmentsPage() { ).map((apt) => { // Find patient name const patient = patientsFromDay.find((p) => p.id === apt.patientId); + const patientName = patient ? `${patient.firstName} ${patient.lastName}` : "Unknown Patient"; - const patientStatus = patient?.status; + + const eligibilityStatus = (apt as any).eligibilityStatus as PatientStatus; const staffId = Number(apt.staffId ?? 1); @@ -422,7 +424,7 @@ export default function AppointmentsPage() { const processed = { ...apt, patientName, - patientStatus, + eligibilityStatus, staffId, status: apt.status ?? null, date: formatLocalDate(apt.date), @@ -621,7 +623,7 @@ export default function AppointmentsPage() { onContextMenu={(e) => handleContextMenu(e, appointment.id ?? 0)} > diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index 7b94162..3763589 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -85,6 +85,8 @@ model Appointment { status String @default("scheduled") // "scheduled", "completed", "cancelled", "no-show" createdAt DateTime @default(now()) + eligibilityStatus PatientStatus @default(UNKNOWN) + patient Patient @relation(fields: [patientId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id]) staff Staff? @relation(fields: [staffId], references: [id])