@@ -141,7 +141,7 @@ const determineSessionType = (sessionTimes) => {
141141 return startHour < 12 ? 'morning' : 'afternoon'
142142}
143143
144- const generateClinic = ( date , location , breastScreeningUnit , sessionTimes , overrides = null ) => {
144+ const generateClinic = ( date , location , breastScreeningUnit , sessionTimes , overrides = null , id = null ) => {
145145 const clinicType = overrides ?. clinicType || determineClinicType ( location , breastScreeningUnit )
146146 const slots = generateTimeSlots ( date , sessionTimes , clinicType )
147147
@@ -163,7 +163,7 @@ const generateClinic = (date, location, breastScreeningUnit, sessionTimes, overr
163163 const totalSlots = slots . length * ( isToday && clinicType !== 'assessment' ? 2 : 1 )
164164
165165 return {
166- id : generateId ( ) ,
166+ id : id || generateId ( ) ,
167167 clinicCode : generateClinicCode ( ) ,
168168 date : clinicDate . format ( 'YYYY-MM-DD' ) ,
169169 breastScreeningUnitId : breastScreeningUnit . id ,
@@ -197,6 +197,9 @@ const generateClinicsForBSU = ({ date, breastScreeningUnit }) => {
197197 // Check if this is today's generation
198198 const isToday = dayjs ( date ) . startOf ( 'day' ) . isSame ( dayjs ( ) . startOf ( 'day' ) )
199199
200+ // Check if this is the first clinic of today - used to assign a specific ID
201+ let isFirstClinicOfToday = isToday // Only track this for today
202+
200203 // Generate clinics for each selected location
201204 return selectedLocations . flatMap ( ( location , locationIndex ) => {
202205 // Use location-specific patterns if available, otherwise use BSU patterns
@@ -207,26 +210,30 @@ const generateClinicsForBSU = ({ date, breastScreeningUnit }) => {
207210
208211 if ( selectedPattern . type === 'single' ) {
209212 // For single sessions, create one clinic
210- return [ generateClinic (
213+ const clinic = generateClinic (
211214 date ,
212215 location ,
213216 breastScreeningUnit ,
214217 selectedPattern . sessions [ 0 ] ,
215- // Force first clinic of today to be screening
216- isToday && locationIndex === 0 ? { clinicType : 'screening' } : null
217- ) ]
218+ isToday && locationIndex === 0 ? { clinicType : 'screening' } : null ,
219+ isFirstClinicOfToday ? 'wtrl7jud' : null
220+ )
221+ isFirstClinicOfToday = false
222+ return [ clinic ]
218223 } else {
219224 // For paired sessions, create two clinics
220- return selectedPattern . sessions . map ( ( sessionTimes , sessionIndex ) =>
221- generateClinic (
225+ return selectedPattern . sessions . map ( ( sessionTimes , sessionIndex ) => {
226+ const clinic = generateClinic (
222227 date ,
223228 location ,
224229 breastScreeningUnit ,
225- sessionTimes ,
226- // Force first clinic of today to be screening
227- isToday && locationIndex === 0 && sessionIndex === 0 ? { clinicType : 'screening' } : null
230+ selectedPattern . sessions [ 0 ] ,
231+ isToday && locationIndex === 0 ? { clinicType : ' screening' } : null ,
232+ isFirstClinicOfToday ? 'wtrl7jud' : null
228233 )
229- )
234+ isFirstClinicOfToday = false
235+ return clinic
236+ } )
230237 }
231238 } )
232239}
0 commit comments