Skip to content

Commit af8f8b9

Browse files
committed
feat: refactor exportRecords to allow for object array data to be exported
1 parent c119388 commit af8f8b9

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

apps/api/src/instrument-records/instrument-records.service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { accessibleQuery, InjectModel } from '@douglasneuroinformatics/libnest';
33
import type { Model } from '@douglasneuroinformatics/libnest';
44
import { linearRegression } from '@douglasneuroinformatics/libstats';
55
import { Injectable, UnprocessableEntityException } from '@nestjs/common';
6-
import type { ScalarInstrument } from '@opendatacapture/runtime-core';
6+
import type { InstrumentMeasureValue, ScalarInstrument } from '@opendatacapture/runtime-core';
77
import type {
88
CreateInstrumentRecordData,
99
InstrumentRecord,
@@ -149,19 +149,23 @@ export class InstrumentRecordsService {
149149
instruments.set(record.instrumentId, instrument);
150150
}
151151

152-
for (const [measureKey, measureValue] of Object.entries(record.computedMeasures)) {
152+
for (const [dataKey, dataValue] of Object.entries(record.data as object[])) {
153+
let newDataValue;
154+
if (typeof dataValue === 'object' && dataValue && JSON.stringify(dataValue)) {
155+
newDataValue = JSON.stringify(dataValue);
156+
}
153157
data.push({
154158
instrumentEdition: instrument.internal.edition,
155159
instrumentName: instrument.internal.name,
156-
measure: measureKey,
160+
measure: dataKey,
157161
sessionDate: record.session.date.toISOString(),
158162
sessionId: record.session.id,
159163
sessionType: record.session.type,
160164
subjectAge: record.subject.dateOfBirth ? yearsPassed(record.subject.dateOfBirth) : null,
161165
subjectId: record.subject.id,
162166
subjectSex: record.subject.sex,
163167
timestamp: record.date.toISOString(),
164-
value: measureValue
168+
value: newDataValue ?? (dataValue as InstrumentMeasureValue)
165169
});
166170
}
167171
}

0 commit comments

Comments
 (0)