<?php
/**
 * @copyright Gmed Srl
 * @author Sciarrone Riccardo <riccardos@gmed.it>
 *
 * Programma che esegue una chiamata a Orthanc
 */


// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);


include_once 'conf/config.inc.php';
include_once 'include/basic_function.php';

include_once 'include/elsol_function.php';
include_once 'include/dcm_function.php';




$dbg = isset($_GET['debug']) && !IsNull($_GET['debug']) ? true : false;
$GLOBALS['dbg'] = $dbg;
if($dbg){
  //error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
  error_reporting(E_ALL | E_WARNING | E_PARSE | E_NOTICE);
}


echoo( "INIZIO ELABORAZIONE!" );


if ( !isset($argv[1]) && !isset($_GET["cmd"]) ) {
    // NULLA DA elaborare
    echoo( "NULLA DA ELABORARE \n" );
}

$cmd = isset($argv[1]) ? $argv[1] : $_GET["cmd"];
$cmd = orthanc_url . $cmd;

// es. '/studies?expand'
//echoo( "\ncomando: $cmd\t\t" );
//$curl = call_orthanc( $cmd, "TEST", TRUE, 'GET', null, TRUE );

$gg = 10;
$del_due_date = date('Ymd', strtotime("-$gg days"));
echo "trova da -$gg gg da oggi: $del_due_date <br/><br/>";
$cmd = "http://172.20.33.145:8042/tools/find";

$post_fields = '{"Level":"Study","Expand":true,"Limit":101,"Query":{"StudyDate":"-' . $del_due_date . '"}}';
echo "POST:<br/>$post_fields<br/>";

/*
$curl = call_orthanc( $cmd, "TEST", TRUE, 'POST', $post_fields, TRUE );
$result = json_decode($curl);

echoo( "risultato:\t" );
if( is_array($result) ){
    echoo( $result, TRUE, TRUE );
}
else {
    echoo( $result, TRUE );
}
*/

echoo( "\nFINE ELABORAZIONE\n" );
