Skip to content

Commit

Permalink
[FIX] IntendedFor issue on Dataset Review
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Levitas committed Feb 23, 2024
1 parent cb04bb6 commit c6db916
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 35 deletions.
3 changes: 2 additions & 1 deletion ui/src/BaseConvertPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ import { hasAuth, createEventsTSV } from './lib';
import { ElNotification } from 'element-plus';
import 'element-plus/es/components/notification/style/css';
import { setSectionIDs, funcQA, fmapQA, dwiQA, petQA, setRun, setVolumeThreshold } from './libUnsafe';
import { setSectionIDs, funcQA, fmapQA, dwiQA, petQA, setRun, setVolumeThreshold, setIntendedFor } from './libUnsafe';
import niivue from './components/niivue.vue';
Expand Down Expand Up @@ -255,6 +255,7 @@ export default defineComponent({
fmapQA(this.ezbids);
dwiQA(this.ezbids);
setRun(this.ezbids); //keep here for initial func/events mapping to corresponding func/bold
setIntendedFor(this.ezbids);
this.mapObjects();
break;
case 'object':
Expand Down
14 changes: 1 addition & 13 deletions ui/src/Objects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -661,18 +661,6 @@ export default defineComponent({
}
if (o._type.startsWith('fmap/') || o._type === 'perf/m0scan') {
if (!o.IntendedFor) o.IntendedFor = [];
if (o.IntendedFor.length == 0) {
if (o._type.startsWith('fmap/')) {
o.validationWarnings.push(
'It is recommended that field map (fmap) images have IntendedFor set to at least 1 series ID. This is necessary if you plan on using processing BIDS-apps such as fMRIPrep'
);
} else if (o.type === 'perf/m0scan') {
o.validationErrors.push(
'It is required that perfusion m0scan images have IntendedFor set to at least 1 series ID.'
);
}
}
//Ensure other fmap series aren't included in the IntendedFor mapping
if (o.IntendedFor.length > 0) {
o.IntendedFor.forEach((i) => {
Expand Down Expand Up @@ -732,12 +720,12 @@ export default defineComponent({
},
validateAll() {
setIntendedFor(this.ezbids);
alignEntities(this.ezbids);
dwiQA(this.ezbids);
petQA(this.ezbids);
setRun(this.ezbids);
this.ezbids.objects.forEach(this.validate);
setIntendedFor(this.ezbids); // keep this last, otherwise IntendedFor in Dataset Review can be messed up
},
submitForm(data: any) {
Expand Down
63 changes: 42 additions & 21 deletions ui/src/libUnsafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,15 @@ export function setIntendedFor($root: IEzbids) {
section.forEach((obj: IObject) => {
//add IntendedFor information
if (obj._type.startsWith('fmap/') || obj._type === 'perf/m0scan') {
// if user changes datatype/suffix to fmap of some kind
if (!obj.hasOwnProperty('IntendedFor')) {
Object.assign(obj, { IntendedFor: [] });
} else {
if (obj.IntendedFor === null) {
obj.IntendedFor = [];
}
}

let correspindingSeriesIntendedFor = $root.series[obj.series_idx].IntendedFor;
if (correspindingSeriesIntendedFor !== undefined && correspindingSeriesIntendedFor !== null) {
correspindingSeriesIntendedFor.forEach((i: number) => {
Expand All @@ -574,20 +583,32 @@ export function setIntendedFor($root: IEzbids) {
}
});
}
if (obj.hasOwnProperty('IntendedFor')) {
if (obj.IntendedFor?.length !== 0) {
obj.IntendedFor?.forEach((e) => {
let IntendedForObj = section.filter((o) => o.idx === e);
if (!IntendedForObj.length) {
let badIndex = obj.IntendedFor?.indexOf(e);
delete obj.IntendedFor[Object.keys(obj.IntendedFor)[badIndex]];
if (Object.keys(obj.IntendedFor).length === 0) {
obj.analysisResults.warnings = [
'It is recommended that field map (fmap) images have IntendedFor set to at least 1 series ID. This is necessary if you plan on using processing BIDS-apps such as fMRIPrep',
];
}
}
});
if (Object.keys(obj.IntendedFor).length !== 0) {
obj.IntendedFor?.forEach((e) => {
let IntendedForObj = $root.objects.filter((o: IObject) => o.idx === e)[0];
if (IntendedForObj.exclude || IntendedForObj._exclude) {
let badIndexKey: number = obj.IntendedFor.indexOf(e);
delete obj.IntendedFor[badIndexKey];
}
});
}
if (obj._type.startsWith('fmap/')) {
if (Object.keys(obj.IntendedFor).length === 0) {
obj.validationWarnings = [
'It is recommended that field map (fmap) images have IntendedFor set to at least 1 series ID. This is necessary if you plan on using processing BIDS-apps such as fMRIPrep',
];
obj.analysisResults.warnings = obj.validationWarnings;
} else {
obj.analysisResults.warnings = [];
obj.validationWarnings = [];
}
} else if (obj._type === 'perf/m0scan') {
if (Object.keys(obj.IntendedFor).length === 0) {
obj.validationErrors = [
'It is required that perfusion m0scan images have IntendedFor set to at least 1 series ID.',
];
} else {
obj.validationErrors = [];
}
}
}
Expand Down Expand Up @@ -716,15 +737,15 @@ export function dwiQA($root: IEzbids) {
oppDWI: false,
});
}

if (key === '_type' && protocol[key].startsWith('fmap/')) {
//check for field map(s) that might be applied to DWI acquisitions
fmapInfo.push({
IntendedFor: $root.series.filter((e) => e.series_idx == protocol.series_idx)[0].IntendedFor,
});
}
});
}
let fmapIntendedFor = protocolObjects.filter((t) => t._type.startsWith('fmap/'));
fmapIntendedFor.forEach((f) => {
if (f.IntendedFor === null) {
f.IntendedFor = [];
}
fmapInfo.push({ IntendedFor: f.IntendedFor });
});

if (dwiInfo.length) {
let dwiDirs = dwiInfo.map((e) => e.direction);
Expand Down

0 comments on commit c6db916

Please sign in to comment.