Skip to content

Commit 2aa1010

Browse files
Sept 30 bugfixes (#170)
* Reduce number of checked-in participants * Improve generation to prefer existing people for prior snapshots
1 parent ffff084 commit 2aa1010

File tree

5 files changed

+47
-13
lines changed

5 files changed

+47
-13
lines changed

app/data/test-scenarios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module.exports = [
7777
missingViews: ['RMLO', 'RCC'], // ensure all views are present
7878
scheduling: {
7979
whenRelativeToToday: 0,
80-
status: 'event_checked_in',
80+
status: 'event_scheduled',
8181
approximateTime: '11:30'
8282
// slotIndex: 20,
8383
}

app/lib/generate-seed-data.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ const generateClinicsForDay = (
103103
allParticipants,
104104
unit,
105105
usedParticipantsInSnapshot,
106-
indices
106+
indices,
107+
testScenarioParticipantIds = new Set(),
108+
unitEvents = []
107109
) => {
108110
const clinics = []
109111
const events = []
@@ -112,6 +114,12 @@ const generateClinicsForDay = (
112114
// Check if this snapshot date is for the recent period (not historical)
113115
const isRecentSnapshot = dayjs(date).isAfter(dayjs().subtract(1, 'month'))
114116

117+
// For historical snapshots, extract participants who have events in the current period
118+
const participantsWithExistingEvents =
119+
!isRecentSnapshot && unitEvents.length > 0
120+
? new Set(unitEvents.map((event) => event.participantId))
121+
: new Set()
122+
115123
// Check if this is today - we want one in-progress event for today only
116124
const isToday = dayjs(date).isSame(dayjs(), 'day')
117125

@@ -199,9 +207,26 @@ const generateClinicsForDay = (
199207
)
200208

201209
// Get available participants of selected risk level
202-
const availableParticipants = indices.riskLevelIndex[
210+
// EXCLUDE test scenario participants from random selection
211+
let availableParticipants = indices.riskLevelIndex[
203212
selectedRiskLevel
204-
].filter((p) => !usedParticipantsInSnapshot.has(p.id))
213+
].filter(
214+
(p) =>
215+
!usedParticipantsInSnapshot.has(p.id) &&
216+
!testScenarioParticipantIds.has(p.id)
217+
)
218+
219+
// For historical snapshots, prefer participants with existing events
220+
if (!isRecentSnapshot && participantsWithExistingEvents.size > 0) {
221+
const preferred = availableParticipants.filter((p) =>
222+
participantsWithExistingEvents.has(p.id)
223+
)
224+
225+
// Use preferred participants if available, otherwise fall back to all available
226+
if (preferred.length > 0) {
227+
availableParticipants = preferred
228+
}
229+
}
205230

206231
if (availableParticipants.length === 0) {
207232
const newParticipant = generateParticipant({
@@ -276,6 +301,11 @@ const generateData = async () => {
276301
})
277302
})
278303

304+
// Create set of test scenario participant IDs
305+
const testScenarioParticipantIds = new Set(
306+
testScenarios.map((s) => s.participant.id)
307+
)
308+
279309
console.log('Generating random participants...')
280310
const randomParticipants = Array.from(
281311
{ length: config.generation.numberOfParticipants },
@@ -351,7 +381,9 @@ const generateData = async () => {
351381
participants,
352382
unit,
353383
usedParticipantsInSnapshot,
354-
indices
384+
indices,
385+
testScenarioParticipantIds,
386+
unitEvents
355387
)
356388
)
357389

app/lib/generators/event-generator.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ const determineEventStatus = (
5252
if (minutesPassed <= 60) {
5353
// Within 30 mins of appointment
5454
return weighted.select({
55-
event_checked_in: 0.6,
56-
event_complete: 0.1,
55+
event_checked_in: 0.3,
56+
event_complete: 0.2,
5757
event_attended_not_screened: 0.1,
58-
event_scheduled: 0.2
58+
event_scheduled: 0.4
5959
})
6060
} else {
6161
// More than 30 mins after appointment
@@ -82,6 +82,8 @@ const generateEvent = ({
8282
const simulatedDateTime = dayjs()
8383
.hour(parseInt(hours))
8484
.minute(parseInt(minutes))
85+
.second(0)
86+
.millisecond(0)
8587
const slotDateTime = dayjs(slot.dateTime)
8688
const isPast = slotDateTime.isBefore(simulatedDateTime)
8789

app/views/_includes/summary-lists/rows/last-known-mammogram.njk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
<span class="nhsuk-u-font-weight-bold">At this BSU</span><br>
88
{% endif %}
99
{# Temporarily hardcode until we can investigate bug with date #}
10-
{{ "2022-03-23" | formatDate }}
10+
{# {{ "2022-03-23" | formatDate }}
1111
({{ "2022-03-23" | formatDate | formatRelativeDate | asHint }})</br>
12-
West of London BSU
13-
{# {% set mostRecentClinic = data | getParticipantMostRecentClinic(participant.id) %}
12+
West of London BSU #}
13+
{% set mostRecentClinic = data | getParticipantMostRecentClinic(participant.id) %}
1414
{% if mostRecentClinic %}
1515
{{ mostRecentClinic | log }}
1616
{{ mostRecentClinic.event.timing.startTime | formatDate }} ({{ mostRecentClinic.event.timing.startTime | formatDate | formatRelativeDate | asHint }})</br>
@@ -19,7 +19,7 @@
1919

2020
{% else %}
2121
{{ "Not known" | asHint }}
22-
{% endif %} #}
22+
{% endif %}
2323
</p>
2424

2525
{% if hasAdditionalMammograms %}

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ async function startNodemon(done) {
9797
stdout: true,
9898
ext: 'js json',
9999
watch: ['.env', 'app.js', 'app', 'lib'],
100-
ignore: ['app/assets', '**.test.*'],
100+
ignore: ['app/assets', 'app/data/generated', '**.test.*'],
101101
quiet: false
102102
})
103103

0 commit comments

Comments
 (0)