@@ -3,7 +3,7 @@ import { accessibleQuery, InjectModel } from '@douglasneuroinformatics/libnest';
33import type { Model } from '@douglasneuroinformatics/libnest' ;
44import { linearRegression } from '@douglasneuroinformatics/libstats' ;
55import { Injectable , UnprocessableEntityException } from '@nestjs/common' ;
6- import type { ScalarInstrument } from '@opendatacapture/runtime-core' ;
6+ import type { InstrumentMeasureValue , ScalarInstrument } from '@opendatacapture/runtime-core' ;
77import 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