Skip to content

Commit 7d8fd24

Browse files
cmadjarlaemtlLaetitia Fesselierregisocjeffersoncasimir
authored
Merge v24.1.9 into main (#905)
* update the VERSION for the next bug fix release (#816) * [dcm2bids] Remove hardcoded dcm2niix binary to use the value stored in the `converter` Config setting (#815) * modifies the dcm2niix command to use the Config converter value instead of hardcoding dcm2niix * add a check to make sure the converter is a dcm2niix binary * Pull 24.0.3 in 24.1 release (#820) * Reload the mri_upload dictionary before checking if a tarchive has been validated (#783) * reload mri_upload object * remove debugging exit and print statements * fix minor bugs when dealing with scans.tsv files (#774) * fix regex search for excluded series description patterns (#786) * fix_return_statement_of_create_imaging_upload_dict_from_upload_id_function (#787) * [dcm2bids] Insert into MRICandidateErrors if there is a Candidate PatientName mismatch (#790) * insert into MRICandidateErrors when candidate mismatch or pname not matching between DICOMs and NIfTI * remove exit * fix table name to MRICandidateErrors instead of MriCandidateErrors as apparently, it makes a difference on MariaDB/Linux VMs while it just worked on local install on Mac... (#793) * Set DICOM dates to undef if the date does not follow proper DICOM standard (#794) * set date to undef if it does not follow proper DICOM formats * fix all dates set to NULL * Installation and pet fixes (#818) Co-authored-by: Laetitia Fesselier <laetitia.fesselier@mcgill.ca> * Update VERSION file for next bug fix release Co-authored-by: Laetitia Fesselier <laetitia.fesselier@mail.mcgill.ca> Co-authored-by: Laetitia Fesselier <laetitia.fesselier@mcgill.ca> * fix nonetype errors when the visit of a session does not exist so that proper logging is done (#824) * fix some errors when RepetitionTime is not available in JSON file (#825) * Add capability to download file from s3 (#826) * add capability to download file from s3 * fix flake8 error * Upload to S3: support object name starting with s3://bucket_name/ for upload (#827) * add capability to download file from s3 * fix flake8 error * add ability to remove s3://bucketname/ from the object name before upload * fix database class pselect documentation for the return type (#828) * map scan type to scan type ID when scan type provided to run_nifti_insertion.pl (#829) * modify permission of script run_push_imaging_files_to_s3_pipeline.py to make it executable (#830) * skip violation if not found on filesystem since it means the scan has been rerun (#831) * update VERSION file (#832) * do not push files to S3 when their path in the DB is already an S3 URL (#833) * fix violation files path when checking if the files are on the filesystem before adding them to the list of files to push to S3 (#834) * Merge 24.0 release into 24.1 release (#836) * Reload the mri_upload dictionary before checking if a tarchive has been validated (#783) * reload mri_upload object * remove debugging exit and print statements * fix minor bugs when dealing with scans.tsv files (#774) * fix regex search for excluded series description patterns (#786) * fix_return_statement_of_create_imaging_upload_dict_from_upload_id_function (#787) * [dcm2bids] Insert into MRICandidateErrors if there is a Candidate PatientName mismatch (#790) * insert into MRICandidateErrors when candidate mismatch or pname not matching between DICOMs and NIfTI * remove exit * fix table name to MRICandidateErrors instead of MriCandidateErrors as apparently, it makes a difference on MariaDB/Linux VMs while it just worked on local install on Mac... (#793) * Set DICOM dates to undef if the date does not follow proper DICOM standard (#794) * set date to undef if it does not follow proper DICOM formats * fix all dates set to NULL * Installation and pet fixes (#818) Co-authored-by: Laetitia Fesselier <laetitia.fesselier@mcgill.ca> * Update VERSION file for next bug fix release * Project, event validation and protobuf update (#823) * Project, event validation and protobuf update * Site and project search when creating candidate * missing import * correct pscid search * Events validation * flake rules update * review, and NULL value filtered out for site and project * flake * flake Co-authored-by: regisoc <regis.ongaro-carcy@mcin.ca> * fix conflict * fix version * fix version Co-authored-by: Laetitia Fesselier <laetitia.fesselier@mail.mcgill.ca> Co-authored-by: Laetitia Fesselier <laetitia.fesselier@mcgill.ca> Co-authored-by: regisoc <regis.ongaro-carcy@mcin.ca> * fix check if file already inserted in DB (#845) * Fix logic of determining file run number when previously inserted files are already pushed to S3 and not on filesystem anymore (#846) * fix bug * fix listing of filenames * comment new function * update version file (#847) * Chunk creation subprocess failure check (#848) * Chunk creation subprocess failure check Raise error when the chunk creation subprocess fails. Fix #843 * Update python/lib/physiological.py Print actual error message Co-authored-by: Cécile Madjar <cecile.madjar@mcin.ca> Co-authored-by: Cécile Madjar <cecile.madjar@mcin.ca> * Revert chunk_pb2.py changes (#849) * remove prints in nifti_insertion_pipeline.py (#851) * fix permissoin denied upon deletion of tmp dir (#853) * update to next bug fix relesae (#854) * fix duplicated protocols error when same scan type returned (#856) * Add missing exit codes on the python's side (#857) * add some missing exit codes * add some missing exit codes * add ignore case to regex (#859) * add download from S3 and reupload if file provided to run_nifti-insertion was an S3 URL (#860) * fix intended for bug when no acq time available (#861) * fix bug for intended for when getting the list of files needed IntendedFor (#862) * fix paths when there are not / at the end of the Config (#866) Tested on sandbox with Config `data_dir` = `/data/loris/data` * fix NoneType error /opt/loris/bin/mri/python/lib/dcm2bids_imaging_pipeline_lib/dicom_archive_loader_pipeline.py, line 346, in _add_intended_for_to_fieldmap_json_files (#867) Tested on HBCD sandbox on the dataset that caused the issue. * Properly update `mri_upload` 'Inserting' column when different sections of the pipeline are run (#868) * update mri_upload to inserting=0 when push to s3 pipeline is finished * fix Inserting flag being properly set when pipeline is running * update version file to 24.1.6 (#870) * Add download from S3 for fmap already pushed to S3 that needs to have IntendedFor written in them (#874) * add download from S3 for fmap that needs to have IntendedFor written in them * add print * update version to 24.1.7 (#876) * Merge 24.0.4 into 24.1 release (#878) * Reload the mri_upload dictionary before checking if a tarchive has been validated (#783) * reload mri_upload object * remove debugging exit and print statements * fix minor bugs when dealing with scans.tsv files (#774) * fix regex search for excluded series description patterns (#786) * fix_return_statement_of_create_imaging_upload_dict_from_upload_id_function (#787) * [dcm2bids] Insert into MRICandidateErrors if there is a Candidate PatientName mismatch (#790) * insert into MRICandidateErrors when candidate mismatch or pname not matching between DICOMs and NIfTI * remove exit * fix table name to MRICandidateErrors instead of MriCandidateErrors as apparently, it makes a difference on MariaDB/Linux VMs while it just worked on local install on Mac... (#793) * Set DICOM dates to undef if the date does not follow proper DICOM standard (#794) * set date to undef if it does not follow proper DICOM formats * fix all dates set to NULL * Installation and pet fixes (#818) Co-authored-by: Laetitia Fesselier <laetitia.fesselier@mcgill.ca> * Update VERSION file for next bug fix release * Project, event validation and protobuf update (#823) * Project, event validation and protobuf update * Site and project search when creating candidate * missing import * correct pscid search * Events validation * flake rules update * review, and NULL value filtered out for site and project * flake * flake Co-authored-by: regisoc <regis.ongaro-carcy@mcin.ca> * DICOM Archive broken archive link fix (#872) * update version to 24.0.4 (#877) Co-authored-by: Laetitia Fesselier <laetitia.fesselier@mail.mcgill.ca> Co-authored-by: Laetitia Fesselier <laetitia.fesselier@mcgill.ca> Co-authored-by: regisoc <regis.ongaro-carcy@mcin.ca> * add a delete_file function for S3 (#881) * MATLAB 7.3 HDF5 Workaround (#880) * Added workaround for HDF5 files * Added correct file path confirmation * Duplicated code clean-up * Revised conditional logic * Fix nii insertion mri protocol group id bug (#883) * fix no attribute 'mri_protocol_group_id' error when scan type is specified * fix bug * refactor changes * fix bug * fix violation summary key unavailable * fix violation summary key unavailable * fix violation summary key unavailable * fix violation summary key unavailable * fix violation summary key unavailable * fix violation summary key unavailable * Do not register multiple entries of the same violation in `mri_violations_log` and `mri_protocol_violated_scans` (#884) * keep track of additional event data (24.1) (#873) * keep track of additional event data * py eeg/physiological * Copy .set file before updating paths (#886) * change version to 24.1.8 (#887) * fix incomplete format for query to files table for EchoNumber field (#889) * Add a check before inserting in mri_candidate_errors.py (#891) * add a check before inserting in mri_candidate_errors.py * use TE instead of imageType * fix gzip_nifti empty (#898) * Fix bug when scan type is provided to nifti_insertion.py script (#899) * fix NIfTI insertion scan type name attribute not found * fix no scan type id * fix nifti insertion when scan type is not provided (#901) * change Task to Property prefix for additional events (#900) * add image_type to mpvs (#902) * Fix run numbering logic to use SessionID and not TarchiveID to figure out the next number of a run (#903) * fix run number logic to use SessionID instead of TarchiveID to determine run number * fix bug to query the files for the sessionID instead of hte tarchiveid * fix doc * update version to 24.1.9 (#904) --------- Co-authored-by: Laetitia Fesselier <laetitia.fesselier@mail.mcgill.ca> Co-authored-by: Laetitia Fesselier <laetitia.fesselier@mcgill.ca> Co-authored-by: regisoc <regis.ongaro-carcy@mcin.ca> Co-authored-by: regis <regisoc@users.noreply.github.com> Co-authored-by: jeffersoncasimir <15801528+jeffersoncasimir@users.noreply.github.com> Co-authored-by: Zaliqa <zaliqa.rosli@mcin.ca>
1 parent f20a3df commit 7d8fd24

File tree

8 files changed

+77
-14
lines changed

8 files changed

+77
-14
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24.1.8
1+
24.1.9

python/lib/database_lib/files.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def find_file_with_series_uid_and_echo_time(self, series_uid, echo_time, phase_e
6262
query += " AND PhaseEncodingDirection IS NULL "
6363

6464
if echo_number:
65-
query += " AND EchoNumber = % "
65+
query += " AND EchoNumber = %s "
6666
args.append(echo_number)
6767
else:
6868
query += " AND EchoNumber IS NULL "
@@ -192,3 +192,18 @@ def get_files_inserted_for_tarchive_id(self, tarchive_id):
192192
query = "SELECT * FROM files WHERE TarchiveSource = %s"
193193

194194
return self.db.pselect(query=query, args=(tarchive_id,))
195+
196+
def get_files_inserted_for_session_id(self, session_id):
197+
"""
198+
Get the list of files that were inserted into the `files` table for a given `SessionID`.
199+
200+
:param session_id: `SessionID` to restrict the query on
201+
:type session_id: int
202+
203+
:return: list of relative file path present in the `files` table associated to the `SessionID`
204+
:rtype: list
205+
"""
206+
207+
query = "SELECT * FROM files WHERE SessionID = %s"
208+
209+
return self.db.pselect(query=query, args=(session_id,))

python/lib/database_lib/mri_candidate_errors.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,18 @@ def insert_mri_candidate_errors(self, field_value_dict):
4949
values=field_value_dict.values(),
5050
get_last_id=False
5151
)
52+
53+
def get_candidate_errors_for_tarchive_id(self, tarchive_id):
54+
"""
55+
Get the list of MRI candidate errors logged in `MRICandidateErrors` for a given `TarchiveID`.
56+
57+
:param tarchive_id: `TarchiveID` to restrict the query on
58+
:type tarchive_id: int
59+
60+
:return: list of files inserted into the `MRICandidateErrors` table
61+
:rtype: list
62+
"""
63+
64+
query = "SELECT * FROM MRICandidateErrors WHERE TarchiveID = %s"
65+
66+
return self.db.pselect(query=query, args=(tarchive_id,))

python/lib/dcm2bids_imaging_pipeline_lib/nifti_insertion_pipeline.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,15 @@ def __init__(self, loris_getopt_obj, script_name):
127127
message = f"{self.nifti_path}'s acquisition protocol is 'unknown'."
128128
self.log_error_and_exit(message, lib.exitcode.UNKNOWN_PROTOCOL, is_error="Y", is_verbose="N")
129129
else:
130-
self.scan_type_name = self.imaging_obj.get_scan_type_name_from_id(self.scan_type_id)
130+
self.loris_scan_type = self.imaging_obj.get_scan_type_name_from_id(self.scan_type_id)
131131
else:
132+
self.scan_type_id = self.imaging_obj.get_scan_type_id_from_scan_type_name(self.loris_scan_type)
132133
if not self.scan_type_id:
133134
self._move_to_trashbin()
134135
self._register_protocol_violated_scan()
135136
if self.nifti_s3_url: # push violations to S3 if provided file was on S3
136137
self._run_push_to_s3_pipeline()
137-
message = f"{self.nifti_path}'s scan type {self.scan_type_name} provided to run_nifti_insertion.py" \
138+
message = f"{self.nifti_path}'s scan type {self.loris_scan_type} provided to run_nifti_insertion.py" \
138139
f" is not a valid scan type in the database."
139140
self.log_error_and_exit(message, lib.exitcode.UNKNOWN_PROTOCOL, is_error="Y", is_verbose="N")
140141

@@ -147,7 +148,7 @@ def __init__(self, loris_getopt_obj, script_name):
147148
self._register_protocol_violated_scan()
148149
if self.nifti_s3_url: # push violations to S3 if provided file was on S3
149150
self._run_push_to_s3_pipeline()
150-
message = f"Scan type {self.scan_type_name} does not have BIDS tables set up."
151+
message = f"Scan type {self.loris_scan_type} does not have BIDS tables set up."
151152
self.log_error_and_exit(message, lib.exitcode.UNKNOWN_PROTOCOL, is_error="Y", is_verbose="N")
152153

153154
# ---------------------------------------------------------------------------------------------
@@ -435,8 +436,8 @@ def _determine_new_nifti_assembly_rel_path(self):
435436

436437
# determine NIfTI file name
437438
new_nifti_name = self._construct_nifti_filename(file_bids_entities_dict)
438-
already_inserted_filenames = self.imaging_obj.get_list_of_files_already_inserted_for_tarchive_id(
439-
self.dicom_archive_obj.tarchive_info_dict["TarchiveID"]
439+
already_inserted_filenames = self.imaging_obj.get_list_of_files_already_inserted_for_session_id(
440+
self.dicom_archive_obj.tarchive_info_dict["SessionID"]
440441
)
441442
while new_nifti_name in already_inserted_filenames:
442443
file_bids_entities_dict['run'] += 1

python/lib/imaging.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,26 @@ def insert_mri_candidate_errors(self, patient_name, tarchive_id, scan_param, fil
204204
:type reason: str
205205
"""
206206

207+
series_uid = scan_param["SeriesUID"] if "SeriesUID" in scan_param.keys() else None
208+
echo_time = scan_param["EchoTime"] if "EchoTime" in scan_param.keys() else None
209+
210+
existing_cand_errors = self.mri_cand_errors_db_obj.get_candidate_errors_for_tarchive_id(tarchive_id)
211+
212+
for row in existing_cand_errors:
213+
if str(row['SeriesUID']) == str(series_uid) \
214+
and str(row['EchoTime']) == str(echo_time) \
215+
and str(row['PatientName']) == str(patient_name) \
216+
and str(row['Reason']) == str(reason):
217+
return
218+
207219
info_to_insert_dict = {
208220
"TimeRun": datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
209-
"SeriesUID": scan_param["SeriesUID"] if "SeriesUID" in scan_param.keys() else None,
221+
"SeriesUID": series_uid,
210222
"TarchiveID": tarchive_id,
211223
"MincFile": file_rel_path,
212224
"PatientName": patient_name,
213225
"Reason": reason,
214-
"EchoTime": scan_param["EchoTime"] if "EchoTime" in scan_param.keys() else None
226+
"EchoTime": echo_time
215227
}
216228
self.mri_cand_errors_db_obj.insert_mri_candidate_errors(info_to_insert_dict)
217229

@@ -238,6 +250,7 @@ def insert_protocol_violated_scan(self, patient_name, cand_id, psc_id, tarchive_
238250

239251
series_uid = scan_param["SeriesInstanceUID"] if "SeriesInstanceUID" in scan_param.keys() else None
240252
image_type = str(scan_param["ImageType"]) if "ImageType" in scan_param.keys() else None
253+
echo_time = str(scan_param["EchoTime"]) if "EchoTime" in scan_param.keys() else None
241254
echo_number = repr(scan_param["EchoNumber"]) if "EchoNumber" in scan_param.keys() else None
242255
phase_encoding_dir = scan_param["PhaseEncodingDirection"] \
243256
if "PhaseEncodingDirection" in scan_param.keys() else None
@@ -247,7 +260,7 @@ def insert_protocol_violated_scan(self, patient_name, cand_id, psc_id, tarchive_
247260
for row in existing_prot_viol_scans:
248261
if row['SeriesUID'] == series_uid \
249262
and row['PhaseEncodingDirection'] == phase_encoding_dir \
250-
and row['image_type'] == image_type \
263+
and row['TE_range'] == echo_time \
251264
and row['EchoNumber'] == echo_number:
252265
return
253266

@@ -956,6 +969,26 @@ def get_list_of_files_already_inserted_for_tarchive_id(self, tarchive_id):
956969

957970
return files_list
958971

972+
def get_list_of_files_already_inserted_for_session_id(self, session_id):
973+
"""
974+
Get the list of filenames already inserted for a given SessionID.
975+
976+
:param session_id: the Session ID to process
977+
:type session_id: int
978+
979+
:return: a list with file names already inserted in the files table for SessionID
980+
:rtype: list
981+
"""
982+
983+
# get list files from a given tarchive ID
984+
results = self.files_db_obj.get_files_inserted_for_session_id(session_id)
985+
986+
files_list = []
987+
for entry in results:
988+
files_list.append(os.path.basename(entry['File']))
989+
990+
return files_list
991+
959992
def get_list_of_fmap_files_sorted_by_acq_time(self, files_list):
960993
"""
961994
Get the list of fieldmap acquisitions that requires the IntendedFor field in their JSON file.

python/lib/physiological.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,8 @@ def insert_event_file(self, event_data, event_file, physiological_file_id,
826826
# table cols
827827
add_event_fields = (
828828
'PhysiologicalTaskEventID',
829-
'TaskName',
830-
'TaskValue'
829+
'PropertyName',
830+
'PropertyValue'
831831
)
832832
# each additional fields is a new entry
833833
add_event_values = []

python/lib/utilities.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import requests
1515
import re
1616
import io
17-
1817
import mat73
1918
import lib.exitcode
2019

tools/gzip_nifti_files.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ =head2 Methods
166166
# create the gzipped NIfTI file
167167
my $gzip_nifti = &NeuroDB::MRI::gzip_file($nifti_full_path);
168168
unless ($gzip_nifti) {
169-
print "WARNING: Failure to create $gzip_nifti on the filesystem\n";
169+
print "WARNING: Failure to create $nifti_full_path.gz on the filesystem\n";
170170
next;
171171
}
172172

0 commit comments

Comments
 (0)