diff --git a/e2e-tests/steps/apply.ts b/e2e-tests/steps/apply.ts index 12670b5..7555898 100644 --- a/e2e-tests/steps/apply.ts +++ b/e2e-tests/steps/apply.ts @@ -13,13 +13,7 @@ import { completeEqualityAndDiversityTask, completePersonalInformationTask, } from './aboutThePersonSection' -import { - completeHealthNeedsTask, - completeRiskToSelfTask, - completeRoshTask, - enterOldRiskToSelfOasysDate, - enterOldRoshOasysDate, -} from './risksAndNeedsSection' +import { completeHealthNeedsTask, completeRiskToSelfTask, completeRoshTask } from './risksAndNeedsSection' import { completeAreaInformationTask, completeFundingInformationTask } from './areaAndFundingSection' import { completeCurrentOffencesTask, completeOffenceHistoryTask } from './offenceAndLicenceInformationSection' import { completeCheckAnswersTask } from './checkAnswersSection' @@ -80,11 +74,6 @@ export const completeRisksAndNeedsSection = async (page: Page, name: string) => await completeRoshTask(page, name) } -export const enterOldOasysDates = async (page: Page, name: string) => { - await enterOldRiskToSelfOasysDate(page, name) - await enterOldRoshOasysDate(page, name) -} - export const completeOffenceInformationSection = async (page: Page, name: string) => { await completeCurrentOffencesTask(page, name) await completeOffenceHistoryTask(page, name) diff --git a/e2e-tests/steps/risksAndNeedsSection.ts b/e2e-tests/steps/risksAndNeedsSection.ts index b741c2e..5d53be2 100644 --- a/e2e-tests/steps/risksAndNeedsSection.ts +++ b/e2e-tests/steps/risksAndNeedsSection.ts @@ -118,7 +118,6 @@ export const completeRiskToSelfTask = async (page: Page, name: string) => { const taskListPage = new TaskListPage(page) await taskListPage.clickTask('Add risk to self information') - await reviewOasysImportPage(page, name) await completeVulnerabilityPage(page, name) await completeCurrentRisksPage(page, name) await completeHistoricalRisksPage(page, name) @@ -126,34 +125,6 @@ export const completeRiskToSelfTask = async (page: Page, name: string) => { await completeAdditionalInformationPage(page, name) } -export const enterOldRiskToSelfOasysDate = async (page: Page, name: string) => { - const taskListPage = new TaskListPage(page) - await taskListPage.clickTask('Add risk to self information') - - await reviewOasysImportPage(page, name) - await completeOldOasysPage(page, name) - await returnToTaskList(page) -} - -async function reviewOasysImportPage(page: Page, name: string) { - const guidancePage = await ApplyPage.initialize(page, `Import ${name}'s risk to self data from OASys`) - await guidancePage.clickContinue() -} - -async function completeOldOasysPage(page: Page, name: string) { - const oldOasysPage = await ApplyPage.initialize( - page, - `Does ${name} have an older OASys with risk to self information? `, - ) - await oldOasysPage.checkRadio('No') - await oldOasysPage.clickContinue() -} - -async function confirmAndSave(page: TaskListPage | ApplyPage) { - await page.checkCheckboxes(['I confirm this information is relevant and up to date.']) - await page.clickSave() -} - async function completeVulnerabilityPage(page: Page, name: string) { const vulnerabilityPage = await ApplyPage.initialize(page, `${name}'s vulnerability`) @@ -161,7 +132,7 @@ async function completeVulnerabilityPage(page: Page, name: string) { `Describe ${name}'s current circumstances, issues and needs related to vulnerability`, 'some vulnerability', ) - await confirmAndSave(vulnerabilityPage) + await vulnerabilityPage.clickSave() } async function completeCurrentRisksPage(page: Page, name: string) { @@ -171,7 +142,7 @@ async function completeCurrentRisksPage(page: Page, name: string) { `Describe ${name}'s current issues and needs related to self harm and suicide`, 'some needs', ) - await confirmAndSave(currentRisksPage) + await currentRisksPage.clickSave() } async function completeHistoricalRisksPage(page: Page, name: string) { @@ -181,7 +152,7 @@ async function completeHistoricalRisksPage(page: Page, name: string) { `Describe ${name}'s historical issues and needs related to self harm and suicide`, 'some needs', ) - await confirmAndSave(historicalRisksPage) + await historicalRisksPage.clickSave() } async function addAnAcct(page: Page) { @@ -213,50 +184,17 @@ export const completeRoshTask = async (page: Page, name: string) => { const taskListPage = new TaskListPage(page) await taskListPage.clickTask('Add risk of serious harm (RoSH) information') - await reviewRoshOasysImportPage(page, name) - await completeRoshSummaryPage(page, name) - await completeRiskToOthersPage(page) + await completeRiskToOthersPage(page, name) await completeRiskManagementArrangementsPage(page, name) await completeCellShareInformationPage(page, name) await completeAdditionalRiskPage(page, name) } -export const enterOldRoshOasysDate = async (page: Page, name: string) => { - const taskListPage = new TaskListPage(page) - await taskListPage.clickTask('Add risk of serious harm (RoSH) information') - - await reviewRoshOasysImportPage(page, name) - await completeOldOasysRoshPage(page, name) - await returnToTaskList(page) -} - -async function completeOldOasysRoshPage(page: Page, name: string) { - const oldOasysPage = await ApplyPage.initialize( - page, - `Does ${name} have an older OASys with risk of serious harm (RoSH) information? `, - ) - await oldOasysPage.checkRadio('No') - await oldOasysPage.clickContinue() -} - -async function returnToTaskList(page: Page) { - const applyPage = new TaskListPage(page) - await applyPage.clickLink('Back to task list') -} - -async function reviewRoshOasysImportPage(page: Page, name: string) { - const guidancePage = await ApplyPage.initialize(page, `Import ${name}'s risk of serious harm (RoSH) data from OASys`) - await guidancePage.clickContinue() -} - -async function completeRoshSummaryPage(page: Page, name: string) { - const summaryPage = await ApplyPage.initialize(page, `Risk of serious harm (RoSH) summary for ${name}`) - await summaryPage.clickSave() -} - -async function completeRiskToOthersPage(page: Page) { - const riskToOthersPage = new TaskListPage(page) - await confirmAndSave(riskToOthersPage) +async function completeRiskToOthersPage(page: Page, name: string) { + const riskToOthersPage = await ApplyPage.initialize(page, `Risk to others for ${name}`) + await riskToOthersPage.fillField('Who is at risk?', 'a person') + await riskToOthersPage.fillField('What is the nature of the risk?', 'some details about the risk') + await riskToOthersPage.clickSave() } async function completeRiskManagementArrangementsPage(page: Page, name: string) { diff --git a/e2e-tests/tests/01_apply_as_pom.spec.ts b/e2e-tests/tests/01_apply_as_pom.spec.ts index ee2575d..fc7c855 100644 --- a/e2e-tests/tests/01_apply_as_pom.spec.ts +++ b/e2e-tests/tests/01_apply_as_pom.spec.ts @@ -14,7 +14,6 @@ import { submitApplication, viewSubmittedApplication, addNote, - enterOldOasysDates, viewInProgressDashboard, createAnInProgressApplication, } from '../steps/apply' @@ -44,15 +43,6 @@ test('add a note to a submitted application', async ({ page, person, pomUser }) await expect(page.locator('.moj-timeline__title').first()).toContainText('Note') }) -test('create a CAS-2 application with no OASys', async ({ page, personWithoutOasys, pomUser }) => { - await signIn(page, pomUser) - await startAnApplication(page) - await enterPrisonerNumber(page, personWithoutOasys.nomsNumber) - await confirmApplicant(page) - await completeBeforeYouStartSection(page, personWithoutOasys.name) - await enterOldOasysDates(page, personWithoutOasys.name) -}) - test('cancel an in progress application from the task list', async ({ page, pomUser, person }) => { await signIn(page, pomUser) await createAnInProgressApplication(page, person) diff --git a/integration_tests/fixtures/applicationData.json b/integration_tests/fixtures/applicationData.json index 37e79fe..882715c 100644 --- a/integration_tests/fixtures/applicationData.json +++ b/integration_tests/fixtures/applicationData.json @@ -199,11 +199,6 @@ } }, "risk-to-self": { - "oasys-import": { - "oasysImportedDate": "2023-09-21T15:47:51.430Z", - "oasysStartedDate": "2023-09-10", - "oasysCompletedDate": "2023-09-11" - }, "current-risk": { "currentRiskDetail": "[R8.1.1] Review 06.10.21:\r\n\r\n There have been numerous ACCTs opened since 2013 and every subsequent year he has been in custody. In 2021...", "confirmation": "confirmed" @@ -244,27 +239,9 @@ } }, "risk-of-serious-harm": { - "oasys-import": { "oasysImportedDate": "2023-09-21T15:47:51.430Z" }, - "summary-data": { - "oasysImportedDate": "2023-09-21T15:47:51.430Z", - "oasysStartedDate": "2023-09-10", - "oasysCompletedDate": "2023-09-11", - "status": "retrieved", - "value": { - "overallRisk": "High", - "riskToChildren": "High", - "riskToPublic": "Very High", - "riskToKnownAdult": "Medium", - "riskToStaff": "Low" - } - }, - "summary": { - "additionalComments": "some rosh comments" - }, "risk-to-others": { "whoIsAtRisk": "a person", - "natureOfRisk": "a nature", - "confirmation": "confirmed" + "natureOfRisk": "a nature" }, "risk-management-arrangements": { "arrangements": ["mappa", "marac", "iom"], diff --git a/server/@types/ui/index.d.ts b/server/@types/ui/index.d.ts index bfa50c5..3d8ceb6 100644 --- a/server/@types/ui/index.d.ts +++ b/server/@types/ui/index.d.ts @@ -1,7 +1,3 @@ -import { OASysRiskOfSeriousHarm } from '../shared/models/OASysRiskOfSeriousHarm' -import { OASysRiskToSelf } from '../shared/models/OASysRiskToSelf' -import { RoshRisksEnvelope } from '../shared/models/RoshRisksEnvelope' - export type JourneyType = 'applications' export type UiTask = { @@ -46,9 +42,6 @@ export type FormArtifact = Cas2Application export type DataServices = Partial<{ personService: { findByPrisonNumber: (token: string, prisonNumber: string) => Promise - getOasysRiskToSelf: (token: string, crn: string) => Promise - getOasysRosh: (token: string, crn: string) => Promise - getRoshRisks: (token: string, crn: string) => Promise } applicationService: { findApplication: (token: string, id: string) => Promise @@ -91,10 +84,6 @@ export type UserDetails = { roles: Array } -export type OasysImportArrays = ArrayOfOASysRiskOfSeriousHarmSummaryQuestions - -export type RiskLevel = 'Low' | 'Medium' | 'High' | 'Very High' - export type TierNumber = '1' | '2' | '3' | '4' export type TierLetter = 'A' | 'B' | 'C' | 'D' export type RiskTierLevel = `${TierLetter}${TierNumber}` diff --git a/server/data/personClient.test.ts b/server/data/personClient.test.ts index 44d98b9..efff10a 100644 --- a/server/data/personClient.test.ts +++ b/server/data/personClient.test.ts @@ -1,6 +1,5 @@ import PersonClient from './personClient' -import { oasysRiskToSelfFactory, personFactory, oasysRoshFactory, risksFactory } from '../testutils/factories' -import paths from '../paths/api' +import { personFactory } from '../testutils/factories' import describeClient from '../testutils/describeClient' @@ -13,62 +12,6 @@ describeClient('PersonClient', provider => { personClient = new PersonClient(token) }) - describe('oasysRiskToSelf', () => { - it('should return the Risk to Self data', async () => { - const crn = 'crn' - const oasysRiskToSelf = oasysRiskToSelfFactory.build() - - provider.addInteraction({ - state: 'Server is healthy', - uponReceiving: 'A request to get the optional selected sections of OASys for a person', - withRequest: { - method: 'GET', - path: paths.people.oasys.riskToSelf({ crn }), - query: {}, - headers: { - authorization: `Bearer ${token}`, - }, - }, - willRespondWith: { - status: 200, - body: oasysRiskToSelf, - }, - }) - - const result = await personClient.oasysRiskToSelf(crn) - - expect(result).toEqual(oasysRiskToSelf) - }) - }) - - describe('oasysRosh', () => { - it('should return the Rosh data', async () => { - const crn = 'crn' - const oasysRosh = oasysRoshFactory.build() - - provider.addInteraction({ - state: 'Server is healthy', - uponReceiving: 'A request to get the optional selected sections of OASys for a person', - withRequest: { - method: 'GET', - path: paths.people.oasys.rosh({ crn }), - query: {}, - headers: { - authorization: `Bearer ${token}`, - }, - }, - willRespondWith: { - status: 200, - body: oasysRosh, - }, - }) - - const result = await personClient.oasysRosh(crn) - - expect(result).toEqual(oasysRosh) - }) - }) - describe('search', () => { it('should return a person', async () => { const person = personFactory.build() @@ -97,31 +40,4 @@ describeClient('PersonClient', provider => { expect(result).toEqual(person) }) }) - - describe('risks', () => { - it('should return the risks for a person', async () => { - const crn = 'crn' - const risks = risksFactory.build() - - provider.addInteraction({ - state: 'Server is healthy', - uponReceiving: 'A request to get the risks for a person', - withRequest: { - method: 'GET', - path: `/cas2/people/${crn}/risks`, - headers: { - authorization: `Bearer ${token}`, - }, - }, - willRespondWith: { - status: 200, - body: risks, - }, - }) - - const result = await personClient.risks(crn) - - expect(result).toEqual(risks) - }) - }) }) diff --git a/server/data/personClient.ts b/server/data/personClient.ts index 4133e59..907b1e2 100644 --- a/server/data/personClient.ts +++ b/server/data/personClient.ts @@ -1,4 +1,4 @@ -import type { FullPerson, OASysRiskOfSeriousHarm, OASysRiskToSelf, PersonRisks } from '@approved-premises/api' +import type { FullPerson, PersonRisks } from '@approved-premises/api' import RestClient from './restClient' import config, { ApiConfig } from '../config' @@ -12,22 +12,6 @@ export default class PersonClient { this.restClient = new RestClient('personClient', config.apis.approvedPremises as ApiConfig, token) } - async oasysRiskToSelf(crn: string): Promise { - const path = paths.people.oasys.riskToSelf({ crn }) - - const response = (await this.restClient.get({ path })) as OASysRiskToSelf - - return response - } - - async oasysRosh(crn: string): Promise { - const path = paths.people.oasys.rosh({ crn }) - - const response = (await this.restClient.get({ path })) as OASysRiskOfSeriousHarm - - return response - } - async search(nomsNumber: string): Promise { const query = { nomsNumber } as Record diff --git a/server/form-pages/apply/bail-information/bail-hearing-information/bailHearingDate.test.ts b/server/form-pages/apply/bail-information/bail-hearing-information/bailHearingDate.test.ts index 98ff932..2787af1 100644 --- a/server/form-pages/apply/bail-information/bail-hearing-information/bailHearingDate.test.ts +++ b/server/form-pages/apply/bail-information/bail-hearing-information/bailHearingDate.test.ts @@ -9,17 +9,35 @@ describe('BailHearingDate', () => { itShouldHaveNextValue(new BailHearingDate({}, application), 'bail-hearing-medium') describe('response', () => { - const body: BailHearingDateBody = { - bailHearingDate: '2024-03-27', - 'bailHearingDate-month': '10', - 'bailHearingDate-year': '2023', - 'bailHearingDate-day': '01', - } + describe('when a date is provided', () => { + const body: BailHearingDateBody = { + bailHearingDate: '2024-03-27', + 'bailHearingDate-month': '10', + 'bailHearingDate-year': '2023', + 'bailHearingDate-day': '01', + } - it('returns the hearing date', () => { - const page = new BailHearingDate(body, application) - expect(page.response()).toEqual({ - "When is Roger Smith's bail hearing?": '1 October 2023', + it('returns the hearing date', () => { + const page = new BailHearingDate(body, application) + expect(page.response()).toEqual({ + "When is Roger Smith's bail hearing?": '1 October 2023', + }) + }) + }) + + describe('when a date is not provided', () => { + const body: BailHearingDateBody = { + bailHearingDate: '', + 'bailHearingDate-month': '', + 'bailHearingDate-year': '', + 'bailHearingDate-day': '', + } + + it('returns an empty string', () => { + const page = new BailHearingDate(body, application) + expect(page.response()).toEqual({ + "When is Roger Smith's bail hearing?": '', + }) }) }) }) diff --git a/server/form-pages/apply/bail-information/bail-hearing-information/bailHearingDate.ts b/server/form-pages/apply/bail-information/bail-hearing-information/bailHearingDate.ts index 5f1395e..575e76b 100644 --- a/server/form-pages/apply/bail-information/bail-hearing-information/bailHearingDate.ts +++ b/server/form-pages/apply/bail-information/bail-hearing-information/bailHearingDate.ts @@ -49,7 +49,9 @@ export default class BailHearingDate implements TaskListPage { response() { return { - [this.questions.bailHearingDate.question]: DateFormats.dateAndTimeInputsToUiDate(this.body, 'bailHearingDate'), + [this.questions.bailHearingDate.question]: this.body.bailHearingDate + ? DateFormats.dateAndTimeInputsToUiDate(this.body, 'bailHearingDate') + : '', } } } diff --git a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/custom-forms/oasysImport.test.ts b/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/custom-forms/oasysImport.test.ts deleted file mode 100644 index 6326018..0000000 --- a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/custom-forms/oasysImport.test.ts +++ /dev/null @@ -1,187 +0,0 @@ -import { createMock } from '@golevelup/ts-jest' -import type { DataServices } from '@approved-premises/ui' -import { DateFormats } from '../../../../../utils/dateUtils' -import { itShouldHaveNextValue, itShouldHavePreviousValue } from '../../../../shared-examples' -import { personFactory, applicationFactory, roshRisksEnvelopeFactory } from '../../../../../testutils/factories/index' -import OasysImport, { RoshTaskData } from './oasysImport' -import PersonService from '../../../../../services/personService' -import oasysRoshFactory from '../../../../../testutils/factories/oasysRosh' -import Summary from '../summary' -import OldOasys from '../oldOasys' - -jest.mock('../oldOasys') -jest.mock('../summary') - -describe('OasysImport', () => { - const application = applicationFactory.build({ person: personFactory.build({ name: 'Roger Smith' }) }) - const oasys = oasysRoshFactory.build({ - dateCompleted: DateFormats.dateObjToIsoDateTime(new Date(2023, 7, 29)), - dateStarted: DateFormats.dateObjToIsoDateTime(new Date(2023, 7, 28)), - }) - - const dataServices = createMock({ personService: createMock({}) }) - - const now = new Date() - - beforeAll(() => { - jest.useFakeTimers() - jest.setSystemTime(now) - }) - - afterAll(() => { - jest.useRealTimers() - }) - - describe('title', () => { - it('personalises the page title', () => { - const page = new OasysImport({}, application, oasys, '') - - expect(page.title).toEqual("Import Roger Smith's risk of serious harm (RoSH) data from OASys") - }) - }) - - describe('initialize', () => { - describe('when oasys sections are returned', () => { - it('instantiates the class with the task data in the correct format', async () => { - oasys.rosh = [ - { - label: 'Who is at risk', - questionNumber: 'R10.1', - answer: 'who is at risk answer', - }, - { - label: 'What is the nature of the risk', - questionNumber: 'R10.2', - answer: 'nature of risk answer', - }, - { - label: 'What circumstances are likely to reduce the risk', - questionNumber: 'R10.5', - answer: 'circumstances likely to reduce risk answer', - }, - ] - - const riskSummary = roshRisksEnvelopeFactory.build() - - const taskData = { - 'risk-of-serious-harm': { - summary: {}, - 'summary-data': { - ...riskSummary, - oasysImportedDate: now, - oasysStartedDate: oasys.dateStarted, - oasysCompletedDate: oasys.dateCompleted, - }, - 'risk-to-others': { - whoIsAtRisk: 'who is at risk answer', - natureOfRisk: 'nature of risk answer', - }, - 'oasys-import': { oasysImportedDate: now }, - }, - } - - ;(dataServices.personService.getOasysRosh as jest.Mock).mockResolvedValue(oasys) - ;(dataServices.personService.getRoshRisks as jest.Mock).mockResolvedValue(riskSummary) - - const page = (await OasysImport.initialize({}, application, 'some-token', dataServices)) as OasysImport - - expect(page.taskData).toBe(JSON.stringify(taskData)) - expect(page.hasOasysRecord).toBe(true) - expect(page.oasysCompleted).toBe('29 August 2023') - expect(page.oasysStarted).toBe('28 August 2023') - }) - - describe('when there is not a completed date', () => { - it('does not assign a completed date', async () => { - const oasysIncomplete = oasysRoshFactory.build({ dateCompleted: null }) - - ;(dataServices.personService.getOasysRosh as jest.Mock).mockResolvedValue(oasysIncomplete) - ;(dataServices.personService.getRoshRisks as jest.Mock).mockResolvedValue(null) - - const page = (await OasysImport.initialize({}, application, 'some-token', dataServices)) as OasysImport - - expect(page.oasysCompleted).toBe(null) - }) - }) - }) - - describe('when oasys sections are not returned', () => { - it('sets hasOasysRecord to false when an error is returned', async () => { - ;(dataServices.personService.getOasysRosh as jest.Mock).mockRejectedValue(new Error()) - - const page = (await OasysImport.initialize({}, application, 'some-token', dataServices)) as OasysImport - - expect(page.hasOasysRecord).toBe(false) - expect(page.oasysCompleted).toBe(undefined) - expect(page.oasysStarted).toBe(undefined) - }) - }) - - describe('when OASys data has already been imported', () => { - it('returns the Rosh summary page', async () => { - const roshData = { - 'risk-of-serious-harm': { - 'oasys-import': { oasysImportedDate: now }, - }, - } as RoshTaskData - - const applicationWithData = applicationFactory.build({ - person: personFactory.build({ name: 'Roger Smith' }), - data: roshData, - }) - - const roshSummaryPageConstructor = jest.fn() - - ;(Summary as jest.Mock).mockImplementation(() => { - return roshSummaryPageConstructor - }) - - expect(OasysImport.initialize({}, applicationWithData, 'some-token', dataServices)).resolves.toEqual( - roshSummaryPageConstructor, - ) - - expect(Summary).toHaveBeenCalledWith({}, applicationWithData) - }) - - describe("when there is data but it hasn't been imported from OASys", () => { - it('returns the Old OASys page', async () => { - const roshData = { - 'risk-of-serious-harm': { - 'old-oasys': { - hasOldOasys: 'no', - }, - }, - } - - const applicationWithData = applicationFactory.build({ - person: personFactory.build({ name: 'Roger Smith' }), - data: roshData, - }) - - const oldOasysPageConstructor = jest.fn() - - ;(OldOasys as jest.Mock).mockImplementation(() => { - return oldOasysPageConstructor - }) - - expect(OasysImport.initialize({}, applicationWithData, 'some-token', dataServices)).resolves.toEqual( - oldOasysPageConstructor, - ) - - expect(OldOasys).toHaveBeenCalledWith(roshData['risk-of-serious-harm']['old-oasys'], applicationWithData) - }) - }) - }) - }) - - itShouldHaveNextValue(new OasysImport({}, application, oasys, ''), 'summary') - itShouldHavePreviousValue(new OasysImport({}, application, oasys, ''), 'taskList') - - describe('errors', () => { - it('returns empty object', () => { - const page = new OasysImport({}, application, oasys, '') - - expect(page.errors()).toEqual({}) - }) - }) -}) diff --git a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/custom-forms/oasysImport.ts b/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/custom-forms/oasysImport.ts deleted file mode 100644 index e00046f..0000000 --- a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/custom-forms/oasysImport.ts +++ /dev/null @@ -1,157 +0,0 @@ -import type { DataServices, TaskListErrors } from '@approved-premises/ui' -import { Cas2Application as Application, OASysRiskOfSeriousHarm, RoshRisksEnvelope } from '@approved-premises/api' -import { Page } from '../../../../utils/decorators' -import TaskListPage from '../../../../taskListPage' -import { nameOrPlaceholderCopy } from '../../../../../utils/utils' -import { DateFormats } from '../../../../../utils/dateUtils' -import Summary, { SummaryData } from '../summary' -import { logOasysError } from '../../../../utils' -import OldOasys from '../oldOasys' - -type OasysImportBody = Record - -export type RoshTaskData = { - 'risk-of-serious-harm': { - 'oasys-import': { - oasysImportedDate: Date - } - summary: RoshRisksEnvelope & { - oasysImportedDate: Date - } - 'risk-to-others': { - whoIsAtRisk: string - natureOfRisk: string - } - } -} - -@Page({ - name: 'oasys-import', - bodyProperties: [], -}) -export default class OasysImport implements TaskListPage { - personName = nameOrPlaceholderCopy(this.application.person) - - documentTitle = "Import the person's risk of serious harm (RoSH) data from OASys" - - title = `Import ${nameOrPlaceholderCopy(this.application.person)}'s risk of serious harm (RoSH) data from OASys` - - body: OasysImportBody - - taskData: string - - hasOasysRecord: boolean - - oasysCompleted: string - - oasysStarted: string - - noOasysBannerText = `No OASys record available to import for ${this.personName}` - - noOasysDescriptiveText = `No information can be imported for the Risk of Serious Harm (RoSH) section because ${this.personName} - does not have a Layer 3 OASys completed in the last 6 months.` - - taskName = 'risk-of-serious-harm' - - constructor( - body: Partial, - private readonly application: Application, - oasys: OASysRiskOfSeriousHarm, - taskData: string, - ) { - this.body = body as OasysImportBody - this.hasOasysRecord = (oasys && Boolean(Object.keys(oasys).length)) || false - if (this.hasOasysRecord) { - this.oasysStarted = oasys.dateStarted && DateFormats.isoDateToUIDate(oasys.dateStarted, { format: 'medium' }) - this.oasysCompleted = - oasys.dateCompleted && DateFormats.isoDateToUIDate(oasys.dateCompleted, { format: 'medium' }) - } - this.taskData = taskData - } - - static async initialize( - body: Partial, - application: Application, - token: string, - dataServices: DataServices, - ) { - let oasys: OASysRiskOfSeriousHarm - let risks: RoshRisksEnvelope - let taskDataJson - - if (!application.data['risk-of-serious-harm']) { - try { - oasys = await dataServices.personService.getOasysRosh(token, application.person.crn) - risks = await dataServices.personService.getRoshRisks(token, application.person.crn) - taskDataJson = JSON.stringify(OasysImport.getTaskData(oasys, risks)) - } catch (e) { - logOasysError(e, application.person.crn) - oasys = null - } - return new OasysImport(body, application, oasys, taskDataJson) - } - if (OasysImport.isRoshApplicationDataImportedFromOASys(application)) { - return new Summary(application.data['risk-of-serious-harm'].summary ?? {}, application) - } - return new OldOasys(application.data['risk-of-serious-harm']['old-oasys'] ?? {}, application) - } - - private static isRoshApplicationDataImportedFromOASys(application: Application): boolean { - const rosh = application.data['risk-of-serious-harm'] - if (rosh?.['oasys-import']?.oasysImportedDate) { - return true - } - return false - } - - private static getTaskData(oasysSections: OASysRiskOfSeriousHarm, risks: RoshRisksEnvelope): Partial { - const taskData = { 'risk-of-serious-harm': { summary: {} } } as Partial - - const today = new Date() - - // @ts-expect-error Requires refactor to satisfy TS7053 - taskData['risk-of-serious-harm']['summary-data'] = { - ...risks, - oasysImportedDate: today, - oasysStartedDate: oasysSections.dateStarted, - oasysCompletedDate: oasysSections.dateCompleted, - } as SummaryData - - oasysSections.rosh.forEach(question => { - switch (question.questionNumber) { - case 'R10.1': - taskData['risk-of-serious-harm']['risk-to-others'] = { - ...taskData['risk-of-serious-harm']['risk-to-others'], - whoIsAtRisk: question.answer, - } - break - case 'R10.2': - taskData['risk-of-serious-harm']['risk-to-others'] = { - ...taskData['risk-of-serious-harm']['risk-to-others'], - natureOfRisk: question.answer, - } - break - default: - break - } - }) - - taskData['risk-of-serious-harm']['oasys-import'] = { oasysImportedDate: today } - - return taskData - } - - previous() { - return 'taskList' - } - - next() { - return 'summary' - } - - errors() { - const errors: TaskListErrors = {} - - return errors - } -} diff --git a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/index.ts b/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/index.ts index e8ce447..20d5d87 100644 --- a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/index.ts +++ b/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/index.ts @@ -1,23 +1,12 @@ import { Task } from '../../../utils/decorators' -import OasysImport from './custom-forms/oasysImport' -import Summary from './summary' import RiskToOthers from './riskToOthers' import RiskManagementArrangements from './riskManagementArrangements' import CellShareInformation from './cellShareInformation' import AdditionalRiskInformation from './additionalRiskInformation' -import OldOasys from './oldOasys' @Task({ name: 'Add risk of serious harm (RoSH) information', slug: 'risk-of-serious-harm', - pages: [ - OasysImport, - Summary, - OldOasys, - RiskToOthers, - RiskManagementArrangements, - CellShareInformation, - AdditionalRiskInformation, - ], + pages: [RiskToOthers, RiskManagementArrangements, CellShareInformation, AdditionalRiskInformation], }) export default class RiskOfSeriousHarm {} diff --git a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/oldOasys.test.ts b/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/oldOasys.test.ts deleted file mode 100644 index 9750d3d..0000000 --- a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/oldOasys.test.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { itShouldHaveNextValue, itShouldHavePreviousValue } from '../../../shared-examples' -import { personFactory, applicationFactory } from '../../../../testutils/factories/index' -import OldOasys from './oldOasys' -import { dateAndTimeInputsAreValidDates, dateIsComplete } from '../../../../utils/dateUtils' - -jest.mock('../../../../utils/dateUtils', () => { - const actual = jest.requireActual('../../../../utils/dateUtils') - return { - ...actual, - dateAndTimeInputsAreValidDates: jest.fn(), - dateIsComplete: jest.fn(), - } -}) - -describe('OldOasys', () => { - const application = applicationFactory.build({ person: personFactory.build({ name: 'Roger Smith' }) }) - - describe('title', () => { - it('personalises the page title', () => { - const page = new OldOasys({}, application) - - expect(page.title).toEqual(`Does Roger Smith have an older OASys with risk of serious harm (RoSH) information?`) - }) - }) - - itShouldHaveNextValue(new OldOasys({}, application), 'risk-to-others') - itShouldHavePreviousValue(new OldOasys({}, application), 'taskList') - - describe('errors', () => { - it('returns an error when required fields are blank', () => { - const page = new OldOasys({}, application) - expect(page.errors()).toEqual({ - hasOldOasys: 'Confirm whether they have an older OASys with risk of serious harm (RoSH) information', - }) - }) - describe('when hasOldOasys is yes', () => { - it('returns an error when oasysCompletedDate is blank', () => { - const page = new OldOasys({ hasOldOasys: 'yes' }, application) - expect(page.errors()).toEqual({ - oasysCompletedDate: 'Enter the date the OASys was completed', - }) - }) - - describe('when the date is not valid', () => { - beforeEach(() => { - jest.resetAllMocks() - ;(dateAndTimeInputsAreValidDates as jest.Mock).mockImplementation(() => false) - ;(dateIsComplete as jest.Mock).mockImplementation(() => true) - }) - it('returns an error', () => { - const page = new OldOasys({ hasOldOasys: 'yes' }, application) - expect(page.errors()).toEqual({ - oasysCompletedDate: 'OASys completed date must be a real date', - }) - }) - }) - }) - }) - - describe('response', () => { - it('returns the full response when all fields are entered', () => { - const page = new OldOasys( - { - hasOldOasys: 'yes', - 'oasysCompletedDate-year': '2023', - 'oasysCompletedDate-month': '11', - 'oasysCompletedDate-day': '11', - }, - application, - ) - - const expected = { - 'Does Roger Smith have an older OASys with risk of serious harm (RoSH) information?': 'Yes', - 'When was the OASys completed?': '11 November 2023', - } - expect(page.response()).toEqual(expected) - }) - }) - - it('ignores the date field when there is no old OASys', () => { - const page = new OldOasys( - { - hasOldOasys: 'no', - }, - application, - ) - - const expected = { - 'Does Roger Smith have an older OASys with risk of serious harm (RoSH) information?': - 'No, they do not have an OASys', - } - expect(page.response()).toEqual(expected) - }) -}) diff --git a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/oldOasys.ts b/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/oldOasys.ts deleted file mode 100644 index f976a1a..0000000 --- a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/oldOasys.ts +++ /dev/null @@ -1,75 +0,0 @@ -import type { ObjectWithDateParts, TaskListErrors, YesOrNo } from '@approved-premises/ui' -import { Cas2Application as Application } from '@approved-premises/api' -import { Page } from '../../../utils/decorators' -import TaskListPage from '../../../taskListPage' -import { nameOrPlaceholderCopy } from '../../../../utils/utils' -import { dateBodyProperties } from '../../../utils' -import { getQuestions } from '../../../utils/questions' -import { DateFormats, dateAndTimeInputsAreValidDates, dateIsComplete } from '../../../../utils/dateUtils' - -type OldOasysBody = { - hasOldOasys: YesOrNo -} & ObjectWithDateParts<'oasysCompletedDate'> - -@Page({ - name: 'old-oasys', - bodyProperties: ['hasOldOasys', ...dateBodyProperties('oasysCompletedDate')], -}) -export default class OldOasys implements TaskListPage { - documentTitle = 'Does the person have an older OASys with risk of serious harm (RoSH) information?' - - personName = nameOrPlaceholderCopy(this.application.person) - - title = `Does ${this.personName} have an older OASys with risk of serious harm (RoSH) information?` - - body: OldOasysBody - - questions = getQuestions(this.personName)['risk-of-serious-harm']['old-oasys'] - - constructor( - body: Partial, - private readonly application: Application, - ) { - this.body = body as OldOasysBody - } - - previous() { - return 'taskList' - } - - next() { - return 'risk-to-others' - } - - response() { - return { - [this.questions.hasOldOasys.question]: this.questions.hasOldOasys.answers[this.body.hasOldOasys], - ...(this.body.hasOldOasys === 'yes' && { - [this.questions.oasysCompletedDate.question]: DateFormats.dateAndTimeInputsToUiDate( - this.body, - 'oasysCompletedDate', - ), - }), - } - } - - errors() { - const errors: TaskListErrors = {} - - if (!this.body.hasOldOasys) { - errors.hasOldOasys = 'Confirm whether they have an older OASys with risk of serious harm (RoSH) information' - } - if (this.body.hasOldOasys === 'yes') { - if (!dateIsComplete(this.body, 'oasysCompletedDate')) { - errors.oasysCompletedDate = 'Enter the date the OASys was completed' - return errors - } - - if (!dateAndTimeInputsAreValidDates(this.body, 'oasysCompletedDate')) { - errors.oasysCompletedDate = 'OASys completed date must be a real date' - } - } - - return errors - } -} diff --git a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/riskToOthers.test.ts b/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/riskToOthers.test.ts index 7468238..a5ffe6c 100644 --- a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/riskToOthers.test.ts +++ b/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/riskToOthers.test.ts @@ -13,14 +13,6 @@ describe('RiskToOthers', () => { }) }) - describe('import date', () => { - it('sets importDate to null where application contains no OASys import date', () => { - const page = new RiskToOthers({}, application) - - expect(page.importDate).toEqual(null) - }) - }) - itShouldHaveNextValue(new RiskToOthers({}, application), 'risk-management-arrangements') itShouldHavePreviousValue(new RiskToOthers({}, application), 'summary') @@ -28,20 +20,9 @@ describe('RiskToOthers', () => { it('returns an error when required fields are blank', () => { const page = new RiskToOthers({}, application) expect(page.errors()).toEqual({ - confirmation: 'Confirm that the information is relevant and up to date', whoIsAtRisk: 'Enter who is at risk', natureOfRisk: 'Enter the nature of the risk', }) }) }) - - describe('items', () => { - it('returns the checkbox as expected', () => { - const page = new RiskToOthers({}, application) - - expect(page.items()).toEqual([ - { value: 'confirmed', text: 'I confirm this information is relevant and up to date.', checked: false }, - ]) - }) - }) }) diff --git a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/riskToOthers.ts b/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/riskToOthers.ts index 7e28f93..a93505d 100644 --- a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/riskToOthers.ts +++ b/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/riskToOthers.ts @@ -3,11 +3,8 @@ import { Cas2Application as Application } from '@approved-premises/api' import { Page } from '../../../utils/decorators' import TaskListPage from '../../../taskListPage' import { nameOrPlaceholderCopy } from '../../../../utils/utils' -import { getOasysImportDateFromApplication } from '../../../utils' -import { convertKeyValuePairToCheckboxItems } from '../../../../utils/formUtils' import errorLookups from '../../../../i18n/en/errors.json' import { getQuestions } from '../../../utils/questions' -import { hasOasys } from '../../../../utils/applicationUtils' type RiskToOthersBody = { whoIsAtRisk: string; natureOfRisk: string; confirmation: string } @@ -26,16 +23,11 @@ export default class RiskToOthers implements TaskListPage { questions = getQuestions(this.personName)['risk-of-serious-harm']['risk-to-others'] - importDate = getOasysImportDateFromApplication(this.application, 'risk-of-serious-harm') - - hasOasysRecord: boolean - constructor( body: Partial, private readonly application: Application, ) { this.body = body as RiskToOthersBody - this.hasOasysRecord = hasOasys(application, 'risk-of-serious-harm') } previous() { @@ -55,16 +47,7 @@ export default class RiskToOthers implements TaskListPage { if (!this.body.natureOfRisk) { errors.natureOfRisk = errorLookups.natureOfRisk.empty } - if (!this.body.confirmation) { - errors.confirmation = errorLookups.oasysConfirmation.empty - } return errors } - - items() { - return convertKeyValuePairToCheckboxItems({ confirmed: this.questions.confirmation.question }, [ - this.body.confirmation, - ]) - } } diff --git a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/summary.test.ts b/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/summary.test.ts deleted file mode 100644 index c408bbd..0000000 --- a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/summary.test.ts +++ /dev/null @@ -1,149 +0,0 @@ -import { itShouldHaveNextValue, itShouldHavePreviousValue } from '../../../shared-examples' -import { personFactory, applicationFactory } from '../../../../testutils/factories/index' -import Summary, { SummaryData } from './summary' - -describe('Summary', () => { - const roshSummaryData = { - status: 'retrieved' as const, - oasysImportedDate: new Date('2023-09-15'), - oasysStartedDate: '2023-01-30', - oasysCompletedDate: '2023-01-31', - value: { - overallRisk: 'a risk', - riskToChildren: 'another risk', - riskToPublic: 'a third risk', - riskToKnownAdult: 'a fourth risk', - riskToStaff: 'a fifth risk', - }, - } as SummaryData - - const person = personFactory.build({ name: 'Roger Smith' }) - - const applicationWithSummaryData = applicationFactory.build({ - person, - data: { 'risk-of-serious-harm': { 'summary-data': roshSummaryData } }, - }) - - const applicationWithoutSummaryData = applicationFactory.build({ - person, - }) - - describe('title', () => { - it('personalises the page title', () => { - const page = new Summary({}, applicationWithSummaryData) - - expect(page.title).toEqual(`Risk of serious harm (RoSH) summary for Roger Smith`) - }) - }) - - describe('import date', () => { - it('sets importDate to null where application contains no OASys import date', () => { - const page = new Summary({}, applicationWithSummaryData) - - expect(page.importDate).toEqual(null) - }) - }) - - describe('risks', () => { - describe('if the risks have not been found', () => { - it('sets the risks to undefined', () => { - const roshSummaryDataWithoutValue = { - status: 'not_found' as const, - oasysImportedDate: new Date('2023-09-15'), - } as SummaryData - - const page = new Summary( - {}, - { - ...applicationWithSummaryData, - data: { 'risk-of-serious-harm': { 'summary-data': roshSummaryDataWithoutValue } }, - }, - ) - - expect(page.risks).toBe(undefined) - }) - }) - - describe('if the risks have been found but there are no values', () => { - it('sets the risks to undefined', () => { - const roshSummaryDataWithoutValue = { - status: 'retrieved' as const, - oasysImportedDate: new Date('2023-09-15'), - } as SummaryData - - const page = new Summary( - {}, - { - ...applicationWithSummaryData, - data: { 'risk-of-serious-harm': { 'summary-data': roshSummaryDataWithoutValue } }, - }, - ) - - expect(page.risks.value).toBe(undefined) - }) - }) - - describe('if risk values exists', () => { - it('sets the risks', () => { - const page = new Summary({}, applicationWithSummaryData) - expect(page.risks).toEqual(roshSummaryData) - }) - }) - - describe('if there is no summary data', () => { - it('sets the risks to undefined', () => { - const page = new Summary({}, applicationWithoutSummaryData) - - expect(page.risks).toBe(undefined) - }) - }) - }) - - itShouldHaveNextValue(new Summary({}, applicationWithSummaryData), 'risk-to-others') - itShouldHavePreviousValue(new Summary({}, applicationWithSummaryData), 'taskList') - - describe('response', () => { - const body = { - additionalComments: 'some additional comments', - } - - const expectedResponse = { - 'OASys created': '30 January 2023', - 'OASys completed': '31 January 2023', - 'OASys imported': '15 September 2023', - 'Overall risk rating': roshSummaryData.value.overallRisk, - 'Risk to children': roshSummaryData.value.riskToChildren, - 'Risk to known adult': roshSummaryData.value.riskToKnownAdult, - 'Risk to public': roshSummaryData.value.riskToPublic, - 'Risk to staff': roshSummaryData.value.riskToStaff, - } - it('returns page body if no additional comments have been added', () => { - const page = new Summary({}, applicationWithSummaryData) - - expect(page.response()).toEqual(expectedResponse) - }) - - it('returns page body and additional comments if a comment is added', () => { - const page = new Summary(body, applicationWithSummaryData) - - expect(page.response()).toEqual({ - ...expectedResponse, - 'Additional comments (optional)': 'some additional comments', - }) - }) - - it('returns nothing if there is no answer data', () => { - const page = new Summary({}, applicationWithoutSummaryData) - - expect(page.response()).toEqual({}) - }) - }) - - describe('errors', () => { - it('not implemented', () => { - const page = new Summary({}, applicationWithSummaryData) - - expect(page.errors()).toEqual({}) - }) - }) -}) diff --git a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/summary.ts b/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/summary.ts deleted file mode 100644 index 1417a9e..0000000 --- a/server/form-pages/apply/risks-and-needs/risk-of-serious-harm/summary.ts +++ /dev/null @@ -1,101 +0,0 @@ -import type { TaskListErrors } from '@approved-premises/ui' -import { Cas2Application as Application, RoshRisksEnvelope } from '@approved-premises/api' -import { Page } from '../../../utils/decorators' -import TaskListPage from '../../../taskListPage' -import { nameOrPlaceholderCopy } from '../../../../utils/utils' -import { DateFormats } from '../../../../utils/dateUtils' -import { getOasysImportDateFromApplication } from '../../../utils' -import { getQuestions } from '../../../utils/questions' - -export type SummaryBody = { - additionalComments?: string -} - -export type SummaryData = RoshRisksEnvelope & { - oasysImportedDate: Date - oasysStartedDate: string - oasysCompletedDate?: string -} - -@Page({ - name: 'summary', - bodyProperties: ['additionalComments'], -}) -export default class Summary implements TaskListPage { - documentTitle = 'Risk of serious harm (RoSH) summary for the person' - - personName = nameOrPlaceholderCopy(this.application.person) - - title = `Risk of serious harm (RoSH) summary for ${this.personName}` - - body: SummaryBody - - risks: SummaryData - - questions: { - additionalComments: string - } - - importDate = getOasysImportDateFromApplication(this.application, 'risk-of-serious-harm') - - constructor( - body: Partial, - private readonly application: Application, - ) { - this.body = body as SummaryBody - this.application = application - - if (this.isSummaryDataRetrieved(application)) { - const summaryData = application.data['risk-of-serious-harm']['summary-data'] as SummaryData - this.risks = { - ...summaryData, - } - } - const roshQuestions = getQuestions(this.personName)['risk-of-serious-harm'] - - this.questions = { - additionalComments: roshQuestions.summary.additionalComments.question, - } - } - - private isSummaryDataRetrieved(application: Application) { - return application.data['risk-of-serious-harm']?.['summary-data']?.status === 'retrieved' - } - - previous() { - return 'taskList' - } - - next() { - return 'risk-to-others' - } - - errors() { - const errors: TaskListErrors = {} - - return errors - } - - response() { - let response: Record = {} - if (this.isSummaryDataRetrieved(this.application)) { - const oasysData = this.application.data['risk-of-serious-harm']['summary-data'] - response = { - 'OASys created': DateFormats.isoDateToUIDate(oasysData.oasysStartedDate, { format: 'medium' }), - 'OASys completed': oasysData.oasysCompletedDate - ? DateFormats.isoDateToUIDate(oasysData.oasysCompletedDate, { format: 'medium' }) - : 'Unknown', - 'OASys imported': DateFormats.dateObjtoUIDate(oasysData.oasysImportedDate, { format: 'medium' }), - 'Overall risk rating': oasysData.value.overallRisk, - 'Risk to children': oasysData.value.riskToChildren, - 'Risk to known adult': oasysData.value.riskToKnownAdult, - 'Risk to public': oasysData.value.riskToPublic, - 'Risk to staff': oasysData.value.riskToStaff, - } - } - if (this.body.additionalComments) { - response[this.questions.additionalComments] = this.body.additionalComments - } - return response - } -} diff --git a/server/form-pages/apply/risks-and-needs/risk-to-self/currentRisk.test.ts b/server/form-pages/apply/risks-and-needs/risk-to-self/currentRisk.test.ts index 8c304c6..85a28f0 100644 --- a/server/form-pages/apply/risks-and-needs/risk-to-self/currentRisk.test.ts +++ b/server/form-pages/apply/risks-and-needs/risk-to-self/currentRisk.test.ts @@ -14,14 +14,6 @@ describe('CurrentRisk', () => { }) }) - describe('import date', () => { - it('sets importDate to false where application contains no OASys import date', () => { - const page = new CurrentRisk({}, application) - - expect(page.importDate).toEqual(null) - }) - }) - describe('Questions', () => { const page = new CurrentRisk({}, application) @@ -36,59 +28,10 @@ describe('CurrentRisk', () => { itShouldHavePreviousValue(new CurrentRisk({}, application), 'vulnerability') describe('errors', () => { - it('returns an error when the confirmation is blank', () => { + it('returns an error when currentRiskDetail is blank', () => { const page = new CurrentRisk({}, application) expect(page.errors()).toEqual({ currentRiskDetail: "Describe Roger Smith's current issues and needs related to self harm and suicide", - confirmation: 'Confirm that the information is relevant and up to date', - }) - }) - }) - - describe('items', () => { - it('returns the checkbox as expected', () => { - const page = new CurrentRisk({}, application) - - expect(page.items()).toEqual([ - { value: 'confirmed', text: 'I confirm this information is relevant and up to date.', checked: false }, - ]) - }) - }) - - describe('response', () => { - const body = { currentRiskDetail: 'some detail', confirmation: 'confirmed' } - - it('returns with OASys dates where they are in the application data', () => { - const applicationWithOasysDates = applicationFactory.build({ - person, - data: { - 'risk-to-self': { - 'oasys-import': { - oasysImportedDate: '2024-01-05', - oasysStartedDate: '2024-01-01', - oasysCompletedDate: '2024-01-02', - }, - }, - }, - }) - - const page = new CurrentRisk(body, applicationWithOasysDates) - - expect(page.response()).toEqual({ - 'OASys created': '1 January 2024', - 'OASys completed': '2 January 2024', - 'OASys imported': '5 January 2024', - "Describe Roger Smith's current issues and needs related to self harm and suicide": 'some detail', - 'I confirm this information is relevant and up to date.': 'Confirmed', - }) - }) - - it('returns without OASys dates where they are not present in the application data', () => { - const page = new CurrentRisk(body, application) - - expect(page.response()).toEqual({ - "Describe Roger Smith's current issues and needs related to self harm and suicide": 'some detail', - 'I confirm this information is relevant and up to date.': 'Confirmed', }) }) }) diff --git a/server/form-pages/apply/risks-and-needs/risk-to-self/currentRisk.ts b/server/form-pages/apply/risks-and-needs/risk-to-self/currentRisk.ts index aee17a9..c3a3693 100644 --- a/server/form-pages/apply/risks-and-needs/risk-to-self/currentRisk.ts +++ b/server/form-pages/apply/risks-and-needs/risk-to-self/currentRisk.ts @@ -3,12 +3,7 @@ import { Cas2Application as Application } from '@approved-premises/api' import { nameOrPlaceholderCopy } from '../../../../utils/utils' import { Page } from '../../../utils/decorators' import TaskListPage from '../../../taskListPage' -import { getOasysImportDateFromApplication } from '../../../utils' -import { convertKeyValuePairToCheckboxItems } from '../../../../utils/formUtils' -import errorLookups from '../../../../i18n/en/errors.json' import { getQuestions } from '../../../utils/questions' -import { DateFormats } from '../../../../utils/dateUtils' -import { hasOasys } from '../../../../utils/applicationUtils' type CurrentRiskBody = { currentRiskDetail: string; confirmation: string } @@ -27,16 +22,11 @@ export default class CurrentRisk implements TaskListPage { body: CurrentRiskBody - importDate = getOasysImportDateFromApplication(this.application, 'risk-to-self') - - hasOasysRecord: boolean - constructor( body: Partial, private readonly application: Application, ) { this.body = body as CurrentRiskBody - this.hasOasysRecord = hasOasys(application, 'risk-to-self') } previous() { @@ -53,41 +43,7 @@ export default class CurrentRisk implements TaskListPage { if (!this.body.currentRiskDetail) { errors.currentRiskDetail = `Describe ${this.personName}'s current issues and needs related to self harm and suicide` } - if (!this.body.confirmation) { - errors.confirmation = errorLookups.oasysConfirmation.empty - } return errors } - - items() { - return convertKeyValuePairToCheckboxItems({ confirmed: this.questions.confirmation.question }, [ - this.body.confirmation, - ]) - } - - response() { - const oasysData = this.application.data?.['risk-to-self']?.['oasys-import'] - - if (oasysData) { - return { - 'OASys created': DateFormats.isoDateToUIDate(oasysData.oasysStartedDate, { format: 'medium' }), - 'OASys completed': oasysData.oasysCompletedDate - ? DateFormats.isoDateToUIDate(oasysData.oasysCompletedDate, { format: 'medium' }) - : 'Unknown', - 'OASys imported': DateFormats.dateObjtoUIDate(oasysData.oasysImportedDate, { format: 'medium' }), - [this.questions.currentRiskDetail.question]: this.body.currentRiskDetail, - [this.questions.confirmation.question]: - this.questions.confirmation.answers[ - this.body.confirmation as keyof typeof this.questions.confirmation.answers - ], - } - } - - return { - [this.questions.currentRiskDetail.question]: this.body.currentRiskDetail, - [this.questions.confirmation.question]: - this.questions.confirmation.answers[this.body.confirmation as keyof typeof this.questions.confirmation.answers], - } - } } diff --git a/server/form-pages/apply/risks-and-needs/risk-to-self/custom-forms/oasysImport.test.ts b/server/form-pages/apply/risks-and-needs/risk-to-self/custom-forms/oasysImport.test.ts deleted file mode 100644 index d567a0d..0000000 --- a/server/form-pages/apply/risks-and-needs/risk-to-self/custom-forms/oasysImport.test.ts +++ /dev/null @@ -1,222 +0,0 @@ -import { createMock } from '@golevelup/ts-jest' -import type { DataServices } from '@approved-premises/ui' -import { DateFormats } from '../../../../../utils/dateUtils' -import { itShouldHaveNextValue, itShouldHavePreviousValue } from '../../../../shared-examples' -import { personFactory, applicationFactory, oasysRiskToSelfFactory } from '../../../../../testutils/factories/index' -import OasysImport from './oasysImport' -import PersonService from '../../../../../services/personService' -import Vulnerability from '../vulnerability' -import { AcctDataBody } from './acctData' -import OldOasys from '../oldOasys' - -jest.mock('../vulnerability') -jest.mock('../oldOasys') - -describe('OasysImport', () => { - const application = applicationFactory.build({ person: personFactory.build({ name: 'Roger Smith' }) }) - const oasys = oasysRiskToSelfFactory.build({ - dateCompleted: DateFormats.dateObjToIsoDateTime(new Date(2023, 7, 29)), - dateStarted: DateFormats.dateObjToIsoDateTime(new Date(2023, 7, 28)), - }) - - const dataServices = createMock({ personService: createMock({}) }) - - const now = new Date() - - beforeAll(() => { - jest.useFakeTimers() - jest.setSystemTime(now) - }) - - afterAll(() => { - jest.useRealTimers() - }) - - describe('title', () => { - it('personalises the page title', () => { - const page = new OasysImport({}, application, oasys, '') - - expect(page.title).toEqual("Import Roger Smith's risk to self data from OASys") - }) - }) - - describe('initialize', () => { - describe('when oasys sections are returned', () => { - it('instantiates the class with the task data in the correct format', async () => { - oasys.riskToSelf = [ - { - label: 'Current concerns about self-harm or suicide', - questionNumber: 'R8.1.1', - answer: 'self harm answer', - }, - { - label: 'Current concerns about Coping in Custody or Hostel', - questionNumber: 'R8.2.1', - answer: 'coping in custody answer', - }, - { - label: 'Current concerns about Vulnerability', - questionNumber: 'R8.3.1', - answer: 'vulnerability answer', - }, - { - label: 'Historical concerns about self-harm or suicide', - questionNumber: 'R8.1.4', - answer: 'historical answer', - }, - ] - - const taskData = { - 'risk-to-self': { - 'current-risk': { currentRiskDetail: 'self harm answer' }, - vulnerability: { vulnerabilityDetail: 'vulnerability answer' }, - 'historical-risk': { historicalRiskDetail: 'historical answer' }, - 'oasys-import': { - oasysImportedDate: now, - oasysStartedDate: oasys.dateStarted, - oasysCompletedDate: oasys.dateCompleted, - }, - }, - } - - ;(dataServices.personService.getOasysRiskToSelf as jest.Mock).mockResolvedValue(oasys) - - const page = (await OasysImport.initialize({}, application, 'some-token', dataServices)) as OasysImport - - expect(page.taskData).toBe(JSON.stringify(taskData)) - expect(page.hasOasysRecord).toBe(true) - expect(page.oasysCompleted).toBe('29 August 2023') - expect(page.oasysStarted).toBe('28 August 2023') - }) - - describe('when there is not a completed date', () => { - it('does not assign a completed date', async () => { - const oasysIncomplete = oasysRiskToSelfFactory.build({ dateCompleted: null }) - - ;(dataServices.personService.getOasysRiskToSelf as jest.Mock).mockResolvedValue(oasysIncomplete) - - const page = (await OasysImport.initialize({}, application, 'some-token', dataServices)) as OasysImport - - expect(page.oasysCompleted).toBe(null) - }) - }) - }) - - describe('when oasys sections are not returned', () => { - it('sets hasOasysRecord to false when there has been an error', async () => { - ;(dataServices.personService.getOasysRiskToSelf as jest.Mock).mockRejectedValue(new Error()) - - const page = (await OasysImport.initialize({}, application, 'some-token', dataServices)) as OasysImport - - expect(page.hasOasysRecord).toBe(false) - expect(page.oasysCompleted).toBe(undefined) - expect(page.oasysStarted).toBe(undefined) - }) - }) - - describe('when OASys has not been imported but the old OASys page has been completed', () => { - it('returns the Old OASys page', () => { - const riskToSelfData = { - 'risk-to-self': { 'old-oasys': { hasOldOasys: 'no' } }, - } - - const applicationWithData = applicationFactory.build({ - person: personFactory.build({ name: 'Roger Smith' }), - data: riskToSelfData, - }) - - const oldOasysPageConstructor = jest.fn() - - ;(OldOasys as jest.Mock).mockImplementation(() => { - return oldOasysPageConstructor - }) - - expect(OasysImport.initialize({}, applicationWithData, 'some-token', dataServices)).resolves.toEqual( - oldOasysPageConstructor, - ) - - expect(OldOasys).toHaveBeenCalledWith( - applicationWithData.data['risk-to-self']['old-oasys'], - applicationWithData, - ) - }) - }) - - describe('when OASys has been imported', () => { - it('returns the Vulnerability page', async () => { - const riskToSelfData = { - 'risk-to-self': { - 'oasys-import': { - oasysImportedDate: '2023-09-21T15:47:51.430Z', - oasysStartedDate: '2023-09-10', - oasysCompletedDate: '2023-09-11', - }, - vulnerability: { vulnerabilityDetail: 'some answer' }, - }, - } - - const applicationWithData = applicationFactory.build({ - person: personFactory.build({ name: 'Roger Smith' }), - data: riskToSelfData, - }) - - const vulnerabilityPageConstructor = jest.fn() - - ;(Vulnerability as jest.Mock).mockImplementation(() => { - return vulnerabilityPageConstructor - }) - - expect(OasysImport.initialize({}, applicationWithData, 'some-token', dataServices)).resolves.toEqual( - vulnerabilityPageConstructor, - ) - - expect(Vulnerability).toHaveBeenCalledWith( - applicationWithData.data['risk-to-self'].vulnerability, - applicationWithData, - ) - }) - describe('when the Vulnerability page has not been answered', () => { - it('returns the Vulnerability page', async () => { - const riskToSelfData = { - 'risk-to-self': { - 'oasys-import': { - oasysImportedDate: '2023-09-21T15:47:51.430Z', - oasysStartedDate: '2023-09-10', - oasysCompletedDate: '2023-09-11', - }, - 'acct-data': [{ acctDetails: 'some answer' }], - }, - } as Partial - - const applicationWithData = applicationFactory.build({ - person: personFactory.build({ name: 'Roger Smith' }), - data: riskToSelfData, - }) - - const vulnerabilityPageConstructor = jest.fn() - - ;(Vulnerability as jest.Mock).mockImplementation(() => { - return vulnerabilityPageConstructor - }) - - expect(OasysImport.initialize({}, applicationWithData, 'some-token', dataServices)).resolves.toEqual( - vulnerabilityPageConstructor, - ) - - expect(Vulnerability).toHaveBeenCalledWith({}, applicationWithData) - }) - }) - }) - }) - - itShouldHaveNextValue(new OasysImport({}, application, oasys, ''), 'vulnerability') - itShouldHavePreviousValue(new OasysImport({}, application, oasys, ''), 'taskList') - - describe('errors', () => { - it('returns empty object', () => { - const page = new OasysImport({}, application, oasys, '') - - expect(page.errors()).toEqual({}) - }) - }) -}) diff --git a/server/form-pages/apply/risks-and-needs/risk-to-self/custom-forms/oasysImport.ts b/server/form-pages/apply/risks-and-needs/risk-to-self/custom-forms/oasysImport.ts deleted file mode 100644 index 49f5bf5..0000000 --- a/server/form-pages/apply/risks-and-needs/risk-to-self/custom-forms/oasysImport.ts +++ /dev/null @@ -1,146 +0,0 @@ -import type { DataServices, TaskListErrors } from '@approved-premises/ui' -import { Cas2Application as Application, Cas2Application, OASysRiskToSelf } from '@approved-premises/api' -import { Page } from '../../../../utils/decorators' -import TaskListPage from '../../../../taskListPage' -import { DateFormats } from '../../../../../utils/dateUtils' -import { nameOrPlaceholderCopy } from '../../../../../utils/utils' -import Vulnerability from '../vulnerability' -import { logOasysError } from '../../../../utils' -import OldOasys from '../oldOasys' - -type GuidanceBody = Record - -export type RiskToSelfTaskData = { - 'risk-to-self': { - 'oasys-import': { - oasysImportedDate: Date - oasysStartedDate: string - oasysCompletedDate: string - } - 'current-risk': { - currentRiskDetail: string - } - vulnerability: { - vulnerabilityDetail: string - } - 'historical-risk': { - historicalRiskDetail: string - } - } -} - -@Page({ - name: 'oasys-import', - bodyProperties: [], -}) -export default class OasysImport implements TaskListPage { - documentTitle = "Import the person's risk to self data from OASys" - - personName = nameOrPlaceholderCopy(this.application.person) - - title = `Import ${this.personName}'s risk to self data from OASys` - - body: GuidanceBody - - oasysCompleted: string - - oasysStarted: string - - hasOasysRecord: boolean - - noOasysBannerText = `No OASys record available to import for ${this.personName}` - - noOasysDescriptiveText = `No information can be imported for the risk to self section because ${this.personName} - does not have a Layer 3 OASys completed in the last 6 months.` - - taskData: string - - taskName = 'risk-to-self' - - constructor( - body: Partial, - private readonly application: Application, - oasys: OASysRiskToSelf, - taskData: string, - ) { - this.body = body as GuidanceBody - this.hasOasysRecord = (oasys && Boolean(Object.keys(oasys).length)) || false - if (oasys) { - this.oasysStarted = oasys.dateStarted && DateFormats.isoDateToUIDate(oasys.dateStarted, { format: 'medium' }) - this.oasysCompleted = - oasys.dateCompleted && DateFormats.isoDateToUIDate(oasys.dateCompleted, { format: 'medium' }) - } - this.taskData = taskData - } - - static async initialize( - body: Partial, - application: Cas2Application, - token: string, - dataServices: DataServices, - ) { - let oasys - let taskDataJson - - if (!application.data['risk-to-self']) { - try { - oasys = await dataServices.personService.getOasysRiskToSelf(token, application.person.crn) - - taskDataJson = JSON.stringify(OasysImport.getTaskData(oasys)) - } catch (e) { - logOasysError(e, application.person.crn) - oasys = null - } - return new OasysImport(body, application, oasys, taskDataJson) - } - if (!application.data['risk-to-self']['oasys-import']) { - return new OldOasys(application.data['risk-to-self']['old-oasys'] ?? {}, application) - } - return new Vulnerability(application.data['risk-to-self'].vulnerability ?? {}, application) - } - - private static getTaskData(oasysSections: OASysRiskToSelf): Partial { - const taskData = { 'risk-to-self': {} } as Partial - const today = new Date() - - oasysSections.riskToSelf.forEach(question => { - switch (question.questionNumber) { - case 'R8.1.1': - taskData['risk-to-self']['current-risk'] = { currentRiskDetail: question.answer } - break - case 'R8.3.1': - taskData['risk-to-self'].vulnerability = { vulnerabilityDetail: question.answer } - break - case 'R8.1.4': - taskData['risk-to-self']['historical-risk'] = { - historicalRiskDetail: question.answer, - } - break - default: - break - } - }) - - taskData['risk-to-self']['oasys-import'] = { - oasysImportedDate: today, - oasysStartedDate: oasysSections.dateStarted, - oasysCompletedDate: oasysSections.dateCompleted, - } - - return taskData - } - - previous() { - return 'taskList' - } - - next() { - return 'vulnerability' - } - - errors() { - const errors: TaskListErrors = {} - - return errors - } -} diff --git a/server/form-pages/apply/risks-and-needs/risk-to-self/historicalRisk.test.ts b/server/form-pages/apply/risks-and-needs/risk-to-self/historicalRisk.test.ts index a14ed94..2c7aca0 100644 --- a/server/form-pages/apply/risks-and-needs/risk-to-self/historicalRisk.test.ts +++ b/server/form-pages/apply/risks-and-needs/risk-to-self/historicalRisk.test.ts @@ -13,14 +13,6 @@ describe('HistoricalRisk', () => { }) }) - describe('import date', () => { - it('sets importDate to false where application contains no OASys import date', () => { - const page = new HistoricalRisk({}, application) - - expect(page.importDate).toEqual(null) - }) - }) - describe('Questions', () => { const page = new HistoricalRisk({}, application) @@ -35,22 +27,11 @@ describe('HistoricalRisk', () => { itShouldHavePreviousValue(new HistoricalRisk({}, application), 'current-risk') describe('errors', () => { - it('returns an error when the confirmation is blank', () => { + it('returns an error when historicalRiskDetail is blank', () => { const page = new HistoricalRisk({}, application) expect(page.errors()).toEqual({ historicalRiskDetail: "Describe Roger Smith's historical issues and needs related to self harm and suicide", - confirmation: 'Confirm that the information is relevant and up to date', }) }) }) - - describe('items', () => { - it('returns the checkbox as expected', () => { - const page = new HistoricalRisk({}, application) - - expect(page.items()).toEqual([ - { value: 'confirmed', text: 'I confirm this information is relevant and up to date.', checked: false }, - ]) - }) - }) }) diff --git a/server/form-pages/apply/risks-and-needs/risk-to-self/historicalRisk.ts b/server/form-pages/apply/risks-and-needs/risk-to-self/historicalRisk.ts index 1c16494..1506974 100644 --- a/server/form-pages/apply/risks-and-needs/risk-to-self/historicalRisk.ts +++ b/server/form-pages/apply/risks-and-needs/risk-to-self/historicalRisk.ts @@ -3,11 +3,7 @@ import { Cas2Application as Application } from '@approved-premises/api' import { nameOrPlaceholderCopy } from '../../../../utils/utils' import { Page } from '../../../utils/decorators' import TaskListPage from '../../../taskListPage' -import { getOasysImportDateFromApplication } from '../../../utils' -import { convertKeyValuePairToCheckboxItems } from '../../../../utils/formUtils' -import errorLookups from '../../../../i18n/en/errors.json' import { getQuestions } from '../../../utils/questions' -import { hasOasys } from '../../../../utils/applicationUtils' type HistoricalRiskBody = { historicalRiskDetail: string; confirmation: string } @@ -24,18 +20,13 @@ export default class HistoricalRisk implements TaskListPage { questions = getQuestions(this.personName)['risk-to-self']['historical-risk'] - importDate = getOasysImportDateFromApplication(this.application, 'risk-to-self') - body: HistoricalRiskBody - hasOasysRecord: boolean - constructor( body: Partial, private readonly application: Application, ) { this.body = body as HistoricalRiskBody - this.hasOasysRecord = hasOasys(application, 'risk-to-self') } previous() { @@ -52,16 +43,7 @@ export default class HistoricalRisk implements TaskListPage { if (!this.body.historicalRiskDetail) { errors.historicalRiskDetail = `Describe ${this.personName}'s historical issues and needs related to self harm and suicide` } - if (!this.body.confirmation) { - errors.confirmation = errorLookups.oasysConfirmation.empty - } return errors } - - items() { - return convertKeyValuePairToCheckboxItems({ confirmed: this.questions.confirmation.question }, [ - this.body.confirmation, - ]) - } } diff --git a/server/form-pages/apply/risks-and-needs/risk-to-self/index.ts b/server/form-pages/apply/risks-and-needs/risk-to-self/index.ts index 4477f20..f43cfa6 100644 --- a/server/form-pages/apply/risks-and-needs/risk-to-self/index.ts +++ b/server/form-pages/apply/risks-and-needs/risk-to-self/index.ts @@ -6,13 +6,11 @@ import AcctData from './custom-forms/acctData' import AdditionalInformation from './additionalInformation' import CurrentRisk from './currentRisk' import HistoricalRisk from './historicalRisk' -import OasysImport from './custom-forms/oasysImport' import Vulnerability from './vulnerability' -import OldOasys from './oldOasys' @Task({ name: 'Add risk to self information', slug: 'risk-to-self', - pages: [OasysImport, OldOasys, Vulnerability, CurrentRisk, HistoricalRisk, AcctData, Acct, AdditionalInformation], + pages: [Vulnerability, CurrentRisk, HistoricalRisk, AcctData, Acct, AdditionalInformation], }) export default class RiskToSelf {} diff --git a/server/form-pages/apply/risks-and-needs/risk-to-self/oldOasys.test.ts b/server/form-pages/apply/risks-and-needs/risk-to-self/oldOasys.test.ts deleted file mode 100644 index de63c19..0000000 --- a/server/form-pages/apply/risks-and-needs/risk-to-self/oldOasys.test.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { itShouldHaveNextValue, itShouldHavePreviousValue } from '../../../shared-examples' -import { personFactory, applicationFactory } from '../../../../testutils/factories/index' -import OldOasys from './oldOasys' -import { dateAndTimeInputsAreValidDates, dateIsComplete } from '../../../../utils/dateUtils' - -jest.mock('../../../../utils/dateUtils', () => { - const actual = jest.requireActual('../../../../utils/dateUtils') - return { - ...actual, - dateAndTimeInputsAreValidDates: jest.fn(), - dateIsComplete: jest.fn(), - } -}) - -describe('OldOasys', () => { - const application = applicationFactory.build({ person: personFactory.build({ name: 'Roger Smith' }) }) - - describe('title', () => { - it('personalises the page title', () => { - const page = new OldOasys({}, application) - - expect(page.title).toEqual(`Does Roger Smith have an older OASys with risk to self information?`) - }) - }) - - itShouldHaveNextValue(new OldOasys({}, application), 'vulnerability') - itShouldHavePreviousValue(new OldOasys({}, application), 'taskList') - - describe('errors', () => { - it('returns an error when required fields are blank', () => { - const page = new OldOasys({}, application) - expect(page.errors()).toEqual({ - hasOldOasys: 'Confirm whether they have an older OASys with risk to self information', - }) - }) - describe('when hasOldOasys is yes', () => { - it('returns an error when oasysCompletedDate is blank', () => { - const page = new OldOasys({ hasOldOasys: 'yes' }, application) - expect(page.errors()).toEqual({ - oasysCompletedDate: 'Enter the date the OASys was completed', - }) - }) - - describe('when the date is not valid', () => { - beforeEach(() => { - jest.resetAllMocks() - ;(dateAndTimeInputsAreValidDates as jest.Mock).mockImplementation(() => false) - ;(dateIsComplete as jest.Mock).mockImplementation(() => true) - }) - it('returns an error ', () => { - const page = new OldOasys({ hasOldOasys: 'yes' }, application) - expect(page.errors()).toEqual({ - oasysCompletedDate: 'OASys completed date must be a real date', - }) - }) - }) - }) - }) - - describe('response', () => { - it('returns the full response when all fields are entered', () => { - const page = new OldOasys( - { - hasOldOasys: 'yes', - 'oasysCompletedDate-year': '2023', - 'oasysCompletedDate-month': '11', - 'oasysCompletedDate-day': '11', - }, - application, - ) - - const expected = { - 'Does Roger Smith have an older OASys with risk to self information?': 'Yes', - 'When was the OASys completed?': '11 November 2023', - } - expect(page.response()).toEqual(expected) - }) - }) - - it('ignores the date field when there is no old OASys', () => { - const page = new OldOasys( - { - hasOldOasys: 'no', - }, - application, - ) - - const expected = { - 'Does Roger Smith have an older OASys with risk to self information?': 'No, they do not have an OASys', - } - expect(page.response()).toEqual(expected) - }) -}) diff --git a/server/form-pages/apply/risks-and-needs/risk-to-self/oldOasys.ts b/server/form-pages/apply/risks-and-needs/risk-to-self/oldOasys.ts deleted file mode 100644 index 2d382f4..0000000 --- a/server/form-pages/apply/risks-and-needs/risk-to-self/oldOasys.ts +++ /dev/null @@ -1,74 +0,0 @@ -import type { ObjectWithDateParts, TaskListErrors, YesOrNo } from '@approved-premises/ui' -import { Cas2Application as Application } from '@approved-premises/api' -import { Page } from '../../../utils/decorators' -import TaskListPage from '../../../taskListPage' -import { nameOrPlaceholderCopy } from '../../../../utils/utils' -import { dateBodyProperties } from '../../../utils' -import { getQuestions } from '../../../utils/questions' -import { DateFormats, dateAndTimeInputsAreValidDates, dateIsComplete } from '../../../../utils/dateUtils' - -type OldOasysBody = { - hasOldOasys: YesOrNo -} & ObjectWithDateParts<'oasysCompletedDate'> - -@Page({ - name: 'old-oasys', - bodyProperties: ['hasOldOasys', ...dateBodyProperties('oasysCompletedDate')], -}) -export default class OldOasys implements TaskListPage { - documentTitle = 'Does the person have an older OASys with risk to self information?' - - personName = nameOrPlaceholderCopy(this.application.person) - - title = `Does ${this.personName} have an older OASys with risk to self information?` - - body: OldOasysBody - - questions = getQuestions(this.personName)['risk-to-self']['old-oasys'] - - constructor( - body: Partial, - private readonly application: Application, - ) { - this.body = body as OldOasysBody - } - - previous() { - return 'taskList' - } - - next() { - return 'vulnerability' - } - - response() { - return { - [this.questions.hasOldOasys.question]: this.questions.hasOldOasys.answers[this.body.hasOldOasys], - ...(this.body.hasOldOasys === 'yes' && { - [this.questions.oasysCompletedDate.question]: DateFormats.dateAndTimeInputsToUiDate( - this.body, - 'oasysCompletedDate', - ), - }), - } - } - - errors() { - const errors: TaskListErrors = {} - - if (!this.body.hasOldOasys) { - errors.hasOldOasys = 'Confirm whether they have an older OASys with risk to self information' - } - if (this.body.hasOldOasys === 'yes') { - if (!dateIsComplete(this.body, 'oasysCompletedDate')) { - errors.oasysCompletedDate = 'Enter the date the OASys was completed' - return errors - } - if (!dateAndTimeInputsAreValidDates(this.body, 'oasysCompletedDate')) { - errors.oasysCompletedDate = 'OASys completed date must be a real date' - } - } - - return errors - } -} diff --git a/server/form-pages/apply/risks-and-needs/risk-to-self/vulnerability.test.ts b/server/form-pages/apply/risks-and-needs/risk-to-self/vulnerability.test.ts index 354801c..a24383d 100644 --- a/server/form-pages/apply/risks-and-needs/risk-to-self/vulnerability.test.ts +++ b/server/form-pages/apply/risks-and-needs/risk-to-self/vulnerability.test.ts @@ -13,14 +13,6 @@ describe('Vulnerability', () => { }) }) - describe('import date', () => { - it('sets importDate to null where application contains no OASys import date', () => { - const page = new Vulnerability({}, application) - - expect(page.importDate).toEqual(null) - }) - }) - describe('Questions', () => { const page = new Vulnerability({}, application) @@ -35,22 +27,11 @@ describe('Vulnerability', () => { itShouldHavePreviousValue(new Vulnerability({}, application), 'taskList') describe('errors', () => { - it('returns an error when the confirmation is blank', () => { + it('returns an error when vulnerabilityDetail is blank', () => { const page = new Vulnerability({}, application) expect(page.errors()).toEqual({ vulnerabilityDetail: "Describe Roger Smith's current circumstances, issues and needs related to vulnerability", - confirmation: 'Confirm that the information is relevant and up to date', }) }) }) - - describe('items', () => { - it('returns the checkbox as expected', () => { - const page = new Vulnerability({}, application) - - expect(page.items()).toEqual([ - { value: 'confirmed', text: 'I confirm this information is relevant and up to date.', checked: false }, - ]) - }) - }) }) diff --git a/server/form-pages/apply/risks-and-needs/risk-to-self/vulnerability.ts b/server/form-pages/apply/risks-and-needs/risk-to-self/vulnerability.ts index c5d1edc..dd89f56 100644 --- a/server/form-pages/apply/risks-and-needs/risk-to-self/vulnerability.ts +++ b/server/form-pages/apply/risks-and-needs/risk-to-self/vulnerability.ts @@ -3,11 +3,7 @@ import { Cas2Application as Application } from '@approved-premises/api' import { nameOrPlaceholderCopy } from '../../../../utils/utils' import { Page } from '../../../utils/decorators' import TaskListPage from '../../../taskListPage' -import { getOasysImportDateFromApplication } from '../../../utils' -import { convertKeyValuePairToCheckboxItems } from '../../../../utils/formUtils' -import errorLookups from '../../../../i18n/en/errors.json' import { getQuestions } from '../../../utils/questions' -import { hasOasys } from '../../../../utils/applicationUtils' type VulnerabilityBody = { vulnerabilityDetail: string; confirmation: string } @@ -24,18 +20,13 @@ export default class Vulnerability implements TaskListPage { questions = getQuestions(this.personName)['risk-to-self'].vulnerability - importDate = getOasysImportDateFromApplication(this.application, 'risk-to-self') - body: VulnerabilityBody - hasOasysRecord: boolean - constructor( body: Partial, private readonly application: Application, ) { this.body = body as VulnerabilityBody - this.hasOasysRecord = hasOasys(application, 'risk-to-self') } previous() { @@ -52,15 +43,7 @@ export default class Vulnerability implements TaskListPage { if (!this.body.vulnerabilityDetail) { errors.vulnerabilityDetail = `Describe ${this.personName}'s current circumstances, issues and needs related to vulnerability` } - if (!this.body.confirmation) { - errors.confirmation = errorLookups.oasysConfirmation.empty - } - return errors - } - items() { - return convertKeyValuePairToCheckboxItems({ confirmed: this.questions.confirmation.question }, [ - this.body.confirmation, - ]) + return errors } } diff --git a/server/form-pages/utils/index.test.ts b/server/form-pages/utils/index.test.ts index d2eff0b..bcc28e6 100644 --- a/server/form-pages/utils/index.test.ts +++ b/server/form-pages/utils/index.test.ts @@ -9,8 +9,6 @@ import { ApprovedPremisesApplication } from '../../@types/shared' import { applicationFactory } from '../../testutils/factories' import { TaskListPageInterface } from '../taskListPage' -import { DateFormats } from '../../utils/dateUtils' - jest.mock('../../utils/dateUtils') describe('utils', () => { @@ -166,26 +164,6 @@ describe('utils', () => { }) }) - describe('getOasysImportDateFromApplication', () => { - it('calls date formatting function when as OASys import date exists', () => { - const application = applicationFactory.build({ - data: { 'risk-to-self': { 'oasys-import': { oasysImportedDate: 'some date' } } }, - }) - - ;(DateFormats.isoDateToUIDate as jest.Mock).mockImplementation(() => null) - - utils.getOasysImportDateFromApplication(application, 'risk-to-self') - - expect(DateFormats.isoDateToUIDate).toHaveBeenCalledWith('some date', { format: 'medium' }) - }) - - it('returns null where no import date exists on application', () => { - const application = applicationFactory.build({ data: null }) - - expect(utils.getOasysImportDateFromApplication(application, 'risk-to-self')).toEqual(null) - }) - }) - describe('pageBodyShallowEquals', () => { it('returns true when the two parameters are equal', () => { const value1 = { diff --git a/server/form-pages/utils/index.ts b/server/form-pages/utils/index.ts index 175ed12..fdd907a 100644 --- a/server/form-pages/utils/index.ts +++ b/server/form-pages/utils/index.ts @@ -1,9 +1,6 @@ import type { Request } from 'express' -import { Cas2Application as Application } from '@approved-premises/api' import type { FormArtifact, JourneyType, UiTask } from '@approved-premises/ui' -import logger from '../../../logger' import { TaskListPageInterface } from '../taskListPage' -import { DateFormats } from '../../utils/dateUtils' export const getTask = (task: T) => { const taskPages = {} @@ -88,20 +85,6 @@ export function pageDataFromApplication(Page: TaskListPageInterface, application return application.data?.[taskName]?.[pageName] || {} } -export function getOasysImportDateFromApplication(application: Application, taskName: string): string | null { - if (application.data?.[taskName]?.['oasys-import']?.oasysImportedDate) { - return DateFormats.isoDateToUIDate(application.data?.[taskName]?.['oasys-import']?.oasysImportedDate, { - format: 'medium', - }) - } - return null -} - -export function logOasysError(e: Error, crn: string) { - logger.error(`Error retrieving Oasys for crn ${crn}`) - logger.error(e) -} - export function pageBodyShallowEquals(body1: Record, body2: Record) { const body1Keys = Object.keys(body1) const body2Keys = Object.keys(body2) diff --git a/server/form-pages/utils/questions.ts b/server/form-pages/utils/questions.ts index 4ebb55f..a136487 100644 --- a/server/form-pages/utils/questions.ts +++ b/server/form-pages/utils/questions.ts @@ -633,45 +633,23 @@ export const getQuestions = (name: string) => { }, }, 'risk-to-self': { - 'old-oasys': { - hasOldOasys: { - question: `Does ${name} have an older OASys with risk to self information?`, - answers: { yes: 'Yes', no: 'No, they do not have an OASys' }, - }, - oasysCompletedDate: { - question: 'When was the OASys completed?', - hint: `For example, ${dateExample}`, - }, - }, vulnerability: { vulnerabilityDetail: { question: `Describe ${name}'s current circumstances, issues and needs related to vulnerability`, hint: 'Include all current risk information and remove sensitive information, such as names and addresses.', }, - confirmation: { - question: 'I confirm this information is relevant and up to date.', - answers: { confirmed: 'Confirmed' }, - }, }, 'current-risk': { currentRiskDetail: { question: `Describe ${name}'s current issues and needs related to self harm and suicide`, hint: 'Include all current risk information and remove sensitive information, such as names and addresses.', }, - confirmation: { - question: 'I confirm this information is relevant and up to date.', - answers: { confirmed: 'Confirmed' }, - }, }, 'historical-risk': { historicalRiskDetail: { question: `Describe ${name}'s historical issues and needs related to self harm and suicide`, hint: 'Remove sensitive information, such as names and addresses.', }, - confirmation: { - question: 'I confirm this information is relevant and up to date.', - answers: { confirmed: 'Confirmed' }, - }, }, 'acct-data': { createdDate: { @@ -712,16 +690,6 @@ export const getQuestions = (name: string) => { riskToStaff: { question: 'Risk to staff' }, additionalComments: { question: 'Additional comments (optional)' }, }, - 'old-oasys': { - hasOldOasys: { - question: `Does ${name} have an older OASys with risk of serious harm (RoSH) information?`, - answers: { yes: 'Yes', no: 'No, they do not have an OASys' }, - }, - oasysCompletedDate: { - question: 'When was the OASys completed?', - hint: `For example, ${dateExample}`, - }, - }, 'risk-to-others': { whoIsAtRisk: { question: 'Who is at risk?', diff --git a/server/i18n/en/errors.json b/server/i18n/en/errors.json index d3a1ab9..e90e690 100644 --- a/server/i18n/en/errors.json +++ b/server/i18n/en/errors.json @@ -38,9 +38,6 @@ "maritalStatus": { "empty": "Select a marital status or 'Prefer not to say'" }, - "oasysConfirmation": { - "empty": "Confirm that the information is relevant and up to date" - }, "circumstancesLikelyToIncreaseRisk": { "empty": "Enter the circumstances that are likely to increase risk" }, diff --git a/server/paths/api.ts b/server/paths/api.ts index d5407d5..19c4ee5 100644 --- a/server/paths/api.ts +++ b/server/paths/api.ts @@ -2,7 +2,6 @@ import { path } from 'static-path' const peoplePath = path('/cas2/people') const personPath = peoplePath.path(':crn') -const oasysPath = personPath.path('oasys') const applicationsPath = path('/cas2/applications') const abandonPath = applicationsPath.path(':id').path('abandon') const singleApplicationPath = applicationsPath.path(':id') @@ -15,11 +14,6 @@ const singleReportPath = reportsPath.path(':name') export default { people: { - oasys: { - sections: oasysPath.path('sections'), - riskToSelf: oasysPath.path('risk-to-self'), - rosh: oasysPath.path('rosh'), - }, search: peoplePath.path('search'), risks: { show: personPath.path('risks'), diff --git a/server/services/personService.test.ts b/server/services/personService.test.ts index 6822817..0ee7439 100644 --- a/server/services/personService.test.ts +++ b/server/services/personService.test.ts @@ -1,4 +1,4 @@ -import { oasysRiskToSelfFactory, oasysRoshFactory, personFactory, risksFactory } from '../testutils/factories' +import { personFactory } from '../testutils/factories' import PersonService from './personService' import { PersonClient } from '../data' @@ -30,46 +30,4 @@ describe('Person Service', () => { expect(personClient.search).toHaveBeenCalledWith('prisonNumber') }) }) - - describe('getOasysRiskToSelf', () => { - it('returns risk to self data', async () => { - const expectedRiskToSelf = oasysRiskToSelfFactory.build() - personClient.oasysRiskToSelf.mockResolvedValue(expectedRiskToSelf) - - const oasysSections = await service.getOasysRiskToSelf(token, 'crn') - - expect(oasysSections).toEqual(expectedRiskToSelf) - - expect(personClientFactory).toHaveBeenCalledWith(token) - expect(personClient.oasysRiskToSelf).toHaveBeenCalledWith('crn') - }) - }) - - describe('getOasysRosh', () => { - it('returns Rosh data', async () => { - const expectedRosh = oasysRoshFactory.build() - personClient.oasysRosh.mockResolvedValue(expectedRosh) - - const oasysSections = await service.getOasysRosh(token, 'crn') - - expect(oasysSections).toEqual(expectedRosh) - - expect(personClientFactory).toHaveBeenCalledWith(token) - expect(personClient.oasysRosh).toHaveBeenCalledWith('crn') - }) - }) - - describe('getRoshRisks', () => { - it("on success returns the person's risks given their CRN", async () => { - const expectedRisks = risksFactory.build() - personClient.risks.mockResolvedValue(expectedRisks) - - const risks = await service.getRoshRisks(token, 'crn') - - expect(risks).toEqual(expectedRisks.roshRisks) - - expect(personClientFactory).toHaveBeenCalledWith(token) - expect(personClient.risks).toHaveBeenCalledWith('crn') - }) - }) }) diff --git a/server/services/personService.ts b/server/services/personService.ts index 4adaa5a..ffdb09d 100644 --- a/server/services/personService.ts +++ b/server/services/personService.ts @@ -1,4 +1,4 @@ -import type { FullPerson, OASysRiskOfSeriousHarm, OASysRiskToSelf, RoshRisksEnvelope } from '@approved-premises/api' +import type { FullPerson } from '@approved-premises/api' import type { PersonClient, RestClientBuilder } from '../data' export default class PersonService { @@ -10,26 +10,4 @@ export default class PersonService { const person = await personClient.search(nomsNumber) return person } - - async getOasysRiskToSelf(token: string, crn: string): Promise { - const personClient = this.personClientFactory(token) - - const riskToSelf = await personClient.oasysRiskToSelf(crn) - return riskToSelf - } - - async getOasysRosh(token: string, crn: string): Promise { - const personClient = this.personClientFactory(token) - - const rosh = await personClient.oasysRosh(crn) - return rosh - } - - async getRoshRisks(token: string, crn: string): Promise { - const personClient = this.personClientFactory(token) - - const risks = await personClient.risks(crn) - - return risks.roshRisks - } } diff --git a/server/testutils/factories/application.ts b/server/testutils/factories/application.ts index cac9a2d..a74a2cf 100644 --- a/server/testutils/factories/application.ts +++ b/server/testutils/factories/application.ts @@ -3,7 +3,6 @@ import { Factory } from 'fishery' import { Cas2Application as Application } from '@approved-premises/api' import { DateFormats } from '../../utils/dateUtils' import { fullPersonFactory, restrictedPersonFactory } from './person' -import risksFactory from './risks' import nomisUserFactory from './nomisUser' export default Factory.define(() => ({ @@ -16,7 +15,6 @@ export default Factory.define(() => ({ data: {}, document: {}, outdatedSchema: faker.datatype.boolean(), - risks: risksFactory.build(), status: 'inProgress' as const, type: 'CAS2', telephoneNumber: null, diff --git a/server/testutils/factories/index.ts b/server/testutils/factories/index.ts index 85f6cd7..db67aba 100644 --- a/server/testutils/factories/index.ts +++ b/server/testutils/factories/index.ts @@ -1,13 +1,8 @@ -import oasysSectionsFactory, { roshSummaryFactory } from './oasysSections' -import oasysSelectionFactory from './oasysSelection' -import oasysRiskToSelfFactory from './oasysRiskToSelf' import { fullPersonFactory as personFactory, restrictedPersonFactory } from './person' import applicationFactory from './application' import assessmentFactory from './assessment' import submittedApplicationFactory from './submittedApplication' import applicationSummaryFactory from './applicationSummary' -import risksFactory, { roshRisksEnvelopeFactory } from './risks' -import oasysRoshFactory from './oasysRosh' import nomisUserFactory from './nomisUser' import statusUpdateFactory from './statusUpdate' import statusUpdateDetailFactory from './statusUpdateDetail' @@ -20,18 +15,11 @@ import applicationNoteFactory from './applicationNote' export { applicationSummaryFactory, - oasysSectionsFactory, - oasysSelectionFactory, - oasysRiskToSelfFactory, - oasysRoshFactory, - roshSummaryFactory, applicationFactory, assessmentFactory, submittedApplicationFactory, personFactory, restrictedPersonFactory, - risksFactory, - roshRisksEnvelopeFactory, nomisUserFactory, statusUpdateFactory, statusUpdateDetailFactory, diff --git a/server/testutils/factories/oasysRiskToSelf.ts b/server/testutils/factories/oasysRiskToSelf.ts deleted file mode 100644 index b1a1aa0..0000000 --- a/server/testutils/factories/oasysRiskToSelf.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Factory } from 'fishery' -import { faker } from '@faker-js/faker/locale/en_GB' - -import { OASysRiskToSelf } from '@approved-premises/api' -import { DateFormats } from '../../utils/dateUtils' -import { riskToSelfFactory } from './oasysSections' - -export default Factory.define(() => ({ - assessmentId: faker.number.int(), - assessmentState: faker.helpers.arrayElement(['Completed', 'Incomplete']), - dateStarted: DateFormats.dateObjToIsoDateTime(faker.date.past()), - dateCompleted: DateFormats.dateObjToIsoDateTime(faker.date.recent()), - riskToSelf: riskToSelfFactory.buildList(5), -})) diff --git a/server/testutils/factories/oasysRosh.ts b/server/testutils/factories/oasysRosh.ts deleted file mode 100644 index dc31e87..0000000 --- a/server/testutils/factories/oasysRosh.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Factory } from 'fishery' -import { faker } from '@faker-js/faker/locale/en_GB' - -import { OASysRiskOfSeriousHarm } from '@approved-premises/api' -import { DateFormats } from '../../utils/dateUtils' -import { roshSummaryFactory } from './oasysSections' - -export default Factory.define(() => ({ - assessmentId: faker.number.int(), - assessmentState: faker.helpers.arrayElement(['Completed', 'Incomplete']), - dateStarted: DateFormats.dateObjToIsoDateTime(faker.date.past()), - dateCompleted: DateFormats.dateObjToIsoDateTime(faker.date.recent()), - rosh: roshSummaryFactory.buildList(5), -})) diff --git a/server/testutils/factories/oasysSections.ts b/server/testutils/factories/oasysSections.ts deleted file mode 100644 index 1b6178e..0000000 --- a/server/testutils/factories/oasysSections.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { Factory } from 'fishery' -import { faker } from '@faker-js/faker/locale/en_GB' - -import { OASysQuestion, OASysSections, OASysSupportingInformationQuestion } from '@approved-premises/api' -import { DateFormats } from '../../utils/dateUtils' -import oasysSelectionFactory from './oasysSelection' - -export default Factory.define(() => ({ - assessmentId: faker.number.int(), - assessmentState: faker.helpers.arrayElement(['Completed', 'Incomplete']), - dateStarted: DateFormats.dateObjToIsoDateTime(faker.date.past()), - dateCompleted: DateFormats.dateObjToIsoDateTime(faker.date.recent()), - offenceDetails: offenceDetailsFactory.buildList(5), - roshSummary: roshSummaryFactory.buildList(5), - supportingInformation: supportingInformationFactory.buildList(5), - riskToSelf: riskToSelfFactory.buildList(5), - riskManagementPlan: riskManagementPlanFactory.buildList(5), -})) - -export const roshSummaryFactory = Factory.define(options => ({ - questionNumber: options.sequence.toString(), - label: faker.helpers.arrayElement([ - 'Who is at risk', - 'What is the nature of the risk', - 'What circumstances are likely to reduce the risk', - ]), - answer: faker.lorem.paragraph(), -})) - -export const offenceDetailsFactory = Factory.define(options => ({ - questionNumber: options.sequence.toString(), - label: faker.helpers.arrayElement([ - 'Briefly describe the details of the offence(s)', - 'Others involved', - 'Identify issues related to the offence that contribute to the risk of offending and harm. Please include any positive factors', - 'Provide evidence of the motivation and triggers for the offending', - 'Provide details of the impact on the victim', - 'Victim Information', - 'Is there a pattern of offending? Consider details of previous unspent convictions', - ]), - answer: faker.lorem.paragraph(), -})) - -export const supportingInformationFactory = Factory.define(options => { - const oasysSelection = oasysSelectionFactory.build() - - return { - ...oasysSelection, - questionNumber: options.sequence.toString(), - label: oasysSelection.name, - answer: faker.lorem.paragraph(), - } -}) - -const riskManagementPlanFactory = Factory.define(options => ({ - questionNumber: options.sequence.toString(), - label: faker.helpers.arrayElement([ - 'Key information about current situation', - 'Further considerations about current situation', - 'Supervision', - 'Monitoring and control', - 'Intervention and treatment', - 'Victim safety planning', - 'Contingency plans', - 'Additional comments', - ]), - answer: faker.lorem.paragraph(), -})) - -export const riskToSelfFactory = Factory.define(options => { - const oasysSelection = oasysSelectionFactory.build() - - return { - ...oasysSelection, - questionNumber: options.sequence.toString(), - label: faker.helpers.arrayElement([ - 'Current concerns of self harm and suicide', - 'Previous concerns of self harm and suicide', - 'Current concerns about coping in a hostel setting', - 'Previous concerns about coping in a hostel setting', - 'Risk of serious harm', - ]), - answer: faker.lorem.paragraph(), - } -}) diff --git a/server/testutils/factories/oasysSelection.ts b/server/testutils/factories/oasysSelection.ts deleted file mode 100644 index 7a28e74..0000000 --- a/server/testutils/factories/oasysSelection.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Factory } from 'fishery' -import { faker } from '@faker-js/faker/locale/en_GB' - -import type { OASysSection } from '@approved-premises/api' - -class OasysSelectionFactory extends Factory { - needsLinkedToHarm() { - return this.params({ linkedToHarm: true, linkedToReOffending: true }) - } - - needsLinkedToReoffending() { - return this.params({ linkedToHarm: false, linkedToReOffending: true }) - } - - needsNotLinkedToReoffending() { - return this.params({ linkedToHarm: false, linkedToReOffending: false }) - } -} - -export default OasysSelectionFactory.define(() => ({ - section: faker.number.int({ min: 1, max: 20 }), - name: faker.helpers.arrayElement([ - 'accommodation', - 'relationships', - 'emotional', - 'thinking', - 'ete', - 'lifestyle', - 'health', - 'attitudes', - ]), - linkedToHarm: faker.datatype.boolean(), - linkedToReOffending: faker.datatype.boolean(), -})) diff --git a/server/testutils/factories/risks.ts b/server/testutils/factories/risks.ts deleted file mode 100644 index bf57759..0000000 --- a/server/testutils/factories/risks.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { Factory } from 'fishery' -import { faker } from '@faker-js/faker/locale/en_GB' - -import type { PersonRisks, RiskEnvelopeStatus } from '@approved-premises/api' -import { RiskLevel, RiskTierLevel, TierLetter, TierNumber } from '@approved-premises/ui' -import { DateFormats } from '../../utils/dateUtils' - -const riskLevels: Array = ['Low', 'Medium', 'High', 'Very High'] -const riskEnvelopeStatuses: Array = ['retrieved', 'not_found', 'error'] - -export default Factory.define(() => ({ - crn: `C${faker.number.int({ min: 100000, max: 999999 })}`, - roshRisks: roshRisksEnvelopeFactory.build(), - mappa: mappaFactory.build(), - flags: flagsFactory.build(), - tier: tierEnvelopeFactory.build(), -})) - -export const roshRisksEnvelopeFactory = Factory.define(() => ({ - status: faker.helpers.arrayElement(riskEnvelopeStatuses), - value: { - overallRisk: faker.helpers.arrayElement(riskLevels), - riskToChildren: faker.helpers.arrayElement(riskLevels), - riskToPublic: faker.helpers.arrayElement(riskLevels), - riskToKnownAdult: faker.helpers.arrayElement(riskLevels), - riskToStaff: faker.helpers.arrayElement(riskLevels), - }, -})) - -const mappaFactory = Factory.define(() => ({ - status: faker.helpers.arrayElement(riskEnvelopeStatuses), - value: { level: 'CAT 2 / LEVEL 1', lastUpdated: DateFormats.dateObjToIsoDate(faker.date.past()) }, -})) - -const flagsFactory = Factory.define(() => { - return { - status: faker.helpers.arrayElement(riskEnvelopeStatuses), - value: faker.helpers.arrayElements([ - 'Registered Sex Offender', - 'Hate Crime', - 'Non Registered Sex Offender', - 'Not MAPPA Eligible', - 'Sexual Harm Prevention Order/Sexual Risk Order', - 'Street Gangs', - 'Suicide/Self Harm', - 'Weapons', - ]), - } -}) - -const lettersFactory: () => TierLetter = () => faker.helpers.arrayElement(['A', 'B', 'C', 'D']) -const numbersFactory: () => TierNumber = () => faker.helpers.arrayElement(['1', '2', '3', '4']) - -export const riskTierLevel: RiskTierLevel = `${lettersFactory()}${numbersFactory()}` - -export const tierEnvelopeFactory = Factory.define(() => ({ - status: faker.helpers.arrayElement(riskEnvelopeStatuses), - value: { - level: riskTierLevel, - lastUpdated: DateFormats.dateObjToIsoDate(faker.date.past()), - }, -})) diff --git a/server/utils/applicationUtils.test.ts b/server/utils/applicationUtils.test.ts index 07eebdf..919e03f 100644 --- a/server/utils/applicationUtils.test.ts +++ b/server/utils/applicationUtils.test.ts @@ -8,7 +8,6 @@ import { submittedApplicationTableRows, assessmentsTableRows, getStatusTag, - hasOasys, arePreTaskListTasksIncomplete, } from './applicationUtils' import submittedApplicationSummary from '../testutils/factories/submittedApplicationSummary' @@ -169,65 +168,17 @@ describe('documentSummaryListRows', () => { }, ]) }) +}) - describe('getStatusTag', () => { - it('returns the correct HTML string', () => { - const expected = `More information requested` - expect(getStatusTag('More information requested', 'f5cd423b-08eb-4efb-96ff-5cc6bb073905')).toEqual(expected) - }) - - it('returns the Received string if status is undefined', () => { - const expected = `Received` - expect(getStatusTag(undefined, undefined)).toEqual(expected) - }) +describe('getStatusTag', () => { + it('returns the correct HTML string', () => { + const expected = `More information requested` + expect(getStatusTag('More information requested', 'f5cd423b-08eb-4efb-96ff-5cc6bb073905')).toEqual(expected) }) - describe('hasOasys', () => { - it('returns true when there is an oasys import date', () => { - const application = applicationFactory.build({ - data: { - 'risk-to-self': { - 'oasys-import': { - oasysImportedDate: '2023-09-21T15:47:51.430Z', - oasysStartedDate: '2023-09-10', - oasysCompletedDate: '2023-09-11', - }, - }, - }, - }) - - expect(hasOasys(application, 'risk-to-self')).toEqual(true) - }) - - it('returns true when there is an old oasys', () => { - const application = applicationFactory.build({ - data: { - 'risk-of-serious-harm': { - 'old-oasys': { - hasOldOasys: 'yes', - oasysCompletedDate: '2023-09-11', - }, - }, - }, - }) - - expect(hasOasys(application, 'risk-of-serious-harm')).toEqual(true) - }) - - it('returns false when there is no import date or old oasys', () => { - const application = applicationFactory.build({ - data: { - 'risk-of-serious-harm': { - 'old-oasys': { - hasOldOasys: 'no', - oasysCompletedDate: '2023-09-11', - }, - }, - }, - }) - - expect(hasOasys(application, 'risk-of-serious-harm')).toEqual(false) - }) + it('returns the Received string if status is undefined', () => { + const expected = `Received` + expect(getStatusTag(undefined, undefined)).toEqual(expected) }) }) diff --git a/server/utils/applicationUtils.ts b/server/utils/applicationUtils.ts index 245ba25..6d53360 100644 --- a/server/utils/applicationUtils.ts +++ b/server/utils/applicationUtils.ts @@ -114,13 +114,6 @@ const getStatusTagColour = (statusId: string) => { } } -export const hasOasys = (application: Cas2Application, task: 'risk-to-self' | 'risk-of-serious-harm'): boolean => { - if (application.data[task]?.['oasys-import'] || application.data[task]?.['old-oasys']?.hasOldOasys === 'yes') { - return true - } - return false -} - export const arePreTaskListTasksIncomplete = (application: Cas2Application): boolean => { if (application.data?.['confirm-eligibility'] && application.data?.['confirm-consent']) { return false diff --git a/server/utils/checkYourAnswersUtils.test.ts b/server/utils/checkYourAnswersUtils.test.ts index ae79d4f..7f445c4 100644 --- a/server/utils/checkYourAnswersUtils.test.ts +++ b/server/utils/checkYourAnswersUtils.test.ts @@ -144,12 +144,6 @@ describe('checkYourAnswersUtils', () => { oldPageKey: { question1: 'no', }, - 'oasys-import': { - question1: 'no', - }, - 'summary-data': { - question2: 'some answer', - }, }, }, }) @@ -512,19 +506,6 @@ describe('checkYourAnswersUtils', () => { expect(summaryListItemForQuestion(application, 'task1', 'page1', question)).toEqual(expected) }) - - describe('when the question is OASys imported', () => { - it('returns the task response as a Summary List item without the actions object', () => { - const question = { question: 'OASys imported', answer: 'an answer' } - - const expected = { - key: { html: 'OASys imported' }, - value: { html: 'an answer' }, - } - - expect(summaryListItemForQuestion(application, 'task1', 'page1', question)).toEqual(expected) - }) - }) }) describe('getSections', () => { @@ -538,7 +519,6 @@ describe('checkYourAnswersUtils', () => { describe('getKeysForPages', () => { it('returns an array of page keys for risk to self', () => { expect(getKeysForPages(application, 'risk-to-self')).toEqual([ - 'oasys-import', 'current-risk', 'vulnerability', 'historical-risk', diff --git a/server/utils/checkYourAnswersUtils.ts b/server/utils/checkYourAnswersUtils.ts index 085764e..62e80ca 100644 --- a/server/utils/checkYourAnswersUtils.ts +++ b/server/utils/checkYourAnswersUtils.ts @@ -40,7 +40,7 @@ export const getTaskAnswersAsSummaryListItems = ( const questions = getQuestions(nameOrPlaceholderCopy(application.person)) // Get the page keys stored on the application at creation - const applicationPageKeys = getKeysForPages(application, task).filter(key => pagesWeNeverWantToPresent(key) === false) + const applicationPageKeys = getKeysForPages(application, task) // Filter out any keys that are no longer in the latest question schema const relevantPagesKeys = removeAnyOldPageKeys(questions, task, applicationPageKeys) @@ -149,9 +149,6 @@ export const summaryListItemForQuestion = ( pageKey: string, questionAndAnswer: Record, ) => { - const nonEditablePages = ['summary'] - const nonEditableQuestions = ['OASys created', 'OASys completed', 'OASys imported'] - const { question, answer } = questionAndAnswer const actions = { @@ -169,7 +166,7 @@ export const summaryListItemForQuestion = ( html: question, }, value: { html: formatLines(answer as string) }, - ...(nonEditablePages.includes(pageKey) || nonEditableQuestions.includes(question) ? {} : { actions }), + actions, } } @@ -308,6 +305,3 @@ export const removeAnyOldPageKeys = (questions: any, task: string, applicationPa ) return matchedKeys } -const pagesWeNeverWantToPresent = (key: string): boolean => { - return ['summary-data', 'oasys-import'].includes(key) -} diff --git a/server/utils/nunjucksSetup.ts b/server/utils/nunjucksSetup.ts index e968c8c..12c1023 100644 --- a/server/utils/nunjucksSetup.ts +++ b/server/utils/nunjucksSetup.ts @@ -27,7 +27,6 @@ import { applicationStatusRadios, applicationStatusDetailOptions } from './asses import { checkYourAnswersSections, getApplicantDetails } from './checkYourAnswersUtils' import { DateFormats } from './dateUtils' import { dateFieldValues } from './formUtils' -import * as OasysImportUtils from './oasysImportUtils' import { statusTag } from './personUtils' import * as TaskListUtils from './taskListUtils' import { pagination } from './pagination' @@ -74,8 +73,6 @@ export default function nunjucksSetup(app: express.Express): void { return { ...obj1, ...obj2 } }) - njkEnv.addGlobal('OasysImportUtils', OasysImportUtils) - njkEnv.addGlobal('paths', { ...applicationPaths, ...assessPaths, ...reportPaths, ...staticPaths }) njkEnv.addGlobal('TaskListUtils', TaskListUtils) diff --git a/server/utils/oasysImportUtils.test.ts b/server/utils/oasysImportUtils.test.ts deleted file mode 100644 index d0eec3c..0000000 --- a/server/utils/oasysImportUtils.test.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { roshSummaryFactory } from '../testutils/factories' -import { textareas } from './oasysImportUtils' - -describe('OASysImportUtils', () => { - describe('textareas', () => { - it('it returns reoffending needs as textareas', () => { - const roshSummaries = roshSummaryFactory.buildList(2) - const sectionName = 'roshAnswers' - const result = textareas(roshSummaries, sectionName) - - expect(result).toMatchStringIgnoringWhitespace(` -
-

- -

- -
-
-

- -

- -
`) - }) - }) -}) diff --git a/server/utils/oasysImportUtils.ts b/server/utils/oasysImportUtils.ts deleted file mode 100644 index ede0c11..0000000 --- a/server/utils/oasysImportUtils.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { OasysImportArrays } from '../@types/ui' -import { escape } from './formUtils' - -export const textareas = (questions: OasysImportArrays, key: 'roshAnswers' | 'offenceDetails') => { - return questions - .map((question: { questionNumber: string; label: string; answer: string }) => { - return `
-

- -

- -
` - }) - .join('') -} diff --git a/server/views/applications/pages/risk-of-serious-harm/oasys-import.njk b/server/views/applications/pages/risk-of-serious-harm/oasys-import.njk deleted file mode 100644 index 9ac761f..0000000 --- a/server/views/applications/pages/risk-of-serious-harm/oasys-import.njk +++ /dev/null @@ -1,82 +0,0 @@ -{% from "govuk/components/warning-text/macro.njk" import govukWarningText %} -{% from "govuk/components/notification-banner/macro.njk" import govukNotificationBanner %} - -{% extends "../layout.njk" %} - -{% block content %} - -
-
-

{{ page.title }}

- {% if page.hasOasysRecord%} -
- - - - - - {{ showErrorSummary(errorSummary) }} - -

- There is OASys information you can import to complete this section. -

- -

- You can edit the information. Changes made will not affect the OASys record. -

- - {{ govukWarningText({ - text: "You can only import from OASys once. Make sure it is up to date before importing.", - iconFallbackText: "Warning" - }) }} - -
- -
-

OASys record available for {{ page.personName }}

-

Date created: {{ page.oasysStarted }} -

-

Date completed: {{ page.oasysCompleted}} -

-

OASys level: Layer 3 -

-
- - {% block button %} - {{ govukButton({ - text: "Import and continue" - }) }} - - {% endblock %} - -
- {% else %} - {{ govukNotificationBanner({ - text: page.noOasysBannerText - }) }} - -

- {{ page.noOasysDescriptiveText }} -

- -

- To continue, you can choose to: -

- -
    -
  • update OASys before trying again (recommended)
  • -
  • complete the section manually
  • -
- - {{ govukButton({ - text: "Continue", - href: paths.applications.pages.show({ id: applicationId, task: page.taskName, page: 'old-oasys' }) - }) - }} - - {% endif %} - -
-
- -{% endblock %} diff --git a/server/views/applications/pages/risk-of-serious-harm/old-oasys.njk b/server/views/applications/pages/risk-of-serious-harm/old-oasys.njk deleted file mode 100644 index 2b10ac1..0000000 --- a/server/views/applications/pages/risk-of-serious-harm/old-oasys.njk +++ /dev/null @@ -1,55 +0,0 @@ -{% from "govuk/components/inset-text/macro.njk" import govukInsetText %} -{% from "../../../partials/dateOfOasysImport.njk" import dateOfOasysImport %} -{% extends "../layout.njk" %} - -{% block questions %} - - {% set hasOldOasysDetailHtml %} - {{ - formPageDateInput( { - hint: { - text: page.questions.oasysCompletedDate.hint - }, - fieldName: "oasysCompletedDate", - fieldset: { - legend: { - text: page.questions.oasysCompletedDate.question, - classes: "govuk-fieldset__legend--m" - } - }, - items: dateFieldValues('oasysCompletedDate', errors) - }, - fetchContext()) - }} - {% endset %} - - {{ - formPageRadios( - { - fieldName: "hasOldOasys", - fieldset: { - legend: { - text: page.questions.hasOldOasys.question, - classes: "govuk-fieldset__legend--l", - isPageHeading: true - } - }, - items: [ - { - value: "yes", - text: "Yes", - conditional: { - html: hasOldOasysDetailHtml - } - }, - { - value: "no", - text: "No, they do not have an OASys" - } - ] - }, - fetchContext() - ) - }} - -{% endblock %} diff --git a/server/views/applications/pages/risk-of-serious-harm/risk-to-others.njk b/server/views/applications/pages/risk-of-serious-harm/risk-to-others.njk index d3f8fbd..f430a8c 100644 --- a/server/views/applications/pages/risk-of-serious-harm/risk-to-others.njk +++ b/server/views/applications/pages/risk-of-serious-harm/risk-to-others.njk @@ -1,6 +1,5 @@ {% from "govuk/components/inset-text/macro.njk" import govukInsetText %} {% extends "./_risk-of-serious-harm-screen.njk" %} -{% from "../../../partials/dateOfOasysImport.njk" import dateOfOasysImport %} {% set pageName = "risk-to-others" %} @@ -35,10 +34,6 @@ {% endset %} {% block questions %} - {% if page.importDate %} - {{dateOfOasysImport(page.importDate)}} - {% endif %} - {{ formPageTextArea( { @@ -70,21 +65,4 @@ fetchContext() ) }} - - {% if page.hasOasysRecord %} - {{ govukInsetText({ - text: "If you have noticed information in OASys is out of date, you should tell the person responsible for updating OASys." - }) }} - {% endif %} - - {{ - formPageCheckboxes( - { - fieldName: "confirmation", - items: page.items() - }, - fetchContext() - ) - }} - {% endblock %} diff --git a/server/views/applications/pages/risk-of-serious-harm/summary.njk b/server/views/applications/pages/risk-of-serious-harm/summary.njk deleted file mode 100644 index 16993a7..0000000 --- a/server/views/applications/pages/risk-of-serious-harm/summary.njk +++ /dev/null @@ -1,38 +0,0 @@ -{% from "govuk/components/details/macro.njk" import govukDetails %} -{% from "../../../components/roshWidget/macro.njk" import roshWidget %} - -{% extends "../layout.njk" %} - -{% block questions %} - {% set additionalCommentsInput %} - {{ - formPageTextArea( - { - fieldName: 'additionalComments', - label: { - text: page.questions.additionalComments, - classes: "govuk-label--s" - }, - classes: 'govuk-!-margin-0' - }, - fetchContext() - ) - }} - {% endset %} - -

{{ page.title }}

- - {% if page.importDate %} -

- Imported from OASys on {{page.importDate}} -

- {% endif %} - - {{ roshWidget(page.risks) }} - - {{ govukDetails({ - summaryText: "Add comments to this summary ", - html: additionalCommentsInput - }) }} - -{% endblock %} \ No newline at end of file diff --git a/server/views/applications/pages/risk-to-self/current-risk.njk b/server/views/applications/pages/risk-to-self/current-risk.njk index 479d57a..2db2784 100644 --- a/server/views/applications/pages/risk-to-self/current-risk.njk +++ b/server/views/applications/pages/risk-to-self/current-risk.njk @@ -1,17 +1,10 @@ {% from "govuk/components/inset-text/macro.njk" import govukInsetText %} -{% from "govuk/components/checkboxes/macro.njk" import govukCheckboxes %} {% extends "./_risk-to-self-screen.njk" %} -{% from "../../../partials/dateOfOasysImport.njk" import dateOfOasysImport %} {% set pageName = "current-risk" %} {% block questions %} - {% if page.importDate %} - {% set date = page.importDate %} - {{dateOfOasysImport(date)}} - {% endif %} - {% set currentRiskDetailHintHtml %}

If known, provide details including:

@@ -60,20 +53,4 @@ fetchContext() ) }} - - {% if page.hasOasysRecord %} - {{ govukInsetText({ - text: "If you have noticed information in OASys is out of date, you should tell the person responsible for updating OASys." - }) }} - {% endif %} - - {{ govukCheckboxes({ - idPrefix: "confirmation", - name: "confirmation", - errorMessage: errors.confirmation, - items: page.items() - }, - fetchContext() - ) - }} {% endblock %} diff --git a/server/views/applications/pages/risk-to-self/historical-risk.njk b/server/views/applications/pages/risk-to-self/historical-risk.njk index 93f6a9d..c88817c 100644 --- a/server/views/applications/pages/risk-to-self/historical-risk.njk +++ b/server/views/applications/pages/risk-to-self/historical-risk.njk @@ -1,17 +1,10 @@ {% from "govuk/components/inset-text/macro.njk" import govukInsetText %} -{% from "govuk/components/checkboxes/macro.njk" import govukCheckboxes %} {% extends "./_risk-to-self-screen.njk" %} -{% from "../../../partials/dateOfOasysImport.njk" import dateOfOasysImport %} {% set pageName = "historical-risk" %} {% block questions %} - {% if page.importDate %} - {% set date = page.importDate %} - {{dateOfOasysImport(date)}} - {% endif %} - {% set historicalRiskDetailHintHtml %}

If known, provide details including:

@@ -61,19 +54,4 @@ ) }} - {% if page.hasOasysRecord %} - {{ govukInsetText({ - text: "If you have noticed information in OASys is out of date, you should tell the person responsible for updating OASys." - }) }} - {% endif %} - - {{ govukCheckboxes({ - idPrefix: "confirmation", - name: "confirmation", - errorMessage: errors.confirmation, - items: page.items() - }, - fetchContext() - ) - }} {% endblock %} diff --git a/server/views/applications/pages/risk-to-self/oasys-import.njk b/server/views/applications/pages/risk-to-self/oasys-import.njk deleted file mode 100644 index fc30fa1..0000000 --- a/server/views/applications/pages/risk-to-self/oasys-import.njk +++ /dev/null @@ -1,82 +0,0 @@ -{% from "govuk/components/warning-text/macro.njk" import govukWarningText %} -{% from "govuk/components/notification-banner/macro.njk" import govukNotificationBanner %} - -{% extends "../layout.njk" %} - -{% block content %} - -
-
-

{{ page.title }}

- {% if page.hasOasysRecord%} -
- - - - - - {{ showErrorSummary(errorSummary) }} - -

- There is OASys information you can import to complete this section. -

- -

- You can edit the information. Changes made will not affect the OASys record. -

- - {{ govukWarningText({ - text: "You can only import from OASys once. Make sure it is up to date before importing.", - iconFallbackText: "Warning" - }) }} - -
- -
-

OASys record available for {{ page.personName }}

-

Date created: {{ page.oasysStarted }} -

-

Date completed: {{ page.oasysCompleted}} -

-

OASys level: Layer 3 -

-
- - {% block button %} - {{ govukButton({ - text: "Import and continue" - }) }} - - {% endblock %} - -
- {% else %} - {{ govukNotificationBanner({ - text: page.noOasysBannerText - }) }} - -

- {{ page.noOasysDescriptiveText }} -

- -

- To continue, you can choose to: -

- -
    -
  • update OASys before trying again (recommended)
  • -
  • complete the section manually
  • -
- - {{ govukButton({ - text: "Continue", - href: paths.applications.pages.show({ id: applicationId, task: 'risk-to-self', page: 'old-oasys' }) - }) - }} - - {% endif %} - -
-
- -{% endblock %} diff --git a/server/views/applications/pages/risk-to-self/old-oasys.njk b/server/views/applications/pages/risk-to-self/old-oasys.njk deleted file mode 100644 index 2b10ac1..0000000 --- a/server/views/applications/pages/risk-to-self/old-oasys.njk +++ /dev/null @@ -1,55 +0,0 @@ -{% from "govuk/components/inset-text/macro.njk" import govukInsetText %} -{% from "../../../partials/dateOfOasysImport.njk" import dateOfOasysImport %} -{% extends "../layout.njk" %} - -{% block questions %} - - {% set hasOldOasysDetailHtml %} - {{ - formPageDateInput( { - hint: { - text: page.questions.oasysCompletedDate.hint - }, - fieldName: "oasysCompletedDate", - fieldset: { - legend: { - text: page.questions.oasysCompletedDate.question, - classes: "govuk-fieldset__legend--m" - } - }, - items: dateFieldValues('oasysCompletedDate', errors) - }, - fetchContext()) - }} - {% endset %} - - {{ - formPageRadios( - { - fieldName: "hasOldOasys", - fieldset: { - legend: { - text: page.questions.hasOldOasys.question, - classes: "govuk-fieldset__legend--l", - isPageHeading: true - } - }, - items: [ - { - value: "yes", - text: "Yes", - conditional: { - html: hasOldOasysDetailHtml - } - }, - { - value: "no", - text: "No, they do not have an OASys" - } - ] - }, - fetchContext() - ) - }} - -{% endblock %} diff --git a/server/views/applications/pages/risk-to-self/vulnerability.njk b/server/views/applications/pages/risk-to-self/vulnerability.njk index 2254003..6c138e6 100644 --- a/server/views/applications/pages/risk-to-self/vulnerability.njk +++ b/server/views/applications/pages/risk-to-self/vulnerability.njk @@ -1,7 +1,5 @@ {% from "govuk/components/inset-text/macro.njk" import govukInsetText %} -{% from "govuk/components/checkboxes/macro.njk" import govukCheckboxes %} {% extends "./_risk-to-self-screen.njk" %} -{% from "../../../partials/dateOfOasysImport.njk" import dateOfOasysImport %} {% set pageName = "vulnerability" %} @@ -30,11 +28,6 @@
- {% if page.importDate %} - {% set date = page.importDate %} - {{dateOfOasysImport(date)}} - {% endif %} - {{ formPageTextArea( { @@ -51,20 +44,4 @@ ) }} - {% if page.hasOasysRecord %} - {{ govukInsetText({ - text: "If you have noticed information in OASys is out of date, you should tell the person responsible for updating OASys." - }) }} - {% endif %} - - {{ govukCheckboxes({ - idPrefix: "confirmation", - name: "confirmation", - errorMessage: errors.confirmation, - items: page.items() - }, - fetchContext() - ) - }} - {% endblock %} diff --git a/server/views/partials/dateOfOasysImport.njk b/server/views/partials/dateOfOasysImport.njk deleted file mode 100644 index 652093e..0000000 --- a/server/views/partials/dateOfOasysImport.njk +++ /dev/null @@ -1,6 +0,0 @@ -{% macro dateOfOasysImport(date) %} - -

Imported from OASys on {{date}} -

- -{% endmacro %} \ No newline at end of file