Skip to content

Commit c849af3

Browse files
authored
Merge pull request #5829 from masslight/revert-5774-bholyshevskyi/otr-1680-after-consent-forms-complete-paperwork
Revert "Patient. Submit paperwork after Consent Forms completion"
2 parents cc2063e + 52e5be4 commit c849af3

File tree

6 files changed

+97
-4783
lines changed

6 files changed

+97
-4783
lines changed

apps/intake/src/pages/PaperworkPage.tsx

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ import { t } from 'i18next';
1818
import { FC, ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
1919
import { useTranslation } from 'react-i18next';
2020
import { Navigate, Outlet, useLocation, useNavigate, useParams } from 'react-router-dom';
21-
import { ErrorDialog, ErrorDialogConfig } from 'src/components/ErrorDialog';
22-
import ValidationErrorMessageContent from 'src/features/paperwork/components/ValidationErrorMessage';
23-
import { UNEXPECTED_ERROR_CONFIG } from 'src/helpers';
2421
import { useGetPaymentMethods, useSetupPaymentMethod } from 'src/telemed/features/paperwork';
2522
import {
2623
APIError,
@@ -45,7 +42,7 @@ import { persist } from 'zustand/middleware';
4542
import { ottehrApi } from '../api';
4643
import api from '../api/ottehrApi';
4744
import { PageContainer } from '../components';
48-
import { getFormValidationErrors, PaperworkContext, usePaperworkContext } from '../features/paperwork';
45+
import { PaperworkContext, usePaperworkContext } from '../features/paperwork';
4946
import PagedQuestionnaire from '../features/paperwork/PagedQuestionnaire';
5047
import useAppointmentNotFoundInformation from '../helpers/information';
5148
import { useGetFullName } from '../hooks/useGetFullName';
@@ -322,7 +319,6 @@ export const PaperworkPage: FC = () => {
322319
const saveProgress = usePaperworkStore((state) => {
323320
return state.saveProgress;
324321
});
325-
const [errorDialogConfig, setErrorDialogConfig] = useState<ErrorDialogConfig | undefined>(undefined);
326322
const {
327323
paperwork: completedPaperwork,
328324
paperworkInProgress,
@@ -334,58 +330,6 @@ export const PaperworkPage: FC = () => {
334330
} = usePaperworkContext();
335331

336332
const questionnaireResponseId = questionnaireResponse?.id;
337-
338-
const submitPaperwork = useCallback(async (): Promise<boolean> => {
339-
const submitPaperwork = async (
340-
data: QuestionnaireResponseItem[],
341-
questionnaireResponseId: string,
342-
zambdaClient: ZambdaClient,
343-
appointmentId: string
344-
): Promise<void> => {
345-
await api.submitPaperwork(zambdaClient, { answers: data, questionnaireResponseId, appointmentId });
346-
};
347-
if (appointmentID && questionnaireResponseId && zambdaClient) {
348-
try {
349-
setLoading(true);
350-
try {
351-
// try to find out a better way of modeling when appointment id is/isn't needed when consolidating
352-
// this with the telemed code
353-
await submitPaperwork([], questionnaireResponseId, zambdaClient, appointmentID);
354-
return true;
355-
} catch (e) {
356-
const validationErrors = getFormValidationErrors(e);
357-
if (validationErrors) {
358-
console.log('validation errors returned: ', validationErrors);
359-
const links = paperworkPages.reduce(
360-
(accum, current) => {
361-
if (Object.keys(validationErrors).includes(current.linkId)) {
362-
accum[current.linkId] = {
363-
path: `/paperwork/${appointmentID}/${slugFromLinkId(current.linkId)}`,
364-
pageName: current.text ?? current.linkId,
365-
};
366-
}
367-
return accum;
368-
},
369-
{} as { [pageId: string]: { path: string; pageName: string } }
370-
);
371-
setErrorDialogConfig({
372-
title: t('paperworkPages.validationError'),
373-
description: <ValidationErrorMessageContent errorObject={validationErrors} links={links} />,
374-
});
375-
} else {
376-
setErrorDialogConfig(UNEXPECTED_ERROR_CONFIG(t));
377-
}
378-
}
379-
} catch (e) {
380-
// todo: handle this better, direct to page where error was found if available
381-
console.error('error submitting paperwork', e);
382-
} finally {
383-
setLoading(false);
384-
}
385-
}
386-
return false;
387-
}, [appointmentID, questionnaireResponseId, zambdaClient, paperworkPages]);
388-
389333
// this is just for avoiding duplicates in the mixpanel tracking
390334
const [lastLoggedPageName, setLastLoggedPageName] = useState<string>();
391335

@@ -507,14 +451,6 @@ export const PaperworkPage: FC = () => {
507451
});
508452
patchCompletedPaperwork(updatedPaperwork);
509453
saveProgress(currentPage.linkId, undefined);
510-
511-
if (currentPage.linkId === 'consent-forms-page') {
512-
const success = await submitPaperwork();
513-
if (!success) {
514-
return;
515-
}
516-
}
517-
518454
const nextPage = getNextPage(updatedPaperwork);
519455
navigate(
520456
`/paperwork/${appointmentID}/${nextPage !== undefined ? slugFromLinkId(nextPage.linkId) : 'review'}`
@@ -600,7 +536,6 @@ export const PaperworkPage: FC = () => {
600536
saveProgress,
601537
getNextPage,
602538
navigate,
603-
submitPaperwork,
604539
]
605540
);
606541

@@ -638,15 +573,6 @@ export const PaperworkPage: FC = () => {
638573
onContinueClick={validationRoadblockConfig?.onContinueClick}
639574
type={validationRoadblockConfig?.type ?? 'failure'}
640575
/>
641-
<ErrorDialog
642-
open={!!errorDialogConfig}
643-
title={errorDialogConfig?.title || 'Error Validating Form'}
644-
description={errorDialogConfig?.description || ''}
645-
closeButtonText={t('general.button.close')}
646-
handleClose={() => {
647-
setErrorDialogConfig(undefined);
648-
}}
649-
/>
650576
</>
651577
)}
652578
</PageContainer>

apps/intake/src/pages/ReviewPaperwork.tsx

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { EditOutlined } from '@mui/icons-material';
22
import { IconButton, Table, TableBody, TableCell, TableRow, Tooltip, Typography } from '@mui/material';
3+
import { QuestionnaireResponseItem } from 'fhir/r4b';
34
import { t } from 'i18next';
45
import { DateTime } from 'luxon';
56
import { useCallback, useEffect, useMemo, useState } from 'react';
@@ -8,17 +9,20 @@ import { TermsAndConditions } from 'src/components/TermsAndConditions';
89
import { makeValidationSchema, pickFirstValueFromAnswerItem, ServiceMode, uuidRegex, VisitType } from 'utils';
910
import { ValidationError } from 'yup';
1011
import { dataTestIds } from '../../src/helpers/data-test-ids';
12+
import api from '../api/ottehrApi';
1113
import { intakeFlowPageRoute } from '../App';
1214
import { PageContainer } from '../components';
1315
import { ErrorDialog, ErrorDialogConfig } from '../components/ErrorDialog';
1416
import PageForm from '../components/PageForm';
15-
import { usePaperworkContext } from '../features/paperwork';
17+
import { FormValidationErrorObject, getFormValidationErrors, usePaperworkContext } from '../features/paperwork';
18+
import ValidationErrorMessageContent from '../features/paperwork/components/ValidationErrorMessage';
19+
import { UNEXPECTED_ERROR_CONFIG } from '../helpers';
1620
import { getLocaleDateTimeString } from '../helpers/dateUtils';
1721
import { getValueBoolean } from '../helpers/form';
1822
import useAppointmentNotFoundInformation from '../helpers/information';
1923
import { useGetFullName } from '../hooks/useGetFullName';
2024
import { usePaperworkInviteParams } from '../hooks/usePaperworkInviteParams';
21-
import { useUCZambdaClient } from '../hooks/useUCZambdaClient';
25+
import { useUCZambdaClient, ZambdaClient } from '../hooks/useUCZambdaClient';
2226
import { otherColors } from '../IntakeThemeProvider';
2327
import i18n from '../lib/i18n';
2428
import { useAppointmentStore } from '../telemed/features/appointments/appointment.store';
@@ -32,8 +36,10 @@ const ReviewPaperwork = (): JSX.Element => {
3236
const navigate = useNavigate();
3337
const { id: appointmentID } = useParams();
3438
const { pathname } = useLocation();
39+
const [loading, setLoading] = useState(false);
3540
const [appointmentNotFound, setAppointmentNotFound] = useState<boolean>(false);
3641
const zambdaClient = useUCZambdaClient({ tokenless: true });
42+
const [validationErrors, setValidationErrors] = useState<FormValidationErrorObject | undefined>();
3743
const [errorDialogConfig, setErrorDialogConfig] = useState<ErrorDialogConfig | undefined>(undefined);
3844

3945
useEffect(() => {
@@ -186,10 +192,14 @@ const ReviewPaperwork = (): JSX.Element => {
186192
testId: dataTestIds.checkInTimePaperworkReviewScreen,
187193
},
188194
...(paperworkPages ?? []).map((paperworkPage) => {
195+
let hasError = false;
196+
if (validationErrors) {
197+
hasError = validationErrors[paperworkPage.linkId]?.length ? true : false;
198+
}
189199
return {
190200
name: paperworkPage.text ?? 'Review',
191201
path: `/paperwork/${appointmentID}/${slugFromLinkId(paperworkPage.linkId)}`,
192-
valueBoolean: paperworkCompletedStatus[paperworkPage.linkId],
202+
valueBoolean: paperworkCompletedStatus[paperworkPage.linkId] && !hasError,
193203
testId: paperworkPage.linkId + '-status',
194204
rowID: paperworkPage.linkId,
195205
valueTestId: paperworkPage.linkId + '-edit',
@@ -206,9 +216,48 @@ const ReviewPaperwork = (): JSX.Element => {
206216
}
207217
})();
208218

209-
const onSubmit = useCallback(async (): Promise<void> => {
219+
const submitPaperwork = useCallback(async (): Promise<void> => {
220+
const submitPaperwork = async (
221+
data: QuestionnaireResponseItem[],
222+
questionnaireResponseId: string,
223+
zambdaClient: ZambdaClient,
224+
appointmentId: string
225+
): Promise<void> => {
226+
await api.submitPaperwork(zambdaClient, { answers: data, questionnaireResponseId, appointmentId });
227+
};
210228
if (appointmentID && questionnaireResponseId && zambdaClient) {
211229
try {
230+
setLoading(true);
231+
try {
232+
// try to find out a better way of modeling when appointment id is/isn't needed when consolidating
233+
// this with the telemed code
234+
await submitPaperwork([], questionnaireResponseId, zambdaClient, appointmentID);
235+
} catch (e) {
236+
const validationErrors = getFormValidationErrors(e);
237+
if (validationErrors) {
238+
console.log('validation errors returned: ', validationErrors);
239+
setValidationErrors(validationErrors);
240+
const links = paperworkPages.reduce(
241+
(accum, current) => {
242+
if (Object.keys(validationErrors).includes(current.linkId)) {
243+
accum[current.linkId] = {
244+
path: `/paperwork/${appointmentID}/${slugFromLinkId(current.linkId)}`,
245+
pageName: current.text ?? current.linkId,
246+
};
247+
}
248+
return accum;
249+
},
250+
{} as { [pageId: string]: { path: string; pageName: string } }
251+
);
252+
setErrorDialogConfig({
253+
title: t('paperworkPages.validationError'),
254+
description: <ValidationErrorMessageContent errorObject={validationErrors} links={links} />,
255+
});
256+
} else {
257+
setErrorDialogConfig(UNEXPECTED_ERROR_CONFIG(t));
258+
}
259+
return;
260+
}
212261
if (visitType === VisitType.WalkIn) {
213262
if (serviceMode === ServiceMode['virtual']) {
214263
// navigate to waiting room
@@ -245,6 +294,8 @@ const ReviewPaperwork = (): JSX.Element => {
245294
} catch (e) {
246295
// todo: handle this better, direct to page where error was found if available
247296
console.error('error submitting paperwork', e);
297+
} finally {
298+
setLoading(false);
248299
}
249300
}
250301
}, [
@@ -253,6 +304,7 @@ const ReviewPaperwork = (): JSX.Element => {
253304
zambdaClient,
254305
visitType,
255306
serviceMode,
307+
paperworkPages,
256308
navigate,
257309
inviteParams,
258310
createInviteMutation,
@@ -337,8 +389,9 @@ const ReviewPaperwork = (): JSX.Element => {
337389
<PageForm
338390
controlButtons={{
339391
submitLabel: submitButtonLabel,
392+
loading: loading,
340393
}}
341-
onSubmit={onSubmit}
394+
onSubmit={submitPaperwork}
342395
/>
343396
<ErrorDialog
344397
open={!!errorDialogConfig}

apps/intake/tests/specs/in-person/Paperwork.spec.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,20 @@ test.describe.parallel('In-Person - No Paperwork Filled Yet', () => {
549549
// ).toBe('_blank');
550550
// });
551551

552-
await test.step('PCF-6. Fill all fields and click on [Continue]', async () => {
553-
await paperwork.fillConsentForms();
552+
const consentFormsData = await test.step('PCF-6. Fill all fields and click on [Continue]', async () => {
553+
const consentFormsData = await paperwork.fillConsentForms();
554554
await locator.clickContinueButton();
555-
// Given we've opened the page directly and didn't fill all the paperwork this is expected.
556-
await expect(page.getByText(`Error validating form`)).toBeVisible();
555+
await paperwork.checkCorrectPageOpens('Medical history');
556+
return consentFormsData;
557+
});
558+
559+
await test.step('PCF-7. Click on [Back] - all values are saved', async () => {
560+
await locator.clickBackButton();
561+
await expect(locator.hipaaAcknowledgement).toBeChecked();
562+
await expect(locator.consentToTreat).toBeChecked();
563+
await expect(locator.signature).toHaveValue(consentFormsData.signature);
564+
await expect(locator.consentFullName).toHaveValue(consentFormsData.consentFullName);
565+
await expect(locator.consentSignerRelationship).toHaveValue(consentFormsData.relationshipConsentForms);
557566
});
558567
});
559568
});

apps/intake/tests/specs/telemed/PaperworkTelemed.spec.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,11 +908,20 @@ test.describe.parallel('Telemed - No Paperwork Filled Yet', () => {
908908
// ).toBe('_blank');
909909
// });
910910

911-
await test.step('PCF-6. Fill all data and click on [Continue]', async () => {
912-
await paperwork.fillConsentForms();
911+
const consentFormsData = await test.step('PCF-6. Fill all data and click on [Continue]', async () => {
912+
const consentFormsData = await paperwork.fillConsentForms();
913913
await locator.clickContinueButton();
914-
// Given we've opened the page directly and didn't fill all the paperwork this is expected.
915-
await expect(page.getByText(`Error validating form`)).toBeVisible();
914+
await paperwork.checkCorrectPageOpens('Would you like someone to join this call?');
915+
return consentFormsData;
916+
});
917+
918+
await test.step('PCF-7. Click on [Back] - all values are saved', async () => {
919+
await locator.clickBackButton();
920+
await expect(locator.hipaaAcknowledgement).toBeChecked();
921+
await expect(locator.consentToTreat).toBeChecked();
922+
await expect(locator.signature).toHaveValue(consentFormsData.signature);
923+
await expect(locator.consentFullName).toHaveValue(consentFormsData.consentFullName);
924+
await expect(locator.consentSignerRelationship).toHaveValue(consentFormsData.relationshipConsentForms);
916925
});
917926
});
918927

@@ -926,6 +935,14 @@ test.describe.parallel('Telemed - No Paperwork Filled Yet', () => {
926935
await paperwork.checkPatientNameIsDisplayed(patient.firstName, patient.lastName);
927936
});
928937

938+
await test.step('PIP-3. Check required fields', async () => {
939+
await paperwork.checkRequiredFields(
940+
'"Is anyone joining this visit from another device?"',
941+
'Would you like someone to join this call?',
942+
false
943+
);
944+
});
945+
929946
await test.step('PIP-4. Select "No" and click [Continue]', async () => {
930947
await paperworkTelemed.fillAndCheckNoInviteParticipant();
931948
await locator.clickContinueButton();

0 commit comments

Comments
 (0)