class_dicom.php Example: Send all DICOM files in a directory

The script below will look in the directory you specify in $temp_dir and send any images it finds to a DICOM host. When it is done sending it will move the DICOM file to a back up directory.

#!/usr/bin/php
<!--?PHP 

require_once('class_dicom.php');

# WHERE YOUR DICOM FILES ARE
$temp_dir = '../temp';

# WHERE YOU ARE SENDING THEM
$target_host = 'some IP address';
$target_port = '105';
$target_ae = 'BK';
$my_ae = 'BK';

if(!file_exists('bk')) {
  mkdir('bk');
}

$d = new dicom_net;

if($handle = opendir($temp_dir)) {
  while(false !== ($file = readdir($handle))) {
    if($file != "." &#038;& $file != "..") {

      print "Sending $file...\n";

      $d--->file = "$temp_dir/$file";
      $ret = $d-&gt;send_dcm($target_host, $target_port, $my_ae, $target_ae);
      if($ret) {
        print "Send Error: $ret\n";
        continue;
      }
      else {
        print "Good Send\n";
        print "Moving $temp_dir/$file\n";
        rename("$temp_dir/$file", "bk/$file");
      }

    }
  }
  closedir($handle);
}

?&gt;

7 comments

  1. I have some problemas when I try to send:

    E: Store SCP Failed: 0006:0207 DIMSE No data available (timeout in non-blocking mode)
    W: DcmItem: Length of element (bc5c,abca) is odd
    E: DIMSE failure (aborting association): 0006:020d DIMSE Failed to receive message

    and

    E: DcmElement: Unknown Tag & Data (a6f5,18ca) larger (2895592401) than remaining bytes (461587) in file, premature end of stream

Leave a Reply to Problems Cancel reply

Your email address will not be published. Required fields are marked *