Deleting studies by modalities using command line

  • Hi, Marcel.
    Congratulations for this great server!


    I'm looking for a feature, I'm not sure that it is available already. I have a ConQuest server for MR studies, but some radiologists send CT studies to this MR server.
    Now we have hundreds of CT studies at the MR server. Is there any way to delete these CT studies from the MR server?


    Maybe using some command as dgate --deletestudy:"modalityuid".
    Is there a feature like this available?


    Thank you, Marcel!


    [ ]s!

    Gustavo F. Caetano
    Technical Coordinator and Biomedical Informatics Specialized Technician
    Image Sciences and Medical Physics Center
    Hospital das Clínicas - FMRP - USP

  • Here is a solution you may wish to use. It is a perl program that generates a list of study or series UIDs based on modaliity and then feeds each one to --deletestudy or --deleteseries.


    If you don't already have perl you can get a free package from Activestate http://www.activestate.com/Products/activeperl/.


    Copy the following program and call it delete_by_modality.pl

    Code
    ## Create a list of study or series UIDs that match the given modality# and optionally delete them.# eg. delete_by_modality.pl --modality CT --series # Author: Mark Pearson markp@nucmed.crg.cs.nsw.gov.au#use Getopt::Long;sub rtrim;sub getStudyList;sub getSeriesList;my $dgateHome = 'C:\Conquest';my $dgate = "dgate.exe";my $modality = '';my $matchSeries = 0;my $matchStudy = 0;my $verbose = 0;my $delete = 0;my $help = 0;my $print = 0;my $test = 0;my $found = 0;my $deleted = 0;my $limit = 0;my @uids = ();$ret = &GetOptions( "modality=s" => \$modality, "limit=i" => \$limit, "study" => \$matchStudy, "series" => \$matchSeries, "delete" => \$delete, "print" => \$print, "verbose" => \$verbose, "noaction" => \$test, "help" => \$help );if (! $ret || $help) { my $useage = "USAGE: delete_by_modality --options\n"; $usage .= "Options:\n"; $usage .= "\t--modality=XX\t\tfind all uids matching the modality XXX (manditory)\n"; $usage .= "\t--study or --series\tfind study or series UIDs (manditory)\n"; $usage .= "\t--delete\t\tdelete UIDs found.\n"; $usage .= "\t--noaction\t\tdo all actions except delete. Best with --verbose\n"; $usage .= "\t--print\t\tPrint a list of the UIDs found\n"; $usage .= "\t--limit=NN\t\tFind at most NN matches\n"; $usage .= "\t--verbose\t\tShow more detail of actions\n"; die $usage;}if (length($modality) == 0) { die "ERROR: No modality specified. Use --modality=XXX\n";}if ($matchSeries && $matchStudy) { die "ERROR: Specify --study or --series, not both\n";}chdir $dgateHome or die "ERROR: could not cd to $dgateHome\n";;if ($matchStudy) { print "StudyUIDs that match modality $modality\n" if ($verbose); @uids = getStudyList($modality, $limit); foreach $uid (@uids) { print "$uid\n" if ($print); $found++; }}if ($matchSeries) { print "SeriesUIDs that match modality $modality\n" if ($verbose); @uids = getSeriesList($modality, $limit); foreach $uid (@uids) { print "$uid\n" if ($print); $found++; }}print "$found UIDs found\n";if ($delete && $found == 0) { die "WARNING: No UIDs found to delete\n";}if ($delete && $matchStudy) { foreach $uid (@uids) { $cmd = $dgate." --deletestudy:\"".$uid."\""; if ($verbose) { print "Call $cmd\n"; } if (! $test) { my $resp = `$cmd`; $deleted++; } }}if ($delete && $matchSeries) { foreach $uid (@uids) { $cmd = $dgate." --deleteseries:\"".$uid."\""; if ($verbose) { print "Call $cmd\n"; } if (! $test) { my $resp = `$cmd`; $deleted++; } }}print "$deleted UIDs deleted\n";if ($regen) { $cmd = $dgate." --initializetables:"; if ($verbose) { print "Call $cmd\n"; } my $resp = `$cmd`; $cmd = $dgate." --regen:"; if ($verbose) { print "Call $cmd\n"; } my $resp = `$cmd`;}exit;sub getStudyList($) { my ($mod, $lim) = @_; if ($lim) { $cmd = $dgate." --query2:\"DICOMStudies|StudyInsta|StudyModal = '".$mod."'|%s|$lim\""; } else { $cmd = $dgate." --query:\"DICOMStudies|StudyInsta|StudyModal = '".$mod."'|%s\""; } if ($verbose) { print "Call $cmd\n"; } my $resp = `$cmd`; my @suids = split("\n", rtrim($resp)); return @suids;}sub getSeriesList($) { my ($mod, $lim) = @_; if ($lim) { $cmd = $dgate." --query2:\"DICOMSeries|SeriesInst|Modality = '".$mod."'|%s|$lim\""; } else { $cmd = $dgate." --query:\"DICOMSeries|SeriesInst|Modality = '".$mod."'|%s\""; } if ($verbose) { print "Call $cmd\n"; } my $resp = `$cmd`; my @suids = split("\n", rtrim($resp)); return @suids;}# Right trim function to remove trailing whitespacesub rtrim { my ($string) = @_; $string =~ s/\0//g; $string =~ s/\s+$//; return $string;}


    If conquest is not installed in the default location the variable $dgateHome must be adjusted.


    To run the program, open a command shell and type in

    Code
    delete_by_modality.pl --modality CT --series --print1.2.840.113704.1.111.5700.1193965940.89999.9999.7.1196035999.2501.2.840.113704.1.111.4628.1193960088.201.2.840.113704.1.111.5076.1155781949.81.2.840.113704.1.111.5076.1155781894.41.2.840.113704.1.111.2664.1156723230.111.2.840.113704.1.111.5296.1156813228.87 UIDs found0 UIDs deleteddelete_by_modality.pl --modality CT --series --delete7 UIDs found7 UIDs deleted


    To find out what actions wouild be taken without deleting anything add the options --verbose --noaction.


    If there are a very large number of UIDs the program may run out of memory. In that case use the --limit option to restrict the number UIDs found.


    While testing on linux with conquest 1412c I found that if the dabase is Mysql the files were deleted but the database did not update and a manual database re-initialization was necessary. Neither dbase or postgres had these problems.


    To use the program on linux add the location the the perl binary to the top of the program and modify $dgateHome and $dgate

    Perl
    #!/usr/bin/perl
    #
    # Create a list of study or series UIDs that match the given modality
    .....
    my $dgateHome = '/usr/local/conquest/postgres';
    my $dgate = "./dgate";
    .....
  • Thank you for this solution!
    I'll try it as soon as the server gets idle.


    Thank you!


    [ ]s!

    Gustavo F. Caetano
    Technical Coordinator and Biomedical Informatics Specialized Technician
    Image Sciences and Medical Physics Center
    Hospital das Clínicas - FMRP - USP

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!