|
| 1 | +module.exports = router => { |
| 2 | + |
| 3 | + router.post('/vaccinate/answer-patient-nhs-number-known', (req, res) => { |
| 4 | + |
| 5 | + const nhsNumberKnown = req.session.data.nhsNumberKnown; |
| 6 | + |
| 7 | + if (nhsNumberKnown === "yes") { |
| 8 | + |
| 9 | + req.session.data.patientName = "Jodie Brown" |
| 10 | + req.session.data.dateOfBirth = {day: "4", month: "7", year: "1964"} |
| 11 | + req.session.data.postcode = "GD3 I83" |
| 12 | + |
| 13 | + res.redirect('/vaccinate/patient-history') |
| 14 | + } else if (nhsNumberKnown === "no") { |
| 15 | + res.redirect('/vaccinate/patient-search') |
| 16 | + } else { |
| 17 | + res.redirect('/vaccinate/patient?showError=yes') |
| 18 | + } |
| 19 | + |
| 20 | + }) |
| 21 | + |
| 22 | + |
| 23 | + router.post('/vaccinate/patient-search', (req, res) => { |
| 24 | + |
| 25 | + const firstName = req.session.data.firstName; |
| 26 | + const lastName = req.session.data.lastName; |
| 27 | + const dateOfBirth = req.session.data.dateOfBirth; |
| 28 | + const postcode = req.session.data.postcode; |
| 29 | + let errors = [] |
| 30 | + let firstNameError, lastNameError, dateOfBirthError, postcodeError |
| 31 | + |
| 32 | + if (firstName === "") { |
| 33 | + firstNameError = "Enter first name" |
| 34 | + errors.push({ |
| 35 | + text: firstNameError, |
| 36 | + href: "#firstName" |
| 37 | + }) |
| 38 | + } |
| 39 | + |
| 40 | + if (lastName === "") { |
| 41 | + lastNameError = "Enter last name" |
| 42 | + errors.push({ |
| 43 | + text: lastNameError, |
| 44 | + href: "#lastName" |
| 45 | + }) |
| 46 | + } |
| 47 | + |
| 48 | + if (dateOfBirth.day === "" || dateOfBirth.month === "" || dateOfBirth.year === "") { |
| 49 | + dateOfBirthError = "Enter date of birth" |
| 50 | + errors.push({ |
| 51 | + text: dateOfBirthError, |
| 52 | + href: "#dateOfBirth" |
| 53 | + }) |
| 54 | + } |
| 55 | + |
| 56 | + if (postcode === "") { |
| 57 | + postcodeError = "Enter postcode" |
| 58 | + errors.push({ |
| 59 | + text: postcodeError, |
| 60 | + href: "#postcode" |
| 61 | + }) |
| 62 | + } |
| 63 | + |
| 64 | + if (errors.length === 0) { |
| 65 | + |
| 66 | + if (Number(dateOfBirth.day) %2) { |
| 67 | + res.redirect('/vaccinate/no-search-result') |
| 68 | + } else { |
| 69 | + res.redirect('/vaccinate/search-result') |
| 70 | + } |
| 71 | + } else { |
| 72 | + res.render('vaccinate/patient-search', { |
| 73 | + errors, |
| 74 | + firstNameError, |
| 75 | + lastNameError, |
| 76 | + dateOfBirthError, |
| 77 | + postcodeError |
| 78 | + }) |
| 79 | + } |
| 80 | + |
| 81 | + }) |
| 82 | + |
| 83 | + // Routing page after DONE |
| 84 | + router.post('/vaccinate/what-next', (req, res) => { |
| 85 | + |
| 86 | + const answer = req.session.data.nextStep; |
| 87 | + |
| 88 | + req.session.data.injectionSite = "" |
| 89 | + |
| 90 | + if (answer === 'same-vaccination-another-patient') { |
| 91 | + |
| 92 | + req.session.data.patientName = "" |
| 93 | + req.session.data.nhsNumber = "" |
| 94 | + |
| 95 | + res.redirect('/vaccinate/patient?repeatVaccination=yes&repeatPatient=no') |
| 96 | + |
| 97 | + } else if (answer === 'same-patient-another-vaccination') { |
| 98 | + |
| 99 | + req.session.data.vaccine = "" |
| 100 | + req.session.data.vaccineProduct = "" |
| 101 | + req.session.data.vaccineBatch = "" |
| 102 | + |
| 103 | + res.redirect('/vaccinate/vaccine?repeatPatient=yes&repeatVaccination=no') |
| 104 | + |
| 105 | + } else { |
| 106 | + |
| 107 | + res.redirect('/home') |
| 108 | + } |
| 109 | + |
| 110 | + }) |
| 111 | + |
| 112 | +} |
0 commit comments