@@ -53,14 +53,6 @@ type WorkerMessage = { data: InstrumentRecordsExport; success: true } | { error:
5353
5454type InitialMessage = { success : true } ;
5555
56- // type MainThreadMessage = {
57- // data: {
58-
59- // }
60- // } | {
61- // error: string; success: false
62- // }
63-
6456@Injectable ( )
6557export class InstrumentRecordsService {
6658 constructor (
@@ -161,10 +153,17 @@ export class InstrumentRecordsService {
161153 date : true ,
162154 id : true ,
163155 type : true ,
164- user : true
156+ user : { select : { username : true } }
165157 }
166158 } ,
167- subject : true
159+ subject : {
160+ select : {
161+ dateOfBirth : true ,
162+ groupIds : true ,
163+ id : true ,
164+ sex : true
165+ }
166+ }
168167 } ,
169168 where : {
170169 AND : [
@@ -175,7 +174,6 @@ export class InstrumentRecordsService {
175174 ]
176175 }
177176 } ) ;
178-
179177 const instrumentIds = [ ...new Set ( records . map ( ( r ) => r . instrumentId ) ) ] ;
180178
181179 const instrumentsArray = await Promise . all (
@@ -184,65 +182,6 @@ export class InstrumentRecordsService {
184182
185183 const instruments = new Map ( instrumentsArray . map ( ( instrument ) => [ instrument . id , instrument ] ) ) ;
186184
187- // const processRecord = (record: (typeof records)[number]) => {
188- // if (!record.computedMeasures) return [];
189-
190- // const instrument = instruments.get(record.instrumentId)!;
191- // const rows: InstrumentRecordsExport = [];
192-
193- // for (const [measureKey, measureValue] of Object.entries(record.computedMeasures)) {
194- // if (measureValue == null) continue;
195-
196- // if (!Array.isArray(measureValue)) {
197- // rows.push({
198- // groupId: record.subject.groupIds[0] ?? DEFAULT_GROUP_NAME,
199- // instrumentEdition: instrument.internal.edition,
200- // instrumentName: instrument.internal.name,
201- // measure: measureKey,
202- // sessionDate: record.session.date.toISOString(),
203- // sessionId: record.session.id,
204- // sessionType: record.session.type,
205- // subjectAge: record.subject.dateOfBirth ? yearsPassed(record.subject.dateOfBirth) : null,
206- // subjectId: removeSubjectIdScope(record.subject.id),
207- // subjectSex: record.subject.sex,
208- // timestamp: record.date.toISOString(),
209- // username: record.session.user?.username ?? 'N/A',
210- // value: measureValue
211- // });
212- // continue;
213- // }
214-
215- // if (measureValue.length < 1) continue;
216-
217- // const expanded = this.expandData(measureValue);
218- // for (const entry of expanded) {
219- // if (!entry.success) {
220- // throw new Error(`exportRecords: ${instrument.internal.name}.${measureKey} — ${entry.message}`);
221- // }
222- // rows.push({
223- // groupId: record.subject.groupIds[0] ?? DEFAULT_GROUP_NAME,
224- // instrumentEdition: instrument.internal.edition,
225- // instrumentName: instrument.internal.name,
226- // measure: `${measureKey} - ${entry.measure}`,
227- // sessionDate: record.session.date.toISOString(),
228- // sessionId: record.session.id,
229- // sessionType: record.session.type,
230- // subjectAge: record.subject.dateOfBirth ? yearsPassed(record.subject.dateOfBirth) : null,
231- // subjectId: removeSubjectIdScope(record.subject.id),
232- // subjectSex: record.subject.sex,
233- // timestamp: record.date.toISOString(),
234- // username: record.session.user?.username ?? 'N/A',
235- // value: entry.measureValue
236- // });
237- // }
238- // }
239-
240- // return rows;
241- // };
242-
243- // const results = await Promise.all(records.map((record) => processRecord(record)));
244-
245- // return results.flat();
246185 const convertRecords = records . map ( ( record ) => {
247186 return {
248187 computedMeasures : record . computedMeasures ,
@@ -312,67 +251,8 @@ export class InstrumentRecordsService {
312251 } ) ;
313252
314253 const results = await Promise . all ( workerPromises ) ;
315- return results . flat ( ) ;
316254
317- // const data: InstrumentRecordsExport = [];
318- // for (const record of records) {
319- // if (!record.computedMeasures) {
320- // continue;
321- // }
322-
323- // const instrument = instruments.get(record.instrumentId)!;
324-
325- // for (const [measureKey, measureValue] of Object.entries(record.computedMeasures)) {
326- // if (measureValue == null) {
327- // continue;
328- // }
329-
330- // if (!Array.isArray(measureValue)) {
331- // data.push({
332- // groupId: record.subject.groupIds[0] ?? DEFAULT_GROUP_NAME,
333- // instrumentEdition: instrument.internal.edition,
334- // instrumentName: instrument.internal.name,
335- // measure: measureKey,
336- // sessionDate: record.session.date.toISOString(),
337- // sessionId: record.session.id,
338- // sessionType: record.session.type,
339- // subjectAge: record.subject.dateOfBirth ? yearsPassed(record.subject.dateOfBirth) : null,
340- // subjectId: removeSubjectIdScope(record.subject.id),
341- // subjectSex: record.subject.sex,
342- // timestamp: record.date.toISOString(),
343- // username: record.session.user?.username ?? 'N/A',
344- // value: measureValue
345- // });
346- // }
347-
348- // if (Array.isArray(measureValue) && measureValue.length < 1) continue;
349-
350- // if (Array.isArray(measureValue) && measureValue.length >= 1) {
351- // const arrayResult = this.expandData(measureValue);
352- // arrayResult.forEach((arrayEntry: ExpandDataType) => {
353- // if (!arrayEntry.success)
354- // throw new Error(`exportRecords: ${instrument.internal.name}.${measureKey} — ${arrayEntry.message}`);
355- // data.push({
356- // groupId: record.subject.groupIds[0] ?? DEFAULT_GROUP_NAME,
357- // instrumentEdition: instrument.internal.edition,
358- // instrumentName: instrument.internal.name,
359- // measure: `${measureKey} - ${arrayEntry.measure}`,
360- // sessionDate: record.session.date.toISOString(),
361- // sessionId: record.session.id,
362- // sessionType: record.session.type,
363- // subjectAge: record.subject.dateOfBirth ? yearsPassed(record.subject.dateOfBirth) : null,
364- // subjectId: removeSubjectIdScope(record.subject.id),
365- // subjectSex: record.subject.sex,
366- // timestamp: record.date.toISOString(),
367- // username: record.session.user?.username ?? 'N/A',
368- // value: arrayEntry.measureValue
369- // });
370- // });
371- // }
372- // }
373- // }
374-
375- // return data;
255+ return results . flat ( ) ;
376256 }
377257
378258 async find (
0 commit comments