Skip to content

Commit 4f8ead4

Browse files
Review activity log items
1 parent 40fecc5 commit 4f8ead4

20 files changed

Lines changed: 797 additions & 126 deletions

File tree

app/assets/stylesheets/components/_details.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,21 @@
1212
@include nhsuk-responsive-padding(4, "right");
1313
}
1414
}
15+
16+
.app-details--notify-message {
17+
.nhsuk-details__text {
18+
padding: nhsuk-spacing(4);
19+
border: 1px solid $nhsuk-border-colour;
20+
background-color: nhsuk-colour("white");
21+
font-family: Helvetica, Arial, sans-serif;
22+
23+
.nhsuk-inset-text {
24+
margin-top: 0;
25+
border-color: $nhsuk-border-colour;
26+
27+
@include nhsuk-responsive-padding(2, "bottom");
28+
@include nhsuk-responsive-padding(2, "top");
29+
@include nhsuk-responsive-margin(4, "bottom");
30+
}
31+
}
32+
}

app/controllers/activity.js

Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
import activity from '../datasets/activity.js'
2+
import { ArchiveRecordReason, AuditEventType, ScreenOutcome } from '../enums.js'
3+
import { generateParent } from '../generators/parent.js'
4+
import {
5+
AuditEvent,
6+
Gillick,
7+
Patient,
8+
Reply,
9+
Session,
10+
Vaccination
11+
} from '../models.js'
12+
13+
export const activityController = {
14+
list(request, response) {
15+
const { data } = request.session
16+
17+
const auditEvent = (event) => new AuditEvent(event, data)
18+
const createdBy_uid = Object.values(data.users)[0].uid
19+
const gillickCompetent = new Gillick({
20+
q1: true,
21+
q2: true,
22+
q3: true,
23+
q4: true,
24+
q5: true
25+
})
26+
const gillickNotCompetent = new Gillick({
27+
q1: true,
28+
q2: true,
29+
q3: true,
30+
q4: true,
31+
q5: false
32+
})
33+
const patient = Patient.findAll(data).find(
34+
({ hasMissingNhsNumber, invalid }) => !hasMissingNhsNumber && !invalid
35+
)
36+
const mergedPatient = Patient.findAll(data).find(
37+
({ uuid, hasMissingNhsNumber, invalid }) =>
38+
uuid !== patient.uuid && !hasMissingNhsNumber && !invalid
39+
)
40+
const reply = Reply.findAll(data).find(
41+
(reply) => !reply.selfConsent && reply.given
42+
)
43+
const session = Session.findOne(Object.values(data.sessions)[0].id, data)
44+
const vaccinationGiven = Vaccination.findAll(data).find(
45+
(vaccination) => vaccination.given
46+
)
47+
const vaccinationNotGiven = Vaccination.findAll(data).find(
48+
(vaccination) => !vaccination.given
49+
)
50+
51+
// Parent for use in Notify activities; force having both email and phone
52+
const parent = generateParent(patient.lastName)
53+
parent.email =
54+
parent.email ||
55+
`${parent.fullName.replace(' ', '.').toLowerCase()}@example.com`
56+
parent.tel = parent.tel || '07700 900000'
57+
58+
const activityLog = [
59+
{
60+
title: 'Attendance',
61+
items: [
62+
auditEvent({
63+
name: activity.attendance.present(session),
64+
createdBy_uid,
65+
programme_ids: ['menacwy', 'td-ipv']
66+
}),
67+
auditEvent({
68+
name: activity.attendance.absent(session),
69+
createdBy_uid,
70+
programme_ids: ['menacwy', 'td-ipv']
71+
})
72+
]
73+
},
74+
{
75+
title: 'Consent',
76+
items: [
77+
auditEvent({
78+
name: activity.consent.created(reply),
79+
createdBy_uid,
80+
programme_ids: ['flu']
81+
}),
82+
auditEvent({
83+
name: activity.consent.updated(reply),
84+
createdBy_uid,
85+
programme_ids: ['flu']
86+
}),
87+
auditEvent({
88+
name: activity.consent.matched(reply),
89+
createdBy_uid,
90+
programme_ids: ['flu']
91+
}),
92+
auditEvent({
93+
name: activity.consent.invalid(reply),
94+
createdBy_uid,
95+
programme_ids: ['flu']
96+
}),
97+
auditEvent({
98+
name: activity.consent.withdrawn(reply),
99+
createdBy_uid,
100+
programme_ids: ['flu']
101+
})
102+
]
103+
},
104+
{
105+
title: 'Gillick',
106+
items: [
107+
auditEvent({
108+
name: activity.gillick.created(gillickCompetent),
109+
note: 'Child happy to proceed',
110+
createdBy_uid,
111+
programme_ids: ['hpv']
112+
}),
113+
auditEvent({
114+
name: activity.gillick.created(gillickNotCompetent),
115+
note: 'Child did not understand the side effects',
116+
createdBy_uid,
117+
programme_ids: ['hpv']
118+
}),
119+
auditEvent({
120+
name: activity.gillick.updated(gillickCompetent),
121+
note: 'Child now happy to proceed',
122+
createdBy_uid,
123+
programme_ids: ['hpv']
124+
}),
125+
auditEvent({
126+
name: activity.gillick.updated(gillickNotCompetent),
127+
note: 'Child is no longer happy to proceed',
128+
createdBy_uid,
129+
programme_ids: ['hpv']
130+
})
131+
]
132+
},
133+
{
134+
title: 'Notes',
135+
items: [
136+
auditEvent({
137+
name: activity.note.created(AuditEventType.SessionNote),
138+
note: 'Mum phoned to say child will be arriving at school at 11am',
139+
createdBy_uid,
140+
programme_ids: ['flu']
141+
}),
142+
auditEvent({
143+
name: activity.note.created(AuditEventType.RecordNote),
144+
note: 'Child gave consent for HPV and flu vaccinations under Gillick competence and does not want their parents to be notified.',
145+
createdBy_uid
146+
})
147+
]
148+
},
149+
{
150+
title: 'Notify',
151+
items: [
152+
'invite',
153+
'invite-reminder',
154+
'invite-clinic',
155+
'invite-clinic-reminder',
156+
'consent-given',
157+
'consent-given-changed-school',
158+
'consent-needs-triage',
159+
'consent-refused',
160+
'consent-unknown-contact',
161+
'triage-delay-vaccination',
162+
'triage-do-not-vaccinate',
163+
'triage-invite-to-clinic',
164+
'triage-vaccinate',
165+
'triage-vaccinate-second-dose',
166+
'vaccination-reminder',
167+
'vaccination-given',
168+
'vaccination-not-administered',
169+
'vaccination-already-had',
170+
'vaccination-deleted'
171+
].map((name) =>
172+
auditEvent({
173+
name: activity.notify[name](parent),
174+
messageRecipient: parent,
175+
messageTemplate: name,
176+
patient_uuid: patient.uuid,
177+
programme_ids: session.programme_ids,
178+
session_id: session.id
179+
})
180+
)
181+
},
182+
{
183+
title: 'Patient',
184+
items: [
185+
auditEvent({
186+
name: activity.patient.archived({
187+
archiveReason: ArchiveRecordReason.Other
188+
}),
189+
note: 'A brief note about why child record was archived.',
190+
createdBy_uid
191+
}),
192+
auditEvent({
193+
name: activity.patient.expired,
194+
note: `${patient.fullName} was vaccinated`,
195+
createdBy_uid
196+
}),
197+
auditEvent({
198+
name: activity.patient.merged(mergedPatient, patient),
199+
createdBy_uid
200+
})
201+
]
202+
},
203+
{
204+
title: 'Pre-screening',
205+
items: [
206+
auditEvent({
207+
name: activity.preScreen.created,
208+
note: 'A brief note about the pre-screening checks.',
209+
createdBy_uid,
210+
programme_ids: ['flu']
211+
})
212+
]
213+
},
214+
{
215+
title: 'PSD',
216+
items: [
217+
auditEvent({
218+
name: activity.psd.added,
219+
createdBy_uid,
220+
programme_ids: ['flu']
221+
}),
222+
auditEvent({
223+
name: activity.psd.invalidated,
224+
createdBy_uid,
225+
programme_ids: ['flu']
226+
})
227+
]
228+
},
229+
{
230+
title: 'Session',
231+
items: [
232+
auditEvent({
233+
name: activity.session.added(session),
234+
programme_ids: ['flu']
235+
}),
236+
auditEvent({
237+
name: activity.session.removed(session),
238+
createdBy_uid,
239+
programme_ids: ['flu']
240+
})
241+
]
242+
},
243+
{
244+
title: 'Triage',
245+
items: [
246+
auditEvent({
247+
name: activity.triage.decision({
248+
outcome: ScreenOutcome.DelayVaccination
249+
}),
250+
note: 'A brief note about the triage decision.',
251+
createdBy_uid,
252+
programme_ids: ['flu']
253+
})
254+
]
255+
},
256+
{
257+
title: 'Vaccination',
258+
items: [
259+
auditEvent({
260+
name: activity.vaccination.recorded(vaccinationGiven),
261+
note: 'A brief note about the vaccination session.',
262+
createdBy_uid,
263+
programme_ids: [vaccinationGiven.programme_id],
264+
vaccination_uuid: vaccinationGiven.uuid
265+
}),
266+
auditEvent({
267+
name: activity.vaccination.recorded(vaccinationNotGiven),
268+
note: 'A brief note about the vaccination session.',
269+
createdBy_uid,
270+
programme_ids: [vaccinationNotGiven.programme_id],
271+
vaccination_uuid: vaccinationNotGiven.uuid
272+
}),
273+
auditEvent({
274+
name: activity.vaccination.added,
275+
createdBy_uid,
276+
programme_ids: [vaccinationGiven.programme_id],
277+
vaccination_uuid: vaccinationGiven.uuid
278+
}),
279+
auditEvent({
280+
name: activity.vaccination.uploaded,
281+
createdBy_uid,
282+
programme_ids: [vaccinationGiven.programme_id],
283+
vaccination_uuid: vaccinationGiven.uuid
284+
})
285+
]
286+
}
287+
]
288+
289+
response.render('activity/list', { activityLog })
290+
}
291+
}

