Skip to content

Commit

Permalink
Merge pull request #38 from ministryofjustice/CBA-58-add-health-needs…
Browse files Browse the repository at this point in the history
…-question

Add liaison & diversion assessment question to health needs task
  • Loading branch information
libuk authored Dec 16, 2024
2 parents 0f922d7 + e11f66b commit 70f657d
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 2 deletions.
9 changes: 9 additions & 0 deletions e2e-tests/steps/risksAndNeedsSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const completeHealthNeedsTask = async (page: Page, name: string) => {
await completeCommunicationAndLanguagePage(page, name)
await completeLearningDifficultiesPage(page, name)
await completeBrainInjuryPage(page, name)
await completeLiaisonAndDiversionPage(page, name)
await completeOtherHealthPage(page, name)
}

Expand Down Expand Up @@ -92,6 +93,14 @@ async function completeBrainInjuryPage(page: Page, name: string) {
await brainInjuryPage.clickSave()
}

async function completeLiaisonAndDiversionPage(page: Page, name: string) {
const liaisonAndDiversionPage = await ApplyPage.initialize(page, `Liaison & Diversion Assessment for ${name}`)

await liaisonAndDiversionPage.checkRadioInGroup('Liaison & Diversion Assessment', 'No')

await liaisonAndDiversionPage.clickSave()
}

async function completeOtherHealthPage(page: Page, name: string) {
const otherHealthPage = await ApplyPage.initialize(page, `Other health needs for ${name}`)

Expand Down
3 changes: 3 additions & 0 deletions integration_tests/fixtures/applicationData.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@
"requiresAdditionalSupport": "no",
"addSupportDetail": ""
},
"liaison-and-diversion": {
"liaisonAndDiversionAssessment": "no"
},
"other-health": {
"hasLongTermHealthCondition": "no",
"healthConditionDetail": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('BrainInjury', () => {
})
})

itShouldHaveNextValue(new BrainInjury({}, application), 'other-health')
itShouldHaveNextValue(new BrainInjury({}, application), 'liaison-and-diversion')
itShouldHavePreviousValue(new BrainInjury({}, application), 'learning-difficulties')

describe('errors', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class BrainInjury implements TaskListPage {
}

next() {
return 'other-health'
return 'liaison-and-diversion'
}

errors() {
Expand Down
2 changes: 2 additions & 0 deletions server/form-pages/apply/risks-and-needs/health-needs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MentalHealth from './mentalHealth'
import OtherHealth from './otherHealth'
import PhysicalHealth from './physicalHealth'
import SubstanceMisuse from './substanceMisuse'
import LiaisonAndDiversion from './liaisonAndDiversion'

@Task({
name: 'Add health needs',
Expand All @@ -21,6 +22,7 @@ import SubstanceMisuse from './substanceMisuse'
CommunicationAndLanguage,
LearningDifficulties,
BrainInjury,
LiaisonAndDiversion,
OtherHealth,
],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { itShouldHaveNextValue, itShouldHavePreviousValue } from '../../../shared-examples'
import { personFactory, applicationFactory } from '../../../../testutils/factories/index'
import LiaisonAndDiversion from './liaisonAndDiversion'

describe('LiaisonAndDiversion', () => {
const application = applicationFactory.build({ person: personFactory.build({ name: 'Roger Smith' }) })

describe('title', () => {
it('personalises the page title', () => {
const page = new LiaisonAndDiversion({}, application)

expect(page.title).toEqual('Liaison & Diversion Assessment for Roger Smith')
})
})

describe('questions', () => {
const page = new LiaisonAndDiversion({}, application)

describe('liaisonAndDiversion', () => {
it('has a question', () => {
expect(page.questions.liaisonAndDiversionAssessment.question).toBeDefined()
})
})
})

itShouldHaveNextValue(new LiaisonAndDiversion({}, application), 'other-health')
itShouldHavePreviousValue(new LiaisonAndDiversion({}, application), 'brain-injury')

describe('errors', () => {
describe('when top-level questions are unanswered', () => {
const page = new LiaisonAndDiversion({}, application)

it('includes a validation error for _liaisonAndDiversionAssessment_', () => {
expect(page.errors()).toHaveProperty(
'liaisonAndDiversionAssessment',
'Confirm whether a Liaison & Diversion Assessment has been requested',
)
})
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { TaskListErrors, YesOrNo } from '@approved-premises/ui'
import { Cas2Application as Application } from '@approved-premises/api'
import { nameOrPlaceholderCopy } from '../../../../utils/utils'
import { Page } from '../../../utils/decorators'
import TaskListPage from '../../../taskListPage'
import { getQuestions } from '../../../utils/questions'

type LiaisonAndDiversionBody = {
liaisonAndDiversionAssessment: YesOrNo
}

@Page({
name: 'liaison-and-diversion',
bodyProperties: ['liaisonAndDiversionAssessment'],
})
export default class LiaisonAndDiversion implements TaskListPage {
documentTitle = 'Liaison & Diversion Assessment for the person'

personName = nameOrPlaceholderCopy(this.application.person)

title = `Liaison & Diversion Assessment for ${this.personName}`

questions = getQuestions(this.personName)['health-needs']['liaison-and-diversion']

body: LiaisonAndDiversionBody

constructor(
body: Partial<LiaisonAndDiversionBody>,
private readonly application: Application,
) {
this.body = body as LiaisonAndDiversionBody
}

previous() {
return 'brain-injury'
}

next() {
return 'other-health'
}

errors() {
const errors: TaskListErrors<this> = {}

if (!this.body.liaisonAndDiversionAssessment) {
errors.liaisonAndDiversionAssessment = `Confirm whether a Liaison & Diversion Assessment has been requested`
}

return errors
}
}
7 changes: 7 additions & 0 deletions server/form-pages/utils/questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,13 @@ export const getQuestions = (name: string) => {
requiresAdditionalSupport: { question: 'Is additional support required?', answers: yesOrNo },
addSupportDetail: { question: 'Please describe the type of support.' },
},
'liaison-and-diversion': {
liaisonAndDiversionAssessment: {
question:
'Did the police or court request a Liaison & Diversion Assessment to be carried out for this applicant?',
answers: yesOrNo,
},
},
'other-health': {
hasLongTermHealthCondition: {
question: 'Are they managing any long term health conditions?',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
text: 'Brain injury',
href: paths.applications.pages.show({ id: applicationId, task: 'health-needs', page: 'brain-injury' }),
active: (pageName === 'brain-injury')
}, {
text: 'Liaison & Diversion',
href: paths.applications.pages.show({ id: applicationId, task: 'health-needs', page: 'liaison-and-diversion' }),
active: (pageName === 'liaison-and-diversion')
}, {
text: 'Other health',
href: paths.applications.pages.show({ id: applicationId, task: 'health-needs', page: 'other-health' }),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends "./_health-needs-screen.njk" %}
{% set pageName = "liaison-and-diversion" %}

{% block questions %}

{{
formPageRadios(
{
fieldName: "liaisonAndDiversionAssessment",
fieldset: {
legend: {
text: page.questions.liaisonAndDiversionAssessment.question,
classes: "govuk-fieldset__legend--m"
}
},
items: [
{
value: "yes",
text: "Yes"
},
{
value: "no",
text: "No"
}
]
},
fetchContext()
)
}}

{% endblock %}

0 comments on commit 70f657d

Please sign in to comment.