Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ipb 1224/reason for referral #2317

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions integration_tests/integration/amend-referral.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ context('Amend a referral', () => {
.last()
.children()
.should('contain', 'Desired outcomes')
.find('#change-link-2')
.find('#change-link-3')
.click()

cy.location('pathname').should(
Expand All @@ -415,7 +415,7 @@ context('Amend a referral', () => {
.children()
.should('contain', 'Complexity level')
.should('contain', 'Desired outcomes')
.find('#change-link-2')
.find('#change-link-3')
.click()

cy.location('pathname').should(
Expand Down Expand Up @@ -757,10 +757,7 @@ context('Amend a referral', () => {

it('takes the pp to the form when clicking the change link in the details page', () => {
cy.login(`/probation-practitioner/referrals/${sentReferral.id}/details`)
cy.contains(
'.govuk-summary-list__key',
'Reason for the referral and further information for the service provider'
)
cy.contains('.govuk-summary-list__key', 'Reason for referral and referral details')
.next()
.next()
.contains('Change')
Expand Down Expand Up @@ -802,10 +799,10 @@ context('Amend a referral', () => {
cy.get('textarea[name="amend-reason-for-referral"]').clear()
cy.contains('Save and continue').click()

cy.contains('There is a problem').next().contains('Enter reason for the referral and any further information')
cy.contains('There is a problem').next().contains('Enter reason for the referral and referral details')
cy.get('textarea[name="amend-reason-for-referral"]')
.prev()
.contains('Enter reason for the referral and any further information')
.contains('Enter reason for the referral and referral details')
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ describe('Probation practitioner referrals dashboard', () => {
.children()
.should('contain', 'Complexity level')
.should('contain', 'Desired outcomes')
.find('#change-link-2')
.find('#change-link-3')
.click()

cy.location('pathname').should(
Expand Down
8 changes: 5 additions & 3 deletions integration_tests/integration/referral.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ describe('Referral form', () => {
cy.contains('Save and continue').click()
cy.visit(`/referrals/${draftReferral.id}/reason-for-referral`)
cy.get('h1').contains('Provide the reason for this referral and further information for the service provider')
cy.get('textarea').type('Some information about Alex')
cy.get('#reason-for-referral').type('Some information about Alex')
cy.get('#reason-for-referral-further-information').type('Some information about Alex')

// stub completed draft referral to mark section as completed
cy.stubGetDraftReferral(draftReferral.id, completedDraftReferral)
Expand Down Expand Up @@ -560,7 +561,7 @@ describe('Referral form', () => {
.next()
.contains('Change')
.should('have.attr', 'href', `/referrals/${draftReferral.id}/completion-deadline`)
cy.contains('Reason for referral and further information for the service provider')
cy.contains('Reason for referral and referral details')
.next()
.should('contain', 'Some information about Alex')
.next()
Expand Down Expand Up @@ -1171,7 +1172,8 @@ describe('Referral form', () => {

cy.location('pathname').should('equal', `/referrals/${draftReferral.id}/reason-for-referral`)
cy.get('h1').contains('Provide the reason for this referral and further information for the service provider')
cy.get('textarea').type('Some information about Alex')
cy.get('#reason-for-referral').type('Some information about Alex')
cy.get('#reason-for-referral-further-information').type('Some information about Alex')

// stub completed draft referral to mark section as completed
cy.stubGetDraftReferral(draftReferral.id, completedDraftReferral)
Expand Down
13 changes: 8 additions & 5 deletions integration_tests/integration/referralUnAllocatedCom.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,8 @@ describe('Referral form', () => {
cy.contains('Save and continue').click()
cy.visit(`/referrals/${draftReferral.id}/reason-for-referral`)
cy.get('h1').contains('Provide the reason for this referral and further information for the service provider')
cy.get('textarea').type('Some information about Alex')
cy.get('#reason-for-referral').type('Some information about Alex')
cy.get('#reason-for-referral-further-information').type('Some information about Alex')

// stub completed draft referral to mark section as completed
cy.stubGetDraftReferral(draftReferral.id, completedDraftReferral)
Expand Down Expand Up @@ -713,7 +714,7 @@ describe('Referral form', () => {
.next()
.contains('Change')
.should('have.attr', 'href', `/referrals/${draftReferral.id}/completion-deadline`)
cy.contains('Reason for referral and further information for the service provider')
cy.contains('Reason for referral and referral details')
.next()
.should('contain', 'Some information about Alex')
.next()
Expand Down Expand Up @@ -1162,7 +1163,8 @@ describe('Referral form', () => {
cy.contains('Save and continue').click()
cy.visit(`/referrals/${draftReferral.id}/reason-for-referral`)
cy.get('h1').contains('Provide the reason for this referral and further information for the service provider')
cy.get('textarea').type('Some reason')
cy.get('#reason-for-referral').type('Some reason')
cy.get('#reason-for-referral-further-information').type('Some reason')

// stub completed draft referral to mark section as completed
cy.stubGetDraftReferral(draftReferral.id, completedDraftReferral)
Expand Down Expand Up @@ -1323,7 +1325,7 @@ describe('Referral form', () => {
.next()
.contains('Change')
.should('have.attr', 'href', `/referrals/${draftReferral.id}/completion-deadline`)
cy.contains('Reason for referral and further information for the service provider')
cy.contains('Reason for referral and referral details')
.next()
.should('contain', 'Some information about Alex')
.next()
Expand Down Expand Up @@ -1917,7 +1919,8 @@ describe('Referral form', () => {

cy.location('pathname').should('equal', `/referrals/${draftReferral.id}/reason-for-referral`)
cy.get('h1').contains('Provide the reason for this referral and further information for the service provider')
cy.get('textarea').type('Some information about Alex')
cy.get('#reason-for-referral').type('Some information about Alex')
cy.get('#reason-for-referral-further-information').type('Some information about Alex')

// stub completed draft referral to mark section as completed
cy.stubGetDraftReferral(draftReferral.id, completedDraftReferral)
Expand Down
5 changes: 3 additions & 2 deletions integration_tests/integration/updatePPDetails.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,8 @@ describe('Referral form', () => {
cy.contains('Save and continue').click()
cy.visit(`/referrals/${draftReferral.id}/reason-for-referral`)
cy.get('h1').contains('Provide the reason for this referral and further information for the service provider')
cy.get('textarea').type('Some information about Alex')
cy.get('#reason-for-referral').type('Some information about Alex')
cy.get('#reason-for-referral-further-information').type('Some information about Alex')

// stub completed draft referral to mark section as completed
cy.stubGetDraftReferral(draftReferral.id, completedDraftReferral)
Expand Down Expand Up @@ -834,7 +835,7 @@ describe('Referral form', () => {
.next()
.contains('Change')
.should('have.attr', 'href', `/referrals/${draftReferral.id}/completion-deadline`)
cy.contains('Reason for referral and further information for the service provider')
cy.contains('Reason for referral and referral details')
.next()
.should('contain', 'Some reason')
.next()
Expand Down
1 change: 1 addition & 0 deletions server/models/draftReferral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface ReferralFields {
ppLocationType: string | null
allocatedCommunityPP: boolean | null
reasonForReferral: string | null
reasonForReferralFurtherInformation: string | null
reasonForReferralCreationBeforeAllocation: string | null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe(AmendReasonForReferralForm, () => {
expect(data.error?.errors).toContainEqual({
errorSummaryLinkedField: 'amend-reason-for-referral',
formFields: ['amend-reason-for-referral'],
message: 'Enter reason for the referral and any further information',
message: 'Enter reason for the referral and referral details',
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,15 @@ export default class CheckAllReferralInformationPresenter {

if (!isCohortIntervention) {
summaries.push({
key: 'Reason for referral and further information for the service provider',
key: 'Reason for referral and referral details',
lines: [this.determineFurtherInformation(this.referral)],
changeLink: `/referrals/${this.referral.id}/reason-for-referral?amendPPDetails=true`,
})
summaries.push({
key: 'Further Information for the service provider',
lines: [this.determineReasonForReferralFurtherInformation(this.referral)],
changeLink: `/referrals/${this.referral.id}/reason-for-referral?amendPPDetails=true`,
})
}
summaries.push(
{
Expand Down Expand Up @@ -629,6 +634,14 @@ export default class CheckAllReferralInformationPresenter {
return 'None'
}

private determineReasonForReferralFurtherInformation(referral: DraftReferral) {
if (referral.reasonForReferralFurtherInformation !== null) {
return referral.reasonForReferralFurtherInformation!
}

return 'None'
}

private get dateOfBirthWithShortMonth() {
if (this.referral.serviceUser.dateOfBirth === null) {
return ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ describe(ReasonForReferralForm, () => {
it('returns a paramsForUpdate with the reasonForReferral', async () => {
const request = TestUtils.createRequest({
'reason-for-referral': 'To refer him to CRS',
'reason-for-referral-further-information': 'more info',
})
const data = await new ReasonForReferralForm(request).data()

expect(data.paramsForUpdate?.reasonForReferral).toEqual('To refer him to CRS')
expect(data.paramsForUpdate?.reasonForReferralFurtherInformation).toEqual('more info')
})
})
})
Expand All @@ -24,7 +26,7 @@ describe(ReasonForReferralForm, () => {
expect(data.error?.errors).toContainEqual({
errorSummaryLinkedField: 'reason-for-referral',
formFields: ['reason-for-referral'],
message: 'Enter reason for the referral and any further information',
message: 'Enter reason for the referral and referral details',
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ export default class ReasonForReferralForm {
return {
paramsForUpdate: {
reasonForReferral: this.request.body['reason-for-referral'],
reasonForReferralFurtherInformation: this.request.body['reason-for-referral-further-information'],
},
error: null,
}
}

static get validations(): ValidationChain[] {
return [body('reason-for-referral').notEmpty().withMessage(errorMessages.reasonForReferral.empty)]
return [
body('reason-for-referral').notEmpty().withMessage(errorMessages.reasonForReferral.empty),
body('reason-for-referral-further-information')
.notEmpty()
.withMessage(errorMessages.reasonForReferralFurtherInformation.empty),
]
}

private error(validationResult: Result<ValidationError>): FormValidationError | null {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('ReasonForReferralPresenter', () => {
it('returns null', () => {
const presenter = new ReasonForReferralPresenter(referral)

expect(presenter.errorMessage).toBeNull()
expect(presenter.reasonForReferralErrorMessage).toBeNull()
})
})

Expand All @@ -48,7 +48,9 @@ describe('ReasonForReferralPresenter', () => {
],
})

expect(presenter.errorMessage).toEqual('Enter reason for the referral and any further information')
expect(presenter.reasonForReferralErrorMessage).toEqual(
'Enter reason for the referral and any further information'
)
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export default class ReasonForReferralPresenter {
title: `Provide the reason for this referral and further information for the service provider`,
}

readonly errorMessage = PresenterUtils.errorMessage(this.error, 'reason-for-referral')
readonly reasonForReferralErrorMessage = PresenterUtils.errorMessage(this.error, 'reason-for-referral')

readonly reasonForReferralFurtherInformationErrorMessage = PresenterUtils.errorMessage(
this.error,
'reason-for-referral-further-information'
)

readonly errorSummary = PresenterUtils.errorSummary(this.error, {
fieldOrder: ['reason-for-referral'],
Expand All @@ -30,6 +35,10 @@ export default class ReasonForReferralPresenter {

readonly fields = {
reasonForReferral: this.utils.stringValue(this.referral.reasonForReferral, 'reason-for-referral'),
reasonForReferralFurtherInformation: this.utils.stringValue(
this.referral.reasonForReferralFurtherInformation,
'reason-for-referral-further-information'
),
}

private get determinBackUpLink(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,64 +13,71 @@ export default class ReasonForReferralView {
id: 'reason-for-referral',
name: 'reason-for-referral',
value: this.presenter.fields.reasonForReferral,
errorMessage: ViewUtils.govukErrorMessage(this.presenter.errorMessage),
errorMessage: ViewUtils.govukErrorMessage(this.presenter.reasonForReferralErrorMessage),
label: {},
hint: this.renderHints,
hint: this.renderReasonForReferralHints,
}
}

get renderHints(): HintArgs {
get renderReasonForReferralHints(): HintArgs {
const { referral } = this.presenter

const preReleaseWithCom =
referral.personCurrentLocationType === CurrentLocationType.custody &&
referral.isReferralReleasingIn12Weeks === null
const community =
referral.personCurrentLocationType === CurrentLocationType.community &&
referral.isReferralReleasingIn12Weeks === null
// const community =
// referral.personCurrentLocationType === CurrentLocationType.community &&
// referral.isReferralReleasingIn12Weeks === null
const unallocatedPreRelease = referral.isReferralReleasingIn12Weeks

if (preReleaseWithCom || unallocatedPreRelease) {
return {
html: `<p class="govuk-body">Reason for the referral:</p>
html: `<p class="govuk-body">Referral Details:</p>
<ul class="govuk-list govuk-list--bullet">
<li>why ${this.presenter.referral.serviceUser?.firstName} wants the intervention</li>
<li>why ${this.presenter.referral.serviceUser?.firstName} is being referred</li>
<li>what ${this.presenter.referral.serviceUser?.firstName} hopes to achieve</li>
<li>previously completed intervention programmes</li>
<li>other support services ${this.presenter.referral.serviceUser?.firstName} is currently engaging with</li>
</ul>
<p class="govuk-body">Further information could include:</p>
<ul class="govuk-list govuk-list--bullet">
<li>safety warnings (sexual or violent offences, racist behaviour, arson) not covered elsewhere in the referral</li>
<li>if ${this.presenter.referral.serviceUser?.firstName} is currently NFA (no fixed address) leaving custody</li>
<li>${this.presenter.referral.serviceUser?.firstName}’s gender identity (if relevant)</li>
<li>details of any pre-release transition support Alex needs and ongoing post-release support required in the community</li>
<li>any relevant licence/PSS conditions that require consideration to ensure safe delivery of CRS services</li>
<li>previous interventions or activities undertaken in relation to this service need</li>
<li>other support services ${this.presenter.referral.serviceUser?.firstName} is currently engaging with (and times of regular appointments)</li>
</ul>
`,
}
}
if (community) {
return {
html: `<p class="govuk-body">Reason for the referral:</p>
// Community or prison
return {
html: `<p class="govuk-body">Referral Details:</p>
<ul class="govuk-list govuk-list--bullet">
<li>why ${this.presenter.referral.serviceUser?.firstName} wants the intervention</li>
<li>why ${this.presenter.referral.serviceUser?.firstName} is being referred</li>
<li>what ${this.presenter.referral.serviceUser?.firstName} hopes to achieve</li>
<li>previously completed intervention programmes</li>
<li>other support services ${this.presenter.referral.serviceUser?.firstName} is currently engaging with</li>
</ul>
<p class="govuk-body">Further information could include:</p>
<ul class="govuk-list govuk-list--bullet">
<li>safety warnings (sexual or violent offences, racist behaviour, arson) not covered elsewhere in the referral</li>
<li>if ${this.presenter.referral.serviceUser?.firstName} is currently NFA (no fixed address)</li>
<li>${this.presenter.referral.serviceUser?.firstName}’s gender identity (if relevant)</li>
<li>any relevant licence/PSS conditions that require consideration to ensure safe delivery of CRS services</li>
<li>previous interventions or activities undertaken in relation to this service need</li>
<li>other support services ${this.presenter.referral.serviceUser?.firstName} is currently engaging with (and times of regular appointments)</li>
</ul>
`,
}
}
}

private get reasonForReferralFurtherInformationArgs(): TextareaArgs {
return {
id: 'reason-for-referral-further-information',
name: 'reason-for-referral-further-information',
value: this.presenter.fields.reasonForReferralFurtherInformation,
errorMessage: ViewUtils.govukErrorMessage(this.presenter.reasonForReferralFurtherInformationErrorMessage),
label: {},
hint: this.renderFurtherInformationHints,
}
}

get renderFurtherInformationHints(): HintArgs {
return {
html: `<p class="govuk-body">Reason for the referral:</p>
html: `<p class="govuk-body">Further information about ${this.presenter.referral.serviceUser?.firstName}:</p>
<ul class="govuk-list govuk-list--bullet">
<li>why ${this.presenter.referral.serviceUser?.firstName} wants the intervention</li>
<li>what ${this.presenter.referral.serviceUser?.firstName} hopes to achieve</li>
<li>any relevant registration flags on nDelius such as sexual or violent offences, racist behaviour, arson,
risk to staff, MAPPA, domestic abuse perpetrator or victim, modern day slavery perpetrator or victim</li>
<li>if ${this.presenter.referral.serviceUser?.firstName} will be NFA (no fixed address) leaving custody</li>
<li>if ${this.presenter.referral.serviceUser?.firstName} is a victim of domestic abuse or modern-day slavery indicate whether it is safe to contact by phone/email. If not, what is the preferred method of contact?</li>
<li>${this.presenter.referral.serviceUser?.firstName}'s gender identity (if relevant)</li>
</ul>
`,
}
Expand All @@ -83,6 +90,7 @@ export default class ReasonForReferralView {
presenter: this.presenter,
errorSummaryArgs: this.errorSummaryArgs,
reasonForReferralArgs: this.reasonForReferralArgs,
reasonForReferralFurtherInformationArgs: this.reasonForReferralFurtherInformationArgs,
backLinkArgs: { href: this.presenter.backLinkUrl },
suppressServiceUserBanner: true,
},
Expand Down
Loading
Loading