コード例 #1
0
 /**
  * Add file in given feed
  * @return bool
  */
 public static function add($feedID, $files, $ssh_connection)
 {
     // set permissions with the ssh connection
     // get feed path
     $mapper = new Mapper('Feed');
     $mapper->get($feedID);
     $resultsFeed = $mapper->get();
     $mapper = new Mapper('User');
     $mapper->get($resultsFeed['Feed'][0]->user_id);
     $resultsUser = $mapper->get();
     // target directory
     $dir = CHRIS_USERS . '/' . $resultsUser['User'][0]->username . '/file_browser/' . $resultsFeed['Feed'][0]->name . '-' . $resultsFeed['Feed'][0]->id . '/';
     $ssh_connection->exec('chmod 777 ' . $dir);
     foreach ($files as $key => $value) {
         $target_path = $dir . basename($value['name']);
         if (move_uploaded_file($value['tmp_name'], $target_path)) {
             // all good, set permissions correctly
             // not through ssh connection, do it as chris
             exec('chmod 775 ' . $target_path);
         } else {
             // oops.... something went wrong
             return $value['error'];
         }
         $ssh_connection->exec('chmod 755 ' . $dir);
     }
     // all files uploaded successfully
     return 0;
 }
コード例 #2
0
 /**
  * Validate a token. Returns the result and deletes the token if valid.
  *
  * @param string $token The token
  * @return boolean
  */
 public static function validate($token)
 {
     $tokenMapper = new Mapper('Token');
     $tokenMapper->filter('value=(?)', $token);
     $tokenResults = $tokenMapper->get();
     if (count($tokenResults['Token']) == 0) {
         return false;
     }
     // we found the token
     Mapper::delete($tokenResults['Token'][0], $tokenResults['Token'][0]->id);
     return true;
 }
コード例 #3
0
ファイル: feed.view.php プロジェクト: masroore/chrisreloaded
 /**
  * Get username from user id.
  * @param int $userid user ID
  * @return string username
  */
 private static function _getUsername($userid)
 {
     // get user name
     $userMapper = new Mapper('User');
     $userMapper->filter('id = (?)', $userid);
     $userResult = $userMapper->get();
     $username = "******";
     if (count($userResult['User']) == 1) {
         $username = $userResult['User'][0]->username;
     }
     return $username;
 }
コード例 #4
0
ファイル: emailUsr.php プロジェクト: masroore/chrisreloaded
require_once joinPaths(CHRIS_MODEL_FOLDER, 'user.model.php');
// main function
$shortopts = "u:z:";
$options = getopt($shortopts);
$username = '';
if (isset($options['u'])) {
    $username = $options['u'];
}
$zipfile = '';
if (isset($options['z'])) {
    $zipfile = $options['z'];
}
// Get username
$userMapper = new Mapper('User');
$userMapper->filter('username = (?)', $username);
$userResult = $userMapper->get();
$emailTo = '';
if (count($userResult['User']) != 0) {
    $emailTo = $userResult['User'][0]->email;
}
// Build message and link:
$link = CHRIS_URL . "/index.php?";
$link .= "launch_plugin=1";
$link .= "&plugin=zip";
$feedname = "ChRIS_Pushed";
$link .= "&feedname={$feedname}";
$link .= "&status=0";
$link .= "&status_step=100";
$command = "--input={$zipfile} --unzip";
$link .= "&ncommand=" . urlencode($command);
$message = "Please click on the following link to create a new feed for this data: " . PHP_EOL;
コード例 #5
0
ファイル: process.php プロジェクト: masroore/chrisreloaded
 $patientMapper = new Mapper('Data_Patient');
 $patientMapper->ljoin('Patient', 'Patient.id = Data_Patient.patient_id');
 $patientMapper->filter('Data_Patient.data_id = (?)', $dataResult['Data'][0]->id);
 $patientResult = $patientMapper->get();
 // create feed patient directories
 // mkdir if dir doesn't exist
 // create folder if doesnt exists
 $datadirname = $output_directory . '/' . $patientResult['Patient'][0]->uid . '-' . $patientResult['Patient'][0]->id;
 if (!is_dir($datadirname)) {
     mkdir($datadirname);
 }
 // study directory
 // get study description
 $studyMapper = new Mapper('Study');
 $studyMapper->filter('uid = (?)', $process_file['StudyInstanceUID'][0]);
 $studyResult = $studyMapper->get();
 $study_dir_name = formatStudy($studyResult['Study'][0]->date, $studyResult['Study'][0]->age, $studyResult['Study'][0]->description) . '-' . $studyResult['Study'][0]->id;
 $studydirname = $datadirname . '/' . $study_dir_name;
 if (!is_dir($studydirname)) {
     mkdir($studydirname);
 }
 // create data soft links
 $targetbase = CHRIS_DATA . '/' . $patientResult['Patient'][0]->uid . '-' . $patientResult['Patient'][0]->id;
 $series_dir_name = $dataResult['Data'][0]->description . '-' . $dataResult['Data'][0]->name;
 $seriesdirnametarget = $targetbase . '/' . $study_dir_name . '/' . $series_dir_name . '-' . $dataResult['Data'][0]->id;
 $seriesdirnamelink = $datadirname . '/' . $study_dir_name . '/' . $series_dir_name . '-' . $dataResult['Data'][0]->id;
 if (!is_link($seriesdirnamelink)) {
     // create sof link
     symlink($seriesdirnametarget, $seriesdirnamelink);
 }
 $waiting = false;
