Skip to content

Commit

Permalink
Fix file count in mri_upload when deleting a minc file and then re-in…
Browse files Browse the repository at this point in the history
…serting (#180)
  • Loading branch information
MounaSafiHarab authored Aug 1, 2017
1 parent d496ecd commit a576d4d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
24 changes: 24 additions & 0 deletions uploadNeuroDB/minc_deletion.pl
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,27 @@ sub selORdel {

# Delete file records last
selORdel("files","File");

# Update the number of minc inserted in mri_upload by subtracting one
if ($selORdel eq "DELETE ") {
$query = "SELECT number_of_mincInserted FROM mri_upload " .
"WHERE TarchiveID=?";

$sth = $dbh->prepare($query);
$sth->execute($tarchiveid);
my $nmi = $sth->fetchrow_array;

if ($sth->rows > 0) {
my $new_nmi = $nmi - 1;
$query = "UPDATE mri_upload SET number_of_mincInserted=? ".
"WHERE TarchiveID=?";

$sth = $dbh->prepare($query);
my $success = $sth->execute($new_nmi, $tarchiveid);

if ($success) {
print "\nNew count for number of mincs inserted changed to " . $new_nmi . "\n";
}
}
}

18 changes: 16 additions & 2 deletions uploadNeuroDB/tarchiveLoader
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ $utility->computeSNR($tarchiveInfo{TarchiveID},
$tarchiveInfo{'SourceLocation'},
$profile);
################################################################
############### Compute SNR on 3D modalities ###################
####### Add order of acquisition for similar modalities ########
####### within the same session based on series number #########
################################################################
$utility->orderModalitiesByAcq($tarchiveInfo{TarchiveID},
$tarchiveInfo{'SourceLocation'});
Expand All @@ -522,6 +523,19 @@ if ($valid_study) {
### And number_of_mincInserted #############################
############################################################
my $where = "WHERE TarchiveID=?";

$query =
"SELECT number_of_mincInserted FROM mri_upload ";
$query = $query . $where;
if ($debug) {
print $query . "\n";
}

my $sth = $dbh->prepare($query);
$sth->execute($tarchiveInfo{TarchiveID});
my $oldCount = $sth->fetchrow_array;
my $newCount = $minc_inserted + $oldCount;

$query = "UPDATE mri_upload SET number_of_mincInserted=?, ".
"number_of_mincCreated=? ";
$query = $query . $where;
Expand All @@ -531,7 +545,7 @@ if ($valid_study) {

my $mri_upload_update = $dbh->prepare($query);
$mri_upload_update->execute(
$minc_inserted,$mcount,$tarchiveInfo{TarchiveID}
$newCount,$mcount,$tarchiveInfo{TarchiveID}
);

############################################################
Expand Down

0 comments on commit a576d4d

Please sign in to comment.