Skip to content

Commit 04a08a6

Browse files
Make first clinic of today and events for test scenarios predictable (#81)
1 parent 1cea1e7 commit 04a08a6

4 files changed

Lines changed: 24 additions & 14 deletions

File tree

app/data/test-scenarios.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = [
2121
},
2222
extraNeeds: ['Wheelchair user'],
2323
config: {
24+
eventId: '5gpn41oi',
2425
defaultRiskLevel: 'routine',
2526
repeatViews: ['RMLO'],
2627
missingViews: [], // ensure all views are present
@@ -45,6 +46,7 @@ module.exports = [
4546
},
4647
extraNeeds: null,
4748
config: {
49+
eventId: '0gdof6fh',
4850
defaultRiskLevel: 'routine',
4951
missingViews: ['RMLO', 'RCC'], // ensure all views are present
5052
scheduling: {

app/lib/generate-seed-data.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ const generateClinicsForDay = (date, allParticipants, unit, usedParticipantsInSn
144144
slot,
145145
participant,
146146
clinic: firstClinic,
147+
id: scenario?.participant?.config?.eventId,
147148
outcomeWeights: config.screening.outcomes[firstClinic.clinicType],
148149
forceStatus: scenario.participant.config.scheduling.status,
149150
})

app/lib/generators/clinic-generator.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

app/lib/generators/event-generator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const determineEventStatus = (slotDateTime, currentDateTime, attendanceWeights)
5959
}
6060
}
6161

62-
const generateEvent = ({ slot, participant, clinic, outcomeWeights, forceStatus = null }) => {
62+
const generateEvent = ({ slot, participant, clinic, outcomeWeights, forceStatus = null, id = null }) => {
6363
// Parse dates once
6464
const [hours, minutes] = config.clinics.simulatedTime.split(':')
6565
const simulatedDateTime = dayjs().hour(parseInt(hours)).minute(parseInt(minutes))
@@ -81,7 +81,7 @@ const generateEvent = ({ slot, participant, clinic, outcomeWeights, forceStatus
8181
const eventStatus = forceStatus || determineEventStatus(slotDateTime, simulatedDateTime, attendanceWeights)
8282

8383
const eventBase = {
84-
id: generateId(),
84+
id: id || generateId(),
8585
participantId: participant.id,
8686
clinicId: clinic.id,
8787
slotId: slot.id,

0 commit comments

Comments
 (0)