<?php # # You can call this from a URL and it'll print out the header for dean.dcm # require_once '../class_dicom.php'; $file = 'testing.jpg.dcm'; if (!file_exists($file)) { print "{$file}: does not exist\n"; exit; } $d = new dicom_tag(); $d->file = $file; $d->load_tags(); print "<pre>"; print_r($d->tags); $name = $d->get_tag('0010', '0010'); print "Name: {$name}\n";
function send_dcm($host, $port, $my_ae = 'DEANO', $remote_ae = 'DEANO', $send_batch = 0) { if (!$this->transfer_syntax) { $tags = new dicom_tag(); $tags->file = $this->file; $tags->load_tags(); $this->transfer_syntax = $tags->get_tag('0002', '0010'); } $ts_flag = ''; switch ($this->transfer_syntax) { case 'JPEGBaseline': $ts_flag = '-xy'; break; case 'JPEGExtended:Process2+4': $ts_flag = '-xx'; break; case 'JPEGLossless:Non-hierarchical-1stOrderPrediction': $ts_flag = '-xs'; break; } $to_send = $this->file; if ($send_batch) { $to_send = dirname($this->file); $send_command = TOOLKIT_DIR . "/storescu -ta 10 -td 10 -to 10 {$ts_flag} -aet \"{$my_ae}\" -aec {$remote_ae} {$host} {$port} +sd \"{$to_send}\""; } else { $send_command = TOOLKIT_DIR . "/storescu -ta 10 -td 10 -to 10 {$ts_flag} -aet \"{$my_ae}\" -aec {$remote_ae} {$host} {$port} \"{$to_send}\""; } $out = Execute($send_command); if ($out) { return $out; } return 0; }
function process_file($file) { if(!is_dcm($file)) { print("Not a DICOM file: $file\n"); unlink($file); return(0); } $d = new dicom_tag; $d->file = $file; $d->load_tags(); $name = $d->get_tag('0010', '0010'); $id = $d->get_tag('0010', '0020'); $modality = $d->get_tag('0008', '0060'); $appt_date = $d->get_tag('0008', '0020'); $sop_id = $d->get_tag('0002', '0003'); $sex = $d->get_tag('0010', '0040'); $age = $d->get_tag('0010', '1010'); $weight = $d->get_tag('0010', '1030'); $birth = $d->get_tag('0010', '0030'); $birth = substr($birth,0,4).'-'.substr($birth,4,2).'-'.substr($birth,6,2); $appdate = substr($appt_date,0,4).'-'.substr($appt_date,4,2).'-'.substr($appt_date,6,2); $series_id = $d->get_tag('0020', '0052'); $device = $d->get_tag('0008', '0070'); $descp = $d->get_tag('0008', '1080'); $operator = $d->get_tag('0018', '1030'); $model_id = $d->get_tag('0008', '1090'); $diagnoses = $d->get_tag('0010', '0030'); $thick = $d->get_tag('0018', '0050'); $spacing = $d->get_tag('0028', '0030'); $device = $device.$model_id; $pa_id = insert_pa($name,$id,$sex,$age,$weight,$birth); $se_id = insert_se($pa_id,$series_id,$appdate,$modality,$device,$descp,$operator,$thick,$spacing); $year = date('Y', strtotime($appt_date)); $month = date('m', strtotime($appt_date)); $day = date('d', strtotime($appt_date)); $storage = STORAGE . "/".str_pad($pa_id, 5, "0", STR_PAD_LEFT)."_".$name; if(!file_exists($storage)) { mkdir($storage); } $storage = $storage . "/".str_pad($se_id, 8, "0", STR_PAD_LEFT)."_".$modality."_".$appdate; if(!file_exists($storage)) { mkdir($storage); } /* $name = str_replace('^', '_', $name); $arr_replace = array('^', "'", '"', '`', '/', '\\', '?', ':', ';'); foreach($arr_replace as $replace) { $name = str_replace($replace, '', $name); $id = str_replace($replace, '', $id); } $storage = $storage . "/$name" . "_$id"; if(!file_exists($storage)) { mkdir($storage); }*/ $new_file = $modality . "_" . $sop_id . ".dcm"; if(file_exists("$storage/$new_file")) { $new_file = $modality . "_" . $sop_id . "_" . rand(1, 1000) . ".dcm"; } // print "$storage/$new_file\n"; if(!rename($file, "$storage/$new_file")) { print "Failed $file -> $storage/$new_file"; exit; } print "."; // print "$name - $storage\n"; //exit; }
function process_file($file) { if (!is_dcm($file)) { print "Not a DICOM file: {$file}\n"; unlink($file); return 0; } $d = new dicom_tag(); $d->file = $file; $d->load_tags(); $name = $d->get_tag('0010', '0010'); $id = $d->get_tag('0010', '0020'); $modality = $d->get_tag('0008', '0060'); $appt_date = $d->get_tag('0008', '0020'); $sop_id = $d->get_tag('0002', '0003'); $year = date('Y', strtotime($appt_date)); $month = date('m', strtotime($appt_date)); $day = date('d', strtotime($appt_date)); $storage = STORAGE . "/{$year}"; if (!file_exists($storage)) { mkdir($storage); } $storage = $storage . "/{$month}"; if (!file_exists($storage)) { mkdir($storage); } $storage = $storage . "/{$day}"; if (!file_exists($storage)) { mkdir($storage); } $name = str_replace('^', '_', $name); $arr_replace = array('^', "'", '"', '`', '/', '\\', '?', ':', ';'); foreach ($arr_replace as $replace) { $name = str_replace($replace, '', $name); $id = str_replace($replace, '', $id); } $storage = $storage . "/{$name}" . "_{$id}"; if (!file_exists($storage)) { mkdir($storage); } $new_file = $modality . "_" . $sop_id . ".dcm"; if (file_exists("{$storage}/{$new_file}")) { $new_file = $modality . "_" . $sop_id . "_" . rand(1, 1000) . ".dcm"; } // print "$storage/$new_file\n"; if (!rename($file, "{$storage}/{$new_file}")) { print "Failed {$file} -> {$storage}/{$new_file}"; exit; } print "."; // print "$name - $storage\n"; //exit; }