Skip to content

Commit c48dacc

Browse files
Review activity log items
1 parent 182057a commit c48dacc

14 files changed

Lines changed: 508 additions & 101 deletions

File tree

app/controllers/activity.js

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

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)