@@ -79,7 +79,7 @@ export const replyController = {
7979 const { account, invalidUuid } = request . app . locals
8080 const { reply_uuid } = request . params
8181 const { data } = request . session
82- const { __ , patientSession, triage } = response . locals
82+ const { __ , patientSession, triage, vaccination } = response . locals
8383
8484 let reply
8585 let next
@@ -106,6 +106,32 @@ export const replyController = {
106106 } )
107107 }
108108
109+ // Create vaccination if refusal reason is vaccination already given
110+ if ( reply ?. refusalReason === ReplyRefusal . AlreadyVaccinated ) {
111+ const createdVaccination = Vaccination . create (
112+ {
113+ outcome : VaccinationOutcome . AlreadyVaccinated ,
114+ patient_uuid : patientSession . patient . uuid ,
115+ patientSession_uuid : patientSession . uuid ,
116+ programme_id : patientSession . programme . id ,
117+ session_id : patientSession . session . id ,
118+ createdBy_uid : account . uid || '000123456789' ,
119+ createdAt_ : vaccination . createdAt_ ,
120+ clinic_id : vaccination . clinic_id ,
121+ school_id : vaccination . school_id ,
122+ locationName : vaccination . locationName ,
123+ addressLine1 : vaccination . addressLine1 ,
124+ addressLine2 : vaccination . addressLine2 ,
125+ addressLevel1 : vaccination . addressLevel1 ,
126+ country : vaccination . country ,
127+ locationType : vaccination . locationType
128+ } ,
129+ data
130+ )
131+
132+ patientSession . patient . recordVaccination ( createdVaccination )
133+ }
134+
109135 // Invalidate any replaced response
110136 if ( invalidUuid ) {
111137 Reply . update ( invalidUuid , { invalid : true } , data )
@@ -122,6 +148,7 @@ export const replyController = {
122148 // Clean up session data
123149 delete data . reply
124150 delete data . triage
151+ delete data . vaccination
125152
126153 request . flash (
127154 'success' ,
@@ -136,7 +163,7 @@ export const replyController = {
136163 return ( request , response , next ) => {
137164 const { reply_uuid } = request . params
138165 const { data, referrer } = request . session
139- const { patientSession, triage } = response . locals
166+ const { patientSession, triage, vaccination } = response . locals
140167
141168 let reply
142169 if ( type === 'edit' ) {
@@ -172,6 +199,11 @@ export const replyController = {
172199 ...data ?. wizard ?. triage // Wizard values
173200 }
174201
202+ response . locals . vaccination = {
203+ ...( type === 'edit' && vaccination ) , // Previous values
204+ ...data ?. wizard ?. vaccination // Wizard values
205+ }
206+
175207 const journey = {
176208 [ `/` ] : { } ,
177209 [ `/${ reply_uuid } /${ type } /respondent` ] : { } ,
@@ -204,11 +236,11 @@ export const replyController = {
204236 [ `/${ reply_uuid } /${ type } /refusal-reason` ] : {
205237 [ `/${ reply_uuid } /${ type } /refusal-reason-details` ] : {
206238 data : 'reply.refusalReason' ,
207- values : [
208- ReplyRefusal . AlreadyVaccinated ,
209- ReplyRefusal . GettingElsewhere ,
210- ReplyRefusal . Medical
211- ]
239+ values : [ ReplyRefusal . GettingElsewhere , ReplyRefusal . Medical ]
240+ } ,
241+ [ `/ ${ reply_uuid } / ${ type } /refusal-already-vaccinated` ] : {
242+ data : 'reply.refusalReason' ,
243+ value : ReplyRefusal . AlreadyVaccinated
212244 } ,
213245 [ `/${ reply_uuid } /${ type } /refusal-notification` ] : {
214246 data : 'reply.refusalReason' ,
@@ -294,13 +326,12 @@ export const replyController = {
294326 } ,
295327
296328 updateForm ( request , response ) {
297- const { account } = request . app . locals
298329 const { respondent } = request . body
299330 const { reply_uuid } = request . params
300331 const { data } = request . session
301- const { paths, patientSession, reply , triage } = response . locals
332+ let { paths, patientSession, triage , vaccination } = response . locals
302333
303- Reply . update ( reply_uuid , request . body . reply , data . wizard )
334+ const reply = Reply . update ( reply_uuid , request . body . reply , data . wizard )
304335
305336 // Create parent based on choice of respondent
306337 if ( respondent ) {
@@ -312,7 +343,7 @@ export const replyController = {
312343 break
313344 case 'self' :
314345 reply . method = ReplyMethod . InPerson
315- reply . parent = false
346+ reply . parent = null
316347 reply . selfConsent = true
317348 break
318349 case 'parent-1' : // Consent response is from CHIS record
@@ -336,27 +367,19 @@ export const replyController = {
336367 }
337368 }
338369
339- // Store vaccination if refusal reason is vaccination already given
340- if ( request . body . reply ?. refusalReason === ReplyRefusal . AlreadyVaccinated ) {
341- response . locals . vaccination = {
342- outcome : VaccinationOutcome . AlreadyVaccinated ,
343- patient_uuid : patientSession . patient . uuid ,
344- session_id : patientSession . session . id ,
345- createdBy_uid : account . uid ,
346- ...( data . reply ?. note && { note : data . reply . note } )
347- }
348- }
349-
350370 delete data . healthAnswers
351371 delete data . respondent
352372
353- Reply . update ( reply_uuid , reply , data . wizard )
354-
355373 data . wizard . triage = {
356374 ...triage , // Previous values
357375 ...request . body ?. triage // New value
358376 }
359377
378+ data . wizard . vaccination = {
379+ ...vaccination , // Previous values
380+ ...request ?. body ?. vaccination // Wizard values
381+ }
382+
360383 response . redirect (
361384 paths . next ||
362385 `${ patientSession . uri } /replies/${ reply_uuid } /new/check-answers`
0 commit comments