import React, { useState } from 'react'; import dayjs from 'dayjs'; import { useTranslation } from 'react-i18next'; import { Button, ContentSwitcher, DataTableSkeleton, Layer, Switch, Tile } from '@carbon/react'; import { Add } from '@carbon/react/icons'; import { launchWorkspace, useLayoutType } from '@openmrs/esm-framework'; import { CardHeader, EmptyDataIllustration, ErrorState } from '@openmrs/esm-patient-common-lib'; import { usePatientAppointments } from './patient-appointments.resource'; import { PatientAppointmentContextTypes, usePatientAppointmentContext } from '../hooks/patient-appointment-context'; import PatientAppointmentsTable from './patient-appointments-table.component'; import styles from './patient-appointments-base.scss'; interface PatientAppointmentsBaseProps { patientUuid: string; } enum AppointmentTypes { UPCOMING = 0, TODAY = 1, PAST = 2, } const PatientAppointmentsBase: React.FC = ({ patientUuid }) => { const { t } = useTranslation(); const headerTitle = t('appointments', 'Appointments'); const isTablet = useLayoutType() === 'tablet'; const patientAppointmentContext = usePatientAppointmentContext(); const [switchedView, setSwitchedView] = useState(false); const [contentSwitcherValue, setContentSwitcherValue] = useState(0); const startDate = dayjs(new Date().toISOString()).subtract(6, 'month').toISOString(); const { appointments, isLoading, error, pastAppointments, upcomingAppointments, todaysAppointments } = usePatientAppointments(patientUuid); const handleLaunchAppointmentsForm = () => { if ( (patientAppointmentContext as PatientAppointmentContextTypes) === PatientAppointmentContextTypes.PATIENT_CHART ) { launchWorkspace('appointments-form-workspace'); } else { launchWorkspace('appointments-form-workspace', { context: 'creating', patientUuid, workspaceTitle: t('createNewAppointment', 'Create new appointment'), }); } }; if (isLoading) { return ; } if (error) { return ; } return (
{ setContentSwitcherValue(index); setSwitchedView(true); }} >
|
{(() => { if (contentSwitcherValue === AppointmentTypes.UPCOMING) { if (upcomingAppointments?.length) { return ( ); } return (

{t( 'noUpcomingAppointmentsForPatient', 'There are no upcoming appointments to display for this patient', )}

); } if (contentSwitcherValue === AppointmentTypes.TODAY) { if (todaysAppointments?.length) { return ( ); } return (

{t( 'noCurrentAppointments', 'There are no appointments scheduled for today to display for this patient', )}

); } if (contentSwitcherValue === AppointmentTypes.PAST) { if (pastAppointments?.length) { return ( ); } return (

{t('noPastAppointments', 'There are no past appointments to display for this patient')}

); } })()}
); }; export default PatientAppointmentsBase;