- modules/fotolab updated imagej to current version & some cod fixes to make it work
[care2x.git] / Care2007 / modules / laboratory / labor-data-makegraph.php
blob0c4cdef3adfe7e1929204b2b0159f11e02d8e9e9
1 <?php
3 define('LAB_MAX_DAY_DISPLAY',7); # define the max number or days displayed at one time
5 error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
6 require('./roots.php');
7 require($root_path.'include/inc_environment_global.php');
8 /**
9 * CARE2X Integrated Hospital Information System Deployment 2.2 - 2006-07-10
10 * GNU General Public License
11 * Copyright 2002,2003,2004,2005,2006 Elpidio Latorilla
12 * elpidio@care2x.org,
14 * See the file "copy_notice.txt" for the licence notice
16 ///$db->debug=1;
17 $lang_tables=array('chemlab_groups.php','chemlab_params.php');
18 define('LANG_FILE','lab.php');
19 define('NO_2LEVEL_CHK',1);
20 require_once($root_path.'include/inc_front_chain_lang.php');
22 if($user_origin=='lab'||$user_origin=='lab_mgmt'){
23 $local_user='ck_lab_user';
24 if(isset($from)&&$from=='input') $breakfile=$root_path.'modules/laboratory/labor_datalist_noedit.php'.URL_APPEND.'&encounter_nr='.$encounter_nr.'&job_id='.$job_id.'&parameterselect='.$parameterselect.'&allow_update='.$allow_update.'&user_origin='.$user_origin.'&from=input';
25 else $breakfile=$root_path.'modules/laboratory/labor_datalist_noedit.php'.URL_APPEND.'&encounter_nr='.$encounter_nr.'&user_origin='.$user_origin;
26 }else{
27 $local_user='ck_pflege_user';
28 $breakfile=$root_path.'modules/laboratory/labor_datalist_noedit.php'.URL_APPEND.'&pn='.$encounter_nr.'&user_origin='.$user_origin.'&edit='.$edit;
31 if(!$HTTP_COOKIE_VARS[$local_user.$sid]) {header("Location:".$root_path."language/".$lang."/lang_".$lang."_invalid-access-warning.php"); exit;};
33 if(!$encounter_nr) header("location:".$root_path."modules/laboratory/labor_data_patient_such.php?sid=$sid&lang=$lang");
34 require_once($root_path.'include/inc_config_color.php');
36 $thisfile=basename(__FILE__);
38 /* Create encounter object */
39 require_once($root_path.'include/care_api_classes/class_lab.php');
40 $enc_obj= new Encounter($encounter_nr);
41 $lab_obj=new Lab($encounter_nr);
43 //gjergji :
44 //diff for the date of birth
45 function dateDiff($dformat, $endDate, $beginDate){
46 $date_parts1=explode($dformat, $beginDate);
47 $date_parts2=explode($dformat, $endDate);
48 $start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
49 $end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
50 return $end_date - $start_date;
52 //gjergji
53 //display the median values
54 function medianValue($paramValue,$pName){
55 global $patient;
56 $txt = '';
57 $diff = dateDiff("-", date("Y-m-d"), $patient['date_birth']);
58 switch ($diff) {
59 case ( ($diff >= 1) and ($diff <= 30 ) ) :
60 if($pName['lo_bound_n']!=null&&$pName['hi_bound_n']!=null) $txt.=htmlspecialchars($pName['hi_bound_n'])."<p><br>".htmlspecialchars($pName['lo_bound_n']);
61 break;
62 case ( ($diff >= 31) and ($diff <= 360 ) ) :
63 if($pName['lo_bound__y']&&$pName['hi_bound_y']) $txt.=htmlspecialchars($pName['hi_bound_y'])."<p><br>".htmlspecialchars($pName['lo_bound_y']);
64 break;
65 case ( $diff >= 361) and ($diff <= 5040 ) :
66 if($pName['lo_bound_c']&&$pName['hi_bound_c']) $txt.=htmlspecialchars($pName['hi_bound_c'])."<p><br>".htmlspecialchars($pName['lo_bound_c']);
67 break;
68 case $diff > 5040 :
69 if($patient['sex']=='m')
70 if($pName['lo_bound']&&$pName['hi_bound']) $txt.=htmlspecialchars($pName['hi_bound'])."<p><br>".htmlspecialchars($pName['lo_bound']);
71 elseif($patient['sex']=='f')
72 if($pName['lo_bound_f']&&$pName['hi_bound_f']) $txt.=htmlspecialchars($pName['hi_bound_f'])."<p><br>".htmlspecialchars($pName['lo_bound_f']);
73 break;
75 return $txt;
78 //gjergji
79 //draw the graphs
80 function doGraph($paramValue,$pName,$valueBuff,$cols=1){
81 global $patient,$root_path,$sid,$lang,$sessbuf;
82 $txt = '';
83 $diff = dateDiff("-", date("Y-m-d"), $patient['date_birth']);
84 switch ($diff) {
85 case ( ($diff >= 1) and ($diff <= 30 ) ) :
86 echo $txt.'<img src="'.$root_path.'main/imgcreator/labor-datacurve.php?sid='.$sid.'&lang='.$lang.'&cols='.$cols.'&lo='.$pName['lo_bound_n'].'&hi='.$pName['hi_bound_n'].'&d='.$valueBuff.'" border=0>';
87 break;
88 case ( ($diff >= 31) and ($diff <= 360 ) ) :
89 echo $txt.'<img src="'.$root_path.'main/imgcreator/labor-datacurve.php?sid='.$sid.'&lang='.$lang.'&cols='.$cols.'&lo='.$pName['lo_bound_y'].'&hi='.$pName['hi_bound_y'].'&d='.$valueBuff.'" border=0>';
90 break;
91 case ( $diff >= 361) and ($diff <= 5040 ) :
92 echo $txt.'<img src="'.$root_path.'main/imgcreator/labor-datacurve.php?sid='.$sid.'&lang='.$lang.'&cols='.$cols.'&lo='.$pName['lo_bound_c'].'&hi='.$pName['hi_bound_c'].'&d='.$valueBuff.'" border=0>';
93 break;
94 case $diff > 5040 :
95 if($patient['sex']=='m')
96 echo $txt.'<img src="'.$root_path.'main/imgcreator/labor-datacurve.php?sid='.$sid.'&lang='.$lang.'&cols='.$cols.'&lo='.$pName['lo_bound'].'&hi='.$pName['hi_bound'].'&d='.$valueBuff.'" border=0>';
97 elseif($patient['sex']=='f')
98 echo $txt.'<img src="'.$root_path.'main/imgcreator/labor-datacurve.php?sid='.$sid.'&lang='.$lang.'&cols='.$cols.'&lo='.$pName['lo_bound_f'].'&hi='.$pName['hi_bound_f'].'&d='.$valueBuff.'" border=0>';
99 break;
101 return $txt;
104 require($root_path.'include/inc_labor_param_group.php');
106 if($nostat) $ret=$root_path."modules/laboratory/labor_data_patient_such.php?sid=$sid&lang=$lang&versand=1&keyword=$pn";
107 else $ret=$root_path."modules/nursing/nursing-station-patientdaten.php?sid=$sid&lang=$lang&station=$station&pn=$pn";
109 # Load the date formatter
110 require_once($root_path.'include/inc_date_format_functions.php');
112 $enc_obj->setWhereCondition("encounter_nr='$encounter_nr'");
114 if($encounter=$enc_obj->getBasic4Data($encounter_nr)) {
116 $patient=$encounter->FetchRow();
118 $recs=&$lab_obj->getAllResults($encounter_nr);
120 if ($rows=$lab_obj->LastRecordCount()){
121 # Merge the records to common date key
122 $records=array();
123 $dt=array();
124 while($buffer=$recs->FetchRow()){
125 $records[$buffer['job_id']]=unserialize($buffer['serial_value']);
126 $tdate[$buffer['job_id']]=&$buffer['test_date'];
127 $ttime[$buffer['job_id']]=&$buffer['test_time'];
129 //gjergji :
130 //reverse date from past to current
131 //had to use $tdatePrint for the array_reverse() to work...
132 $tdatePrint = array_reverse($tdate,true);
133 $tdate = array_reverse($tdate);
134 $ttime = array_reverse($ttime);
135 $records = array_reverse($records,true);
136 }else{
137 if($nostat) header("location:".$root_path."modules/laboratory/labor-nodatafound.php?sid=$sid&lang=$lang&patnum=$pn&ln=$result[name]&fn=$result[vorname]&nodoc=labor");
138 else header("location:".$root_path."modules/nursing/nursing-station-patientdaten-nolabreport.php?sid=$sid&lang=$lang&edit=$edit&station=$station&pn=$pn&nodoc=labor&user_origin=$user_origin");
139 exit;
141 }else{
142 echo "<p>".$lab_obj->getLastQuery()."sql$LDDbNoRead";
143 exit;
146 # Start Smarty templating here
148 * LOAD Smarty
150 # Note: it is advisable to load this after the inc_front_chain_lang.php so
151 # that the smarty script can use the user configured template theme
153 require_once($root_path.'gui/smarty_template/smarty_care.class.php');
154 $smarty = new smarty_care('common');
156 # Title in toolbar
157 $smarty->assign('sToolbarTitle',"$LDLabReport - $LDGraph");
159 # href for help button
160 $smarty->assign('pbHelp',"javascript:gethelp('lab_list.php','graph','','','$LDGraph')");
162 # hide return button
163 $smarty->assign('pbBack',FALSE);
165 # href for close button
166 $smarty->assign('breakfile',$breakfile);
168 # Window bar title
169 $smarty->assign('sWindowTitle',"$LDLabReport - $LDGraph");
171 # collect extra javascript code
172 ob_start();
175 <style type="text/css" name="1">
176 .va12_n{font-family:verdana,arial; font-size:12; color:#000099}
177 .a10_b{font-family:arial; font-size:10; color:#000000}
178 .a10_n{font-family:arial; font-size:10; color:#000099}
179 .a12_b{font-family:arial; font-size:12; color:#000000}
180 .j{font-family:verdana; font-size:12; color:#000000}
181 </style>
183 <?php
185 $sTemp = ob_get_contents();
186 ob_end_clean();
188 $smarty->append('JavaScript',$sTemp);
190 # Assign patient basic elements
191 $smarty->assign('LDCaseNr',$LDCaseNr);
192 $smarty->assign('LDLastName',$LDLastName);
193 $smarty->assign('LDName',$LDName);
194 $smarty->assign('LDBday',LDBday);
196 # Assign patient basic data
197 $smarty->assign('encounter_nr',$encounter_nr);
198 $smarty->assign('sLastName',$patient['name_last']);
199 $smarty->assign('sName',$patient['name_first']);
200 $smarty->assign('sBday',formatDate2Local($patient['date_birth'],$date_format));
201 # Buffer page output
203 ob_start();
205 echo '
206 <form action="labor-data-makegraph.php" method="post" name="labdata">
207 <table border=0 cellpadding=0 cellspacing=1 class="frame">';
209 # Get the number of colums
210 $cols=sizeof($tdate);
211 echo'
212 <tr bgcolor="#dd0000" >
213 <td class="va12_n"><font color="#ffffff"> &nbsp;<b>'.$LDParameter.'</b>
214 </td>
215 <td class="j"><font color="#ffffff">&nbsp;<b>'.$LDNormalValue.'</b>&nbsp;</td>
216 <td class="j"><font color="#ffffff">&nbsp;<b>'.$LDMsrUnit.'</b>&nbsp;</td>';
217 while(list($x,$v)=each($tdatePrint))
218 echo '
219 <td class="a12_b"><font color="#ffffff" width="100px">&nbsp;<b>'.formatDate2Local($v,$date_format).'<br> '.$x.'</b>&nbsp;</td>';
220 reset($tdate);
223 echo '</tr>';
224 echo'
225 <tr bgcolor="#ffddee" >
226 <td class="va12_n"><font color="#ffffff">&nbsp;</td>
227 <td class="va12_n"><font color="#ffffff">&nbsp;</td>
228 <td class="j"><font color="#ffffff">&nbsp;</td>';
231 while(list($x,$v)=each($ttime))
232 echo '
233 <td class="a12_b" width="100px"><font color="#0000cc">&nbsp;<b>'.convertTimeToLocal($v).'</b> '.$LDOClock.'&nbsp;</td>';
235 # Reset array
236 reset($ttime);
239 # Prepare the graph values
240 $tparam=explode('~',$HTTP_POST_VARS['params']);
241 //order the values
242 $requestData=array();
243 reset($records);
244 $jIDArray = array();
245 while (list($job_id,$paramgroupvalue)=each($records)) {
246 $jIDArray[] = $job_id;
247 while(list($paramgroup,$paramvalue)=each($paramgroupvalue)) {
248 $ext = substr(stristr($paramgroup, '__'), 2);
249 $requestData[$ext][$paramgroup][$job_id] = $paramvalue;
253 //display the values
254 $class='wardlistrow1';
255 $columns=0;
256 $ptrack=0;
257 $temp = '';
258 while (list($groupId,$paramEnc)=each($requestData)) {
259 $valueBuff = '';
260 $gName = $lab_obj->getGroupName($groupId) ;
261 echo "<tr><td class=\"va12_n\" colspan=\"".($cols + 3)."\"><b>" .$gName->fields['name'] . "</b></td></tr>";
262 while (list($paramId,$encounterNr)=each($paramEnc)) {
263 $pName = $lab_obj->TestParamsDetails($paramId);
264 echo "<tr>";
265 echo "<td class=\"" . $class ."\">" . $pName['name'] . "</td>";
266 echo "<td class=\"" . $class ."\">" . medianValue($paramValue,$pName) . "</td>";
267 echo "<td class=\"" . $class ."\">" . $pName['msr_unit'] . "</td>";
268 for($i=0;$i<count($jIDArray);$i++) {
269 if(array_key_exists($jIDArray[$i],$encounterNr)) {
270 $valueBuff == '' ? ($valueBuff = $encounterNr[$jIDArray[$i]]) : ($valueBuff .= '~' . $encounterNr[$jIDArray[$i]]);
271 $ptrack++;
272 $columns++;
273 } else {
274 $valueBuff == '' ? ($valueBuff = '0') : ($valueBuff .= '~'.'0');
275 $ptrack++;
276 $columns++;
279 if($cols != $columns)
280 echo "<td align=\"right\" colspan=\"". ($cols - $columns) ."\" class=\"" . $class ."\">&nbsp;</td>";
281 echo "<td align=\"right\" colspan=\"". $columns ."\" class=\"" . $class ."\">";
282 echo doGraph($paramValue,$pName,$valueBuff,$columns)."</td>";
283 $valueBuff = '';
284 echo "</tr>";
285 $class=='wardlistrow1' ? $class='wardlistrow2' : $class='wardlistrow1';
286 $columns=0;
289 echo '
290 </table>
291 </form>';
293 $sTemp = ob_get_contents();
294 ob_end_clean();
296 $smarty->assign('sLabResultsGraphTable',$sTemp);
298 $smarty->assign('sClose','<a href="'.$breakfile.'"><img '.createLDImgSrc($root_path,'close2.gif','0','absmiddle').' alt="'.$LDClose.'"></a>');
300 # Assign the include file to main frame template
302 $smarty->assign('sMainBlockIncludeFile','laboratory/chemlab_data_results_graph.tpl');
305 * show Template
307 $smarty->display('common/mainframe.tpl');