generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,270 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import Page from '../pages/page' | ||
import RiskPage from '../pages/risk' | ||
import RemovedRiskPage from '../pages/removedRisk' | ||
import RemovedRiskDetailPage from '../pages/removedRiskDetail' | ||
import RiskDetailPage from '../pages/riskDetail' | ||
|
||
context('Risk', () => { | ||
it('Risk overview page is rendered', () => { | ||
cy.visit('/case/X000001/risk') | ||
const page = Page.verifyOnPage(RiskPage) | ||
page.getRowData('riskOfHarmInCommunity', 'overall', 'Value').should('contain.text', 'HIGH') | ||
page.getRowData('riskOfHarmInCommunity', 'veryHigh', 'Value').should('contain.text', 'Staff') | ||
page.getRowData('riskOfHarmInCommunity', 'high', 'Value').should('contain.text', 'Public') | ||
page.getRowData('riskOfHarmInCommunity', 'medium', 'Value').should('contain.text', 'Known Adult') | ||
page.getRowData('riskOfHarmInCommunity', 'low', 'Value').should('contain.text', 'Children') | ||
page | ||
.getRowData('riskOfHarmInCommunity', 'who', 'Value') | ||
.should('contain.text', 'NOD-849Meaningful content for AssSumm Testing') | ||
page | ||
.getRowData('riskOfHarmInCommunity', 'nature', 'Value') | ||
.should('contain.text', 'NOD-849 Meaningful content for AssSumm Testing') | ||
page | ||
.getRowData('riskOfHarmInCommunity', 'imminence', 'Value') | ||
.should('contain.text', 'NOD-849 R10.3Meaningful content for AssSumm Testing') | ||
page | ||
.getRowData('riskOfHarmToThemselves', 'riskOfSuicideOrSelfHarm', 'Value') | ||
.should('contain.text', 'Immediate concerns about suicide and self-harm') | ||
page | ||
.getRowData('riskOfHarmToThemselves', 'copingInCustody', 'Value') | ||
.should( | ||
'contain.text', | ||
'Immediate concerns about coping in custody and previous concerns about coping in a hostel', | ||
) | ||
page | ||
.getRowData('riskOfHarmToThemselves', 'vulnerability', 'Value') | ||
.should('contain.text', 'Immediate concerns about a vulnerability') | ||
page.getRowData('riskFlags', 'risk1Description', 'Value').should('contain.text', 'Restraining Order') | ||
page.getRowData('riskFlags', 'risk2Description', 'Value').should('contain.text', 'Domestic Abuse Perpetrator') | ||
page.getRowData('riskFlags', 'risk3Description', 'Value').should('contain.text', 'Risk to Known Adult') | ||
}) | ||
it('Removed risk page is rendered', () => { | ||
cy.visit('/case/X000001/risk/removed-risk-flags') | ||
const page = Page.verifyOnPage(RemovedRiskPage) | ||
page.getRowData('removedRisks', 'removedRisk1', 'Value').should('contain.text', 'Restraining Order') | ||
page.getRowData('removedRisks', 'removedRisk2', 'Value').should('contain.text', 'Domestic Abuse Perpetrator') | ||
page.getRowData('removedRisks', 'removedRisk3', 'Value').should('contain.text', 'Risk to Known Adult') | ||
}) | ||
it('Removed Risk Detail page is rendered', () => { | ||
cy.visit('/case/X000001/risk/flag/4') | ||
const page = Page.verifyOnPage(RemovedRiskDetailPage) | ||
page.getRowData('riskFlagRemoved', 'removalDate', 'Value').should('contain.text', '18 November 2022 by Paul Smith') | ||
page.getRowData('riskFlagRemoved', 'removalNotes', 'Value').should('contain.text', 'Some removal notes') | ||
page.getCardHeader('riskFlag').should('contain.text', 'Before it was removed') | ||
page.getRowData('riskFlag', 'riskFlagNotes', 'Value').should('contain.text', 'Some notes') | ||
page | ||
.getRowData('riskFlag', 'mostRecentReviewDate', 'Value') | ||
.should('contain.text', '12 December 2023 by Paul Smith') | ||
page.getRowData('riskFlag', 'createdDate', 'Value').should('contain.text', '12 December 2023 by Paul Smith') | ||
}) | ||
it('Risk Detail page is rendered', () => { | ||
cy.visit('/case/X000001/risk/flag/2') | ||
const page = Page.verifyOnPage(RiskDetailPage) | ||
page.getCardHeader('riskFlag').should('contain.text', 'About this flag') | ||
page.getRowData('riskFlag', 'riskFlagNotes', 'Value').should('contain.text', 'Some notes') | ||
page.getRowData('riskFlag', 'nextReviewDate', 'Value').should('contain.text', '18 August 2025') | ||
page | ||
.getRowData('riskFlag', 'mostRecentReviewDate', 'Value') | ||
.should('contain.text', '18 December 2023 by Paul Smith') | ||
page.getRowData('riskFlag', 'createdDate', 'Value').should('contain.text', '18 December 2022 by Paul Smith') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Page from './page' | ||
|
||
export default class RemovedRiskPage extends Page { | ||
constructor() { | ||
super('Removed risk flags') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Page from './page' | ||
|
||
export default class RemovedRiskDetailPage extends Page { | ||
constructor() { | ||
super('Restraining Order') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Page from './page' | ||
|
||
export default class RiskPage extends Page { | ||
constructor() { | ||
super('Risk') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Page from './page' | ||
|
||
export default class RiskDetailPage extends Page { | ||
constructor() { | ||
super('Domestic Abuse Perpetrator') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Name, PersonSummary } from './common' | ||
|
||
export interface PersonRiskFlags { | ||
personSummary: PersonSummary | ||
riskFlags: RiskFlag[] | ||
removedRiskFlags: RiskFlag[] | ||
} | ||
|
||
export interface PersonRiskFlag { | ||
personSummary: PersonSummary | ||
riskFlag: RiskFlag | ||
} | ||
|
||
export interface RemovalHistory { | ||
notes?: string | ||
removalDate: string | ||
removedBy: Name | ||
} | ||
|
||
export interface RiskFlag { | ||
id: number | ||
description: string | ||
notes?: string | ||
nextReviewDate?: string | ||
mostRecentReviewDate?: string | ||
createdDate: string | ||
createdBy: Name | ||
removed: boolean | ||
removalHistory: RemovalHistory[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { type RequestHandler, Router } from 'express' | ||
import { auditService } from '@ministryofjustice/hmpps-audit-client' | ||
import { v4 } from 'uuid' | ||
import asyncMiddleware from '../middleware/asyncMiddleware' | ||
import type { Services } from '../services' | ||
import MasApiClient from '../data/masApiClient' | ||
import ArnsApiClient from '../data/arnsApiClient' | ||
|
||
export default function risksRoute(router: Router, { hmppsAuthClient }: Services) { | ||
const get = (path: string | string[], handler: RequestHandler) => router.get(path, asyncMiddleware(handler)) | ||
|
||
get('/case/:crn/risk', async (req, res, _next) => { | ||
const { crn } = req.params | ||
const token = await hmppsAuthClient.getSystemClientToken(res.locals.user.username) | ||
const masClient = new MasApiClient(token) | ||
const arnsClient = new ArnsApiClient(token) | ||
|
||
await auditService.sendAuditMessage({ | ||
action: 'VIEW_MAS_RISKS', | ||
who: res.locals.user.username, | ||
subjectId: crn, | ||
subjectType: 'CRN', | ||
correlationId: v4(), | ||
service: 'hmpps-manage-a-supervision-ui', | ||
}) | ||
|
||
const [personRisk, risks] = await Promise.all([masClient.getPersonRiskFlags(crn), arnsClient.getRisks(crn)]) | ||
res.render('pages/risk', { | ||
personRisk, | ||
risks, | ||
crn, | ||
}) | ||
}) | ||
|
||
get('/case/:crn/risk/flag/:id', async (req, res, _next) => { | ||
const { crn, id } = req.params | ||
const token = await hmppsAuthClient.getSystemClientToken(res.locals.user.username) | ||
const masClient = new MasApiClient(token) | ||
|
||
await auditService.sendAuditMessage({ | ||
action: 'VIEW_MAS_RISK_DETAIL', | ||
who: res.locals.user.username, | ||
subjectId: crn, | ||
subjectType: 'CRN', | ||
correlationId: v4(), | ||
service: 'hmpps-manage-a-supervision-ui', | ||
}) | ||
|
||
const personRiskFlag = await masClient.getPersonRiskFlag(crn, id) | ||
|
||
res.render('pages/risk/flag', { | ||
personRiskFlag, | ||
crn, | ||
}) | ||
}) | ||
|
||
get('/case/:crn/risk/removed-risk-flags', async (req, res, _next) => { | ||
const { crn } = req.params | ||
const token = await hmppsAuthClient.getSystemClientToken(res.locals.user.username) | ||
const masClient = new MasApiClient(token) | ||
|
||
await auditService.sendAuditMessage({ | ||
action: 'VIEW_MAS_REMOVED_RISKS', | ||
who: res.locals.user.username, | ||
subjectId: crn, | ||
subjectType: 'CRN', | ||
correlationId: v4(), | ||
service: 'hmpps-manage-a-supervision-ui', | ||
}) | ||
|
||
const personRisk = await masClient.getPersonRiskFlags(crn) | ||
|
||
res.render('pages/risk/removed-risk-flags', { | ||
personRisk, | ||
crn, | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{% extends "../partials/case.njk" %} | ||
{% from "govuk/components/notification-banner/macro.njk" import govukNotificationBanner %} | ||
{% set pageTitle = applicationName + " - Risk" %} | ||
{% set currentNavSection = 'risk' %} | ||
{% set currentSectionName = 'Risk' %} | ||
{% set headerPersonName = personRisk.personSummary.name | fullName %} | ||
{% set headerCRN = crn %} | ||
{% set hasRiskAssessment = risks.assessedOn %} | ||
|
||
{% block beforeContent %} | ||
{{ govukBreadcrumbs({ | ||
items: [ | ||
{ | ||
text: "Your cases", | ||
href: "/search" | ||
}, | ||
{ | ||
text: headerPersonName, | ||
href: "/case/" + crn | ||
}, | ||
{ | ||
text: currentSectionName | ||
} | ||
] | ||
}) }} | ||
{% endblock %} | ||
|
||
{% block pageContent %} | ||
|
||
{% if hasRiskAssessment %} | ||
{% include './risk/_risk-in-the-community.njk' %} | ||
{% include './risk/_risk-to-themselves.njk' %} | ||
{% else %} | ||
{% set html %} | ||
<h2 class="govuk-heading-m">There is no OASys risk assessment for {{ overview.personalDetails.name | fullName }}</h2> | ||
{% include './risk/_no-oasys-risk-assessment.njk' %} | ||
{% endset %} | ||
{{ govukNotificationBanner({ html: html }) }} | ||
{% endif %} | ||
{% include './risk/_risk-flags.njk' %} | ||
|
||
{% endblock %} |
Oops, something went wrong.