@@ -6,6 +6,8 @@ const { generateMammogramImages } = require('../lib/generators/mammogram-generat
66const { getEvent, saveTempEventToEvent, updateEventStatus } = require ( '../lib/utils/event-data' )
77const generateId = require ( '../lib/utils/id-generator' )
88const { getReturnUrl, urlWithReferrer, appendReferrer } = require ( '../lib/utils/referrers' )
9+ const { createDynamicTemplateRoute } = require ( '../lib/utils/dynamic-routing' )
10+
911
1012/**
1113 * Get single event and its related data
@@ -123,6 +125,8 @@ module.exports = router => {
123125 } )
124126 } )
125127
128+
129+
126130 router . post ( '/clinics/:clinicId/events/:eventId/personal-details/ethnicity-answer' , ( req , res ) => {
127131 const { clinicId, eventId } = req . params
128132 const data = req . session . data
@@ -217,7 +221,7 @@ module.exports = router => {
217221 // Main route in to starting an event - used to clear any temp data
218222 router . get ( '/clinics/:clinicId/events/:eventId/previous-mammograms/add' , ( req , res ) => {
219223 delete req . session . data ?. event ?. previousMammogramTemp
220- res . render ( 'events/mammography/ previous-mammograms/edit' )
224+ res . render ( 'events/previous-mammograms/edit' )
221225 } )
222226
223227 // Save data about a mammogram
@@ -581,42 +585,6 @@ module.exports = router => {
581585 res . redirect ( urlWithReferrer ( `/clinics/${ clinicId } /events/${ eventId } /medical-information/symptoms/type` , req . query . referrerChain ) )
582586 } )
583587
584- const MAMMOGRAPHY_VIEWS = [
585- 'medical-information-check' ,
586- 'record-medical-information' ,
587- 'ready-for-imaging' ,
588- 'awaiting-images' ,
589-
590- 'confirm' ,
591- 'screening-complete' ,
592- 'attended-not-screened-reason' ,
593- 'previous-mammograms/edit' ,
594- 'previous-mammograms/appointment-should-not-proceed' ,
595- 'previous-mammograms/proceed-anyway' ,
596- 'medical-information/symptoms/type' ,
597- 'medical-information/symptoms/details' ,
598- 'personal-details/ethnicity' ,
599-
600- // Completed screenings
601- 'images' ,
602- 'medical-information' ,
603- ]
604-
605- // Event within clinic context
606- router . get ( '/clinics/:clinicId/events/:eventId/*' , ( req , res , next ) => {
607- const view = req . params [ 0 ] // Gets the wildcard part
608-
609- if ( MAMMOGRAPHY_VIEWS . some ( viewPath => viewPath === view ) ) {
610- res . render ( `events/mammography/${ view } ` , { } )
611- } else {
612- next ( )
613- }
614- } )
615-
616- // Event within clinic context
617- router . get ( '/clinics/:clinicId/events/:eventId/medical-information/:view' , ( req , res , next ) => {
618- res . render ( `events/mammography/medical-information/${ req . params . view } ` , { } )
619- } )
620588
621589 // Specific route for imaging view
622590 router . get ( '/clinics/:clinicId/events/:eventId/imaging' , ( req , res ) => {
@@ -637,7 +605,7 @@ module.exports = router => {
637605 res . locals . event = data . event
638606 }
639607
640- res . render ( 'events/mammography/ imaging' , { } )
608+ res . render ( 'events/imaging' , { } )
641609 } )
642610
643611
@@ -660,7 +628,7 @@ module.exports = router => {
660628 router . post ( '/clinics/:clinicId/events/:eventId/record-medical-information-answer' , ( req , res ) => {
661629 const { clinicId, eventId } = req . params
662630 const data = req . session . data
663- const imagingCanProceed = data . event . appointment . imagingCanProceed
631+ const imagingCanProceed = data ? .event ? .appointment ? .imagingCanProceed
664632
665633 if ( ! imagingCanProceed ) {
666634 res . redirect ( `/clinics/${ clinicId } /events/${ eventId } /record-medical-information` )
@@ -758,4 +726,12 @@ module.exports = router => {
758726 // res.redirect(`/clinics/${clinicId}/events/${eventId}/screening-complete`)
759727 } )
760728
729+ // General purpose dynamic template route for events
730+ // This should come after any more specific routes
731+ router . get ( '/clinics/:clinicId/events/:eventId/*' ,
732+ createDynamicTemplateRoute ( {
733+ templatePrefix : 'events'
734+ } )
735+ )
736+
761737}
0 commit comments