コード例 #6
0
 public static function AddStudy(&$db, &$process_file, &$study_chris_id, &$study_description)
 {
     $db->lock('study', 'WRITE');
     // Does data exist: SeriesInstanceUID
     if (array_key_exists('StudyInstanceUID', $process_file)) {
         // does study exist??
         $studyMapper = new Mapper('Study');
         $studyMapper->filter('uid = (?)', $process_file['StudyInstanceUID'][0]);
         $studyResult = $studyMapper->get();
         // if study doesn't exist, create it
         if (count($studyResult['Study']) == 0) {
             // create object
             // create data model
             $studyObject = new Study();
             //
             // get data uid
             //
             $studyObject->uid = $process_file['StudyInstanceUID'][0];
             //
             // get data name (series description)
             //
             if (array_key_exists('StudyDescription', $process_file)) {
                 $studyObject->description = sanitize($process_file['StudyDescription'][0]);
             } else {
                 $studyObject->description = 'NoStudyDescription';
             }
             if (array_key_exists('Modality', $process_file)) {
                 $studyObject->modality = sanitize($process_file['Modality'][0]);
             } else {
                 $studyObject->modality = 'NoModality';
             }
             if (array_key_exists('StudyDate', $process_file)) {
                 $studyObject->date = PACS::getDate($process_file);
             }
             $studyObject->age = PACS::getAge($process_file);
             $studyObject->location = PACS::getLocation($process_file);
             $study_description = formatStudy($studyObject->date, $studyObject->age, $studyObject->description);
             $study_chris_id = Mapper::add($studyObject);
         } else {
             // Content to be updated
             if ($studyResult['Study'][0]->age == -1) {
                 //
                 // get data name (series description)
                 //
                 if (array_key_exists('StudyDescription', $process_file)) {
                     $studyResult['Study'][0]->description = sanitize($process_file['StudyDescription'][0]);
                 } else {
                     $studyResult['Study'][0]->description = 'NoStudyDescription';
                 }
                 if (array_key_exists('Modality', $process_file)) {
                     $studyResult['Study'][0]->modality = sanitize($process_file['Modality'][0]);
                 } else {
                     $studyResult['Study'][0]->modality = 'NoModality';
                 }
                 $studyResult['Study'][0]->date = PACS::getDate($process_file);
                 $studyResult['Study'][0]->age = PACS::getAge($process_file);
                 $studyResult['Study'][0]->location = PACS::getLocation($process_file);
                 $study_description = formatStudy($studyResult['Study'][0]->date, $studyResult['Study'][0]->age, $studyResult['Study'][0]->description);
                 $study_chris_id = $studyResult['Study'][0]->id;
                 Mapper::update($studyResult['Study'][0], $studyResult['Study'][0]->id);
             } else {
                 $study_chris_id = $studyResult['Study'][0]->id;
                 $study_description = formatStudy($studyResult['Study'][0]->date, $studyResult['Study'][0]->age, $studyResult['Study'][0]->description);
             }
         }
     } else {
         echo 'Study UID not provided in DICOM file' . PHP_EOL;
         // finish data table lock
         $db->unlock();
         return 0;
     }
     // finish data table lock
     $db->unlock();
     return 1;
 }
