@@ -138,10 +138,90 @@ const generateReadingData = (events, users) => {
138138 console . log ( `Added first and second reads to ${ count } events in the 2 oldest clinics` )
139139 }
140140
141+ // NEW: Add clinic where both reads are completed, but neither by the current user
142+ if ( clinics . length >= 3 ) {
143+ let count = 0
144+ // Use the next clinic for this scenario
145+ const clinic = clinics [ 2 ]
146+ console . log ( `Adding a clinic with both reads completed by users other than current user to clinic ${ clinic . id } ` )
147+
148+ // Use the same base time for all reads in this clinic, then advance by 1 minute for each event
149+ let baseReadTime = dayjs ( generateRecentTimestamp ( clinic . date , 30 , 48 ) )
150+
151+ // Add full first reads by third user
152+ clinic . events . forEach ( event => {
153+ // Skip if already updated
154+ if ( updatedEventIds . has ( event . id ) ) return
155+
156+ // Find the event in our array
157+ const eventIndex = updatedEvents . findIndex ( e => e . id === event . id )
158+ if ( eventIndex === - 1 ) return
159+
160+ // Ensure the imageReading structure exists
161+ if ( ! updatedEvents [ eventIndex ] . imageReading ) {
162+ updatedEvents [ eventIndex ] . imageReading = { reads : { } }
163+ }
164+
165+ // Advance time by 1 minute for each read
166+ baseReadTime = baseReadTime . add ( 1 , 'minute' )
167+
168+ // First read (by third user)
169+ const firstResult = weighted . select ( readResults )
170+ const firstReadTime = baseReadTime . toISOString ( )
171+
172+ updatedEvents [ eventIndex ] . imageReading . reads [ thirdReader . id ] = {
173+ result : firstResult ,
174+ readerId : thirdReader . id ,
175+ readerType : thirdReader . role ,
176+ timestamp : firstReadTime
177+ }
178+
179+ updatedEventIds . add ( event . id )
180+ count ++
181+ } )
182+
183+ // Add second reads by second user to 60% of events
184+ const eventsForSecondRead = clinic . events
185+ . filter ( event => updatedEventIds . has ( event . id ) )
186+ . slice ( 0 , Math . ceil ( clinic . events . length * 0.6 ) ) // Take 60% of events for second read
187+
188+ baseReadTime = dayjs ( generateRecentTimestamp ( clinic . date , 12 , 24 ) ) // More recent timestamp for second reads
189+
190+ eventsForSecondRead . forEach ( event => {
191+ const eventIndex = updatedEvents . findIndex ( e => e . id === event . id )
192+ if ( eventIndex === - 1 ) return
193+
194+ // Get the first read result
195+ const firstRead = updatedEvents [ eventIndex ] . imageReading . reads [ thirdReader . id ]
196+ if ( ! firstRead ) return
197+
198+ // Second read (by second user) - 80% chance of agreement
199+ let secondResult = firstRead . result
200+ if ( Math . random ( ) > 0.8 ) {
201+ // Different result for disagreement
202+ const otherResults = Object . keys ( readResults ) . filter ( r => r !== firstRead . result )
203+ secondResult = otherResults [ Math . floor ( Math . random ( ) * otherResults . length ) ]
204+ }
205+
206+ // Advance time by 1-2 minutes for each read
207+ baseReadTime = baseReadTime . add ( 1 + Math . floor ( Math . random ( ) * 2 ) , 'minute' )
208+ const secondReadTime = baseReadTime . toISOString ( )
209+
210+ updatedEvents [ eventIndex ] . imageReading . reads [ secondReader . id ] = {
211+ result : secondResult ,
212+ readerId : secondReader . id ,
213+ readerType : secondReader . role ,
214+ timestamp : secondReadTime
215+ }
216+ } )
217+
218+ console . log ( `Added a clinic with ${ clinic . events . length } first reads and ${ eventsForSecondRead . length } second reads, both done by users other than current user` )
219+ }
220+
141221 // NEXT TWO CLINICS: First user (current user) reads all first, but no second reads
142- if ( clinics . length >= 4 ) {
222+ if ( clinics . length >= 5 ) {
143223 let count = 0
144- for ( let i = 2 ; i < 4 && i < clinics . length ; i ++ ) {
224+ for ( let i = 3 ; i < 5 && i < clinics . length ; i ++ ) {
145225 const clinic = clinics [ i ]
146226 console . log ( `Adding first reads by current user to clinic ${ clinic . id } ` )
147227
@@ -183,9 +263,9 @@ const generateReadingData = (events, users) => {
183263 }
184264
185265 // NEXT TWO CLINICS: Second user reads all first, waiting for first user (current user) to do second reads
186- if ( clinics . length >= 6 ) {
266+ if ( clinics . length >= 7 ) {
187267 let count = 0
188- for ( let i = 4 ; i < 6 && i < clinics . length ; i ++ ) {
268+ for ( let i = 5 ; i < 7 && i < clinics . length ; i ++ ) {
189269 const clinic = clinics [ i ]
190270 console . log ( `Adding first reads by second user to clinic ${ clinic . id } ` )
191271
@@ -227,9 +307,9 @@ const generateReadingData = (events, users) => {
227307 }
228308
229309 // NEXT TWO OLDEST CLINICS: 75% first read by third user
230- if ( clinics . length >= 8 ) {
310+ if ( clinics . length >= 9 ) {
231311 let count = 0
232- for ( let i = 6 ; i < 8 && i < clinics . length ; i ++ ) {
312+ for ( let i = 7 ; i < 9 && i < clinics . length ; i ++ ) {
233313 const clinic = clinics [ i ]
234314 console . log ( `Adding partial first reads to clinic ${ clinic . id } ` )
235315
0 commit comments