Skip to content

Commit 0114075

Browse files
authored
[EEG Browser] EEGLAB fdt fixes (#8323)
Fix a few issues with EEGLAB set/fdt files: - Download link broken - Incorrect placement, it should be logically after the .set file Download All files fails when no annotations exists. Migrate the annotation files creation logic from update to updateFiles, since update handles DB updates only.
1 parent 86a0494 commit 0114075

File tree

5 files changed

+59
-61
lines changed

5 files changed

+59
-61
lines changed

htdocs/mri/jiv/get_file.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@
132132
$DownloadFilename = basename($File);
133133
break;
134134
case 'edf':
135-
$FullPath = $imagePath . '/' . $File;
136-
$MimeType = 'application/octet-stream';
137-
$DownloadFilename = basename($File);
138-
break;
135+
case 'fdt':
139136
case 'set':
140137
$FullPath = $imagePath . '/' . $File;
141138
$MimeType = 'application/octet-stream';

modules/electrophysiology_browser/jsx/components/DownloadPanel.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,9 @@ class DownloadPanel extends Component {
5555
margin: '0 auto',
5656
}
5757
}>
58-
{panel.links.map((download, j) => {
58+
{Object.entries(panel.links).map(([type, download], j) => {
5959
const disabled = (download.file === '');
6060

61-
// Hide the download in this particular case
62-
// It does not make sense to display Not Available for FDT files
63-
if (disabled && download.type === 'physiological_fdt_file') {
64-
return null;
65-
}
66-
6761
return (
6862
<div
6963
key={j}
@@ -92,16 +86,16 @@ class DownloadPanel extends Component {
9286
: <a
9387
className='btn btn-primary download col-xs-6'
9488
href={
95-
(download.type ==
89+
(type ==
9690
'physiological_annotation_files' ||
97-
download.type == 'all_files') ?
91+
type == 'all_files') ?
9892
this.state.annotationsAction
9993
+ '?physioFileID=' + this.state.physioFileID
10094
+ '&filePath=' + download.file
10195
: '/mri/jiv/get_file.php?file=' + download.file
10296
}
10397
target='_blank'
104-
download={this.state.downloads[0].file}
98+
download
10599
style={{
106100
margin: 0,
107101
}}

modules/electrophysiology_browser/jsx/electrophysiologySessionView.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class ElectrophysiologySessionView extends Component {
123123
},
124124
downloads: [
125125
{
126-
type: 'physiological_file',
126+
type: 'physiological_files',
127127
file: '',
128128
},
129129
{
@@ -146,10 +146,6 @@ class ElectrophysiologySessionView extends Component {
146146
type: 'all_files',
147147
file: '',
148148
},
149-
{
150-
type: 'physiological_fdt_file',
151-
file: '',
152-
},
153149
],
154150
},
155151
chunksURL: null,
@@ -226,10 +222,10 @@ class ElectrophysiologySessionView extends Component {
226222
dbEntry
227223
&& dbEntry.file.downloads.map(
228224
(group) =>
229-
group.links[1]?.file
225+
group.links['physiological_electrode_file']?.file
230226
&& loris.BaseURL
231227
+ '/electrophysiology_browser/file_reader/?file='
232-
+ group.links[1].file
228+
+ group.links['physiological_electrode_file'].file
233229
),
234230
events:
235231
dbEntry

modules/electrophysiology_browser/php/models/electrophysioannotations.class.inc

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ElectrophysioAnnotations
119119
}
120120

121121
//If no derivative files exist, must create new files
122-
$annotationFID = $db->pselect(
122+
$annotationFIDs = $db->pselect(
123123
"SELECT AnnotationFileID
124124
FROM physiological_annotation_file
125125
WHERE PhysiologicalFileID=:PFID",
@@ -144,10 +144,7 @@ class ElectrophysioAnnotations
144144
];
145145

146146
//Insert new files and data into DB
147-
if (empty($annotationFID)) {
148-
149-
//Create new annotation files
150-
$this->_createFiles();
147+
if (empty($annotationFIDs)) {
151148

152149
//Get new annotation file ID
153150
$annotation_tsv_ID = $db->pselectOne(
@@ -277,7 +274,7 @@ class ElectrophysioAnnotations
277274
}
278275

279276
/**
280-
* Updates the derivative files associated with the given
277+
* Updates the derivative files associated with the
281278
* physiological file ID
282279
*
283280
* @return void
@@ -287,6 +284,19 @@ class ElectrophysioAnnotations
287284
{
288285
$db = \NDB_Factory::singleton()->database();
289286

287+
//If no derivative files exist, must create new files
288+
$annotationFIDs = $db->pselect(
289+
"SELECT AnnotationFileID
290+
FROM physiological_annotation_file
291+
WHERE PhysiologicalFileID=:PFID",
292+
['PFID' => $this->_physioFileID]
293+
);
294+
//Insert new files and data into DB
295+
if (empty($annotationFIDs)) {
296+
//Create new annotation files
297+
$this->_createFiles();
298+
}
299+
290300
//Get data directory base path from Config
291301
$dataDir = $db->pselectOne(
292302
'SELECT Value
@@ -334,9 +344,7 @@ class ElectrophysioAnnotations
334344
//Update the three files with the given paths
335345
$labels = []; // Label Name => Label Description
336346
$tsv_file = fopen($tsv_path, 'w'); //Will override all file content
337-
//Add columns
338-
$columns = implode("\t", $tsv_entries);
339-
fwrite($tsv_file, $columns."\n");
347+
340348
//Get all annotation instances
341349
//Then go thru each and get the label name + description
342350
//add label name to file and also to an array for json file
@@ -357,6 +365,14 @@ class ElectrophysioAnnotations
357365
['AFID' => $tsv[0]['id']]
358366
);
359367

368+
if (count($instances) < 1) {
369+
return;
370+
}
371+
372+
//Add columns
373+
$columns = implode("\t", $tsv_entries);
374+
fwrite($tsv_file, $columns."\n");
375+
360376
foreach ($instances as $instance) {
361377
//Add labels to list for parameter file
362378
$labels[$instance['LabelName']] = $instance['LabelDescription'];

modules/electrophysiology_browser/php/sessions.class.inc

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,29 @@ class Sessions extends \NDB_Page
559559
$downloadLinks[] = [
560560
'type' => 'physiological_file',
561561
'file' => $physioFile,
562-
'label' => 'EEG File',
562+
'label' => 'EEG File(s)',
563563
];
564564

565+
$queryFDT = "SELECT
566+
Value AS FilePath,
567+
'physiological_fdt_file' AS FileType
568+
FROM
569+
physiological_parameter_file
570+
JOIN parameter_type AS pt USING (ParameterTypeID)
571+
WHERE
572+
pt.Name='fdt_file'
573+
AND PhysiologicalFileID=:PFID";
574+
$queryFDT = $db->pselectRow($queryFDT, ['PFID' => $physioFileID]);
575+
if (isset($queryFDT['FileType'])) {
576+
$downloadLinks[] = [
577+
'type' => $queryFDT['FileType'],
578+
'file' => $queryFDT['FilePath'],
579+
'label' => '',
580+
];
581+
}
582+
583+
// Metadata
584+
565585
$queries = [
566586
'physiological_electrode' => 'physiological_electrode_file',
567587
'physiological_channel' => 'physiological_channel_file',
@@ -580,7 +600,7 @@ class Sessions extends \NDB_Page
580600

581601
foreach ($queries as $query_key => $query_value) {
582602
$query_statement = "SELECT
583-
DISTINCT(FilePath), '$query_value' AS FileType
603+
DISTINCT(FilePath)
584604
FROM
585605
$query_key
586606
WHERE
@@ -589,44 +609,19 @@ class Sessions extends \NDB_Page
589609
$query_statement,
590610
['PFID' => $physioFileID]
591611
);
592-
if (isset($query_statement['FileType'])) {
593-
$downloadLinks[] = [
594-
'type' => $query_statement['FileType'],
612+
if ($query_statement) {
613+
$downloadLinks[$query_value] = [
595614
'file' => $query_statement['FilePath'],
596-
'label' => $labels[$query_statement['FileType']]
615+
'label' => $labels[$query_value],
597616
];
598617
} else {
599-
$downloadLinks[] = [
600-
'type' => $query_value,
618+
$downloadLinks[$query_value] = [
601619
'file' => '',
602620
'label' => $labels[$query_value],
603621
];
604622
}
605623
}
606624

607-
$queryFDT = "SELECT
608-
Value AS FilePath,
609-
'physiological_fdt_file' AS FileType
610-
FROM
611-
physiological_parameter_file
612-
JOIN parameter_type AS pt USING (ParameterTypeID)
613-
WHERE
614-
pt.Name='fdt_file'
615-
AND PhysiologicalFileID=:PFID";
616-
$queryFDT = $db->pselectRow($queryFDT, ['PFID' => $physioFileID]);
617-
if (isset($queryFDT['FileType'])) {
618-
$downloadLinks[] = [
619-
'type' => $queryFDT['FileType'],
620-
'file' => $queryFDT['FilePath'],
621-
'label' => '',
622-
];
623-
} else {
624-
$downloadLinks[] = [
625-
'type' => 'physiological_fdt_file',
626-
'file' => '',
627-
'label' => '',
628-
];
629-
}
630625
return $downloadLinks;
631626
}
632627

0 commit comments

Comments
 (0)