- modules/fotolab updated imagej to current version & some cod fixes to make it work
[care2x.git] / Care2007 / modules / radiology / upload.php
blobaf33f9834de1e1c3b2194867c35f7dc797fc63bb
1 <?php
2 error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
3 require('./roots.php');
4 require($root_path.'include/inc_environment_global.php');
5 /**
6 * CARE2X Integrated Hospital Information System Deployment 2.1 - 2004-10-02
7 * GNU General Public License
8 * Copyright 2002,2003,2004,2005 Elpidio Latorilla
9 * elpidio@care2x.org,
11 * See the file "copy_notice.txt" for the licence notice
14 define('FILE_DISCRIM','.dcm'); # define here the file discrimator string
16 $thisfile=basename(__FILE__);
18 $returnfile=$HTTP_SESSION_VARS['sess_file_return'];
20 ///$db->debug=1;
22 # Load paths und dirs
23 require_once($root_path.'global_conf/inc_remoteservers_conf.php');
24 # Create image object
25 require_once($root_path.'include/care_api_classes/class_image.php');
26 $img=new Image();
29 if(!isset($mode)){
30 $mode='new';
31 } elseif(($mode=='create'||$mode=='update')&&$maxpic) {
33 # makedir lock flags
34 $persd=true;
35 $imgd=true;
36 $notyetsaved=true;
37 # Internal counter used for prepending the filename. Do not use zero!
38 $icount=1;
39 # Begin storage of files
40 for ($i=0;$i<$maxpic;$i++)
42 $picfile='f'.$i;
43 # Check the image, use 'dcm' as discriminator
44 if($img->isValidUploadedImage($HTTP_POST_FILES[$picfile],'dcm'))
46 //$data['mime_type']=$picext;
47 # Hard code image type to "dicom"
48 $data=array('pid'=>$pid,
49 'encounter_nr'=>$HTTP_POST_VARS['encounter_nr'],
50 'doc_ref_ids'=>$HTTP_POST_VARS['doc_ref_ids'],
51 'img_type'=>'dicom',
52 'notes'=>$HTTP_POST_VARS['notes'],
53 'upload_date'=>date('Y-m-d'),
54 'history'=>"Upload ".date('Y-m-d H:i:s')." ".$HTTP_SESSION_VARS['sess_user_name']."\n",
55 'create_id'=>$HTTP_SESSION_VARS['sess_user_name'],
56 'create_time'=>date('YmdHis'));
58 # Save data into the database
59 if($notyetsaved){
60 if($oid=$img->saveImgDiagnosticData($data)){
61 # Get the primar key of the saved record
62 $picnr = $img->LastInsertPK('nr',$oid);
63 //echo $img->getLastQuery();
64 # Lock save this save routine
65 $notyetsaved=false;
66 }else{
67 echo $img->getLastQuery();
70 if(!$notyetsaved&&$picnr){
71 //$picfilename[$i]=$picnr.'.'.$picext;
73 # Compose the prepend number
74 # This will be prepended to filename eg. => 1003_angio.dcm
75 # to simplify sorting of the filenames according to order of upload
76 $prep=1000+$icount;
78 $picfilename=$prep.'_'.$HTTP_POST_FILES[$picfile]['name'];
80 //echo $HTTP_POST_FILES[$picfile]['name'].' <img '.createComIcon($root_path,'fwd.gif','0','absmiddle').'> ';
81 # Echo for debugging
82 //echo $picfilename.'<br>';
84 # Compose the PID nr subdir
85 if($persd){
86 $persondir=$root_path.$dicom_img_localpath.$pid;
88 if(!is_dir($persondir)){
89 # if $d directory not exist create it with CHMOD 777
90 mkdir($persondir,0777);
91 # Copy the trap files to this new directory
92 copy($root_path.$dicom_img_localpath.'donotremove/index.htm',$persondir.'/index.htm');
93 //echo $root_path.$dicom_img_localpath.'donotremove/index.htm'.$persondir.'/index.htm'.'<br>';
94 copy($root_path.$dicom_img_localpath.'donotremove/index.php',$persondir.'/index.php');
95 //echo $root_path.$dicom_img_localpath.'donotremove/index.php'.$persondir.'/index.php'.'<br>';
96 # Lock make dir
97 $persd=false;
100 # Compose the img nr subdir
101 if($imgd){
102 $imgdir=$persondir."/$picnr";
103 if(!is_dir($imgdir)){
104 # if $d directory not exist create it with CHMOD 777
105 mkdir($imgdir,0777);
106 # Copy the trap files to this new directory
107 copy($root_path.$dicom_img_localpath.'donotremove/donotremove/index.htm',$imgdir.'/index.htm');
108 //echo $root_path.$dicom_img_localpath.'donotremove/donotremove/index.htm'.$imgdir.'/index.htm'.'<br>';
109 copy($root_path.$dicom_img_localpath.'donotremove/donotremove/index.php',$imgdir.'/index.php');
110 //echo $root_path.$dicom_img_localpath.'donotremove/donotremove/index.php'.$imgdir.'/index.php'.'<br>';
111 # Lock make dir
115 $imgd=false;
116 # Store to the newly created directory
117 $dir_path=$imgdir.'/';
119 # Save the uploaded image
120 if($img->saveUploadedImage($HTTP_POST_FILES[$picfile],$dir_path,$picfilename)){
121 # Increse internal count
122 $icount++;
124 }else{
125 echo $img->getLastQuery();
127 } # end of if()
128 } # End of for() loop
129 # Now check if data integrity is ok
130 # Check if data is stored in the database but image not correctly uploaded
131 if(!$notyetsaved&&$picnr&&($icount==1)){
132 $img->useImgDiagnostic();
133 # delete the record entry from the database
134 # Note: __delete is a private method and is used only in this exception case.
135 $img->__delete($picnr);
136 }else{
137 # Upload is successful, update datase with actual nr of files successfully uploaded
138 $img->setImgMaxNr($picnr,$icount-1);
139 # Redirect to fresh mode
140 header("location:$thisfile".URL_REDIRECT_APPEND."&pid=$pid&saved=1&mode=show&nr=$picnr&maxpic=$maxpic");
141 exit;
145 $lang_tables[]='radio.php';
146 $lang_tables[]='prompt.php';
147 require('./include/init_show.php');
149 $page_title=$LDUploadDicom;
151 if($mode=='show'&&$nr) {
152 $imgpath=$root_path.$dicom_img_localpath.$pid."/$nr";
153 $files=&$img->FilesListArray($imgpath,FILE_DISCRIM);
154 $rows=$img->LastRecordCount();
157 # Default nr of files
158 if(!isset($maxpic)||!$maxpic||!is_numeric($maxpic)||$maxpic<0) $maxpic=4;
160 # Prepare some parameters based on selected dicom viewer module
161 $pop_only=false;
163 switch($HTTP_SESSION_VARS['sess_dicom_viewer']){
164 case 'raimjava':
165 $pop_only=true;
166 break;
167 default:
168 # Default viewer
171 # Set break file
172 require('include/inc_breakfile.php');
174 if($mode=='show') $glob_obj->getConfig('medocs_%');
175 /* Load GUI page */
176 require('./gui_bridge/default/gui_show_upload.php');