diff --git a/apps/Backend/src/routes/appointments.ts b/apps/Backend/src/routes/appointments.ts index 91bb04ab..cd7fdd4a 100755 --- a/apps/Backend/src/routes/appointments.ts +++ b/apps/Backend/src/routes/appointments.ts @@ -56,7 +56,20 @@ router.get("/day", async (req: Request, res: Response): Promise => { ? await storage.getPatientsByIds(patientIds) : []; - return res.json({ appointments, patients }); + // Enrich each appointment with procedure / claim status flags + const appointmentIds = appointments.map((a) => a.id).filter((id): id is number => id != null); + const [idsWithProcedures, idsWithClaimNumbers] = await Promise.all([ + storage.getAppointmentIdsWithProcedures(appointmentIds), + storage.getAppointmentIdsWithClaimNumbers(appointmentIds), + ]); + + const enrichedAppointments = appointments.map((a) => ({ + ...a, + hasProcedures: a.id != null && idsWithProcedures.has(a.id), + hasClaimWithNumber: a.id != null && idsWithClaimNumbers.has(a.id), + })); + + return res.json({ appointments: enrichedAppointments, patients }); } catch (err) { console.error("Error in /api/appointments/day:", err); res.status(500).json({ message: "Failed to load appointments for date" }); diff --git a/apps/Backend/src/storage/appointment-procedures-storage.ts b/apps/Backend/src/storage/appointment-procedures-storage.ts index 62c75ef8..7a1f80b2 100755 --- a/apps/Backend/src/storage/appointment-procedures-storage.ts +++ b/apps/Backend/src/storage/appointment-procedures-storage.ts @@ -37,6 +37,7 @@ export interface IAppointmentProceduresStorage { ): Promise; deleteProcedure(id: number): Promise; clearByAppointmentId(appointmentId: number): Promise; + getAppointmentIdsWithProcedures(ids: number[]): Promise>; } export const appointmentProceduresStorage: IAppointmentProceduresStorage = { @@ -130,4 +131,14 @@ export const appointmentProceduresStorage: IAppointmentProceduresStorage = { where: { appointmentId }, }); }, + + async getAppointmentIdsWithProcedures(ids: number[]): Promise> { + if (!ids.length) return new Set(); + const rows = await db.appointmentProcedure.findMany({ + where: { appointmentId: { in: ids } }, + select: { appointmentId: true }, + distinct: ["appointmentId"], + }); + return new Set(rows.map((r) => r.appointmentId)); + }, }; diff --git a/apps/Backend/src/storage/claims-storage.ts b/apps/Backend/src/storage/claims-storage.ts index ebf3615f..214952ce 100755 --- a/apps/Backend/src/storage/claims-storage.ts +++ b/apps/Backend/src/storage/claims-storage.ts @@ -23,6 +23,7 @@ export interface IStorage { updateClaim(id: number, updates: UpdateClaim): Promise; updateClaimStatus(id: number, status: ClaimStatus): Promise; deleteClaim(id: number): Promise; + getAppointmentIdsWithClaimNumbers(ids: number[]): Promise>; } export const claimsStorage: IStorage = { @@ -120,4 +121,14 @@ export const claimsStorage: IStorage = { throw new Error(`Claim with ID ${id} not found`); } }, + + async getAppointmentIdsWithClaimNumbers(ids: number[]): Promise> { + if (!ids.length) return new Set(); + const rows = await db.claim.findMany({ + where: { appointmentId: { in: ids }, claimNumber: { not: null } }, + select: { appointmentId: true }, + distinct: ["appointmentId"], + }); + return new Set(rows.map((r) => r.appointmentId)); + }, }; diff --git a/apps/Frontend/src/components/appointments/patient-status-badge.tsx b/apps/Frontend/src/components/appointments/patient-status-badge.tsx index 312cee0b..30a9c38f 100755 --- a/apps/Frontend/src/components/appointments/patient-status-badge.tsx +++ b/apps/Frontend/src/components/appointments/patient-status-badge.tsx @@ -24,7 +24,7 @@ export function PatientStatusBadge({ } // Type assertion to make TypeScript happy - className={`${staff.color} border border-white shadow-md text-white rounded p-1 text-xs h-full overflow-hidden cursor-move relative ${ + className={`${appointmentCardColor(appointment)} border shadow-md rounded p-1 text-xs h-full overflow-visible cursor-move relative ${ isDragging ? "opacity-50" : "opacity-100" }`} style={{ fontWeight: 500 }} @@ -668,7 +697,7 @@ export default function AppointmentsPage() { onContextMenu={(e) => handleContextMenu(e, appointment.id ?? 0)} > @@ -1247,24 +1276,52 @@ export default function AppointmentsPage() {
-
+
+ {/* << prev week */} + {/* < prev day */} + -

+ {/* today circle */} +

+ + {/* > next day */} + {/* >> next week */} +
{/* Top button with popover calendar */}