コード例 #7
0
 public static function status($feedid, $status, $op)
 {
     // get $db instance
     $db = DB::getInstance();
     $db->lock('feed', 'WRITE');
     // grab the feed
     $feedResult = Mapper::getStatic('Feed', $feedid);
     if (count($feedResult['Feed']) == 0) {
         $db->unlock();
         die('Invalid feed id.');
     }
     # grab old status
     $old_status = $feedResult['Feed'][0]->status;
     $type = gettype($status);
     echo "Performing '{$op}' with value '{$status}' on current status '{$old_status}'\n";
     if ($op == 'inc') {
         // increasing mode
         echo "Increasing status of feed {$feedid} by {$status}... ";
         # increase status
         $status = $old_status + $status;
     }
     if ($op == 'set') {
         // set mode
         if ($old_status >= $status || $status > 100) {
             $db->unlock();
             die("Ignoring setting the status since the old status {$old_status} >= the new status {$status} or the old status >= 100.\n");
         } else {
             echo "Setting status of feed {$feedid} to {$status}... ";
         }
     }
     echo "status now {$status}.\n";
     # clamp the addition
     if ($status >= 100) {
         $status = 100;
         $startTime = $feedResult['Feed'][0]->time;
         $endTime = microtime(true);
         $duration = $endTime - $startTime;
         $feedResult['Feed'][0]->time = $endTime;
         $feedResult['Feed'][0]->duration = $duration;
     }
     # push to database
     $feedResult['Feed'][0]->status = $status;
     Mapper::update($feedResult['Feed'][0], $feedid);
     $db->unlock();
     # update related shared feeds
     $relatedMapper = new Mapper('Feed');
     $relatedMapper->join('Meta', 'Meta.target_id = Feed.id')->filter('Meta.name = (?)', 'root_id')->filter('Meta.value = (?)', $feedResult['Feed'][0]->id)->filter('Feed.id != (?)', $feedResult['Feed'][0]->id);
     $relatedResult = $relatedMapper->get();
     foreach ($relatedResult['Feed'] as $key => $value) {
         $relatedResult['Feed'][$key]->time = $feedResult['Feed'][0]->time;
         $relatedResult['Feed'][$key]->duration = $feedResult['Feed'][0]->duration;
         $relatedResult['Feed'][$key]->status = $feedResult['Feed'][0]->status;
         Mapper::update($relatedResult['Feed'][$key], $relatedResult['Feed'][$key]->id);
     }
     # send email if status == 100
     if ($status == 100) {
         // user's email
         $userMapper = new Mapper('User');
         $userMapper->filter('user.id = (?)', $feedResult['Feed'][0]->user_id);
         $userResult = $userMapper->get();
         // if nothing in DB yet, return -1
         if (count($userResult['User']) > 0) {
             $subject = "ChRIS2 - " . $feedResult['Feed'][0]->plugin . " plugin finished";
             $message = "Hello " . $userResult['User'][0]->username . "," . PHP_EOL . PHP_EOL;
             $message .= "Your results are available at:" . PHP_EOL . PHP_EOL;
             $dirRoot = joinPaths(CHRIS_USERS, $userResult['User'][0]->username, $feedResult['Feed'][0]->plugin, $feedResult['Feed'][0]->name . '-' . $feedResult['Feed'][0]->id);
             $dataDir = array_diff(scandir($dirRoot), array('..', '.'));
             foreach ($dataDir as $dir) {
                 $mailFilePath = $dirRoot . '/' . $dir . '/_chrisRun_/' . 'chris.mail';
                 if (file_exists($mailFilePath)) {
                     $mailContents = file_get_contents($mailFilePath);
                     $message .= $dirRoot . '/' . $dir . PHP_EOL . $mailContents . PHP_EOL . PHP_EOL;
                 } else {
                     $message .= $dirRoot . '/' . $dir . PHP_EOL . PHP_EOL;
                 }
             }
             $message .= "Thank you for using ChRIS.";
             echo "Sending email to " . $userResult['User'][0]->email . " since the status is '{$status}'%.\n";
             // get user email address
             email(CHRIS_PLUGIN_EMAIL_FROM, $userResult['User'][0]->email, $subject, $message);
         }
     }
 }
