Skip to content

Commit f5db12d

Browse files
Review activity log items
1 parent ebd3b49 commit f5db12d

13 files changed

Lines changed: 502 additions & 103 deletions

File tree

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/home.js

Lines changed: 278 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
import { UserRole } from '../enums.js'
2-
import { Notice } from '../models.js'
1+
import activity from '../datasets/activity.js'
2+
import {
3+
ArchiveRecordReason,
4+
AuditEventType,
5+
ScreenOutcome,
6+
UserRole
7+
} from '../enums.js'
8+
import { generateParent } from '../generators/parent.js'
9+
import {
10+
AuditEvent,
11+
Gillick,
12+
Notice,
13+
Patient,
14+
Reply,
15+
Session,
16+
Vaccination
17+
} from '../models.js'
318

419
export const homeController = {
520
redirect(request, response, next) {
@@ -27,5 +42,266 @@ export const homeController = {
2742

2843
start(request, response) {
2944
response.render('views/start')
45+
},
46+
47+
activity(request, response) {
48+
const { data } = request.session
49+
50+
const auditEvent = (event) => new AuditEvent(event, data)
51+
const createdBy_uid = Object.values(data.users)[0].uid
52+
const gillickCompetent = new Gillick({
53+
q1: true,
54+
q2: true,
55+
q3: true,
56+
q4: true,
57+
q5: true
58+
})
59+
const gillickNotCompetent = new Gillick({
60+
q1: true,
61+
q2: true,
62+
q3: true,
63+
q4: true,
64+
q5: false
65+
})
66+
const parent = generateParent('Jones')
67+
const patient = Patient.findAll(data).find(
68+
({ hasMissingNhsNumber, invalid }) => !hasMissingNhsNumber && !invalid
69+
)
70+
const mergedPatient = Patient.findAll(data).find(
71+
({ uuid, hasMissingNhsNumber, invalid }) =>
72+
uuid !== patient.uuid && !hasMissingNhsNumber && !invalid
73+
)
74+
const reply = Reply.findAll(data).find((reply) => !reply.selfConsent)
75+
const session = Session.findOne(Object.values(data.sessions)[0].id, data)
76+
const vaccinationGiven = Vaccination.findAll(data).find(
77+
(vaccination) => vaccination.given
78+
)
79+
const vaccinationNotGiven = Vaccination.findAll(data).find(
80+
(vaccination) => !vaccination.given
81+
)
82+
83+
const auditEventLog = [
84+
{
85+
title: 'Attendance',
86+
items: [
87+
auditEvent({
88+
name: activity.attendance.present(session),
89+
createdBy_uid,
90+
programme_ids: ['menacwy', 'td-ipv']
91+
}),
92+
auditEvent({
93+
name: activity.attendance.absent(session),
94+
createdBy_uid,
95+
programme_ids: ['menacwy', 'td-ipv']
96+
})
97+
]
98+
},
99+
{
100+
title: 'Consent',
101+
items: [
102+
auditEvent({
103+
name: activity.consent.created(reply),
104+
createdBy_uid,
105+
programme_ids: ['flu']
106+
}),
107+
auditEvent({
108+
name: activity.consent.updated(reply),
109+
createdBy_uid,
110+
programme_ids: ['flu']
111+
}),
112+
auditEvent({
113+
name: activity.consent.matched(reply),
114+
createdBy_uid,
115+
programme_ids: ['flu']
116+
}),
117+
auditEvent({
118+
name: activity.consent.invalid(reply),
119+
createdBy_uid,
120+
programme_ids: ['flu']
121+
}),
122+
auditEvent({
123+
name: activity.consent.withdrawn(reply),
124+
createdBy_uid,
125+
programme_ids: ['flu']
126+
})
127+
]
128+
},
129+
{
130+
title: 'Gillick',
131+
items: [
132+
auditEvent({
133+
name: activity.gillick.created(gillickCompetent),
134+
note: 'Child happy to proceed',
135+
createdBy_uid,
136+
programme_ids: ['hpv']
137+
}),
138+
auditEvent({
139+
name: activity.gillick.created(gillickNotCompetent),
140+
note: 'Child did not understand the side effects',
141+
createdBy_uid,
142+
programme_ids: ['hpv']
143+
}),
144+
auditEvent({
145+
name: activity.gillick.updated(gillickCompetent),
146+
note: 'Child now happy to proceed',
147+
createdBy_uid,
148+
programme_ids: ['hpv']
149+
}),
150+
auditEvent({
151+
name: activity.gillick.updated(gillickNotCompetent),
152+
note: 'Child is no longer happy to proceed',
153+
createdBy_uid,
154+
programme_ids: ['hpv']
155+
})
156+
]
157+
},
158+
{
159+
title: 'Notes',
160+
items: [
161+
auditEvent({
162+
name: activity.note.created(AuditEventType.SessionNote),
163+
note: 'Mum phoned to say child will be arriving at school at 11am',
164+
createdBy_uid,
165+
programme_ids: ['flu']
166+
}),
167+
auditEvent({
168+
name: activity.note.created(AuditEventType.RecordNote),
169+
note: 'Child gave consent for HPV and flu vaccinations under Gillick competence and does not want their parents to be notified.',
170+
createdBy_uid
171+
})
172+
]
173+
},
174+
{
175+
title: 'Notify',
176+
items: [
177+
'invitedToClinic',
178+
'invitedToClinicReminder',
179+
'requestedConsent',
180+
'requestedConsentReminder',
181+
'consentGiven',
182+
'consentGivenClinic',
183+
'consentGivenTriage',
184+
'consentRefused',
185+
'consentUnknownContact',
186+
'sessionReminder',
187+
'triageDelayVaccination',
188+
'triageDoNotVaccinate',
189+
'triageInviteToClinic',
190+
'triageSafeToVaccinate',
191+
'triageSecondDose',
192+
'vaccinationGiven',
193+
'vaccinationAlreadyGiven',
194+
'vaccinationDeleted',
195+
'vaccinationNotGiven'
196+
].map((name) =>
197+
auditEvent({
198+
name: activity.notify[name](parent),
199+
programme_ids: ['mmr']
200+
})
201+
)
202+
},
203+
{
204+
title: 'Patient',
205+
items: [
206+
auditEvent({
207+
name: activity.patient.archived({
208+
archiveReason: ArchiveRecordReason.Other
209+
}),
210+
note: 'A brief note about why child record was archived.',
211+
createdBy_uid
212+
}),
213+
auditEvent({
214+
name: activity.patient.expired,
215+
note: `${patient.fullName} was vaccinated`,
216+
createdBy_uid
217+
}),
218+
auditEvent({
219+
name: activity.patient.merged(mergedPatient, patient),
220+
createdBy_uid
221+
})
222+
]
223+
},
224+
{
225+
title: 'Pre-screening',
226+
items: [
227+
auditEvent({
228+
name: activity.preScreen.created,
229+
note: 'A brief note about the pre-screening checks.',
230+
createdBy_uid,
231+
programme_ids: ['flu']
232+
})
233+
]
234+
},
235+
{
236+
title: 'PSD',
237+
items: [
238+
auditEvent({
239+
name: activity.psd.added,
240+
programme_ids: ['flu']
241+
}),
242+
auditEvent({
243+
name: activity.psd.invalidated,
244+
createdBy_uid,
245+
programme_ids: ['flu']
246+
})
247+
]
248+
},
249+
{
250+
title: 'Session',
251+
items: [
252+
auditEvent({
253+
name: activity.session.added(session),
254+
programme_ids: ['flu']
255+
}),
256+
auditEvent({
257+
name: activity.session.removed(session),
258+
createdBy_uid,
259+
programme_ids: ['flu']
260+
})
261+
]
262+
},
263+
{
264+
title: 'Triage',
265+
items: [
266+
auditEvent({
267+
name: activity.triage.decision({
268+
outcome: ScreenOutcome.DelayVaccination
269+
}),
270+
note: 'A brief note about the triage decision.',
271+
createdBy_uid,
272+
programme_ids: ['flu']
273+
})
274+
]
275+
},
276+
{
277+
title: 'Vaccination',
278+
items: [
279+
auditEvent({
280+
name: activity.vaccination.added,
281+
createdBy_uid,
282+
programme_ids: ['flu']
283+
}),
284+
auditEvent({
285+
name: activity.vaccination.recorded(vaccinationGiven),
286+
note: 'A brief note about the vaccination session.',
287+
createdBy_uid,
288+
programme_ids: ['flu']
289+
}),
290+
auditEvent({
291+
name: activity.vaccination.recorded(vaccinationNotGiven),
292+
note: 'A brief note about the vaccination session.',
293+
createdBy_uid,
294+
programme_ids: ['flu']
295+
}),
296+
auditEvent({
297+
name: activity.vaccination.uploaded,
298+
createdBy_uid,
299+
programme_ids: ['flu']
300+
})
301+
]
302+
}
303+
]
304+
305+
response.render('views/activity', { auditEventLog })
30306
}
31307
}

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)