Skip to content

Commit 58b379f

Browse files
Review activity log items
1 parent ebd3b49 commit 58b379f

13 files changed

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

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)