Index: trunk/ippToPsps/perl/checkOdmStatus.pl
===================================================================
--- trunk/ippToPsps/perl/checkOdmStatus.pl	(revision 28953)
+++ trunk/ippToPsps/perl/checkOdmStatus.pl	(revision 28954)
@@ -9,17 +9,36 @@
 use File::Temp qw(tempfile);
 use ippToPsps::IppToPspsDb;
+use ippToPsps::Datastore;
 
 my $singleBatch = undef;
 my $verbose = undef;
 my $save_temps = undef;
+my $fromTime = undef;
+my $toTime = undef;
+my $product = undef;
+
 
 GetOptions(
         'batch|b=s' => \$singleBatch,
+        'from|f=s' => \$fromTime,
+        'to|t=s' => \$toTime,
+        'product|p=s' => \$product,
         'verbose|v' => \$verbose,
         'save_temps|s' => \$save_temps
         );
 
+if (!defined $product) {
+    print "* OPTIONAL: a datastore product name        -p <name>\n";
+}
 if (!defined $singleBatch) {
     print "* OPTIONAL: a single batch                  -b                   (default = none)\n";
+}
+if (!defined $fromTime) {
+    $fromTime = "2010-01-01";
+    print "* OPTIONAL: from time                       -f                   (default = $fromTime)\n";
+}
+if (!defined $toTime) {
+    $toTime = "2099-12-31";
+    print "* OPTIONAL: to time                         -t                   (default = $toTime)\n";
 }
 if (!defined $verbose) {
@@ -33,7 +52,6 @@
 
 
+my $datastore = new ippToPsps::Datastore($product, 0, 0);
 my $ippToPspsDb = new ippToPsps::IppToPspsDb("ippToPsps", "ippdb01", "ipp", "ipp", $verbose, $save_temps);
-my $fromFilter = "2010-08-01";
-my $toFilter = "2099-12-31";
 my $odmUrl = "http://web01.psps.ifa.hawaii.edu/a01/OdmWebService/OdmWebService.asmx/GetBatchStatus";
 my $ua = LWP::UserAgent->new;
@@ -55,12 +73,12 @@
 
     if (defined $singleBatch ) { $numOfBatches = $ippToPspsDb->getSingleBatch($singleBatch, \$batches);}
-    else { $numOfBatches = $ippToPspsDb->getBatchList(\$batches);}
+    else { $numOfBatches = $ippToPspsDb->getBatchList(\$batches, $fromTime, $toTime);}
 
     if ($numOfBatches < 1) {return 0;}
 
     print "\n";
-    printf("+--------------+--------------+----------------+---------------+---------+\n");
-    printf("|    Batch     |  Exposure ID | Loaded to ODM? | Merge worthy? | Merged? |\n");
-    printf("+--------------+--------------+----------------+---------------+---------+\n");
+    printf("+----------------------+--------------+--------------+----------------+---------------+---------+----------+\n");
+    printf("|      Timestamp       |    Batch     |  Exposure ID | Loaded to ODM? | Merge worthy? | Merged? | Deleted? |\n");
+    printf("+----------------------+--------------+--------------+----------------+---------------+---------+----------+\n");
 
     # loop round batches
@@ -68,10 +86,10 @@
     my $numChecked = 0;
     foreach $batch ( @{$batches} ) {
-        my ($expId, $batchId, $surveyType) =  @{$batch};
+        my ($timestamp, $expId, $batchId, $surveyType, $deleted) =  @{$batch};
 
-if (checkBatch($expId, $batchId, $surveyType)) {$numChecked++;}
+        if (checkBatch($timestamp, $expId, $batchId, $surveyType, $deleted)) {$numChecked++;}
 
     }
-    printf("+--------------+--------------+----------------+---------------+---------+\n");
+    printf("+----------------------+--------------+--------------+----------------+---------------+---------+----------+\n");
 
     printf( "* Successfully checked %d batch%s out of %d\n", $numChecked, ($numChecked==1) ? "" : "es", $numOfBatches);
@@ -85,5 +103,5 @@
 ########################################################################################
 sub checkBatch {
-    my ($expId, $batchId, $surveyType) = @_;
+    my ($timestamp, $expId, $batchId, $surveyType, $deleted) = @_;
 
 
@@ -94,6 +112,6 @@
             [batchNameFilter => $batchFilter,
             statusFilter => $statusFilter,
-            fromFilter => $fromFilter,
-            toFilter => $toFilter]
+            fromFilter => "2010-01-01",
+            toFilter => "2099-01-01"]
             );
 
@@ -110,17 +128,33 @@
     close($tempFile);
 
-    my $loadedToOdm;
-    my $mergeWorthy;
-    my $mergeCompleted;
+    my $loadedToOdm = 0;
+    my $mergeWorthy = 0;
+    my $mergeCompleted = 0;
 
     parseXml($tempName, \$loadedToOdm, \$mergeWorthy, \$mergeCompleted);
-    printf( "| %11s  | %10d   |    %6s      |    %6s     | %6s  |\n", 
+
+    # delete from datastore
+    if(defined $product) {
+    
+        if (!$deleted && $loadedToOdm && $mergeWorthy) {
+        
+            $deleted = $datastore->remove($batchFilter);
+            if ($deleted) {
+                $ippToPspsDb->setBatchAsDeleted($batchId, $expId);
+            }
+        }
+    }
+    
+    printf( "| %18s  | %11s  | %10d   |    %6s      |    %6s     | %6s  |  %5s   |\n", 
+            $timestamp, 
             $batchFilter, 
             $expId, 
             $loadedToOdm ? "yes" : "no", 
             $mergeWorthy ? "yes" : "no", 
-            $mergeCompleted ? "yes" : "no");
+            $mergeCompleted ? "yes" : "no",
+            $deleted ? "yes" : "no");
 
-    $ippToPspsDb->updateODMStatus($batchId, $expId, $loadedToOdm, $mergeWorthy, $mergeCompleted);
+    $ippToPspsDb->updateODMStatus($batchId, $expId, $loadedToOdm, $mergeWorthy, $mergeCompleted, $deleted);
+
 }
 
