Skip to content

Commit 10032f4

Browse files
Add legal mechanism to Record vaccinations and Records sections (#495)
This adds legal mechanism into the streamlined journey. It also adds legal mechanisms to the vaccines section as checkbox option you can select. This then reduces the number of options shown when recording a vaccination, or if you only select a single option then it skips the question entirely. ## Record vaccinations <img width="761" height="552" alt="Screenshot 2025-10-21 at 13 42 49" src="https://github.com/user-attachments/assets/476f95ed-dedb-41b8-88fa-c26bcf3f4346" /> ## Check answers summary <img width="782" height="698" alt="Screenshot 2025-10-21 at 13 43 31" src="https://github.com/user-attachments/assets/fbdb5785-62a6-405c-a62a-2a2046b51f2b" /> ## Records section <img width="692" height="695" alt="Screenshot 2025-10-21 at 13 57 09" src="https://github.com/user-attachments/assets/35cfa19c-820d-4778-a155-eba3fb69e2b6" /> --------- Co-authored-by: Anna-Sutton <[email protected]>
1 parent b831511 commit 10032f4

32 files changed

+443
-106
lines changed

app/data/session-data-defaults.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,27 @@ module.exports = {
1717
currentOrganisationId: "RW3",
1818
currentRegionId: "Y62",
1919
vaccinationsRecorded: [],
20+
legalMechanisms: [
21+
{
22+
value: "National protocol",
23+
text: "National protocol"
24+
},
25+
{
26+
value: "Patient group direction",
27+
text: "Patient group direction (PGD)"
28+
},
29+
{
30+
value: "Patient specific direction",
31+
text: "Patient specific direction (PSD)"
32+
},
33+
{
34+
value: "Written instruction",
35+
text: "Written instruction",
36+
hint: {
37+
text: "Occupational health only"
38+
}
39+
}
40+
],
2041
data: [
2142
"Patients", "Staff", "Site or delivery team", "Assessment and consent", "Vaccination"
2243
],

app/routes/helpers.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module.exports = router => {
66
const data = req.session.data
77
const currentOrganisation = res.locals.currentOrganisation
88

9+
const allLegalMechanisms = data.legalMechanisms.map((legalMechaism) => legalMechaism.value)
10+
911
let vaccineStock = data.vaccineStock
1012

1113
const organisationVaccines = currentOrganisation.vaccines
@@ -55,6 +57,7 @@ module.exports = router => {
5557
id: generatedVaccineId,
5658
vaccine: vaccine.name,
5759
vaccineProduct: vaccineProduct.name,
60+
legalMechanisms: allLegalMechanisms,
5861
siteId: siteId,
5962
batches: batches
6063
})
@@ -103,6 +106,8 @@ module.exports = router => {
103106
const randomVaccineProduct = randomItem(vaccineProductsInStock)
104107
const randombatchNumber = randomItem(randomVaccineProduct.batches)
105108

109+
const randomLegalMechanism = randomItem(data.legalMechanisms).value
110+
106111
const vaccinator = randomItem(vaccinators)
107112

108113
const randomName = randomItem(listOfFirstNames) + " " + randomItem(listOfLastNames)
@@ -127,6 +132,7 @@ module.exports = router => {
127132
batchNumber: randombatchNumber.batchNumber,
128133
batchExpiryDate: "2025-01-05",
129134
vaccinatorId: vaccinator.id,
135+
legalMechanism: randomLegalMechanism,
130136
eligibility: ["Pregnant"],
131137
pregnancyDueDate: {
132138
day: "04",

app/routes/record-vaccinations.js

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ module.exports = router => {
7272

7373

7474
if (req.query.showErrors === "yes") {
75-
if (!req.session.data.deliveryTeam) {
75+
if (!req.session.data.siteId) {
7676
errors.push({
7777
text: "Select a site",
78-
href: "#delivery-team-1"
78+
href: "#site-id"
7979
})
8080
}
8181
}
@@ -89,7 +89,7 @@ module.exports = router => {
8989
router.post('/record-vaccinations/answer-delivery-team', (req, res) => {
9090
const data = req.session.data
9191

92-
if (!data.deliveryTeam) {
92+
if (!data.siteId) {
9393
return res.redirect('/record-vaccinations/delivery-team?showErrors=yes')
9494
} else {
9595
res.redirect('/record-vaccinations/vaccinator')
@@ -144,7 +144,7 @@ module.exports = router => {
144144
let vaccineError, vaccineProductError
145145
const data = req.session.data
146146

147-
const vaccineStock = data.vaccineStock.filter((vaccine) => vaccine.siteId === data.deliveryTeam)
147+
const vaccineStock = data.vaccineStock.filter((vaccine) => vaccine.siteId === data.siteId)
148148
const vaccinesAdded = [...new Set(vaccineStock.map((vaccineAdded) => vaccineAdded.vaccine))]
149149
const vaccineProductsAdded = [...new Set(vaccineStock.map((vaccineAdded) => vaccineAdded.vaccineProduct))]
150150

@@ -190,7 +190,8 @@ module.exports = router => {
190190

191191
if (nhsNumberKnown === "yes" && nhsNumber.match(/^\d{10}$/) && nhsNumber.startsWith('9')) {
192192

193-
req.session.data.patientName = "Jodie Brown"
193+
req.session.data.firstName = "Jodie"
194+
req.session.data.lastName = "Brown"
194195
req.session.data.dateOfBirth = {day: "15", month: "8", year: "1949"}
195196
req.session.data.postcode = "GD3 I83"
196197

@@ -309,7 +310,8 @@ module.exports = router => {
309310
// Otherwise pretend there is a single result and
310311
// go to patient details page
311312
} else {
312-
data.patientName = 'Jodie Brown'
313+
data.firstName = 'Jodie'
314+
data.lastName = 'Brown'
313315
data.nhsNumber = '9123456788'
314316
res.redirect('/record-vaccinations/patient-history')
315317
}
@@ -405,6 +407,26 @@ module.exports = router => {
405407

406408
})
407409

410+
router.get('/record-vaccinations/legal-mechanism', (req, res) => {
411+
const data = req.session.data
412+
413+
const vaccine = data.vaccineStock.find(function(batch) {
414+
return (batch.vaccineProduct === data.vaccineProduct) &&
415+
(batch.vaccine === data.vaccine)
416+
})
417+
if (!vaccine) { res.redirect('/record-vaccinations'); return }
418+
419+
const allLegalMechanisms = data.legalMechanisms
420+
421+
const legalMechanisms = allLegalMechanisms.filter((legalMechanism) => {
422+
return vaccine.legalMechanisms.includes(legalMechanism.value)
423+
})
424+
425+
res.render('record-vaccinations/legal-mechanism', {
426+
legalMechanisms
427+
})
428+
429+
})
408430

409431
router.get('/record-vaccinations/patient-estimated-due-date', (req, res) => {
410432

@@ -524,7 +546,6 @@ module.exports = router => {
524546

525547
})
526548

527-
528549
router.get('/record-vaccinations/eligibility', (req, res) => {
529550
const data = req.session.data
530551
const eligibility = data.eligibility
@@ -554,7 +575,7 @@ module.exports = router => {
554575

555576
nextPage = "/record-vaccinations/eligibility?showErrors=yes"
556577

557-
} else if (data.patientName && data.patientName != "" && data.repeatPatient === "yes") {
578+
} else if (data.firstName && data.firstName != "" && data.repeatPatient === "yes") {
558579

559580
if (data.vaccine === "Pertussis" || ((data.vaccine == "RSV") && (eligibility === "Pregnant"))) {
560581
nextPage = "/record-vaccinations/patient-estimated-due-date"
@@ -580,6 +601,7 @@ module.exports = router => {
580601
router.post('/record-vaccinations/confirmed', (req, res) => {
581602

582603
const data = req.session.data
604+
const currentOrganisation = res.locals.currentOrganisation
583605

584606
const generatedId = Math.floor(Math.random() * 10000000).toString()
585607

@@ -591,9 +613,9 @@ module.exports = router => {
591613
const yearToday = (dateToday.getFullYear())
592614

593615
if (data.vaccinationToday === 'yes') {
594-
data.vaccinationDate.day = dayToday
595-
data.vaccinationDate.month = monthToday
596-
data.vaccinationDate.year = yearToday
616+
data.vaccinationDate.day = String(dayToday)
617+
data.vaccinationDate.month = String(monthToday)
618+
data.vaccinationDate.year = String(yearToday)
597619
}
598620

599621
data.vaccinationsRecorded.push({
@@ -602,13 +624,15 @@ module.exports = router => {
602624
vaccine: data.vaccine,
603625
vaccineProduct: data.vaccineProduct,
604626
patient: {
605-
name: data.firstName + " " + data.lastName,
627+
name: "" + data.firstName + " " + data.lastName,
606628
nhsNumber: data.nhsNumber
607629
},
608630
batchNumber: data.vaccineBatch,
609631
batchExpiryDate: "2025-12-05",
610-
siteId: data.deliveryTeam,
632+
organisationId: currentOrganisation.id,
633+
siteId: data.siteId,
611634
vaccinatorId: data.vaccinatorId,
635+
legalMechanism: data.legalMechanism,
612636
eligibility: data.eligibility,
613637
pregnancyDueDate: data.pregnancyDueDate,
614638
consent: data.consent,
@@ -703,7 +727,8 @@ module.exports = router => {
703727

704728
if (answer === 'same-vaccination-another-patient') {
705729

706-
req.session.data.patientName = ""
730+
req.session.data.firstName = ""
731+
req.session.data.lastName = ""
707732
req.session.data.nhsNumber = ""
708733

709734
// newly added batch becomes the default
@@ -721,6 +746,7 @@ module.exports = router => {
721746
req.session.data.vaccineProduct = ""
722747
req.session.data.vaccineBatch = ""
723748
req.session.data.eligibility = ""
749+
req.session.data.legalMechanism = ""
724750

725751
res.redirect('/record-vaccinations/vaccine?repeatPatient=yes&repeatVaccination=no')
726752

@@ -731,6 +757,7 @@ module.exports = router => {
731757
req.session.data.vaccineBatch = ""
732758
req.session.data.eligibility = ""
733759
req.session.data.nhsNumber = ""
760+
req.session.data.legalMechanism = ""
734761

735762
res.redirect('/record-vaccinations/vaccine')
736763
} else {
@@ -813,14 +840,35 @@ module.exports = router => {
813840
const vaccineBatch = data.vaccineBatch
814841
const vaccine = data.vaccine
815842

843+
const vaccineOptions = data.vaccineStock.find(function(batch) {
844+
return (batch.vaccineProduct === data.vaccineProduct) &&
845+
(batch.vaccine === data.vaccine)
846+
})
847+
if (!vaccineOptions) { res.redirect('/record-vaccinations'); return }
848+
849+
const allLegalMechanisms = data.legalMechanisms
850+
851+
const legalMechanisms = allLegalMechanisms.filter((legalMechanism) => {
852+
return vaccineOptions.legalMechanisms.includes(legalMechanism['value'])
853+
})
854+
816855
let redirectPath
817856

818857
if (vaccineBatch === "add-new") {
819858
redirectPath = "/record-vaccinations/add-batch"
820859
} else if (!vaccineBatch) {
821860
redirectPath = "/record-vaccinations/batch?showError=yes"
822861
} else if (["COVID-19", "flu", "flu (London service)", "RSV", "pneumococcal"].includes(data.vaccine)) {
823-
redirectPath = "/record-vaccinations/eligibility"
862+
863+
if (legalMechanisms.length > 1) {
864+
redirectPath = "/record-vaccinations/legal-mechanism"
865+
} else {
866+
// Set legal mechanism to the only option available and skip
867+
// the question
868+
data.legalMechanism = legalMechanisms[0].value
869+
redirectPath = "/record-vaccinations/eligibility"
870+
}
871+
824872
} else if (data.repeatPatient === "yes") {
825873
redirectPath = "/record-vaccinations/patient-estimated-due-date"
826874
} else {
@@ -868,7 +916,7 @@ module.exports = router => {
868916
} else if ((data.vaccine === "pertussis") || (data.vaccine === "MMR")) {
869917
nextPage = "/record-vaccinations/patient"
870918
} else {
871-
nextPage = "/record-vaccinations/eligibility"
919+
nextPage = "/record-vaccinations/legal-mechanism"
872920
}
873921

874922
res.redirect(nextPage)
@@ -959,6 +1007,24 @@ module.exports = router => {
9591007
})
9601008
})
9611009

1010+
router.post('/record-vaccinations/answer-legal-mechanism', (req, res) => {
1011+
const data = req.session.data
1012+
1013+
if (!data.legalMechanism) {
1014+
1015+
const legalMechanismError = {
1016+
text: "Select legal mechanism",
1017+
href: "#legal-mechanism"
1018+
}
1019+
1020+
res.render('record-vaccinations/legal-mechanism', {
1021+
legalMechanismError
1022+
})
1023+
} else {
1024+
res.redirect('/record-vaccinations/eligibility')
1025+
}
1026+
})
1027+
9621028
router.post('/record-vaccinations/answer-consent', (req, res) => {
9631029
const data = req.session.data
9641030
const consent = data.consent

app/routes/records.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ module.exports = router => {
5353

5454
if (data.nhsNumberKnown === "yes") {
5555

56-
req.session.data.patientName = "Jodie Brown"
56+
req.session.data.firstName = "Jodie"
57+
req.session.data.firstName = "Brown"
5758
req.session.data.dateOfBirth = {day: "15", month: "8", year: "1949"}
5859
req.session.data.postcode = "GD3 I83"
5960

@@ -135,6 +136,10 @@ module.exports = router => {
135136
vaccination.batchNumber = data.batchNumber
136137
}
137138

139+
if (data.legalMechanism) {
140+
vaccination.legalMechanism = data.legalMechanism
141+
}
142+
138143
if (data.notes) {
139144
vaccination.notes = data.notes
140145
}
@@ -157,7 +162,6 @@ module.exports = router => {
157162

158163
if (firstName && lastName && dateOfBirth) {
159164

160-
data.patientName = firstName + " " + lastName
161165
data.nhsNumber = '9123456788'
162166

163167
res.redirect('/records/patient-history')

app/routes/vaccines.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = (router) => {
1414
vaccine: data.vaccine,
1515
vaccineProduct: data.vaccineProduct,
1616
siteId: data.siteId,
17+
legalMechanisms: data.vaccineLegalMechanisms,
1718
batches: [
1819
{
1920
id: Math.floor(Math.random() * 10000000).toString(),
@@ -33,6 +34,7 @@ module.exports = (router) => {
3334
req.session.data.batchExpiryDate.day = ''
3435
req.session.data.batchExpiryDate.month = ''
3536
req.session.data.batchExpiryDate.year = ''
37+
req.session.data.vaccineLegalMechanisms = ''
3638

3739
res.redirect('/vaccines/' + generatedId)
3840
})
@@ -107,6 +109,12 @@ module.exports = (router) => {
107109
res.render('vaccines/add-batch')
108110
})
109111

112+
// Viewing legal mechanisms page
113+
router.get('/vaccines/legal-mechanisms', (req, res) => {
114+
115+
res.render('vaccines/legal-mechanisms')
116+
})
117+
110118
// Viewing check answers page
111119
router.get('/vaccines/check', (req, res) => {
112120

@@ -145,6 +153,7 @@ module.exports = (router) => {
145153
req.session.data.batchExpiryDate.day = ''
146154
req.session.data.batchExpiryDate.month = ''
147155
req.session.data.batchExpiryDate.year = ''
156+
req.session.data.vaccineLegalMechanisms = ''
148157

149158
res.redirect('/vaccines/' + vaccine.id)
150159
})

app/views/lists/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ <h1 class="nhsuk-heading-l">{{ pageName }}</h1>
9696
{{ patient.dateOfBirth | govukDate }}
9797
</td>
9898
<td class="nhsuk-table__cell">
99-
<a class="nhsuk-link" href="/record-vaccinations/patient-history?patientName={{ patient.firstName}} {{ patient.lastName }}&nhsNumber={{ patient.nhsNumber }}&dateOfBirth={{ patient.dateOfBirth }}?fromListId={{ patientList.id }}">Record</a>
99+
<a class="nhsuk-link" href="/record-vaccinations/patient-history?firstName={{ patient.firstName}}&lastName{{ patient.lastName }}&nhsNumber={{ patient.nhsNumber }}&dateOfBirth={{ patient.dateOfBirth }}?fromListId={{ patientList.id }}">Record</a>
100100
</td>
101101
<td class="nhsuk-table__cell nhsuk-table__cell--numeric">
102102
<a class="nhsuk-link" href="/lists/remove">Remove

app/views/lists/record/done.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
{% set pageName = "Vaccination saved" %}
44

5-
{% set patientName = data.patientName if data.patientName else "Jodies Smith" %}
6-
75
{% set currentSection = "vaccinate" %}
86

97
{% block content %}

0 commit comments

Comments
 (0)