From ea6f319981685fbae73b35d819dda3c47aeb83c5 Mon Sep 17 00:00:00 2001 From: Mark Goodrich Date: Wed, 8 May 2024 09:48:52 -0400 Subject: [PATCH] (fix) O3-3154: Patient Appointments Card does not properly set default appointment selection (#1127) --- ...nt-upcoming-appointments-card.component.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/esm-appointments-app/src/patient-appointments/patient-upcoming-appointments-card.component.tsx b/packages/esm-appointments-app/src/patient-appointments/patient-upcoming-appointments-card.component.tsx index 65a6ef5f9..f06b0c9b9 100644 --- a/packages/esm-appointments-app/src/patient-appointments/patient-upcoming-appointments-card.component.tsx +++ b/packages/esm-appointments-app/src/patient-appointments/patient-upcoming-appointments-card.component.tsx @@ -44,9 +44,18 @@ const PatientUpcomingAppointmentsCard: React.FC appointment.status !== 'CheckedIn'); - // If there is only one appointment, select it by default - if (appointments?.length === 1) { - setUpcomingAppointment(appointments[0]); + const defaultAppointment = ((appointments) => { + // if there's only one appointment today, select it by default, otherwise no default + const appts = appointments?.filter((appointment) => + dayjs(new Date(appointment.startDateTime).toISOString()).isToday(), + ); + if (appts?.length === 1) { + return appts[0]; + } + })(appointments); + + if (defaultAppointment) { + setUpcomingAppointment(defaultAppointment); } if (isError) { @@ -69,7 +78,7 @@ const PatientUpcomingAppointmentsCard: React.FC (e.target.checked ? setUpcomingAppointment(appointment) : '')} /> @@ -100,6 +109,7 @@ const PatientUpcomingAppointmentsCard: React.FC ); } + return (