コード例 #8
0
 public function testGet()
 {
     // get a patient by id
     $patientObject = new Patient();
     $patientObject->id = 2;
     $patientObject->name = 'Rannou';
     $patientObject->dob = '1987-03-27';
     $patientObject->sex = 'M';
     $patientObject->uid = 'CH156525;';
     $patientObject2 = new Patient();
     $patientObject2->id = 2;
     $patientObject2->name = 'Rannou';
     $patientObject2->dob = '1987-03-27';
     $patientObject2->sex = 'M';
     $patientObject2->uid = 'CH156525;';
     $patientMapper = new Mapper($patientObject);
     $patientResult = $patientMapper->get(2);
     // should be equal
     //$this->assertTrue($patientResult['Patient'][0]->equals($patientObject2) == True);
     $patientMapper2 = new Mapper('Patient');
     $patientResult2 = $patientMapper2->get(-3);
     // should return nothing
     $this->assertTrue(count($patientResult2['Patient']) == 0);
     // get all
     $patientMapper3 = new Mapper($patientObject);
     $patientMapper3->filter('AND', '', 0);
     $patientResult3 = $patientMapper3->get();
     // should return 6 patients
     $this->assertTrue(count($patientResult3['Patient']) == 6);
 }
コード例 #9
0
ファイル: search.php プロジェクト: masroore/chrisreloaded
       $processLog .= 'agemin: '. $input.PHP_EOL;
    
      $mapper->filter('study.age <= (?)', $input);
      $processLog .= 'agemax: '. $input.PHP_EOL; */
    /*   $mapper->filter('study.date >= (?)', $input);
       $processLog .= 'datemin: '. $input.PHP_EOL;
    
      $mapper->filter('study.date <= (?)', $input);
      $processLog .= 'datemax: '. $input.PHP_EOL; */
}
$fh = fopen($logFile, 'a') or die("can't open file");
fwrite($fh, $processLog);
fclose($fh);
$processLog = '=======================================' . PHP_EOL;
$processLog .= date('Y-m-d h:i:s') . ' ---> Process results...' . PHP_EOL;
$results = $mapper->get();
if (count($results['Data']) >= 1) {
    foreach ($results['Data'] as $key => $value) {
        $processLog .= $results['Patient'][$key]->id . PHP_EOL;
        // create patient directory
        $fs_location = $results['Patient'][$key]->uid . '-' . $results['Patient'][$key]->id;
        $patientdir = $output_dir . $fs_location;
        // create study directory
        $fs_location .= '/' . formatStudy($results['Study'][$key]->date, $results['Study'][$key]->age, $results['Study'][$key]->description) . '-' . $results['Study'][$key]->id;
        $studydir = $output_dir . $fs_location;
        // create data symlink
        // loop through results and create links
        $processLog .= date('Y-m-d h:i:s') . ' Creates soft link for Patient' . PHP_EOL;
        // create data soft links
        $name = '';
        if (file_exists(CHRIS_DATA . '/' . $fs_location . '/' . $value->description . '-' . $value->name . '-' . $value->id)) {
コード例 #10
0
            $targetbase = CHRIS_DATA . '/' . $patientResult['Patient'][0]->uid . '-' . $patientResult['Patient'][0]->id;
            $series_dir_name = $dataResult['Data'][0]->description . '-' . $dataResult['Data'][0]->name;
            $seriesdirnametarget = $targetbase . '/' . $study_dir_name . '/' . $series_dir_name . '-' . $dataResult['Data'][0]->id;
            $seriesdirnamelink = $datadirname . '/' . $study_dir_name . '/' . $series_dir_name . '-' . $dataResult['Data'][0]->id;
            if (file_exists($seriesdirnametarget)) {
                if (!is_link($seriesdirnamelink)) {
                    // create sof link
                    symlink($seriesdirnametarget, $seriesdirnamelink);
                }
            } else {
                $dataLog .= "ERROR: Directory does not exist: " . $seriesdirnametarget . PHP_EOL;
            }
            // update feed status?
            $fh = fopen($logFile, 'a') or die("can't open file");
            fwrite($fh, $dataLog);
            fclose($fh);
            $waiting = false;
        } else {
            sleep(2);
        }
    }
    // update status
    $counter++;
}
// update feed status in db
$feedMapper = new Mapper('Feed');
$feedMapper->filter('id = (?)', $feed_chris_id);
$feedResult = $feedMapper->get();
$feedResult['Feed'][0]->status = 99;
Mapper::update($feedResult['Feed'][0], $feedResult['Feed'][0]->id);
exit(0);
コード例 #11
0
 public static function getTagsList()
 {
     $n = new Template('tags_list.html');
     $tagMapper = new Mapper('Tag');
     $tagMapper->filter('user_id=(?)', $_SESSION['userid']);
     $tagresults = $tagMapper->get();
     $tags = '';
     foreach ($tagresults['Tag'] as $key => $value) {
         $tags .= '<option value="' . $value->name . '" data-backgroundcolor="' . $value->color . '" data-color="' . invertColor($value->color) . '">' . $value->name . '</option>';
     }
     $n->replace('TAGS_LIST', $tags);
     return $n;
 }
