Skip to content

Commit 99e5859

Browse files
Add some basic validation errors (#164)
This adds some validation and error messages. Not all screens done yet, but it’s a start. ## Screenshots ### Date ![error-1](https://github.com/user-attachments/assets/e6c22d44-aeec-4d95-b445-c5b5fdd27649) ### Vaccinator ![error-2](https://github.com/user-attachments/assets/ac2e148a-f144-4db8-89df-fb97aefb0b4d) ### Vaccine ![error-3](https://github.com/user-attachments/assets/110dfa84-b0ff-4e49-97b1-c49d1a718a2f) ### Vaccine product ![error-4](https://github.com/user-attachments/assets/7fa87b15-e78c-4557-9aa3-504961fe7c5a)
1 parent d61c6a2 commit 99e5859

File tree

4 files changed

+151
-8
lines changed

4 files changed

+151
-8
lines changed

app/routes/vaccinate.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,82 @@ function daysBetweenDates(date1, date2) {
3030

3131
module.exports = router => {
3232

33+
router.get('/vaccinate', (req, res) => {
34+
let vaccinationTodayError
35+
36+
if (req.query.showErrors === 'yes') {
37+
if (!req.session.data.vaccinationToday) {
38+
vaccinationTodayError = 'Select if vaccination was today'
39+
}
40+
}
41+
42+
res.render('vaccinate/index', {
43+
vaccinationTodayError
44+
})
45+
})
46+
47+
router.post('/vaccinate/answer-date', (req, res) => {
48+
const data = req.session.data
49+
50+
if (!data.vaccinationToday) {
51+
return res.redirect('/vaccinate/?showErrors=yes')
52+
}
53+
res.redirect('/vaccinate/delivery-team')
54+
})
55+
56+
router.get('/vaccinate/vaccinator', (req, res) => {
57+
let vaccinatorError
58+
59+
if (req.query.showErrors === 'yes') {
60+
if (!req.session.data.vaccinator) {
61+
vaccinatorError = 'Select the vaccinator'
62+
}
63+
}
64+
65+
res.render('vaccinate/vaccinator', {
66+
vaccinatorError
67+
})
68+
})
69+
70+
router.post('/vaccinate/answer-vaccinator', (req, res) => {
71+
const data = req.session.data
72+
73+
if (!data.vaccinator) {
74+
return res.redirect('/vaccinate/vaccinator?showErrors=yes')
75+
}
76+
res.redirect('/vaccinate/vaccine')
77+
})
78+
79+
router.get('/vaccinate/vaccine', (req, res) => {
80+
let vaccineError, vaccineProductError
81+
const data = req.session.data
82+
83+
if (req.query.showErrors === 'yes') {
84+
if (!data.vaccine) {
85+
vaccineError = 'Select the vaccine'
86+
}
87+
88+
if (data.vaccine && !req.session.data.vaccineProduct) {
89+
vaccineProductError = 'Select the vaccine product'
90+
}
91+
}
92+
93+
res.render('vaccinate/vaccine', {
94+
vaccineError,
95+
vaccineProductError
96+
})
97+
})
98+
99+
router.post('/vaccinate/answer-vaccine', (req, res) => {
100+
const data = req.session.data
101+
102+
if (!data.vaccine || !data.vaccineProduct) {
103+
return res.redirect('/vaccinate/vaccine?showErrors=yes')
104+
}
105+
res.redirect('/vaccinate/batch')
106+
})
107+
108+
33109
router.post('/vaccinate/answer-patient-nhs-number-known', (req, res) => {
34110

35111
const nhsNumberKnown = req.session.data.nhsNumberKnown;

app/views/vaccinate/index.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@
1010
<div class="nhsuk-grid-row">
1111
<div class="nhsuk-grid-column-two-thirds">
1212

13-
<form action="/vaccinate/delivery-team" method="post" novalidate>
13+
{% if vaccinationTodayError %}
14+
{{ errorSummary({
15+
titleText: "There is a problem",
16+
errorList: [
17+
{
18+
text: vaccinationTodayError,
19+
href: "#vaccinationToday-1"
20+
}
21+
]
22+
}) }}
23+
{% endif %}
24+
25+
<form action="/vaccinate/answer-date" method="post" novalidate>
1426
{% set previousDateHtml %}
1527

1628
{{ dateInput({
@@ -52,6 +64,9 @@
5264
isPageHeading: "true"
5365
}
5466
},
67+
errorMessage: {
68+
text: vaccinationTodayError
69+
} if vaccinationTodayError,
5570
items: [
5671
{
5772
value: "yes",

app/views/vaccinate/vaccinator.html

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,19 @@
1414
<div class="nhsuk-grid-row">
1515
<div class="nhsuk-grid-column-two-thirds">
1616

17+
{% if vaccinatorError %}
18+
{{ errorSummary({
19+
titleText: "There is a problem",
20+
errorList: [
21+
{
22+
text: vaccinatorError,
23+
href: "#vaccinator-1"
24+
}
25+
]
26+
}) }}
27+
{% endif %}
1728

18-
19-
<form action="/vaccinate/vaccine" method="post" novalidate>
29+
<form action="/vaccinate/answer-vaccinator" method="post" novalidate>
2030

2131
{% set otherVaccinatorHtml %}
2232
<div class="nhsuk-form-group">
@@ -39,7 +49,6 @@ <h1 class="nhsuk-label-wrapper">
3949
</div>
4050
{% endset %}
4151

42-
4352
{{ radios({
4453
idPrefix: "vaccinator",
4554
name: "vaccinator",
@@ -50,6 +59,9 @@ <h1 class="nhsuk-label-wrapper">
5059
isPageHeading: "true"
5160
}
5261
},
62+
errorMessage: {
63+
text: vaccinatorError
64+
} if vaccinatorError,
5365
items: [
5466
{
5567
value: "Jane Smith",

app/views/vaccinate/vaccine.html

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,32 @@
1414
<div class="nhsuk-grid-row">
1515
<div class="nhsuk-grid-column-two-thirds">
1616

17-
<form action="/vaccinate/batch" method="post" novalidate>
17+
{% if vaccineError %}
18+
{% set error = {text: vaccineError, href: "#vaccine-1"} %}
19+
{% elseif vaccineProductError %}
20+
{% if data.vaccine == "RSV" %}
21+
{% set errorHref = "#vaccineProductRsv-1" %}
22+
{% elseif data.vaccine == "COVID-19" %}
23+
{% set errorHref = "#vaccineProductCovid-1" %}
24+
{% elseif data.vaccine == "Pertussis" %}
25+
{% set errorHref = "#vaccineProductPertussis-1" %}
26+
{% elseif data.vaccine == "Flu" %}
27+
{% set errorHref = "#vaccineProductFlu-1" %}
28+
{% endif %}
29+
30+
{% set error = {text: vaccineProductError, href: errorHref} %}
31+
{% endif %}
32+
33+
{% if error %}
34+
{{ errorSummary({
35+
titleText: "There is a problem",
36+
errorList: [
37+
error
38+
]
39+
}) }}
40+
{% endif %}
41+
42+
<form action="/vaccinate/answer-vaccine" method="post" novalidate>
1843

1944
{% set covid19Product %}
2045
{{ radios({
@@ -25,6 +50,9 @@
2550
"text": "Vaccine product"
2651
}
2752
},
53+
errorMessage: {
54+
text: vaccineProductError
55+
} if vaccineProductError and data.vaccine == "COVID-19",
2856
"items": [
2957
{
3058
"value": "Comirnaty 30 JN.1",
@@ -59,6 +87,9 @@
5987
"text": "Vaccine product"
6088
}
6189
},
90+
errorMessage: {
91+
text: vaccineProductError
92+
} if vaccineProductError and data.vaccine == "Flu",
6293
"items": [
6394
{
6495
"value": "Adjuvanted Quadrivalent Influenza Vaccine (aQIV)",
@@ -69,7 +100,7 @@
69100
"value": "Cell-based Quadrivalent Influenza Vaccine (QIVc)",
70101
"text": "Cell-based Quadrivalent Influenza Vaccine (QIVc)",
71102
checked: (data.vaccineProduct == "Cell-based Quadrivalent Influenza Vaccine (QIVc)")
72-
},
103+
},
73104
{
74105
"value": "Fluenz (LAIV)",
75106
"text": "Fluenz (LAIV)",
@@ -92,7 +123,7 @@
92123
}
93124
]
94125
}) }}
95-
126+
96127
{% endset %}
97128

98129
{% set pertussisProduct %}
@@ -104,6 +135,9 @@
104135
"text": "Vaccine product"
105136
}
106137
},
138+
errorMessage: {
139+
text: vaccineProductError
140+
} if vaccineProductError and data.vaccine == "Pertussis",
107141
"items": [
108142
{
109143
"value": "Adacel vaccine supsension",
@@ -133,14 +167,17 @@
133167
"text": "Vaccine product"
134168
}
135169
},
170+
errorMessage: {
171+
text: vaccineProductError
172+
} if vaccineProductError and data.vaccine == "RSV",
136173
"items": [
137174
{
138175
"value": "Abrysvo",
139176
"text": "Abrysvo",
140177
checked: (data.vaccineProduct == "Abrysvo")
141178
}
142179
]
143-
}) }}
180+
}) }}
144181
{% endset %}
145182

146183
{% if data.repeatPatient == 'yes' and data.patientName %}
@@ -160,6 +197,9 @@
160197
"isPageHeading": true
161198
}
162199
},
200+
errorMessage: {
201+
text: vaccineError
202+
} if vaccineError,
163203
"items": [
164204
{
165205
"value": "COVID-19",

0 commit comments

Comments
 (0)