Skip to content

Commit fce2eeb

Browse files
Review activity log items
1 parent ebd3b49 commit fce2eeb

13 files changed

Lines changed: 485 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: 261 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,249 @@ 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+
'triageDoNotVaccinate',
172+
'triageInviteToClinic',
173+
'triageSafeToVaccinate',
174+
'triageSecondDose',
175+
'vaccinationGiven',
176+
'vaccinationAlreadyGiven',
177+
'vaccinationDeleted',
178+
'vaccinationNotGiven'
179+
].map((name) =>
180+
auditEvent({
181+
name: activity.notify[name](parent),
182+
programme_ids: ['mmr']
183+
})
184+
)
185+
},
186+
{
187+
title: 'Patient',
188+
items: [
189+
auditEvent({
190+
name: activity.patient.archived({
191+
archiveReason: ArchiveRecordReason.Other
192+
}),
193+
note: 'A brief note about why child record was archived.',
194+
createdBy_uid
195+
}),
196+
auditEvent({
197+
name: activity.patient.expired,
198+
note: `${patient.fullName} was vaccinated`,
199+
createdBy_uid
200+
}),
201+
auditEvent({
202+
name: activity.patient.merged(mergedPatient, patient),
203+
createdBy_uid
204+
})
205+
]
206+
},
207+
{
208+
title: 'Pre-screening',
209+
items: [
210+
auditEvent({
211+
name: activity.preScreen.created,
212+
note: 'A brief note about the pre-screening checks.',
213+
createdBy_uid,
214+
programme_ids: ['flu']
215+
})
216+
]
217+
},
218+
{
219+
title: 'PSD',
220+
items: [
221+
auditEvent({
222+
name: activity.psd.added,
223+
programme_ids: ['flu']
224+
}),
225+
auditEvent({
226+
name: activity.psd.invalidated,
227+
createdBy_uid,
228+
programme_ids: ['flu']
229+
})
230+
]
231+
},
232+
{
233+
title: 'Session',
234+
items: [
235+
auditEvent({
236+
name: activity.session.added(session),
237+
programme_ids: ['flu']
238+
}),
239+
auditEvent({
240+
name: activity.session.removed(session),
241+
createdBy_uid,
242+
programme_ids: ['flu']
243+
})
244+
]
245+
},
246+
{
247+
title: 'Triage',
248+
items: [
249+
auditEvent({
250+
name: activity.triage.decision({
251+
outcome: ScreenOutcome.DelayVaccination
252+
}),
253+
note: 'A brief note about the triage decision.',
254+
createdBy_uid,
255+
programme_ids: ['flu']
256+
})
257+
]
258+
},
259+
{
260+
title: 'Vaccination',
261+
items: [
262+
auditEvent({
263+
name: activity.vaccination.added,
264+
createdBy_uid,
265+
programme_ids: ['flu']
266+
}),
267+
auditEvent({
268+
name: activity.vaccination.recorded(vaccinationGiven),
269+
note: 'A brief note about the vaccination session.',
270+
createdBy_uid,
271+
programme_ids: ['flu']
272+
}),
273+
auditEvent({
274+
name: activity.vaccination.recorded(vaccinationNotGiven),
275+
note: 'A brief note about the vaccination session.',
276+
createdBy_uid,
277+
programme_ids: ['flu']
278+
}),
279+
auditEvent({
280+
name: activity.vaccination.uploaded,
281+
createdBy_uid,
282+
programme_ids: ['flu']
283+
})
284+
]
285+
}
286+
]
287+
288+
response.render('views/activity', { auditEventLog })
30289
}
31290
}

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)