From e75f35d239b7a979deb81e10a92a190d85713cae Mon Sep 17 00:00:00 2001 From: MounaSafiHarab Date: Wed, 14 Sep 2016 13:55:33 -0400 Subject: [PATCH 1/4] Added a ScannerCandID column to files table: Redmine 10939 --- uploadNeuroDB/NeuroDB/MRI.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/uploadNeuroDB/NeuroDB/MRI.pm b/uploadNeuroDB/NeuroDB/MRI.pm index 5fcc19b4e..bf26068fc 100755 --- a/uploadNeuroDB/NeuroDB/MRI.pm +++ b/uploadNeuroDB/NeuroDB/MRI.pm @@ -715,14 +715,22 @@ sub register_db { return 0; } + # get the ScannerCandID to then insert into files + my $query = "SELECT CandID FROM session WHERE ID=".$fileData->{'SessionID'}; + my $sth = $dbh->prepare($query); + $sth->execute(); + my $rowhr = $sth->fetchrow_hashref(); + my $ScannerCandID = $rowhr->{'CandID'}; + # build the insert query - my $query = "INSERT INTO files SET "; + $query = "INSERT INTO files SET "; foreach my $key ('File', 'SessionID','EchoTime', 'CoordinateSpace', 'OutputType', 'AcquisitionProtocolID', 'FileType', 'InsertedByUserID', 'Caveat', 'SeriesUID', 'TarchiveSource','SourcePipeline','PipelineDate','SourceFileID') { # add the key=value pair to the query $query .= "$key=".$dbh->quote($${fileData{$key}}).", "; } - $query .= "InsertTime=UNIX_TIMESTAMP()"; + $query .= "InsertTime=UNIX_TIMESTAMP(), "; + $query .= "ScannerCandID=" . $ScannerCandID; # run the query $dbh->do($query); From 2ddc5aca0ae9a0f53a83ddd9df2456cd3bb424eb Mon Sep 17 00:00:00 2001 From: MounaSafiHarab Date: Thu, 15 Sep 2016 12:46:16 -0400 Subject: [PATCH 2/4] Populate ScannerID not ScannerCandID --- uploadNeuroDB/NeuroDB/MRI.pm | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/uploadNeuroDB/NeuroDB/MRI.pm b/uploadNeuroDB/NeuroDB/MRI.pm index bf26068fc..b7aada154 100755 --- a/uploadNeuroDB/NeuroDB/MRI.pm +++ b/uploadNeuroDB/NeuroDB/MRI.pm @@ -715,13 +715,6 @@ sub register_db { return 0; } - # get the ScannerCandID to then insert into files - my $query = "SELECT CandID FROM session WHERE ID=".$fileData->{'SessionID'}; - my $sth = $dbh->prepare($query); - $sth->execute(); - my $rowhr = $sth->fetchrow_hashref(); - my $ScannerCandID = $rowhr->{'CandID'}; - # build the insert query $query = "INSERT INTO files SET "; @@ -729,8 +722,7 @@ sub register_db { # add the key=value pair to the query $query .= "$key=".$dbh->quote($${fileData{$key}}).", "; } - $query .= "InsertTime=UNIX_TIMESTAMP(), "; - $query .= "ScannerCandID=" . $ScannerCandID; + $query .= "InsertTime=UNIX_TIMESTAMP()"; # run the query $dbh->do($query); @@ -760,6 +752,12 @@ sub register_db { # run query $dbh->do($query); } + # get the ScannerID to then insert into files + my $query = "UPDATE files SET ScannerID=". $file->getParameter('ScannerID') . + " WHERE FileID=".$fileData->{'FileID'}; + my $sth = $dbh->prepare($query); + $sth->execute(); + return $fileID; } From b19bb30273fcb4c9b7475c5bf9edc008d45ffbd3 Mon Sep 17 00:00:00 2001 From: MounaSafiHarab Date: Thu, 22 Sep 2016 15:12:52 -0400 Subject: [PATCH 3/4] better way to populate the scannerID in files table --- uploadNeuroDB/NeuroDB/MRI.pm | 10 ++-------- uploadNeuroDB/minc_insertion.pl | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/uploadNeuroDB/NeuroDB/MRI.pm b/uploadNeuroDB/NeuroDB/MRI.pm index b7aada154..362f11c48 100755 --- a/uploadNeuroDB/NeuroDB/MRI.pm +++ b/uploadNeuroDB/NeuroDB/MRI.pm @@ -716,9 +716,9 @@ sub register_db { } # build the insert query - $query = "INSERT INTO files SET "; + my $query = "INSERT INTO files SET "; - foreach my $key ('File', 'SessionID','EchoTime', 'CoordinateSpace', 'OutputType', 'AcquisitionProtocolID', 'FileType', 'InsertedByUserID', 'Caveat', 'SeriesUID', 'TarchiveSource','SourcePipeline','PipelineDate','SourceFileID') { + foreach my $key ('File', 'SessionID','EchoTime', 'CoordinateSpace', 'OutputType', 'AcquisitionProtocolID', 'FileType', 'InsertedByUserID', 'Caveat', 'SeriesUID', 'TarchiveSource','SourcePipeline','PipelineDate','SourceFileID', 'ScannerID') { # add the key=value pair to the query $query .= "$key=".$dbh->quote($${fileData{$key}}).", "; } @@ -752,12 +752,6 @@ sub register_db { # run query $dbh->do($query); } - # get the ScannerID to then insert into files - my $query = "UPDATE files SET ScannerID=". $file->getParameter('ScannerID') . - " WHERE FileID=".$fileData->{'FileID'}; - my $sth = $dbh->prepare($query); - $sth->execute(); - return $fileID; } diff --git a/uploadNeuroDB/minc_insertion.pl b/uploadNeuroDB/minc_insertion.pl index e0d018814..57ee4b923 100755 --- a/uploadNeuroDB/minc_insertion.pl +++ b/uploadNeuroDB/minc_insertion.pl @@ -378,7 +378,7 @@ ## at this point things will appear in the database ############ ## Set some file information ################################### ################################################################ -$file->setParameter('ScannerID', $scannerID); +$file->setFileData('ScannerID', $scannerID); $file->setFileData('SessionID', $sessionID); $file->setFileData('SeriesUID', $file->getParameter('series_instance_uid')); $file->setFileData('EchoTime', $file->getParameter('echo_time')); From 1de5021926351bf97f1a21e8839c59dc0502e219 Mon Sep 17 00:00:00 2001 From: MounaSafiHarab Date: Thu, 22 Sep 2016 15:17:25 -0400 Subject: [PATCH 4/4] updated DTIPrep files --- uploadNeuroDB/registerFile.pl | 2 +- uploadNeuroDB/register_processed_data.pl | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/uploadNeuroDB/registerFile.pl b/uploadNeuroDB/registerFile.pl index 08e1d0279..d447afa03 100755 --- a/uploadNeuroDB/registerFile.pl +++ b/uploadNeuroDB/registerFile.pl @@ -176,7 +176,7 @@ $file->getParameter('software_versions'), $centerID, \$dbh, 0); - $file->setParameter('ScannerID', $scannerID); + $file->setFileData('ScannerID', $scannerID); print "Set scannerid = $scannerID\n" if $verbose; # get ids from the headers diff --git a/uploadNeuroDB/register_processed_data.pl b/uploadNeuroDB/register_processed_data.pl index bd69f8192..bbb9a4376 100755 --- a/uploadNeuroDB/register_processed_data.pl +++ b/uploadNeuroDB/register_processed_data.pl @@ -168,7 +168,7 @@ print LOG "\nERROR: could not determine scannerID based on sourceFileID $sourceFileID.\n\n"; exit 2; } -$file->setParameter('ScannerID',$scannerID); +$file->setFileData('ScannerID',$scannerID); print LOG "\t -> Set ScannerID to $scannerID.\n"; @@ -302,16 +302,15 @@ sub getSessionID { =pod -This function gets ScannerID from parameter_file using sourceFileID +This function gets ScannerID from files using sourceFileID =cut sub getScannerID { my ($sourceFileID,$dbh) = @_; my $scannerID; - my $query = "SELECT pf.Value AS ScannerID " . - "FROM parameter_file AS pf " . - "JOIN parameter_type AS pt ON (pt.ParameterTypeID=pf.ParameterTypeID) " . - "WHERE pt.Name='ScannerID' AND pf.FileID=?"; + my $query = "SELECT f.ScannerID AS ScannerID " . + "FROM files AS f " . + "WHERE f.FileID=?"; my $sth = $dbh->prepare($query); $sth->execute($sourceFileID); if($sth->rows > 0) {