diff --git a/SQL/0000-00-00-schema.sql b/SQL/0000-00-00-schema.sql index 064ac6b8298..57c32cc58b1 100644 --- a/SQL/0000-00-00-schema.sql +++ b/SQL/0000-00-00-schema.sql @@ -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` -- @@ -468,6 +495,7 @@ 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`), @@ -475,11 +503,13 @@ CREATE TABLE `files` ( 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`; @@ -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` -- diff --git a/SQL/Archive/17.0/2016-09-13-AddScannerIDInFiles.sql b/SQL/Archive/17.0/2016-09-13-AddScannerIDInFiles.sql new file mode 100644 index 00000000000..97225259d04 --- /dev/null +++ b/SQL/Archive/17.0/2016-09-13-AddScannerIDInFiles.sql @@ -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'; +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`); diff --git a/modules/imaging_browser/php/NDB_Form_imaging_browser.class.inc b/modules/imaging_browser/php/NDB_Form_imaging_browser.class.inc index 423952f3712..d33871dc16e 100644 --- a/modules/imaging_browser/php/NDB_Form_imaging_browser.class.inc +++ b/modules/imaging_browser/php/NDB_Form_imaging_browser.class.inc @@ -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)) @@ -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) @@ -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'), @@ -651,4 +651,4 @@ class NDB_Form_Imaging_Browser extends NDB_Form } -?> \ No newline at end of file +?> diff --git a/tools/CouchDB_MRI_Importer.php b/tools/CouchDB_MRI_Importer.php index 374afa3c579..1a17c1cd0d1 100644 --- a/tools/CouchDB_MRI_Importer.php +++ b/tools/CouchDB_MRI_Importer.php @@ -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(); @@ -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 *