diff --git a/tools/deletemincsqlwrapper.pl b/tools/deletemincsqlwrapper.pl deleted file mode 100755 index ffd6a159c..000000000 --- a/tools/deletemincsqlwrapper.pl +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; -no warnings 'once'; -use Data::Dumper; -use File::Basename; -use File::Copy; -use Term::ANSIColor qw(:constants); -use NeuroDB::DBI; - -my $profile = "prod"; -{ package Settings; do "$ENV{LORIS_CONFIG}/.loris_mri/" . $profile} -my $dbh = &NeuroDB::DBI::connect_to_db(@Settings::db); - -# Only the f.SeriesUID is really needed for minc_deletion, other fields are for information only -my $queryF = <prepare($queryF); - -my $keepgoing = 1; -my ($rF, $fF, $stdin, $i); - -printf ("%-6s", '| L# '); -printf ("%-64s",'| SeriesUID'); -printf ("%-20s",'| Value'); -printf ("%-20s",'| Scan Type'); -printf ("%-60s",'| File'); -print "|\n"; - -$rF = $sthF->execute(); - -while ($fF = $sthF->fetchrow_hashref()) { - - if ($sthF->rows > 0) { - $i++; - - printf ("%-6s", '| '. $i); - printf ("%-64s",'| '. $fF->{'SeriesUID'}); - printf ("%-20s",'| '. $fF->{'Value'}); - printf ("%-20s",'| '. $fF->{'Scan_type'}); - printf ("%-60s",'| '. $fF->{'file'}); - print "|\n"; - - if ($keepgoing) { - print "Press ENTER (or A and ENTER to do it all)\n"; - $stdin = ; - if ($stdin eq "A\n") { - print "Ok, I will keep going until it's done.\n"; - $keepgoing = 0; - } - } - - my $minc_delete_cmd = "../uploadNeuroDB/minc_deletion.pl -profile " . $profile . " -seriesuid " . $fF->{'SeriesUID'} . " confirm"; - print $minc_delete_cmd . "\n"; - my $minc_delete_log = `$minc_delete_cmd`; - print $minc_delete_log . "\n"; - - } -} diff --git a/tools/example_scripts/README.md b/tools/example_scripts/README.md new file mode 100755 index 000000000..8addb8baf --- /dev/null +++ b/tools/example_scripts/README.md @@ -0,0 +1,11 @@ +### Example scripts + + - **deletemincsqlwrapper.pl** + - An example script to delete multiple minc files fitting a common criterion from the database. + - The script also provides the option to re-insert deleted scans with their seriesUID when using the `-insertminc` flag. + - **Projects should modify the query as needed to suit their needs**. + - For the example query provided (in `$queryF`), all inserted scans with types like `t1` or `t2`, having a `slice thickness` in the range of `4 mm` will be deleted. + - A use case of this deletion query might be that initially the project did not exclude `t1` or `t2` modalities having 4 mm slice thickness, and subsequently, the + study `mri_protocol` has been changed to add tighter checks on slice thickness. + + diff --git a/tools/example_scripts/deletemincsqlwrapper.pl b/tools/example_scripts/deletemincsqlwrapper.pl new file mode 100755 index 000000000..d1a88f246 --- /dev/null +++ b/tools/example_scripts/deletemincsqlwrapper.pl @@ -0,0 +1,124 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Getopt::Tabular; +no warnings 'once'; +use Data::Dumper; +use File::Basename; +use File::Copy; +use Term::ANSIColor qw(:constants); +use NeuroDB::DBI; + +my $profile = undef; +my $insertminc; + +my @opt_table = ( + [ "Basic options", "section" ], + [ + "-profile", "string", 1, \$profile, + "name of config file in ../../dicom-archive/.loris_mri" + ], + [ + "-insertminc", "boolean", 0, \$insertminc, "Re-insert the deleted minc" + ] +); + +my $Help = <prepare($queryF); + +my $keepgoing = 1; +my ($fF, $stdin, $i); + +printf ("%-6s", '| L# '); +printf ("%-64s",'| SeriesUID'); +printf ("%-20s",'| Value'); +printf ("%-20s",'| Scan Type'); +printf ("%-60s",'| File'); +print "|\n"; + +$sthF->execute(); + +if ($sthF->rows > 0) { + + while ($fF = $sthF->fetchrow_hashref()) { + + $i++; + + printf ("%-6s", '| '. $i); + printf ("%-64s",'| '. $fF->{'SeriesUID'}); + printf ("%-20s",'| '. $fF->{'Value'}); + printf ("%-20s",'| '. $fF->{'Scan_type'}); + printf ("%-60s",'| '. $fF->{'file'}); + print "|\n"; + + if ($keepgoing) { + print "Press ENTER (or A and ENTER to do it all)\n"; + $stdin = ; + if ($stdin eq "A\n") { + print "Ok, I will keep going until it's done.\n"; + $keepgoing = 0; + } + } + + my $minc_delete_cmd = "uploadNeuroDB/minc_deletion.pl -profile " . $profile . " -seriesuid " . $fF->{'SeriesUID'} . " confirm"; + print $minc_delete_cmd . "\n"; + my $minc_delete_log = `$minc_delete_cmd`; + print $minc_delete_log . "\n"; + + if ($insertminc) { + # Running tarchiveLoader on the archived tar as a whole will only insert new minc files that are not already in the files table + my $tar_loader_cmd = "uploadNeuroDB/tarchiveLoader -profile " . $profile . " -verbose -globLocation " . $fF->{'ArchiveLocation'}; + print $tar_loader_cmd . "\n"; + my $tar_loader_log = `$tar_loader_cmd`; + print $tar_loader_log . "\n"; + } + } +} else { + print "\n***No files were found that match the following query:***\n\n" . $queryF . "\n"; +}