Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imaging Preprocessing Scripts: Added a ScannerID column to files table: Redmine 10939 #2189

Merged
merged 10 commits into from
Sep 28, 2016
Merged
59 changes: 31 additions & 28 deletions SQL/0000-00-00-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,33 @@ CREATE TABLE `mri_processing_protocol` (
/*!40101 SET character_set_client = @saved_cs_client */;


--
-- Table structure for table `mri_scanner`
--

DROP TABLE IF EXISTS `mri_scanner`;
CREATE TABLE `mri_scanner` (
`ID` int(11) unsigned NOT NULL auto_increment,
`Manufacturer` varchar(255) default NULL,
`Model` varchar(255) default NULL,
`Serial_number` varchar(255) default NULL,
`Software` varchar(255) default NULL,
`CandID` int(11) default NULL,
PRIMARY KEY (`ID`),
KEY `FK_mri_scanner_1` (`CandID`),
CONSTRAINT `FK_mri_scanner_1` FOREIGN KEY (`CandID`) REFERENCES `candidate` (`CandID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `mri_scanner`
--

LOCK TABLES `mri_scanner` WRITE;
/*!40000 ALTER TABLE `mri_scanner` DISABLE KEYS */;
INSERT INTO `mri_scanner` VALUES (0,NULL,NULL,NULL,NULL,NULL);
/*!40000 ALTER TABLE `mri_scanner` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `files`
--
Expand All @@ -468,18 +495,21 @@ CREATE TABLE `files` (
`ProcessProtocolID` int(11) unsigned,
`Caveat` tinyint(1) default NULL,
`TarchiveSource` int(11) default NULL,
`ScannerID` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`FileID`),
KEY `file` (`File`),
KEY `sessionid` (`SessionID`),
KEY `outputtype` (`OutputType`),
KEY `filetype_outputtype` (`FileType`,`OutputType`),
KEY `staging_filetype_outputtype` (`PendingStaging`,`FileType`,`OutputType`),
KEY `AcquiIndex` (`AcquisitionProtocolID`,`SessionID`),
KEY `scannerid` (`ScannerID`),
CONSTRAINT `FK_files_2` FOREIGN KEY (`AcquisitionProtocolID`) REFERENCES `mri_scan_type` (`ID`),
CONSTRAINT `FK_files_1` FOREIGN KEY (`SessionID`) REFERENCES `session` (`ID`),
CONSTRAINT `FK_files_3` FOREIGN KEY (`SourceFileID`) REFERENCES `files` (`FileID`),
CONSTRAINT `FK_files_4` FOREIGN KEY (`ProcessProtocolID`) REFERENCES `mri_processing_protocol` (`ProcessProtocolID`),
CONSTRAINT `FK_files_FileTypes` FOREIGN KEY (`FileType`) REFERENCES `ImagingFileTypes`(`type`)
CONSTRAINT `FK_files_FileTypes` FOREIGN KEY (`FileType`) REFERENCES `ImagingFileTypes`(`type`),
CONSTRAINT `FK_files_scannerID` FOREIGN KEY (`ScannerID`) REFERENCES `mri_scanner` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `files_qcstatus`;
Expand Down Expand Up @@ -706,33 +736,6 @@ INSERT INTO `mri_scan_type` VALUES
/*!40000 ALTER TABLE `mri_scan_type` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `mri_scanner`
--

DROP TABLE IF EXISTS `mri_scanner`;
CREATE TABLE `mri_scanner` (
`ID` int(11) unsigned NOT NULL auto_increment,
`Manufacturer` varchar(255) default NULL,
`Model` varchar(255) default NULL,
`Serial_number` varchar(255) default NULL,
`Software` varchar(255) default NULL,
`CandID` int(11) default NULL,
PRIMARY KEY (`ID`),
KEY `FK_mri_scanner_1` (`CandID`),
CONSTRAINT `FK_mri_scanner_1` FOREIGN KEY (`CandID`) REFERENCES `candidate` (`CandID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `mri_scanner`
--

LOCK TABLES `mri_scanner` WRITE;
/*!40000 ALTER TABLE `mri_scanner` DISABLE KEYS */;
INSERT INTO `mri_scanner` VALUES (0,NULL,NULL,NULL,NULL,NULL);
/*!40000 ALTER TABLE `mri_scanner` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `notification_spool`
--
Expand Down
5 changes: 5 additions & 0 deletions SQL/Archive/17.0/2016-09-13-AddScannerIDInFiles.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Add ScannerCandID column to files, back-populate the newly added column from parameter_file table, then add foreign key constraints
ALTER TABLE files ADD `ScannerID` int(10) unsigned NOT NULL default '0';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set this to NULL (default)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in: #2251

CREATE TEMPORARY TABLE ScannerIDs AS SELECT pf.FileID, pf.Value AS ScannerID FROM parameter_file AS pf LEFT JOIN parameter_type AS pt ON pf.ParameterTypeID=pt.ParameterTypeID WHERE pt.Name='ScannerID';
UPDATE files AS f, ScannerIDs AS S SET f.ScannerID=S.ScannerID where f.FileID=S.FileID;
ALTER TABLE files ADD CONSTRAINT `FK_files_scannerID` FOREIGN KEY (`ScannerID`) REFERENCES mri_scanner (`ID`);
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class NDB_Form_Imaging_Browser extends NDB_Form
}
}
$files = $this->DB->pselect(
"SELECT files.FileID FROM files LEFT JOIN files_qcstatus as sel on (
"SELECT files.FileID, files.ScannerID FROM files LEFT JOIN files_qcstatus as sel on (
files.FileID=sel.FileID)
WHERE SessionID=:SID AND (AcquisitionProtocolID IS NULL
OR AcquisitionProtocolID not in (1, 2, 3, 52))
Expand All @@ -154,7 +154,7 @@ class NDB_Form_Imaging_Browser extends NDB_Form
foreach ($files as $fileRow) {
$FileObj = new MRIFile($fileRow['FileID']);
if (empty($scannerID)) {
$scannerID = $FileObj->getParameter('ScannerID');
$scannerID = $fileRow['ScannerID'];
if (!empty($scannerID)) {
$query = "SELECT
CONCAT_WS(' ', Manufacturer, Model, Serial_number)
Expand Down Expand Up @@ -222,7 +222,7 @@ class NDB_Form_Imaging_Browser extends NDB_Form
'Xstep' => number_format($FileObj->getParameter('xstep'), 2),
'Ystep' => number_format($FileObj->getParameter('ystep'), 2),
'Zstep' => number_format($FileObj->getParameter('zstep'), 2),
'Selected' => $this->_getSelected((int)$FileObj->getParameter('FileID')),
'Selected' => $this->_getSelected((int)$FileObj->getParameter('FileID')),
'QCStatus' => $FileObj->getParameter('QCStatus'),
'QCDate' => $FileObj->getParameter('QCLastChangeTime'),
'Caveat' => $FileObj->getParameter('Caveat'),
Expand Down Expand Up @@ -651,4 +651,4 @@ class NDB_Form_Imaging_Browser extends NDB_Form

}

?>
?>
20 changes: 19 additions & 1 deletion tools/CouchDB_MRI_Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function _addMRIHeaderInfo($FileObj, $scan_type)
$inter_rej = 'IntergradientRejected_'.$type;
$pipeline = 'processing:pipeline';

$header['ScannerID_'.$type] = $FileObj->getParameter('ScannerID');
$header['ScannerID_'.$type] = $this->_getScannerID((int)$FileObj->getParameter('FileID'));
$header['Pipeline_'.$type] = $FileObj->getParameter('Pipeline');
$header['OutputType_'.$type] = $FileObj->getParameter('OutputType');
$header['AcquisitionProtocol_'.$type] = $FileObj->getAcquisitionProtocol();
Expand Down Expand Up @@ -192,6 +192,24 @@ function _getDate($file, $type, $array)
}
}

/**
* Gets the scannerID
*
* @param MRIFile $file file object
*
* @return scannerID
*/
function _getScannerID($FileID){

$scannerID = $this->SQLDB->pselectOne("SELECT ScannerID FROM files ".
"WHERE FileID =:FileID",
array(
'FileID' => $FileID
)
);
return $scannerID;
}

/**
* Gets a rejected parameter according to its type
*
Expand Down