PageRenderTime 65ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/include/imgcreator/gd_test_request_chemlabor.php

https://github.com/timschofield/2.8
PHP | 553 lines | 380 code | 105 blank | 68 comment | 48 complexity | 818f91aa53bedced78486601a5e1430d MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-2.0
  1. <?php
  2. /*------begin------ This protection code was suggested by Luki R. luki@karet.org ---- */
  3. if (stristr($PHP_SELF, 'inc_test_request_gd_chemlabor.php')) die("<meta http-equiv='refresh' content='0; url=../'>");
  4. /*------end------*/
  5. /**
  6. * CARE2X Integrated Hospital Information System
  7. * GNU General Public License
  8. * Copyright 2002 Elpidio Latorilla
  9. * elpidio@care2x.org,
  10. *
  11. * See the file "copy_notice.txt" for the licence notice
  12. */
  13. /**
  14. * This script works only with the barcode_label_single_large.php
  15. */
  16. /* Load additional language table */
  17. if(file_exists(CARE_BASE .'language/'.$lang.'/lang_'.$lang.'_konsil_'.$subtarget.'.php')) include_once(CARE_BASE .'language/'.$lang.'/lang_'.$lang.'_konsil_'.$subtarget.'.php');
  18. else include_once(CARE_BASE .'language/'.LANG_DEFAULT.'/lang_'.LANG_DEFAULT.'_konsil_'.$subtarget.'.php');
  19. function doBlock()
  20. {
  21. global $sx, $sy, $im, $pink, $black, $top_border, $mark_v_offset,$ewhite;
  22. $width=10;
  23. $height=5;
  24. $ex=$sx+$width;
  25. $ey=$sy+$height+$mark_v_offset;
  26. ImageRectangle($im,$sx,($sy+$mark_v_offset),$ex,($ey),$pink);
  27. ImageFilledRectangle($im,($sx+1),(($sy+$mark_v_offset)+1),($ex-1),($ey-1),$ewhite);
  28. }
  29. function doFilledBlock()
  30. {
  31. global $sx, $sy, $im, $pink, $black, $mark_v_offset;
  32. $width=10;
  33. $height=5;
  34. $ex=$sx+$width;
  35. $ey=$sy+$height+$mark_v_offset;
  36. ImageRectangle($im,$sx,($sy+$mark_v_offset),$ex,($ey),$pink);
  37. ImageFilledRectangle($im,($sx+1),(($sy+$mark_v_offset)+1),($ex-1),($ey-1),$black);
  38. }
  39. function doSyncBlocks()
  40. {
  41. global $w, $h, $hdiv, $vdiv, $im, $black, $top_border;
  42. $width=14;
  43. $height=7;
  44. $x1=$w-($width+1);
  45. $x2=$w-1;
  46. for($i=0,$y1=$top_border; $i<67; $i++, $y1=$y1+$vdiv)
  47. {
  48. ImageFilledRectangle($im,$x1,$y1,$x2,($y1+$height),$black);
  49. }
  50. }
  51. function doTitel($titel,$len=6)
  52. {
  53. global $sx, $sy, $hdiv, $vdiv, $im, $pink, $black, $left_border, $top_border, $mark_v_offset,$ewhite, $dark_pink;
  54. ImageFilledRectangle($im,($sx-$left_border),($sy-3),($sx+($hdiv*$len)-8),($sy+10),$dark_pink);
  55. ImageString($im,2,($sx),($sy-3),$titel,$ewhite);
  56. }
  57. function doWrite($item,$len=6)
  58. {
  59. global $sx, $sy, $hdiv, $vdiv, $im, $pink, $black, $left_border, $top_border, $mark_v_offset,$ewhite, $dark_pink, $bgcolor, $purple;
  60. // ImageFilledRectangle($im,($sx-$left_border),($sy-5),($sx+($hdiv*6)),($sy+5),$bgcolor);
  61. ImageString($im,1,($sx+14),($sy),$item,$purple);
  62. ImageLine($im,($sx-$left_border),($sy+10),($sx+($hdiv*$len)-8),($sy+10),$pink);
  63. }
  64. function doBgColor($len=6)
  65. {
  66. global $sx, $sy, $hdiv, $im, $pink, $left_border, $bgcolor;
  67. ImageFilledRectangle($im,($sx-$left_border),($sy-2),($sx+($hdiv*$len)-8),($sy+10),$bgcolor);
  68. ImageLine($im,($sx-$left_border),($sy+10),($sx+($hdiv*$len)-8),($sy+10),$pink);
  69. }
  70. function showphone()
  71. {
  72. global $sx, $sy, $hdiv, $vdiv, $im, $v_phone;
  73. if($v_phone) ImageCopy($im,$v_phone,($sx-5),($sy-1),0,0,14,10);
  74. }
  75. /**
  76. * Initializations
  77. * Create the image $im and allocate colors
  78. */
  79. $left_border=4; /* The left border for drawing of blocks */
  80. $top_border=24; /* The top border for drawing of blocks */
  81. $mark_v_offset=1; /* Vertical offset of the marking blocks */
  82. /* Load the violet phone icon */
  83. if(file_exists(CARE_BASE .'gui/img/common/default/violet_phone2.png'))
  84. {
  85. $v_phone = ImageCreateFrompng(CARE_BASE .'gui/img/common/default/violet_phone2.png');
  86. }
  87. /* Load the batch nr barcode */
  88. if(file_exists(CARE_BASE .'cache/barcodes/form_'.$batch_nr.'.png'))
  89. {
  90. $fbc = ImageCreateFrompng(CARE_BASE .'cache/barcodes/form_'.$batch_nr.'.png');
  91. }
  92. /* Load the label nr barcode */
  93. if(file_exists(CARE_BASE .'cache/barcodes/lab_'.$batch_nr.'.png'))
  94. {
  95. $lab_bc = ImageCreateFrompng(CARE_BASE .'cache/barcodes/lab_'.$batch_nr.'.png');
  96. }
  97. /* Set dimensions of the form */
  98. $w=745;
  99. $h=1080;
  100. $im=@ ImageCreate($w,$h);
  101. /* Allocate colors used for the form */
  102. $white = ImageColorAllocate ($im, 255,255,255); //white bkgrnd
  103. $blue=ImageColorAllocate($im, 0, 127, 255);
  104. $purple=ImageColorAllocate($im, 186, 124, 237);
  105. $light_violet=ImageColorAllocate($im, 243, 241, 254);
  106. $black = ImageColorAllocate ($im, 000, 000, 000);
  107. $pink=ImageColorAllocate ($im, 255, 206, 206);
  108. $light_pink=ImageColorAllocate ($im, 255, 243, 243);
  109. $dark_pink=ImageColorAllocate ($im, 238, 102, 102);
  110. $red=ImageColorAllocate ($im, 255, 0, 0);
  111. $green=ImageColorAllocate ($im, 0, 255, 0);
  112. $yellow=ImageColorAllocate ($im, 255, 255, 0);
  113. /*calculate the divisions */
  114. $hdiv=(int)$w/42;
  115. $vdiv=(int)$h/81;
  116. /* fill the form with color */
  117. ImageFillToBorder($im,2,2,$blue, $light_pink);
  118. $lab_x1=(int)($w-($label_w))/2;
  119. $lab_y1=(int)($label_h+1);
  120. ImageFilledRectangle($im,($lab_x1-7),1,($lab_x1+$label_w+14),($lab_y1+14),$dark_pink);
  121. /* Copy the patient label into the form */
  122. ImageCopy($im,$label,($lab_x1+4),8,0,0,$label_w,$label_h);
  123. /* Write the info part */
  124. ImageString($im,5,$left_border,15,$LDHospitalName,$dark_pink);
  125. ImageString($im,4,$left_border,30,$LDCentralLab,$dark_pink);
  126. /* Create the synchronizing blocks on the right edge of the form */
  127. doSyncBlocks();
  128. /* Create Room nr box */
  129. ImageRectangle($im,15,80,150,115,$dark_pink);
  130. ImageFilledRectangle($im,16,81,149,114,$ewhite);
  131. ImageString($im,1,19,83,$LDRoomNr,$purple);
  132. ImageString($im,4,22,90,$stored_request['room_nr'],$dark_pink);
  133. /* Create the Sampling time info */
  134. $sx=$left_border; // set start x
  135. $sy=$top_border+($vdiv*10); // set start y column
  136. ImageString($im,1,($sx),($sy-4),$LDSamplingTime,$purple);
  137. $sx+=($hdiv*5); /* advance to right */
  138. ImageString($im,1,($sx),($sy-4),$LDDay,$purple);
  139. $sx+=($hdiv*2); /* advance to right */
  140. ImageString($im,1,($sx),($sy-4),$LDMinutes,$purple);
  141. $sy+=$vdiv; // advance to next row
  142. $sx=$left_border; // set start x
  143. /* Sampling day */
  144. $day_names=(int)$stored_request['sample_weekday'];
  145. if(!$day_names) $day_names=7;
  146. for($i=1;$i<8;$i++)
  147. {
  148. if($day_names==$i)
  149. {
  150. doFilledBlock();
  151. }
  152. else
  153. {
  154. doBlock();
  155. }
  156. ImageString($im,1,($sx+1),($sy-8),$LDShortDay[$i],$dark_pink);
  157. $sx+=$hdiv;
  158. }
  159. /* Sampling time */
  160. list($hour,$quarter_mins)=explode(":",$stored_request['sample_time']);
  161. if($quarter_mins>44)
  162. {
  163. $quarter_mins=45;
  164. }
  165. elseif($quarter_mins>29)
  166. {
  167. $quarter_mins=30;
  168. }
  169. elseif($quarter_mins>14)
  170. {
  171. $quarter_mins=15;
  172. }
  173. else $quarter_mins=0;
  174. /* For the 10's */
  175. if($quarter_mins==15)
  176. {
  177. doFilledBlock();
  178. }
  179. else
  180. {
  181. doBlock();
  182. }
  183. ImageString($im,1,($sx+1),($sy-8),15,$dark_pink);
  184. $sx+=$hdiv; /* advance to right */
  185. /* For the 30's */
  186. if($quarter_mins==30)
  187. {
  188. doFilledBlock();
  189. }
  190. else
  191. {
  192. doBlock();
  193. }
  194. ImageString($im,1,($sx+1),($sy-8),30,$dark_pink);
  195. $sx+=$hdiv; /* advance to right */
  196. /* For the 45's */
  197. if($quarter_mins==45)
  198. {
  199. doFilledBlock();
  200. }
  201. else
  202. {
  203. doBlock();
  204. }
  205. ImageString($im,1,($sx+1),($sy-8),45,$dark_pink);
  206. $sx+=$hdiv; /* advance to right */
  207. $sy+=$vdiv; /* Advance to next row */
  208. $sx=$left_border+$hdiv;
  209. /* 10's hours */
  210. if($hour>19)
  211. {
  212. $hour_tens=20;
  213. $hour_ones=$hour-$hour_tens;
  214. }
  215. elseif($hour>9)
  216. {
  217. $hour_tens=10;
  218. $hour_ones=$hour-$hour_tens;
  219. }
  220. else
  221. {
  222. $hour_ones=$hour;
  223. }
  224. if($hour_tens==10)
  225. {
  226. doFilledBlock();
  227. }
  228. else
  229. {
  230. doBlock();
  231. }
  232. ImageString($im,1,($sx+1),($sy-7),10,$dark_pink);
  233. $sx+=$hdiv; /* advance to right */
  234. if($hour_tens==20)
  235. {
  236. doFilledBlock();
  237. }
  238. else
  239. {
  240. doBlock();
  241. }
  242. ImageString($im,1,($sx+1),($sy-7),20,$dark_pink);
  243. $sx+=($hdiv*5); /* advance to right */
  244. ImageString($im,1,($sx),($sy-4),$LDHours,$purple);
  245. /* 1's hours */
  246. $sy+=$vdiv; /* Advance to next row */
  247. $sx=$left_border;
  248. for($i=0;$i<10;$i++)
  249. {
  250. if($hour_ones==$i)
  251. {
  252. doFilledBlock();
  253. }
  254. else
  255. {
  256. doBlock();
  257. }
  258. ImageString($im,1,($sx+1),($sy-7),$i,$dark_pink);
  259. $sx+=$hdiv; /* advance to right */
  260. }
  261. /*Urgent*/
  262. $sy+=$vdiv; /* Advance to next row */
  263. $sx=$left_border;
  264. ImageString($im,1,($sx),($sy),$LDUrgent,$purple);
  265. $sx=$left_border+($hdiv*4);
  266. $urgent = $stored_request['urgent'];
  267. if($urgent == '1') {
  268. doFilledBlock();
  269. } else {
  270. doBlock();
  271. }
  272. /* end urgent */
  273. /* Write batch nr */
  274. $sy+=$vdiv; /* Advance to next row */
  275. $sx=$left_border;
  276. ImageString($im,1,($sx),($sy),$LDBatchNr,$purple);
  277. $sx=$left_border+($hdiv*4);
  278. ImageString($im,2,($sx),($sy),$stored_request['batch_nr'],$purple);
  279. /* Create the batch nr code */
  280. $sy=$top_border+($vdiv*14);
  281. /* Added because i fave add a row for the urgent marker */
  282. $sy+=$vdiv; /* Advance to next row */
  283. for($i=0,$sx=($left_border+($hdiv*10));$i<30; $i++, $sx=$sx+$hdiv)
  284. {
  285. doBlock();
  286. }
  287. /* Create initialization markers */
  288. $sy=$top_border+$vdiv;
  289. $sx=$left_border+($hdiv*30);
  290. doBlock();
  291. $sx=$left_border+($hdiv*33);
  292. doFilledBlock();
  293. $sx=$left_border+($hdiv*34);
  294. doFilledBlock();
  295. $sx=$left_border+($hdiv*39);
  296. doFilledBlock();
  297. $sx=$left_border+($hdiv*40);
  298. doFilledBlock();
  299. /* Create the case number markers */
  300. $sy=$top_border+$vdiv;
  301. for($n=0;$n<8;$n++)
  302. {
  303. $sy+=$vdiv;
  304. for($i=0,$sx=($left_border+($hdiv*30));$i<10;$i++,$sx=$sx+$hdiv)
  305. {
  306. ImageString($im,1,($sx+3),($sy-6),$i,$dark_pink);
  307. if(substr($fen,$n,1)==$i) doFilledBlock();
  308. else doBlock();
  309. }
  310. }
  311. /* Place the form batch nr barcode */
  312. $sx=$left_border+($hdiv*37);
  313. $sy=$top_border+($vdiv*11)-10;
  314. ImageString($im,2,($sx),($sy),$stored_request['batch_nr'],$purple);
  315. $sx=$left_border+($hdiv*32);
  316. $sy+=$vdiv;
  317. /* Copy the batch nr barcode into the form */
  318. if($fbc) ImageCopy($im,$fbc,$sx,$sy,6,7,139,28);
  319. /* Now Create the form elements */
  320. //$tdcount=0; /* $tdcount limits the number of columns (7) for test elements */
  321. $sy=$top_border+($vdiv*16); /* Set the first row's y-dim */
  322. // $tdcount=0;
  323. $sx=$left_border;
  324. for($i=0;$i<=$max_row;$i++) {
  325. if($i>$max_row) $len=5; else $len=6;
  326. for($j=0;$j<=$column;$j++) {
  327. /* write the param group */
  328. if($LD_Elements[$j][$i]['type']=='top') {
  329. doTitel($LD_Elements[$j][$i]['value'],$len);
  330. $sx+=($hdiv*$len); /* Move to next column */
  331. } else {
  332. /* Write the item */
  333. doWrite($LD_Elements[$j][$i]['value'],$len);
  334. if( $stored_param[$LD_Elements[$j][$i]['id']] == 1) {
  335. doFilledBlock();
  336. } else {
  337. doBlock();
  338. }
  339. $sx+=($hdiv*$len); /* Move to next column */
  340. }
  341. }
  342. $sy+=$vdiv; /* Adjust to next row */
  343. $sx=$left_border;
  344. }
  345. /* Create the lower boxes for the doctor's sign, etc. */
  346. $sx=1;
  347. $sy=$top_border+($vdiv*66);
  348. ImageRectangle($im,$sx,($sy+10),($sx+($hdiv*16)),($sy+($vdiv*2.5)),$dark_pink);
  349. ImageRectangle($im,($sx+($hdiv*17)),($sy+10),($sx+($hdiv*40)),($sy+($vdiv*2.5)),$dark_pink);
  350. /* Convert any possible html special chars to normal chars and print the text */
  351. $translation_table= array_flip(get_html_translation_table(HTML_SPECIALCHARS));
  352. ImageString($im,2,($sx+$left_border),($sy+15),strtr($stored_request['doctor_sign'],$translation_table),$dark_pink);
  353. ImageString($im,2,($sx+($hdiv*17)+4),($sy+15),strtr($stored_request['notes'],$translation_table),$dark_pink);
  354. /* Write the notices below */
  355. $sy=$top_border+($vdiv*68)+8;
  356. ImageString($im,3,($sx+$left_border),($sy),$LDEmergencyProgram,$purple);
  357. $sx=($sx+($hdiv*26));
  358. $sy=$top_border+($vdiv*68)+11;
  359. showPhone();
  360. $sy=$top_border+($vdiv*68)+8;
  361. ImageString($im,3,($sx+10),($sy),$LDPhoneOrder,$purple);
  362. /* Create white background */
  363. $sy=$top_border+($vdiv*70);
  364. ImageFilledRectangle($im,1,$sy,($w-2),($h-2),$white);
  365. /* Create the bloodsugar & glucose label barcodes */
  366. $sx=$left_border+$hdiv;
  367. $sy=$top_border+($vdiv*73)-4;
  368. /* Copy the lab barcode into the form */
  369. for($i=0;$i<6;$i++)
  370. {
  371. ImageCopy($im,$lab_bc,$sx,$sy,38,16,73,25);
  372. if($i==2)
  373. {
  374. $sx=$left_border+$hdiv;
  375. $sy=$top_border+($vdiv*77)-4;
  376. }
  377. else
  378. {
  379. $sx+=($hdiv*5);
  380. }
  381. }
  382. $sy=$top_border+($vdiv*72);
  383. /* Write the horizontal batch nr.s */
  384. $sugar=array('',$LDSober,$LD9Hour,$LD15Hour,$LDBloodPlasma,$LDBloodSugar,$LDBloodSugar1);
  385. for($i=3,$n=1;$i<16;$i+=5,$n++)
  386. {
  387. $sx=$left_border+($hdiv*$i)-10;
  388. ImageString($im,2,($sx-13),($sy-6),$stored_request['batch_nr'],$black);
  389. ImageString($im,1,($sx-$hdiv),($sy-$vdiv),$n,$dark_pink);
  390. ImageString($im,1,($sx),($sy-$vdiv),$sugar[$n],$dark_pink);
  391. ImageStringUp($im,1,($sx+($hdiv*3)-3),($sy+($vdiv*2)+6),$LDGlucose.' '.$n,$dark_pink);
  392. if($n==3)
  393. {
  394. $i=(-2);
  395. $sy+=($vdiv*4);
  396. }
  397. }
  398. /* Create the RGY vertical bars*/
  399. // red
  400. $sx=$left_border+($hdiv*22);
  401. $sy=$top_border+($vdiv*70);
  402. ImageFilledRectangle($im,$sx,($sy+10),($sx+10),($sy+($vdiv*5)-6),$red);
  403. ImageStringUp($im,1,($sx-15),($sy+($vdiv*5)-6),$LDHematology,$dark_pink);
  404. // green
  405. $sx=$left_border+($hdiv*28);
  406. ImageFilledRectangle($im,$sx,($sy+10),($sx+10),($sy+($vdiv*5)-6),$green);
  407. ImageStringUp($im,1,($sx-15),($sy+($vdiv*5)-6),$LDCoagulation,$dark_pink);
  408. // yellow
  409. $sx=$left_border+($hdiv*34);
  410. ImageFilledRectangle($im,$sx,($sy+10),($sx+10),($sy+($vdiv*5)-6),$yellow);
  411. ImageStringUp($im,1,($sx-15),($sy+($vdiv*5)-6),$LDUrine,$dark_pink);
  412. // white
  413. $sx=$left_border+($hdiv*40);
  414. ImageFilledRectangle($im,$sx,($sy+10),($sx+10),($sy+($vdiv*5)-6),$white);
  415. ImageStringUp($im,1,($sx-15),($sy+($vdiv*5)-6),$LDSerum,$dark_pink);
  416. /* Write the vertical batch nr.s */
  417. for($i=23,$n=0;$i<42;$i+=6,$n++)
  418. {
  419. $sx=$left_border+($hdiv*$i)-10;
  420. ImageStringUp($im,2,($sx-13),($sy+($vdiv*5)-6),$stored_request['batch_nr'],$black);
  421. if($n==3)
  422. {
  423. $i=17;
  424. $sy+=($vdiv*4);
  425. }
  426. if($n>2) ImageStringUp($im,1,($sx-22),($sy+($vdiv*5)-6),$LDSerum,$dark_pink);
  427. }
  428. /* Create the Urin,Serum,etc. label barcodes */
  429. $sx=$left_border+($hdiv*17);
  430. $sy=$top_border+($vdiv*72);
  431. /* Copy the lab barcode into the form */
  432. for($i=0;$i<8;$i++)
  433. {
  434. ImageCopy($im,$lab_bc,$sx,$sy,38,16,73,41);
  435. if($i==3)
  436. {
  437. $sx=$left_border+($hdiv*17);
  438. $sy=$top_border+($vdiv*76);
  439. }
  440. else
  441. {
  442. $sx+=($hdiv*6);
  443. }
  444. }
  445. /* Output the image form */
  446. Imagepng($im);
  447. ImageDestroy($im);
  448. ?>