@@ -28,25 +28,75 @@ function getEventData(data, clinicId, eventId) {
2828 }
2929}
3030
31+ // Update event status and add to history
32+ function updateEventStatus ( event , newStatus ) {
33+ return {
34+ ...event ,
35+ status : newStatus ,
36+ statusHistory : [
37+ ...event . statusHistory ,
38+ {
39+ status : newStatus ,
40+ timestamp : new Date ( ) . toISOString ( )
41+ }
42+ ]
43+ }
44+ }
45+
3146module . exports = router => {
3247
33- // Event within clinic context
34- router . get ( '/clinics/:clinicId/events/:eventId' , ( req , res ) => {
48+ // Set clinics to active in nav for all urls starting with /clinics
49+ router . use ( '/clinics/:clinicId/events/:eventId' , ( req , res , next ) => {
3550 const eventData = getEventData ( req . session . data , req . params . clinicId , req . params . eventId )
36-
51+
3752 if ( ! eventData ) {
53+ console . log ( `No event ${ req . params . eventId } found for clinic ${ req . params . clinicId } ` )
3854 res . redirect ( '/clinics/' + req . params . clinicId )
3955 return
4056 }
4157
58+ res . locals . eventData = eventData
59+ res . locals . clinic = eventData . clinic ,
60+ res . locals . event = eventData . event ,
61+ res . locals . participant = eventData . participant ,
62+ res . locals . unit = eventData . unit ,
63+ res . locals . clinicId = req . params . clinicId ,
64+ res . locals . eventId = req . params . eventId
65+
66+ next ( ) ;
67+ } ) ;
68+
69+ // Event within clinic context
70+ router . get ( '/clinics/:clinicId/events/:eventId' , ( req , res ) => {
4271 res . render ( 'events/show' , {
43- clinic : eventData . clinic ,
44- event : eventData . event ,
45- participant : eventData . participant ,
46- unit : eventData . unit ,
47- clinicId : req . params . clinicId ,
48- eventId : req . params . eventId
4972 } )
5073 } )
5174
75+ // Event within clinic context
76+ router . get ( '/clinics/:clinicId/events/:eventId/imaging' , ( req , res ) => {
77+ res . render ( 'events/mamography/imaging' , {
78+ } )
79+ } )
80+
81+ // // Advance status to attened / complete
82+ // router.post('/clinics/:clinicId/events/:eventId/attended', (req, res) => {
83+
84+ // res.redirect(`/clinics/${req.params.clinicId}/events/${req.params.eventId}`, {
85+ // })
86+ // })
87+
88+ // Handle screening completion
89+ router . post ( '/clinics/:clinicId/events/:eventId/complete' , ( req , res ) => {
90+ const { clinicId, eventId } = req . params
91+
92+ // Update event status to attended
93+ const eventIndex = req . session . data . events . findIndex ( e => e . id === eventId )
94+ req . session . data . events [ eventIndex ] = updateEventStatus (
95+ req . session . data . events [ eventIndex ] ,
96+ 'attended'
97+ )
98+
99+ res . redirect ( `/clinics/${ clinicId } /events/${ eventId } ` )
100+ } )
101+
52102} ;
0 commit comments