Skip to content

Commit

Permalink
[Imaging browser] Fix loading error for t1-defaced and t2-defaced sca…
Browse files Browse the repository at this point in the history
…n types (#6668)

Adding 't1-defaced' or 't2-defaced' scan types to the imaging browser was causing an SQL error due to the hyphen in the name. Escape (or quote as necessary) the references to the scan type in the SQL query.

    Resolves #6616
  • Loading branch information
h-karim authored Jun 5, 2020
1 parent 47f57e2 commit edc545b
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions modules/imaging_browser/php/imagingbrowserrowprovisioner.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ class ImagingBrowserRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisi
/**
* Create an ImagingBrowserRowProvisioner, which gets rows for
* the imaging browser menu table.
*
* @throws \ConfigurationException
*/
function __construct()
{
$config = \NDB_Config::singleton();
$DB = \NDB_Factory::singleton()->database();

// ===========================================================
// Get the different scan types to be displayed in data table
Expand Down Expand Up @@ -92,7 +95,7 @@ class ImagingBrowserRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisi
}

$NewDataSubquery = "
CASE
CASE
COALESCE(Max(fqc.QCLastChangeTime), 'new')
WHEN 'new' THEN {$acqpif}
WHEN '' THEN {$acqpif}
Expand All @@ -109,9 +112,9 @@ class ImagingBrowserRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisi
$coalesce_desc = array();

foreach ($scan_id_types as $id => $type) {
$pass[$id] = $type . 'pass';
$qc[$id] = $type . 'QC';
$coalesce_desc[$id] = $pass[$id] . '.' . $qc[$id];
$pass[$id] = $DB->escape($type);
$qc[$id] = $DB->quote($type);
$coalesce_desc[$id] = $DB->quote($pass[$id] . '.' . $qc[$id]);
$case_desc[$id] = "
CASE
COALESCE($coalesce_desc[$id], '')
Expand All @@ -126,15 +129,15 @@ class ImagingBrowserRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisi
WHEN 'Fail' THEN
IF(s.MRIQCPending='Y', 'Pending Fail', 'Fail')
WHEN 'Pass' THEN
IF(s.MRIQCPending='Y', 'Pending Pass', 'Pass')
IF(s.MRIQCPending='Y', 'Pending Pass', 'Pass')
ELSE s.MRIQCStatus
END
END
";

$PendingNewquery = "
CASE
CASE
WHEN s.MRIQCPending='Y' THEN 'P'
WHEN MAX(fqc.QCFirstChangeTime) IS NULL $newQueryCase THEN 'N'
WHEN MAX(fqc.QCFirstChangeTime) IS NULL $newQueryCase THEN 'N'
END";

// ====================================================
Expand All @@ -146,13 +149,13 @@ class ImagingBrowserRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisi
foreach ($case_desc as $key => $value) {
$left_joins .= "
LEFT JOIN (
SELECT files.SessionID,
MIN(files_qcstatus.QCStatus+0) as $qc[$key]
FROM files
JOIN files_qcstatus USING (FileID)
WHERE files.AcquisitionProtocolID= $key
AND files_qcstatus.QCStatus IN (1, 2)
GROUP BY files.SessionID) $pass[$key]
SELECT files.SessionID,
MIN(files_qcstatus.QCStatus+0) as $qc[$key]
FROM files
JOIN files_qcstatus USING (FileID)
WHERE files.AcquisitionProtocolID= $key
AND files_qcstatus.QCStatus IN (1, 2)
GROUP BY files.SessionID) $pass[$key]
ON ($pass[$key].SessionID=f.SessionID
) ";
}
Expand All @@ -166,15 +169,16 @@ class ImagingBrowserRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisi
// $scan_types are set in the configuration module
$modalities_subquery = '';
foreach ($case_desc as $key => $value) {
$modalities_subquery = "$value as $scan_id_types[$key]_QC_Status";
$modalities_subquery = $value." as " .
$DB->quote("$scan_id_types[$key]_QC_Status");
}

// =================================================
// Final query
// =================================================

parent::__construct(
"SELECT
"SELECT
p.Name as Site,
c.PSCID as PSCID,
c.CandID as DCCID,
Expand All @@ -189,22 +193,22 @@ class ImagingBrowserRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisi
s.ID as sessionID,
GROUP_CONCAT(DISTINCT modality.Scan_type) as sequenceType,
$PendingNewquery as pending," .
($modalities_subquery==''?'':"$modalities_subquery,") .
"s.CenterID as CenterID,
($modalities_subquery==''?'':"$modalities_subquery,") .
"s.CenterID as CenterID,
c.Entity_type as entityType,
s.ProjectID
FROM psc AS p
JOIN session s ON (s.CenterID=p.CenterID)
JOIN candidate c ON (c.CandID=s.CandID)
FROM psc AS p
JOIN session s ON (s.CenterID=p.CenterID)
JOIN candidate c ON (c.CandID=s.CandID)
LEFT JOIN Project ON (s.ProjectID=Project.ProjectID)
JOIN files f ON (f.SessionID=s.ID)
LEFT JOIN files_qcstatus fqc ON (fqc.FileID=f.FileID)
JOIN files f ON (f.SessionID=s.ID)
LEFT JOIN files_qcstatus fqc ON (fqc.FileID=f.FileID)
JOIN parameter_file pf ON (f.FileID=pf.FileID)
JOIN parameter_type pt USING (ParameterTypeID)
LEFT JOIN mri_scan_type modality ON
LEFT JOIN mri_scan_type modality ON
(f.AcquisitionProtocolID=modality.ID)
$left_joins
WHERE
$left_joins
WHERE
s.Active = 'Y' AND
f.FileType IN ('mnc', 'nii')
GROUP BY s.ID
Expand Down

0 comments on commit edc545b

Please sign in to comment.