Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def __init__(self, loris_getopt_obj, script_name):
# ---------------------------------------------------------------------------------------------
# Determine acquisition protocol (or register into mri_protocol_violated_scans and exits)
# ---------------------------------------------------------------------------------------------
self.scan_type_id, self.mri_protocol_group_id = self._determine_acquisition_protocol()
if not self.loris_scan_type:
self.scan_type_id, self.mri_protocol_group_id = self._determine_acquisition_protocol()
if not self.scan_type_id:
self._move_to_trashbin()
self._register_protocol_violated_scan()
Expand All @@ -129,7 +129,6 @@ def __init__(self, loris_getopt_obj, script_name):
else:
self.scan_type_name = self.imaging_obj.get_scan_type_name_from_id(self.scan_type_id)
else:
self.scan_type_id = self.imaging_obj.get_scan_type_id_from_scan_type_name(self.loris_scan_type)
if not self.scan_type_id:
self._move_to_trashbin()
self._register_protocol_violated_scan()
Expand All @@ -154,6 +153,8 @@ def __init__(self, loris_getopt_obj, script_name):
# ---------------------------------------------------------------------------------------------
# Run extra file checks to determine possible protocol violations
# ---------------------------------------------------------------------------------------------
self.warning_violations_list = []
self.exclude_violations_list = []
if not self.bypass_extra_checks:
self.violations_summary = self.imaging_obj.run_extra_file_checks(
self.session_obj.session_info_dict['ProjectID'],
Expand All @@ -162,8 +163,8 @@ def __init__(self, loris_getopt_obj, script_name):
self.scan_type_id,
self.json_file_dict
)
self.warning_violations_list = self.violations_summary['warning']
self.exclude_violations_list = self.violations_summary['exclude']
self.warning_violations_list = self.violations_summary['warning']
self.exclude_violations_list = self.violations_summary['exclude']

# ---------------------------------------------------------------------------------------------
# Register files in the proper tables
Expand Down Expand Up @@ -350,7 +351,9 @@ def _determine_acquisition_protocol(self):
self.scanner_id
)

protocol_info = self.imaging_obj.get_acquisition_protocol_info(protocols_list, nifti_name, scan_param)
protocol_info = self.imaging_obj.get_acquisition_protocol_info(
protocols_list, nifti_name, scan_param, self.loris_scan_type
)
self.log_info(protocol_info['error_message'], is_error="N", is_verbose="Y")

return protocol_info['scan_type_id'], protocol_info['mri_protocol_group_id']
Expand Down Expand Up @@ -396,7 +399,7 @@ def _move_to_assembly_and_insert_file_info(self):
self.log_info(message, is_error='N', is_verbose='Y')

# add an entry in the violations log table if there is a warning violation associated to the file
if self.violations_summary['warning']:
if self.warning_violations_list:
message = f"Inserting warning violations related to {self.assembly_nifti_rel_path}." \
f" List of violations found: {self.warning_violations_list}"
self.log_info(message, is_error='N', is_verbose='Y')
Expand Down
12 changes: 8 additions & 4 deletions python/lib/imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def map_bids_param_to_loris_param(self, file_parameters):

return file_parameters

def get_acquisition_protocol_info(self, protocols_list, nifti_name, scan_param):
def get_acquisition_protocol_info(self, protocols_list, nifti_name, scan_param, scan_type=None):
"""
Get acquisition protocol information (scan_type_id or message to be printed in the log).
- If the protocols list provided as input is empty, the scan_type_id will be set to None and proper message
Expand Down Expand Up @@ -608,7 +608,7 @@ def get_acquisition_protocol_info(self, protocols_list, nifti_name, scan_param):

# look for matching protocols
mri_protocol_group_id = protocols_list[0]['MriProtocolGroupID']
matching_protocols_list = self.look_for_matching_protocols(protocols_list, scan_param)
matching_protocols_list = self.look_for_matching_protocols(protocols_list, scan_param, scan_type)

# if more than one protocol matching, return False, otherwise, return the scan type ID
if not matching_protocols_list:
Expand Down Expand Up @@ -648,7 +648,7 @@ def get_bids_categories_mapping_for_scan_type_id(self, scan_type_id):

return self.mri_prot_db_obj.get_bids_info_for_scan_type_id(scan_type_id)

def look_for_matching_protocols(self, protocols_list, scan_param):
def look_for_matching_protocols(self, protocols_list, scan_param, scan_type=None):
"""
Look for matching protocols in protocols_list given scan parameters stored in scan_param.

Expand All @@ -661,9 +661,13 @@ def look_for_matching_protocols(self, protocols_list, scan_param):
:rtype: list
"""

scan_type_id = self.get_scan_type_id_from_scan_type_name(scan_type) if scan_type else None

matching_protocols_list = []
for protocol in protocols_list:
if protocol['series_description_regex']:
if scan_type_id and protocol['Scan_type'] == scan_type_id:
matching_protocols_list.append(protocol['Scan_type'])
elif protocol['series_description_regex']:
if re.search(
rf"{protocol['series_description_regex']}", scan_param['SeriesDescription'], re.IGNORECASE
):
Expand Down