@@ -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
0 commit comments