Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('DeleteSubmitStage', () => {
});
});

it('renders DeletionConfirmationStage when the Yes is selected and Continue clicked, when user role is GP_ADMIN', async () => {
it('renders lloyd george DeletionCompleteStage when the Yes is selected and Continue clicked, when user role is GP_ADMIN and feature flag is disabled', async () => {
mockedUseRole.mockReturnValue(REPOSITORY_ROLE.GP_ADMIN);

mockedAxios.delete.mockReturnValue(Promise.resolve({ status: 200, data: 'Success' }));
Expand All @@ -162,13 +162,18 @@ describe('DeleteSubmitStage', () => {

await waitFor(() => {
expect(mockedUseNavigate).toHaveBeenCalledWith(
routeChildren.DOCUMENT_DELETE_COMPLETE,
routeChildren.LLOYD_GEORGE_DELETE_COMPLETE,
);
});
});

it('calls resetDocState when the Yes is selected and Continue clicked', async () => {
it('renders DeletionCompleteStage when the Yes is selected and Continue clicked, when user role is GP_ADMIN and feature flag is enabled', async () => {
mockedUseRole.mockReturnValue(REPOSITORY_ROLE.GP_ADMIN);
mockuseConfig.mockReturnValue({
featureFlags: {
uploadDocumentIteration3Enabled: true,
},
});

mockedAxios.delete.mockReturnValue(Promise.resolve({ status: 200, data: 'Success' }));

Expand All @@ -181,12 +186,14 @@ describe('DeleteSubmitStage', () => {
await userEvent.click(screen.getByRole('button', { name: 'Continue' }));

await waitFor(() => {
expect(mockResetDocState).toHaveBeenCalled();
expect(mockedUseNavigate).toHaveBeenCalledWith(
routeChildren.DOCUMENT_DELETE_COMPLETE,
);
});
});

it('renders DeletionConfirmationStage when the Yes is selected and Continue clicked, when user role is PCSE', async () => {
mockedUseRole.mockReturnValue(REPOSITORY_ROLE.PCSE);
it('calls resetDocState when the Yes is selected and Continue clicked', async () => {
mockedUseRole.mockReturnValue(REPOSITORY_ROLE.GP_ADMIN);

mockedAxios.delete.mockReturnValue(Promise.resolve({ status: 200, data: 'Success' }));

Expand All @@ -199,9 +206,7 @@ describe('DeleteSubmitStage', () => {
await userEvent.click(screen.getByRole('button', { name: 'Continue' }));

await waitFor(() => {
expect(mockedUseNavigate).toHaveBeenCalledWith(
routeChildren.DOCUMENT_DELETE_COMPLETE,
);
expect(mockResetDocState).toHaveBeenCalled();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import useBaseAPIHeaders from '../../../../helpers/hooks/useBaseAPIHeaders';
import { DOWNLOAD_STAGE } from '../../../../types/generic/downloadStage';
import SpinnerButton from '../../../generic/spinnerButton/SpinnerButton';
import ServiceError from '../../../layout/serviceErrorBox/ServiceErrorBox';
import { SUBMISSION_STATE } from '../../../../types/pages/documentSearchResultsPage/types';
import {
DocumentReference,
SUBMISSION_STATE,
} from '../../../../types/pages/documentSearchResultsPage/types';
import { AxiosError } from 'axios';
import { routeChildren, routes } from '../../../../types/generic/routes';
import { Outlet, Route, Routes, useNavigate } from 'react-router-dom';
Expand All @@ -23,12 +26,18 @@ import useTitle from '../../../../helpers/hooks/useTitle';
import ErrorBox from '../../../layout/errorBox/ErrorBox';
import BackButton from '../../../generic/backButton/BackButton';
import PatientSummary, { PatientInfo } from '../../../generic/patientSummary/PatientSummary';
import { DOCUMENT_TYPE, getDocumentTypeLabel } from '../../../../helpers/utils/documentType';
import {
DOCUMENT_TYPE,
DOCUMENT_TYPE_CONFIG,
getConfigForDocType,
getDocumentTypeLabel,
} from '../../../../helpers/utils/documentType';
import { getLastURLPath } from '../../../../helpers/utils/urlManipulations';
import DeleteResultStage from '../deleteResultStage/DeleteResultStage';

export type Props = {
docType: DOCUMENT_TYPE;
document?: DocumentReference;
docType?: DOCUMENT_TYPE;
setDownloadStage?: Dispatch<SetStateAction<DOWNLOAD_STAGE>>;
resetDocState: () => void;
};
Expand All @@ -39,11 +48,13 @@ enum DELETE_DOCUMENTS_OPTION {
}

type IndexViewProps = {
docType: DOCUMENT_TYPE;
document?: DocumentReference;
docType?: DOCUMENT_TYPE;
resetDocState: () => void;
};

const DeleteSubmitStageIndexView = ({
export const DeleteSubmitStageIndexView = ({
document,
docType,
resetDocState,
}: IndexViewProps): React.JSX.Element => {
Expand All @@ -62,15 +73,26 @@ const DeleteSubmitStageIndexView = ({
'Select whether you want to permanently delete these patient files';
const userIsGP = role === REPOSITORY_ROLE.GP_ADMIN || role === REPOSITORY_ROLE.GP_CLINICAL;

let documentConfig: DOCUMENT_TYPE_CONFIG | null = null;
if (docType !== DOCUMENT_TYPE.ALL) {
documentConfig = getConfigForDocType(document?.documentSnomedCodeType ?? docType!)
docType = documentConfig.snomedCode as DOCUMENT_TYPE;
}

const handleYesOption = async (): Promise<void> => {
const onSuccess = (): void => {
resetDocState();
setDeletionStage(SUBMISSION_STATE.SUCCEEDED);
navigate(routeChildren.DOCUMENT_DELETE_COMPLETE);
navigate(
config.featureFlags.uploadDocumentIteration3Enabled
? routeChildren.DOCUMENT_DELETE_COMPLETE
: routeChildren.LLOYD_GEORGE_DELETE_COMPLETE,
);
};
try {
setDeletionStage(SUBMISSION_STATE.PENDING);
const response: DeleteResponse = await deleteAllDocuments({
documentId: !documentConfig?.singleDocumentOnly ? document?.id : undefined,
docType: docType,
nhsNumber: nhsNumber,
baseUrl,
Expand Down Expand Up @@ -116,8 +138,15 @@ const DeleteSubmitStageIndexView = ({
}
};

const pageTitle = `You are removing the ${getDocumentTypeLabel(docType) ?? 'records'} of`;
useTitle({ pageTitle });
const pageTitle = (): string => {
if (docType) {
return `You are removing the ${getDocumentTypeLabel(docType) ?? 'records'} of`;
}

return `You are removing a record from patient`;
};

useTitle({ pageTitle: pageTitle() });

return (
<>
Expand All @@ -141,13 +170,23 @@ const DeleteSubmitStageIndexView = ({
)}
<form onSubmit={handleSubmit(submit)}>
<Fieldset id="radio-selection">
<Fieldset.Legend isPageHeading>{pageTitle}:</Fieldset.Legend>
<Fieldset.Legend isPageHeading>{pageTitle()}:</Fieldset.Legend>
<PatientSummary showDeceasedTag>
<PatientSummary.Child item={PatientInfo.FULL_NAME} />
<PatientSummary.Child item={PatientInfo.NHS_NUMBER} />
<PatientSummary.Child item={PatientInfo.BIRTH_DATE} />
</PatientSummary>

{document && (
<>
<p>
Record type:{' '}
{documentConfig?.displayName}
</p>
<p>Filename: {document.fileName}</p>
</>
)}

{!userIsGP && (
<WarningCallout>
<WarningCallout.Label>Before removing</WarningCallout.Label>
Expand Down Expand Up @@ -223,6 +262,7 @@ const DeleteSubmitStageIndexView = ({
};

const DeleteSubmitStage = ({
document,
docType,
setDownloadStage,
resetDocState,
Expand All @@ -234,21 +274,12 @@ const DeleteSubmitStage = ({
index
element={
<DeleteSubmitStageIndexView
document={document}
docType={docType}
resetDocState={resetDocState}
/>
}
/>
<Route
path={getLastURLPath(routeChildren.DOCUMENT_DELETE_CONFIRMATION)}
element={
<DeleteSubmitStage
docType={docType}
setDownloadStage={setDownloadStage}
resetDocState={resetDocState}
/>
}
/>
<Route
path={getLastURLPath(routeChildren.DOCUMENT_DELETE_COMPLETE)}
element={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import ProgressBar from '../../../generic/progressBar/ProgressBar';
import { isMock } from '../../../../helpers/utils/isLocal';
import { buildSearchResult } from '../../../../helpers/test/testBuilders';
import { getLastURLPath } from '../../../../helpers/utils/urlManipulations';
import DeleteSubmitStage from '../deleteSubmitStage/DeleteSubmitStage';
import { DeleteSubmitStageIndexView } from '../deleteSubmitStage/DeleteSubmitStage';
import DeleteResultStage from '../deleteResultStage/DeleteResultStage';
import { DOWNLOAD_STAGE } from '../../../../types/generic/downloadStage';
import PatientSummary from '../../../generic/patientSummary/PatientSummary';
Expand Down Expand Up @@ -204,7 +204,12 @@ const RemoveRecordStage = ({
<Route index element={PageIndexView()}></Route>
<Route
path={getLastURLPath(routeChildren.LLOYD_GEORGE_DELETE_CONFIRMATION) + '/*'}
element={<DeleteSubmitStage docType={docType} resetDocState={resetDocState} />}
element={
<DeleteSubmitStageIndexView
docType={docType}
resetDocState={resetDocState}
/>
}
></Route>
<Route
path={getLastURLPath(routeChildren.LLOYD_GEORGE_DELETE_COMPLETE)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const mockUsePatient = usePatient as Mock;
const mockUseTitle = useTitle as Mock;
const mockUseRole = useRole as Mock;
const mockUseNavigate = vi.fn();
const mockRemoveDocuments = vi.fn();
const mockRemoveDocument = vi.fn();
const mockCreateSearchParams = vi.fn();

const EMBEDDED_PDF_VIEWER_TITLE = 'Embedded PDF Viewer';
Expand Down Expand Up @@ -89,7 +89,7 @@ const TestApp = ({ documentReference }: Props) => {
<ReactRouter.Router navigator={history} location={history.location}>
<DocumentView
documentReference={documentReference}
removeDocuments={mockRemoveDocuments}
removeDocument={mockRemoveDocument}
/>
</ReactRouter.Router>
);
Expand Down Expand Up @@ -321,15 +321,13 @@ describe('DocumentView', () => {
});

describe('Document actions', () => {
it('calls removeDocuments when remove action is triggered', () => {
it('calls removeDocument when remove action is triggered', () => {
renderComponent();

// Assuming the first record link is remove action
const removeRecordLink = screen.getByTestId(lloydGeorgeRecordLinks[0].key);
fireEvent.click(removeRecordLink);
expect(mockRemoveDocuments).toHaveBeenCalledWith(
mockDocumentReference.documentSnomedCodeType,
);
expect(mockRemoveDocument).toHaveBeenCalled();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import useRole from '../../../../helpers/hooks/useRole';

type Props = {
documentReference: DocumentReference | null;
removeDocuments: (docType: DOCUMENT_TYPE) => void;
removeDocument: () => void;
};

const DocumentView = ({
documentReference,
removeDocuments,
removeDocument,
}: Readonly<Props>): React.JSX.Element => {
const [session, setUserSession] = useSessionContext();
const role = useRole();
Expand Down Expand Up @@ -95,7 +95,7 @@ const DocumentView = ({

const removeClicked = (): void => {
disableFullscreen();
removeDocuments(documentReference.documentSnomedCodeType);
removeDocument();
};

const getCardLinks = (): Array<LGRecordActionLink> => {
Expand Down
5 changes: 4 additions & 1 deletion app/src/helpers/requests/deleteAllDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { AuthHeaders } from '../../types/blocks/authHeaders';
import { DOCUMENT_TYPE } from '../utils/documentType';

type Args = {
docType: DOCUMENT_TYPE;
documentId?: string;
docType?: DOCUMENT_TYPE;
nhsNumber: string;
baseUrl: string;
baseHeaders: AuthHeaders;
Expand All @@ -14,6 +15,7 @@ export type DeleteResponse = {
status: number;
};
const deleteAllDocuments = async ({
documentId,
docType,
nhsNumber,
baseUrl,
Expand All @@ -29,6 +31,7 @@ const deleteAllDocuments = async ({
params: {
patientId: nhsNumber,
docType,
documentId,
},
});
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const DocumentSearchResultsPage = (): React.JSX.Element => {
const config = useConfig();
const mounted = useRef(false);
const activeSearchResult = useRef<SearchResult | null>(null);
const [removeDocType, setRemoveDocType] = useState<DOCUMENT_TYPE | undefined>(undefined);

useEffect(() => {
const onPageLoad = async (): Promise<void> => {
Expand Down Expand Up @@ -159,8 +158,7 @@ const DocumentSearchResultsPage = (): React.JSX.Element => {
return URL.createObjectURL(data);
};

const removeDocuments = (docType: DOCUMENT_TYPE): void => {
setRemoveDocType(docType);
const removeDocument = (): void => {
navigate(routeChildren.DOCUMENT_DELETE);
};

Expand All @@ -186,15 +184,16 @@ const DocumentSearchResultsPage = (): React.JSX.Element => {
element={
<DocumentView
documentReference={documentReference}
removeDocuments={removeDocuments}
removeDocument={removeDocument}
/>
}
/>
<Route
path={getLastURLPath(routeChildren.DOCUMENT_DELETE) + '/*'}
element={
<DeleteSubmitStage
docType={removeDocType ?? DOCUMENT_TYPE.ALL}
document={documentReference ?? undefined}
docType={documentReference ? undefined : DOCUMENT_TYPE.ALL}
resetDocState={(): void => {
mounted.current = false;
}}
Expand Down
4 changes: 4 additions & 0 deletions lambdas/enums/lambda_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ def create_error_body(self, params: Optional[dict] = None, **kwargs) -> str:
"err_code": "DDS_4002",
"message": "Failed to delete document object",
}
DocDelInvalidRequest = {
"err_code": "DDS_4003",
"message": "Invalid Request"
}
DocDelClient = {
"err_code": "DDS_5001",
"message": "Failed to delete documents",
Expand Down
Loading
Loading