@@ -3,6 +3,7 @@ import { useEffect, useMemo, useState } from 'react';
33import { toBasicISOString } from '@douglasneuroinformatics/libjs' ;
44import { useDownload , useNotificationsStore , useTranslation } from '@douglasneuroinformatics/libui/hooks' ;
55import type { AnyUnilingualScalarInstrument , InstrumentKind } from '@opendatacapture/runtime-core' ;
6+ import { removeSubjectIdScope } from '@opendatacapture/subject-utils' ;
67import { omit } from 'lodash-es' ;
78import { unparse } from 'papaparse' ;
89
@@ -36,14 +37,6 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
3637 const [ minDate , setMinDate ] = useState < Date | null > ( null ) ;
3738 const [ instrumentId , setInstrumentId ] = useState < null | string > ( null ) ;
3839
39- function afterFirstDollar ( str : string ) {
40- if ( ! str ) return str ;
41- const match = / \$ ( .* ) / . exec ( str ) ;
42- if ( ! match ) return str ;
43- if ( ! match [ 1 ] ) return str ;
44- return match [ 1 ] ;
45- }
46-
4740 const instrument = useInstrument ( instrumentId ) as AnyUnilingualScalarInstrument ;
4841
4942 const instrumentInfoQuery = useInstrumentInfoQuery ( {
@@ -80,7 +73,7 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
8073 return exportRecords . map ( ( item ) => {
8174 const obj : { [ key : string ] : any } = {
8275 GroupID : currentGroup ? currentGroup . id : 'root' ,
83- subjectId : afterFirstDollar ( params . subjectId )
76+ subjectId : removeSubjectIdScope ( params . subjectId )
8477 } ;
8578 for ( const key of columnNames ) {
8679 const val = item [ key ] ;
@@ -113,7 +106,7 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
113106 GroupID : currentGroup ? currentGroup . id : 'root' ,
114107 // eslint-disable-next-line perfectionist/sort-objects
115108 Date : toBasicISOString ( date ) ,
116- SubjectID : afterFirstDollar ( params . subjectId ) ,
109+ SubjectID : removeSubjectIdScope ( params . subjectId ) ,
117110 Variable : `${ objKey } -${ arrKey } ` ,
118111 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, perfectionist/sort-objects
119112 Value : arrItem
@@ -125,7 +118,7 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
125118 GroupID : currentGroup ? currentGroup . id : 'root' ,
126119 // eslint-disable-next-line perfectionist/sort-objects
127120 Date : toBasicISOString ( date ) ,
128- SubjectID : afterFirstDollar ( params . subjectId ) ,
121+ SubjectID : removeSubjectIdScope ( params . subjectId ) ,
129122 Value : objVal ,
130123 Variable : objKey
131124 } ) ;
0 commit comments