Skip to content

Commit c4e306e

Browse files
Make vaccines in reports dynamic (#417)
This makes the vaccines list in the Reports section dynamic, so that it now includes all enabled vaccines. ## Before <img width="580" height="418" alt="Screenshot 2025-07-22 at 15 07 35" src="https://github.com/user-attachments/assets/2f72a908-0803-4024-9d7f-cb047ec33d8a" /> ## After (with all 7 vaccine types enabled) <img width="672" height="546" alt="Screenshot 2025-07-22 at 15 08 05" src="https://github.com/user-attachments/assets/7816c0a0-9570-4977-80a0-033add119ee1" />
1 parent b540c85 commit c4e306e

File tree

4 files changed

+63
-58
lines changed

4 files changed

+63
-58
lines changed

app/routes/helpers.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
module.exports = router => {
22

33
router.get('/prototype-setup/setup-batches', (req, res) => {
4-
54
const data = req.session.data
5+
const currentOrganisation = res.locals.currentOrganisation
6+
67
let vaccineStock = data.vaccineStock
78

9+
const organisationVaccines = currentOrganisation.vaccines
10+
811
const dateNow = new Date()
912
const millisecondsPerDay = 86400000
1013

1114
const vaccines = data.vaccines
1215
const siteId = "RW3NM"
1316

1417
for (vaccine of vaccines) {
18+
19+
const organisationVaccine = organisationVaccines.find((organisationVaccine) => organisationVaccine.name === vaccine.name)
20+
21+
if (organisationVaccine) {
22+
organisationVaccine.status = "enabled"
23+
} else {
24+
organisationVaccines.push({
25+
name: vaccine.name,
26+
status: "enabled"
27+
})
28+
}
29+
1530
for (vaccineProduct of vaccine.products) {
1631

1732
const numberOfBatchesToAdd = 1 + Math.floor(Math.random() * 10)

app/routes/reports.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ const filters = require('.././filters.js')()
22

33
module.exports = (router) => {
44

5+
router.get('/reports/choose-vaccines', (req, res) => {
6+
const data = req.session.data
7+
8+
const organisationVaccines = res.locals.currentOrganisation.vaccines || []
9+
10+
const enabledVaccines = organisationVaccines
11+
.filter((vaccine) => vaccine.status === "enabled")
12+
13+
res.render('reports/choose-vaccines', {
14+
enabledVaccines
15+
})
16+
})
17+
18+
519
router.get('/reports/choose-dates', (req, res) => {
620
const data = req.session.data
721

app/views/reports/check.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h1 class="nhsuk-heading-xl">{{ pageName }}</h1>
3131
actions: {
3232
items: [
3333
{
34-
href: "/reports/choose-dates-2",
34+
href: "/reports/choose-dates",
3535
text: "Change",
3636
visuallyHiddenText: "name"
3737
}
@@ -60,12 +60,10 @@ <h1 class="nhsuk-heading-xl">{{ pageName }}</h1>
6060
},
6161
{
6262
key: {
63-
text: ("Vaccines" if (data.vaccines | length) > 1 else "Vaccine"),
64-
classes: "xnhsuk-u-font-weight-bold"
63+
text: ("Vaccines" if (data.vaccines | length) > 1 else "Vaccine")
6564
},
6665
value: {
67-
text: (data.vaccines | join(", ")) if data.vaccines,
68-
classes: "xnhsuk-u-font-weight-bold"
66+
text: (data.vaccines | sort(false, false, "name") | join(", ") | capitaliseFirstLetter) if data.vaccines
6967
},
7068
actions: {
7169
items: [

app/views/reports/choose-vaccines.html

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,58 +13,36 @@
1313
{% endblock %}
1414

1515
{% block content %}
16-
17-
<div class="nhsuk-grid-row">
18-
<div class="nhsuk-grid-column-two-thirds">
19-
20-
21-
22-
<form action="/reports/choose-site" method="post">
23-
{{ checkboxes({
24-
"idPrefix": "vaccines",
25-
"name": "vaccines",
26-
"fieldset": {
27-
"legend": {
28-
"text": "Choose vaccines",
29-
"classes": "nhsuk-fieldset__legend--xl",
30-
isPageHeading: true
31-
}
32-
},
33-
"items": [
34-
{
35-
"value": "COVID-19",
36-
"text": "COVID-19",
37-
checked: (data.vaccines | arrayOrStringIncludes("COVID-19"))
38-
},
39-
{
40-
"value": "Flu",
41-
"text": "Flu",
42-
checked: (data.vaccines | arrayOrStringIncludes("Flu"))
43-
},
44-
{
45-
"value": "Pertussis",
46-
"text": "Pertussis",
47-
checked: (data.vaccines | arrayOrStringIncludes("Pertussis"))
48-
},
49-
{
50-
"value": "RSV",
51-
"text": "RSV",
52-
checked: (data.vaccines | arrayOrStringIncludes("RSV"))
53-
}
54-
]
55-
}) }}
56-
{{ button({
57-
"text": "Continue"
58-
}) }}
59-
</form>
60-
61-
62-
</div>
63-
</div>
64-
65-
66-
67-
16+
<div class="nhsuk-grid-row">
17+
<div class="nhsuk-grid-column-two-thirds">
18+
<form action="/reports/choose-site" method="post">
19+
20+
{% set items = [] %}
21+
22+
{% for vaccine in (enabledVaccines | sort(false, false, "name")) %}
23+
{% set items = (items.push({
24+
value: vaccine.name,
25+
text: (vaccine.name | capitaliseFirstLetter)
26+
}), items) %}
27+
{% endfor %}
28+
29+
{{ checkboxes({
30+
idPrefix: "vaccines",
31+
name: "vaccines",
32+
fieldset: {
33+
legend: {
34+
text: "Choose vaccines",
35+
classes: "nhsuk-fieldset__legend--xl",
36+
isPageHeading: true
37+
}
38+
},
39+
values: data.vaccines,
40+
items: items
41+
}) }}
42+
{{ button({
43+
"text": "Continue"
44+
}) }}
45+
</form>
6846
</div>
6947
</div>
7048
{% endblock %}

0 commit comments

Comments
 (0)