Skip to content

Commit

Permalink
reverts unnecesarry changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GiladSchneider committed Nov 25, 2024
1 parent 63bb327 commit 0239835
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface AppointmentState {
providerID?: string;
groupID?: string;
scheduleType?: 'location' | 'provider';
slug?: string;
}

const APOINTMENT_STATE_INITIAL: AppointmentState = {};
Expand Down
29 changes: 27 additions & 2 deletions packages/telemed-intake/app/src/pages/ConfirmDateOfBirth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { CustomContainer } from '../features/common';
import { useGetPaperwork, usePaperworkStore } from '../features/paperwork';
import { usePatientInfoStore } from '../features/patient-info';
import { useZapEHRAPIClient } from '../utils';
import { handleClosePastTimeErrorDialog, isSlotTimePassed, useZapEHRAPIClient } from '../utils';
import { decode } from 'html-entities';

const ConfirmDateOfBirth = (): JSX.Element => {
Expand All @@ -26,7 +26,11 @@ const ConfirmDateOfBirth = (): JSX.Element => {
const [requestErrorDialogOpen, setRequestErrorDialogOpen] = useState<boolean>(false);
const createAppointment = useCreateAppointmentMutation();
const [getPaperworkEnabled, setGetPaperworkEnabled] = useState<boolean>(false);
const { appointmentID } = getSelectors(useAppointmentStore, ['appointmentID']);
const { appointmentID, selectedSlot, visitType, visitService, scheduleType, slug } = getSelectors(
useAppointmentStore,
['appointmentID', 'selectedSlot', 'visitType', 'visitService', 'scheduleType', 'slug'],
);
const [isPastTimeErrorDialogOpen, setIsPastTimeErrorDialogOpen] = useState<boolean>(false);
const { patchCompletedPaperwork, setQuestions } = getSelectors(usePaperworkStore, [
'patchCompletedPaperwork',
'setQuestions',
Expand Down Expand Up @@ -116,6 +120,11 @@ const ConfirmDateOfBirth = (): JSX.Element => {
}, [challengeDay.name, challengeMonth.name, challengeYear.name, formValuesCopy]);

const createOrUpdateAppointment = (unconfirmedDateOfBirth = false): void => {
if (isSlotTimePassed(selectedSlot, visitType)) {
setIsPastTimeErrorDialogOpen(true);
return;
}

if (!apiClient) {
throw new Error('apiClient is not defined');
}
Expand Down Expand Up @@ -261,6 +270,22 @@ const ConfirmDateOfBirth = (): JSX.Element => {
closeButtonText={t('general.button.close')}
handleClose={() => setRequestErrorDialogOpen(false)}
/>
<ErrorDialog
open={isPastTimeErrorDialogOpen}
title={t('patientInfo.pastTimeError.title')}
description={t('patientInfo.pastTimeError.description')}
closeButtonText={t('patientInfo.pastTimeError.button')}
handleClose={() =>
handleClosePastTimeErrorDialog(
setIsPastTimeErrorDialogOpen,
navigate,
visitType,
visitService,
scheduleType,
slug,
)
}
/>
</>
</CustomContainer>
);
Expand Down
29 changes: 27 additions & 2 deletions packages/telemed-intake/app/src/pages/PatientInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { CustomContainer } from '../features/common';
import { useFilesStore } from '../features/files';
import { useGetPaperwork, usePaperworkStore } from '../features/paperwork';
import { usePatientInfoStore } from '../features/patient-info';
import { useZapEHRAPIClient } from '../utils';
import { handleClosePastTimeErrorDialog, isSlotTimePassed, useZapEHRAPIClient } from '../utils';

const UPDATEABLE_PATIENT_INFO_FIELDS: (keyof Omit<PatientInfo, 'id'>)[] = [
'firstName',
Expand Down Expand Up @@ -69,13 +69,17 @@ const PatientInformation = (): JSX.Element => {
const { t } = useTranslation();
const [ageErrorDialogOpen, setAgeErrorDialogOpen] = useState<boolean>(false);
const [requestErrorDialogOpen, setRequestErrorDialogOpen] = useState<boolean>(false);
const [isPastTimeErrorDialogOpen, setIsPastTimeErrorDialogOpen] = useState<boolean>(false);
const { patientInfo: currentPatientInfo, pendingPatientInfoUpdates } = getSelectors(usePatientInfoStore, [
'patientInfo',
'pendingPatientInfoUpdates',
]);
const patientInfo = { ...currentPatientInfo, ...pendingPatientInfoUpdates, id: currentPatientInfo.id };
const initialPatientInfoRef = useRef(currentPatientInfo);
const { appointmentID } = getSelectors(useAppointmentStore, ['appointmentID']);
const { appointmentID, visitType, visitService, scheduleType, slug, selectedSlot } = getSelectors(
useAppointmentStore,
['appointmentID', 'visitType', 'visitService', 'scheduleType', 'slug', 'selectedSlot'],
);
const { patchCompletedPaperwork, setQuestions } = getSelectors(usePaperworkStore, [
'patchCompletedPaperwork',
'setQuestions',
Expand Down Expand Up @@ -165,6 +169,11 @@ const PatientInformation = (): JSX.Element => {
return;
}

if (isSlotTimePassed(selectedSlot, visitType)) {
setIsPastTimeErrorDialogOpen(true);
return;
}

if (!apiClient) {
throw new Error('apiClient is not defined');
}
Expand Down Expand Up @@ -397,6 +406,22 @@ const PatientInformation = (): JSX.Element => {
closeButtonText={t('general.button.close')}
handleClose={() => setRequestErrorDialogOpen(false)}
/>
<ErrorDialog
open={isPastTimeErrorDialogOpen}
title={t('patientInfo.pastTimeError.title')}
description={t('patientInfo.pastTimeError.description')}
closeButtonText={t('patientInfo.pastTimeError.button')}
handleClose={() =>
handleClosePastTimeErrorDialog(
setIsPastTimeErrorDialogOpen,
navigate,
visitType,
visitService,
scheduleType,
slug,
)
}
/>
</CustomContainer>
);
};
Expand Down
9 changes: 7 additions & 2 deletions packages/telemed-intake/app/src/pages/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ const Welcome = (): JSX.Element => {
}, [visitService, setAppointment, visitType, scheduleType]);

useEffect(() => {
setAppointment({ locationID: schedule?.locationID, providerID: schedule?.providerID, groupID: schedule?.groupID });
}, [schedule?.groupID, schedule?.locationID, schedule?.providerID, setAppointment]);
setAppointment({
locationID: schedule?.locationID,
providerID: schedule?.providerID,
groupID: schedule?.groupID,
slug,
});
}, [schedule?.groupID, schedule?.locationID, schedule?.providerID, setAppointment, slug]);

const clearState = (): void => {
useAppointmentStore.setState({ appointmentID: undefined, appointmentDate: undefined });
Expand Down
5 changes: 5 additions & 0 deletions packages/telemed-intake/app/src/theme/ottehr/i18n-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@
"requestError": {
"title": "Error",
"description": "An error occurred. Please, try again in a moment."
},
"pastTimeError": {
"title": "Error booking visit",
"description": "We are sorry, your selected check-in time has passed. Please click below to select a different time slot.",
"button": "Select a time slot"
}
},
"patientPortal": {
Expand Down
40 changes: 40 additions & 0 deletions packages/telemed-intake/app/src/utils/checkSlotTime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { DateTime } from 'luxon';
import { NavigateFunction } from 'react-router-dom';
import { IntakeFlowPageRoute } from 'src/App';

export const isSlotTimePassed = (selectedSlot: string | undefined, visitType: string | undefined): boolean => {
if (visitType === 'now') {
return false;
}
if (!selectedSlot) return false;
const slotDateTime = DateTime.fromISO(selectedSlot);
console.log('slotDateTime', slotDateTime);
const now = DateTime.now();
console.log('now', now);
return slotDateTime < now;
};

export const handleClosePastTimeErrorDialog = (
setIsPastTimeErrorDialogOpen: (value: boolean) => void,
navigate: NavigateFunction,
visitType: string | undefined,
visitService: string | undefined,
scheduleType: string | undefined,
slug: string | undefined,
): void => {
if (!visitService || !visitType || !scheduleType || !slug) {
console.error('One or more required parameters are missing');
navigate(IntakeFlowPageRoute.PatientPortal.path);
return;
}

setIsPastTimeErrorDialogOpen(false);

navigate(
`${IntakeFlowPageRoute.Welcome.path
.replace(':schedule-type', scheduleType)
.replace(':slug', slug)
.replace(':visit-service', visitService)
.replace(':visit-type', visitType)}`,
);
};
1 change: 1 addition & 0 deletions packages/telemed-intake/app/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './getZapEHRAPI';
export * from './getPaperworkPageInfo';
export * from './mapQuestionsToFormInputFields';
export * from './zustandDevtools';
export * from './checkSlotTime';
8 changes: 4 additions & 4 deletions packages/telemed-intake/zambdas/scripts/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import devConfig from '../.env/development.json';
import testingConfig from '../.env/testing.json';
// import testingConfig from '../.env/testing.json';
import { FhirClient, ZambdaClient } from '@zapehr/sdk';
import { getM2MClientToken } from '../src/shared';

Expand All @@ -10,9 +10,9 @@ export const performEffectWithEnvFile = async (callback: (config: any) => void)
case 'development':
await callback(devConfig);
break;
case 'testing':
await callback(testingConfig);
break;
// case 'testing':
// await callback(testingConfig);
// break;
default:
throw new Error('¯\\_(ツ)_/¯ environment must match a valid zapEHR environment.');
}
Expand Down

0 comments on commit 0239835

Please sign in to comment.