app/controllers/consent.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,10 @@ export const consentController = {
159159
)
160160

161161
// Add to session
162-
patient.addToSession(patientSession)
162+
patient.addToSession(patientSession.session)
163163

164164
// Invite parent to give consent
165-
const session = Session.findOne(patientSession.session_id, data)
166-
patient.inviteToSession(session)
165+
patient.requestConsent(patientSession)
167166

168167
// Link consent with patient record
169168
consent.linkToPatient(patient)

app/controllers/patient-session.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ import {
66
PreScreenQuestion,
77
ProgrammeType,
88
RegistrationOutcome,
9-
ScreenOutcome,
109
UserRole,
1110
VaccinationOutcome,
1211
VaccineMethod
1312
} from '../enums.js'
1413
import {
15-
Gillick,
1614
Instruction,
1715
PatientSession,
1816
Programme,
@@ -261,16 +259,11 @@ export const patientSessionController = {
261259
gillick.updatedAt = today()
262260
}
263261

264-
const name = __(`patientSession.gillick.${type}.success`)
265-
request.flash('success', name)
262+
gillick.createdBy_uid = account.uid
266263

267-
patientSession.assessGillick(
268-
{
269-
name,
270-
createdBy_uid: account.uid
271-
},
272-
new Gillick(gillick)
273-
)
264+
request.flash('success', __(`patientSession.gillick.${type}.success`))
265+
266+
patientSession.assessGillick(gillick)
274267

275268
// Clean up session data
276269
delete data.patientSession?.gillick
@@ -306,8 +299,8 @@ export const patientSessionController = {
306299
const { account } = request.app.locals
307300
const { __, back, patient, patientSession } = response.locals
308301

309-
patient.inviteToSession({
310-
session: patientSession.session,
302+
patient.requestConsent({
303+
patientSession,
311304
createdBy_uid: account.uid
312305
})
313306

@@ -355,10 +348,6 @@ export const patientSessionController = {
355348
patientSession.recordTriage({
356349
outcome: triage.outcome,
357350
outcomeAt_: triage.outcomeAt_,
358-
name:
359-
triage.outcome === ScreenOutcome.NeedsTriage
360-
? 'Triaged decision: Keep in triage'
361-
: `Triaged decision: ${triage.outcome}`,
362351
note: triage.note,
363352
createdBy_uid: account.uid
364353
})

app/controllers/session.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ export const sessionController = {
713713
patientSession.removeFromSession({
714714
createdBy_uid: account.uid
715715
})
716-
patient.addToSession(patientSession)
716+
patient.addToSession(patientSession.session)
717717
Patient.update(patientSession.patient_uuid, {}, data)
718718
}
719719
}

0 commit comments

Comments
 (0)