Skip to content

Commit bfe3f6b

Browse files
authored
Merge pull request #1217 from david-roper/add-group-column
refactor: use removeSubjectIDScope method instead of regex function
2 parents caad09f + 3272e17 commit bfe3f6b

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
LinearRegressionResults,
1515
UploadInstrumentRecordsData
1616
} from '@opendatacapture/schemas/instrument-records';
17+
import { removeSubjectIdScope } from '@opendatacapture/subject-utils';
1718
import { Prisma } from '@prisma/client';
1819
import type { Session } from '@prisma/client';
1920
import { isNumber, mergeWith, pickBy } from 'lodash-es';
@@ -38,14 +39,6 @@ type ExpandDataType =
3839
success: false;
3940
};
4041

41-
function afterFirstDollar(str: string) {
42-
if (!str) return str;
43-
const match = /\$(.*)/.exec(str);
44-
if (!match) return str;
45-
if (!match[1]) return str;
46-
return match[1];
47-
}
48-
4942
@Injectable()
5043
export class InstrumentRecordsService {
5144
constructor(
@@ -188,7 +181,7 @@ export class InstrumentRecordsService {
188181
sessionId: record.session.id,
189182
sessionType: record.session.type,
190183
subjectAge: record.subject.dateOfBirth ? yearsPassed(record.subject.dateOfBirth) : null,
191-
subjectId: afterFirstDollar(record.subject.id),
184+
subjectId: removeSubjectIdScope(record.subject.id),
192185
subjectSex: record.subject.sex,
193186
timestamp: record.date.toISOString(),
194187
value: measureValue
@@ -211,7 +204,7 @@ export class InstrumentRecordsService {
211204
sessionId: record.session.id,
212205
sessionType: record.session.type,
213206
subjectAge: record.subject.dateOfBirth ? yearsPassed(record.subject.dateOfBirth) : null,
214-
subjectId: afterFirstDollar(record.subject.id),
207+
subjectId: removeSubjectIdScope(record.subject.id),
215208
subjectSex: record.subject.sex,
216209
timestamp: record.date.toISOString(),
217210
value: arrayEntry.measureValue

apps/web/src/hooks/useInstrumentVisualization.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useEffect, useMemo, useState } from 'react';
33
import { toBasicISOString } from '@douglasneuroinformatics/libjs';
44
import { useDownload, useNotificationsStore, useTranslation } from '@douglasneuroinformatics/libui/hooks';
55
import type { AnyUnilingualScalarInstrument, InstrumentKind } from '@opendatacapture/runtime-core';
6+
import { removeSubjectIdScope } from '@opendatacapture/subject-utils';
67
import { omit } from 'lodash-es';
78
import { 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

Comments
 (0)