コード例 #12
0
                // delete the temp file
                unlink($study_directory . '/' . $entry2);
            }
        }
    }
    closedir($handle2);
    // delete directory
    $logFile .= 'delete: ' . $study_directory . PHP_EOL;
    rmdir($study_directory);
}
// add warning if we didn't receive all the expected files
// todo: all queries at once
foreach ($received as $key => $value) {
    $dataMapper = new Mapper('Data');
    $dataMapper->filter('id = (?)', $value);
    $dataResult = $dataMapper->get();
    if ($dataResult['Data'][0]->status != $dataResult['Data'][0]->nb_files) {
        $logFile .= 'WARNING => DATA ID : ' . $dataResult['Data'][0]->id . '(' . $dataResult['Data'][0]->status . '/' . $dataResult['Data'][0]->nb_files . ')' . $entry . PHP_EOL;
        // update db to unlock plugin
        if ($dataResult['Data'][0]->nb_files == -1) {
            $dataResult['Data'][0]->nb_files = $dataResult['Data'][0]->status;
        } else {
            $dataResult['Data'][0]->status = min($dataResult['Data'][0]->status, $dataResult['Data'][0]->nb_files);
            $dataResult['Data'][0]->nb_files = $dataResult['Data'][0]->status;
        }
        Mapper::update($dataResult['Data'][0], $dataResult['Data'][0]->id);
    }
}
sendEmail($process_file, $datadirname, $emailTo, $link);
echo $logFile;
return;
コード例 #13
0
 /**
  * Set a user email address.
  *
  * @param string $uid
  * @param string $email
  */
 public static function setEmail($uid, $email)
 {
     $userMapper = new Mapper('User');
     $userMapper->filter('id=(?)', $uid);
     $userResults = $userMapper->get();
     // if user exist, return its id
     if (isset($userResults['User'][0])) {
         // update email address
         $userResults['User'][0]->email = $email;
         Mapper::update($userResults['User'][0], $uid);
     }
 }