Support for optional logging of print actions.
[openemr.git] / interface / forms / vitals / growthchart / chart.php
blob2657397433995f9bbb93522f7770f0382cf5ae77
1 <?php
3 // be careful with the relative paths here...
5 // Description
6 // Script can create growth charts for following formats:
7 // 1)png image
8 // 2)pdf
9 // 3)html (css for printing)
11 // The png image and pdf require following files in current directory:
12 // 2-20yo_boys_BMI.png
13 // 2-20yo_girls_BMI.png
14 // birth-24mos_boys_HC.png
15 // birth-24mos_girls_HC.png
17 // The html (css for printing) require the following files in current directory
18 // 2-20yo_boys_BMI-1.png
19 // 2-20yo_boys_BMI-2.png
20 // 2-20yo_girls_BMI-1.png
21 // 2-20yo_girls_BMI-2.png
22 // birth-24mos_boys_HC-1.png
23 // birth-24mos_boys_HC-2.png
24 // birth-24mos_girls_HC-1.png
25 // birth-24mos_girls_HC-2.png
26 // bluedot.gif
27 // redbox.gif
28 // reddot.gif
29 // chart.php
30 // page1.css
31 // page2.css
34 include_once ("../../../../interface/globals.php");
35 include_once ($GLOBALS['fileroot']."/library/patient.inc");
36 $chartpath = $GLOBALS['fileroot']."/interface/forms/vitals/growthchart/";
38 $name = "";
39 $pid = $_GET['pid'];
41 if ($pid == "") {
42 // no pid? no graph for you.
43 echo "<p>" . xl('Missing PID.','','',' ') . xl('Please close this window.') . "</p>";
44 exit;
47 $patient_data = "";
48 if (isset($pid) && is_numeric($pid)) {
49 $patient_data = getPatientData($pid, "fname, lname, sex, DATE_FORMAT(DOB,'%Y%m%d') as DOB");
50 $nowAge = getPatientAge($patient_data['DOB']);
51 $dob = $patient_data['DOB'];
52 $name = $patient_data['fname'] ." ".$patient_data['lname'];
55 // The first data point in the DATA set is significant. It tells date
56 // of the currently viewed vitals by the user. We will use this
57 // date to define which chart is displayed on the screen
58 $charttype = "2-20"; // default the chart-type to ages 2-20
59 $datapoints = explode('~', $_GET['data']);
60 if (isset($datapoints) && $datapoints != "") {
61 list($date, $height, $weight, $head_circ) = explode('-', $datapoints[0]);
62 if ($date != "") { $charttype_date = $date; }
63 $tmpAge = getPatientAgeInDays($patient_data['DOB'], $date);
64 // use the birth-24 chart if the age-on-date-of-vitals is 24months or younger
65 if ($tmpAge < (365*2)) { $charttype = "birth"; }
68 if(isset($_GET['chart_type']))
70 $charttype=$_GET['chart_type'];
73 //sort the datapoints
74 rsort($datapoints);
77 // convert to applicable weight units from the globals.php setting
78 function unitsWt($wt) {
79 if (($GLOBALS['units_of_measurement'] == 2) || ($GLOBALS['units_of_measurement'] == 4)) {
80 //convert to metric
81 return (number_format(($wt*0.45359237),2,'.','').xl('kg','',' '));
83 else {
84 //keep US units
85 return $wt.xl('lb','',' ');
89 // convert to applicable weight units from the globals.php setting
90 function unitsDist($dist) {
91 if (($GLOBALS['units_of_measurement'] == 2) || ($GLOBALS['units_of_measurement'] == 4)) {
92 //convert to metric
93 return (number_format(($dist*2.54),2,'.','').xl('cm','',' '));
95 else {
96 //keep US units
97 return $dist.xl('in','',' ');
101 /******************************/
102 /******************************/
103 /******************************/
106 $name_x = 650;
107 $name_y = 50;
108 $name_x1 = 1650;
109 $name_y1 = 60;
111 $ageOffset = 0;
112 $heightOffset = 0;
113 $weightOffset = 0;
115 if ($charttype == 'birth') {
116 // Use birth to 24 months chart
118 $dot_x = 190; //months starts here (pixel)
119 $delta_x = 26.13; //pixels per month - length
120 $dot_y1 = 768; //height starts here - at 15 inches
121 $delta_y1 = 24.92; //pixels per inch - height
122 $dot_y2 = 1170; //weight starts here - at 3 lbs
123 $delta_y2 = 22.16; //pixels per pound - weight
125 $HC_dot_x = 1180; //months starts here for Head circumference chart
126 $HC_delta_x = 26.04; //pixels per month for Head circumference chart
127 $HC_dot_y = 764; //Head circumference starts here - at 11 inches
128 $HC_delta_y = 60.00; //calculated pixels per inch for head circumference
130 $WT_y = 1127; //start here to draw wt and height graph at bottom of Head circumference chart
131 $WT_delta_y = 12.96;
132 $HT_x = 1187; //start here to draw wt and height graph at bottom of Head circumference chart
133 $HT_delta_x = 24.32;
135 if (preg_match('/^male/i', $patient_data['sex'])) {
136 $chart = "birth-24mos_boys_HC.png";
138 // added by BM for CSS html output
139 $chartCss1 = "birth-24mos_boys_HC-1.png";
140 $chartCss2 = "birth-24mos_boys_HC-2.png";
142 elseif (preg_match('/^female/i', $patient_data['sex'])) {
143 $chart = "birth-24mos_girls_HC.png";
145 // added by BM for CSS html output
146 $chartCss1 = "birth-24mos_girls_HC-1.png";
147 $chartCss2 = "birth-24mos_girls_HC-2.png";
150 $ageOffset = 0;
151 $heightOffset = 15; // Substract 15 because the graph starts at 15 inches
152 $weightOffset = 3; // graph starts at 3 lbs
153 $WToffset = 0; //for wt and ht table at bottom half of HC graph
154 $HToffset = 18; // starting inch for wt and ht table at bottom half of HC graph
156 // pixel positions and offsets for data table
157 $datatable_x = 370;
158 $datatable_age_offset = 75;
159 $datatable_weight_offset = 145;
160 $datatable_height_offset = 220;
161 $datatable_hc_offset = 300;
162 $datatable_y = 1052;
163 $datatable_y_increment = 17;
165 // pixel positions and offsets for head-circ data table
166 $datatable2_x = 1360;
167 $datatable2_age_offset = 75;
168 $datatable2_weight_offset = 145;
169 $datatable2_height_offset = 210;
170 $datatable2_hc_offset = 290;
171 $datatable2_y = 1098;
172 $datatable2_y_increment = 18;
174 elseif ($charttype == "2-20") {
175 // current patient age between 2 and 20 years
177 $dot_x = 177;
178 $delta_x = 35.17;
179 $dot_y1 = 945;
180 $delta_y1 = 16.74;
181 $dot_y2 = 1176; //at 14 lbs, 1157 at 20 lbs
182 $delta_y2 = 3.01;
184 $bmi_dot_x = 1135;
185 $bmi_delta_x = 39.89;
186 $bmi_dot_y = 1130;
187 $bmi_delta_y = 37.15;
189 if (preg_match('/^male/i', $patient_data['sex'])) {
190 $chart = "2-20yo_boys_BMI.png";
192 // added by BM for CSS html output
193 $chartCss1 = "2-20yo_boys_BMI-1.png";
194 $chartCss2 = "2-20yo_boys_BMI-2.png";
196 elseif (preg_match('/^female/i', $patient_data['sex'])) {
197 $chart = "2-20yo_girls_BMI.png";
199 // added by BM for CSS html output
200 $chartCss1 = "2-20yo_girls_BMI-1.png";
201 $chartCss2 = "2-20yo_girls_BMI-2.png";
204 $ageOffset = 2;
205 $heightOffset = 30;
206 $weightOffset = 14;
208 // pixel positions and offsets data table
209 $datatable_x = 96;
210 $datatable_age_offset = 84;
211 $datatable_weight_offset = 180;
212 $datatable_height_offset = 270;
213 $datatable_bmi_offset = 360;
214 $datatable_y = 188;
215 $datatable_y_increment = 18;
217 // pixel positions and offsets for BMI data table
218 $datatable2_x = 1071;
219 $datatable2_age_offset = 73;
220 $datatable2_weight_offset = 145;
221 $datatable2_height_offset = 215;
222 $datatable2_bmi_offset = 310;
223 $datatable2_y = 152;
224 $datatable2_y_increment = 17;
227 else {
228 // bad age data? no graph for you.
229 echo "<p>" . xl('Age data is out of range.') . "</p>";
230 exit;
233 /******************************/
234 // Section for the CSS HTML table
235 // this will bypass gd and pdf requirements
236 // to allow internationalization and flexibility
237 // with fonts
239 $cssWidth = 524;
240 $cssHeight = 668;
242 function cssHeader() {
243 global $cssWidth, $cssHeight;
246 <html>
247 <head>
248 <link rel="stylesheet" type="text/css" title="page1" href="page1.css">
249 <link rel="stylesheet" type="text/css" title="page2" href="page2.css">
250 <style>
251 html {
252 padding: 0;
253 margin: 0;
255 body {
256 font-family: sans-serif;
257 font-weight: normal;
258 font-size: 10pt;
259 background: white;
260 color: red;
261 margin: 0;
262 padding: 0;
264 div {
265 padding: 0;
266 margin: 0;
268 div.paddingdiv {
269 width: <?php echo $cssWidth; ?>pt;
270 height: <?php echo $cssHeight; ?>pt;
271 page-break-after: always;
273 div.label {
274 font-size: 7pt;
276 div.DoNotPrint {
277 position: absolute;
278 top: 2pt;
279 left: 200pt;
281 img {
282 margin: 0;
283 padding: 0;
285 img.background {
286 width: <?php echo $cssWidth; ?>pt;
287 height: <?php echo $cssHeight; ?>pt;
289 @media print {
290 div.DoNotPrint {
291 display: none;
294 </style>
295 <SCRIPT LANGUAGE="JavaScript">
296 function FormSetup() {
297 changeStyle('page1')
299 function changeStyle(css_title) {
300 var i, link_tag ;
301 for (i = 0, link_tag = document.getElementsByTagName("link") ; i < link_tag.length ; i++ ) {
302 if ((link_tag[i].rel.indexOf( "stylesheet" ) != -1) && link_tag[i].title) {
303 link_tag[i].disabled = true ;
304 if (link_tag[i].title == css_title) {
305 link_tag[i].disabled = false ;
310 function pagePrint(title) {
311 changeStyle(title);
312 var win = top.printLogPrint ? top : opener.top;
313 win.printLogPrint(window);
315 </SCRIPT>
316 <title><?php xl('Growth Chart','e'); ?></title>
317 </head>
318 <body Onload="FormSetup()">
319 <div class="DoNotPrint">
320 <table>
321 <tr>
322 <td>
323 <input type="button" value="<?php xl('View Page 1','e'); ?>" onclick="javascript:changeStyle('page1')" class="button">
324 <input type="button" value="<?php xl('View Page 2','e'); ?>" onclick="javascript:changeStyle('page2')" class="button">
325 <input type="button" value="<?php xl('Print Page 1','e'); ?>" onclick="javascript:pagePrint('page1')" class="button">
326 <input type="button" value="<?php xl('Print Page 2','e'); ?>" onclick="javascript:pagePrint('page2')" class="button">
327 </td>
328 </tr>
329 </table>
330 </div>
331 <?php
334 function cssFooter() {
336 </body>
337 </html>
338 <?php
341 function cssPage($image1,$image2) {
343 <div class='paddingdiv' id='page1'>
344 <img class='background' src='<?php echo $image1; ?>' />
345 </div>
346 <div class='paddingdiv' id='page2'>
347 <img class='background' src='<?php echo $image2; ?>' />
348 </div>
349 <?php
352 // Convert a point from above settings for gd into a
353 // a format (pt) to use for css html document
354 // return - Array(Xcoord,Ycoord,page)
355 function convertpoint($coord) {
356 global $cssWidth, $cssHeight;
358 //manual offsets to help line up output
359 $Xoffset=-3;
360 $Yoffset=-2;
362 //collect coordinates from input array
363 $Xcoord=$coord[0];
364 $Ycoord=$coord[1];
366 //adjust with offsets
367 $Xcoord = $Xcoord + $Xoffset;
368 $Ycoord = $Ycoord + $Yoffset;
371 if ($Xcoord > 1000) {
372 //on second page so subtract 1000 from x
373 $Xcoord = $Xcoord - 1000;
374 $page = "page2";
376 else {
377 $page = "page1";
380 //calculate conversion to pt (decrease number of decimals)
381 $Xcoord = ($cssWidth*$Xcoord)/1000;
382 $Xcoord = number_format($Xcoord,1,'.','');
383 $Ycoord = ($cssHeight*$Ycoord)/1294;
384 $Ycoord = number_format($Ycoord,1,'.','');
386 //return point
387 return(Array($Xcoord,$Ycoord,$page));
391 if ($_GET['html'] == 1) {
392 //build the html css page if selected
393 cssHeader();
394 cssPage($chartCss1,$chartCss2);
396 //output name
397 $point = convertpoint(Array($name_x,$name_y));
398 echo("<div id='" . $point[2] . "' class='name' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . $name . "</div>\n");
399 $point = convertpoint(Array($name_x1,$name_y1));
400 echo("<div id='" . $point[2] . "' class='name' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . $name . "</div>\n");
402 // counter to limit the number of data points plotted
403 $count = 0;
405 // plot the data points
406 foreach ($datapoints as $data) {
407 list($date, $height, $weight, $head_circ) = explode('-', $data);
408 if ($date == "") { continue; }
410 // only plot if we have both weight and heights. Skip if either is 0.
411 // Rational is only well visit will need both, sick visit only needs weight
412 // for some clinic.
413 if ($weight == 0 || $height == 0 ) { continue; }
415 // get age of patient at this data-point
416 // to get data from function getPatientAgeYMD including $age,$age_in_months, $ageinYMD
417 extract(getPatientAgeYMD($dob, $date));
418 if($charttype=='birth')
420 // for birth style chart, we use the age in months
421 $age=$age_in_months;
423 // exclude data points that do not belong on this chart
424 // for example, a data point for a 18 month old can be excluded
425 // from that patient's 2-20 yr chart
426 $daysold = getPatientAgeInDays($dob, $date);
427 if ($daysold >= (365*2) && $charttype == "birth") { continue; }
428 if ($daysold <= (365*2) && $charttype == "2-20") { continue; }
430 // calculate the x-axis (Age) value
431 $x = $dot_x + $delta_x * ($age - $ageOffset);
433 // Draw Height dot
434 $y1 = $dot_y1 - $delta_y1 * ($height - $heightOffset);
435 $point = convertpoint(Array($x,$y1));
436 echo("<div id='" . $point[2] . "' class='graphic' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'><img src='reddot.gif' /></div>\n");
438 // Draw Weight bullseye
439 $y2 = $dot_y2 - $delta_y2 * ($weight - $weightOffset);
440 $point = convertpoint(Array($x,$y2));
441 echo("<div id='" . $point[2] . "' class='graphic' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'><img src='redbox.gif' /></div>\n");
443 if ($charttype == "birth") {
444 // Draw Head circumference
445 $HC_x = $HC_dot_x + $HC_delta_x * $age;
446 $HC_y = $HC_dot_y - $HC_delta_y * ($head_circ - 11);
447 $point = convertpoint(Array($HC_x,$HC_y));
448 echo("<div id='" . $point[2] . "' class='graphic' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'><img src='bluedot.gif' /></div>\n");
449 // Draw Wt and Ht graph at the bottom half
450 $WT = $WT_y - $WT_delta_y * ($weight - $WToffset);
451 $HT = $HT_x + $HT_delta_x * ($height - $HToffset);
452 $point = convertpoint(Array($HT,$WT));
453 echo("<div id='" . $point[2] . "' class='graphic' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'><img src='reddot.gif' /></div>\n");
455 else if ($charttype == "2-20") {
456 // Draw BMI
457 $bmi = $weight/$height/$height*703;
458 $bmi_x = $bmi_dot_x + $bmi_delta_x * ($age - 2);
459 $bmi_y = $bmi_dot_y - $bmi_delta_y * ($bmi - 10);
460 $point = convertpoint(Array($bmi_x,$bmi_y));
461 echo("<div id='" . $point[2] . "' class='graphic' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'><img src='bluedot.gif' /></div>\n");
464 // fill in data tables
466 $datestr = substr($date,0,4)."/".substr($date,4,2)."/".substr($date,6,2);
468 //birth to 24 mos chart has 8 rows to fill.
469 if ($count < 8 && $charttype == "birth") {
470 $point = convertpoint(Array($datatable_x,$datatable_y));
471 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . $datestr . "</div>\n");
472 $point = convertpoint(Array($datatable_x+$datatable_age_offset,$datatable_y));
473 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . $ageinYMD . "</div>\n");
474 $point = convertpoint(Array($datatable_x+$datatable_weight_offset,$datatable_y));
475 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . unitsWt($weight) . "</div>\n");
476 $point = convertpoint(Array($datatable_x+$datatable_height_offset,$datatable_y));
477 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . unitsDist($height) . "</div>\n");
478 $point = convertpoint(Array($datatable_x+$datatable_hc_offset,$datatable_y));
479 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . unitsDist($head_circ) . "</div>\n");
480 $datatable_y = $datatable_y + $datatable_y_increment; // increment the datatable "row pointer"
483 // 2 to 20 year-old chart has 7 rows to fill.
484 if ($count < 7 && $charttype == "2-20") {
485 $point = convertpoint(Array($datatable_x,$datatable_y));
486 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . $datestr . "</div>\n");
487 $point = convertpoint(Array($datatable_x+$datatable_age_offset,$datatable_y));
488 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . $ageinYMD . "</div>\n");
489 $point = convertpoint(Array($datatable_x+$datatable_weight_offset,$datatable_y));
490 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . unitsWt($weight) . "</div>\n");
491 $point = convertpoint(Array($datatable_x+$datatable_height_offset,$datatable_y));
492 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . unitsDist($height) . "</div>\n");
493 $point = convertpoint(Array($datatable_x+$datatable_bmi_offset,$datatable_y));
494 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . substr($bmi,0,5) . "</div>\n");
495 $datatable_y = $datatable_y + $datatable_y_increment; // increment the datatable "row pointer"
498 // Head Circumference chart has 5 rows to fill in
499 if ($count < 5 && $charttype == "birth") {
500 $point = convertpoint(Array($datatable2_x,$datatable2_y));
501 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . $datestr . "</div>\n");
502 $point = convertpoint(Array($datatable2_x+$datatable2_age_offset,$datatable2_y));
503 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . $ageinYMD . "</div>\n");
504 $point = convertpoint(Array($datatable2_x+$datatable2_weight_offset,$datatable2_y));
505 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . unitsWt($weight) . "</div>\n");
506 $point = convertpoint(Array($datatable2_x+$datatable2_height_offset,$datatable2_y));
507 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . unitsDist($height) . "</div>\n");
508 $point = convertpoint(Array($datatable2_x+$datatable2_hc_offset,$datatable2_y));
509 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . unitsDist($head_circ) . "</div>\n");
510 $datatable2_y = $datatable2_y + $datatable2_y_increment; // increment the datatable2 "row pointer"
513 // BMI chart has 14 rows to fill in.
514 if ($count < 14 && $charttype == "2-20") {
515 $point = convertpoint(Array($datatable2_x,$datatable2_y));
516 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . $datestr . "</div>\n");
517 $point = convertpoint(Array($datatable2_x+$datatable2_age_offset,$datatable2_y));
518 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . $ageinYMD . "</div>\n");
519 $point = convertpoint(Array($datatable2_x+$datatable2_weight_offset,$datatable2_y));
520 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . unitsWt($weight) . "</div>\n");
521 $point = convertpoint(Array($datatable2_x+$datatable2_height_offset,$datatable2_y));
522 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . unitsDist($height) . "</div>\n");
523 $point = convertpoint(Array($datatable2_x+$datatable2_bmi_offset,$datatable2_y));
524 echo("<div id='" . $point[2] . "' class='label' style='position: absolute; top: " . $point[1] . "pt; left: " . $point[0] . "pt;'>" . substr($bmi,0,5) . "</div>\n");
525 $datatable2_y = $datatable2_y + $datatable2_y_increment; // increment the datatable2 "row pointer"
528 $count++;
531 cssFooter();
532 exit;
534 // Done creating CSS HTML output
535 /******************************/
538 // create the graph
539 $im = imagecreatefrompng($chartpath.$chart);
540 $color1 = imagecolorallocate($im, 0, 0, 255); //blue - color scheme imagecolorallocate($im, Red, Green, Blue)
541 $color = imagecolorallocate($im, 255, 51, 51); //red
543 // draw the patient's name
544 imagestring($im, 12, $name_x, $name_y, $name, $color);
545 imagestring($im, 12, $name_x1, $name_y1, $name, $color);
547 // counter to limit the number of data points plotted
548 $count = 0;
550 // plot the data points
551 foreach ($datapoints as $data) {
552 list($date, $height, $weight, $head_circ) = explode('-', $data);
553 if ($date == "") { continue; }
555 // only plot if we have both weight and heights. Skip if either is 0.
556 // Rational is only well visit will need both, sick visit only needs weight
557 // for some clinic.
558 if ($weight == 0 || $height == 0 ) { continue; }
560 // get age of patient at this data-point
561 // to get data from function getPatientAgeYMD including $age, $ageinYMD, $age_in_months
562 extract(getPatientAgeYMD($dob, $date));
563 if($charttype=='birth')
565 // for birth style chart, we use the age in months
566 $age=$age_in_months;
569 // exclude data points that do not belong on this chart
570 // for example, a data point for a 18 month old can be excluded
571 // from that patient's 2-20 yr chart
572 $daysold = getPatientAgeInDays($dob, $date);
573 if ($daysold > (365*2) && $charttype == "birth") { continue; }
574 if ($daysold < (365*2) && $charttype == "2-20") { continue; }
576 // calculate the x-axis (Age) value
577 $x = $dot_x + $delta_x * ($age - $ageOffset);
579 // Draw Height dot
580 $y1 = $dot_y1 - $delta_y1 * ($height - $heightOffset);
581 imagefilledellipse($im, $x, $y1, 10, 10, $color);
583 // Draw Weight bullseye
584 $y2 = $dot_y2 - $delta_y2 * ($weight - $weightOffset);
585 imageellipse($im, $x, $y2, 12, 12, $color); // outter ring
586 imagefilledellipse($im, $x, $y2, 5, 5, $color); //center dot
588 if ($charttype == "birth") {
589 // Draw Head circumference
590 $HC_x = $HC_dot_x + $HC_delta_x * $age;
591 $HC_y = $HC_dot_y - $HC_delta_y * ($head_circ - 11);
592 imagefilledellipse($im, $HC_x, $HC_y, 10, 10, $color1);
593 // Draw Wt and Ht graph at the bottom half
594 $WT = $WT_y - $WT_delta_y * ($weight - $WToffset);
595 $HT = $HT_x + $HT_delta_x * ($height - $HToffset);
596 imagefilledellipse($im, $HT, $WT, 10, 10, $color);
598 else if ($charttype == "2-20") {
599 // Draw BMI
600 $bmi = $weight/$height/$height*703;
601 $bmi_x = $bmi_dot_x + $bmi_delta_x * ($age - 2);
602 $bmi_y = $bmi_dot_y - $bmi_delta_y * ($bmi - 10);
603 imagefilledellipse($im, $bmi_x, $bmi_y, 10, 10, $color1);
606 // fill in data tables
608 $datestr = substr($date,0,4)."/".substr($date,4,2)."/".substr($date,6,2);
610 //birth to 24 mos chart has 8 rows to fill.
611 if ($count < 8 && $charttype == "birth") {
612 imagestring($im, 2, $datatable_x, $datatable_y, $datestr, $color);
613 imagestring($im, 2, ($datatable_x+$datatable_age_offset), $datatable_y, $ageinYMD, $color);
614 imagestring($im, 2, ($datatable_x+$datatable_weight_offset), $datatable_y, unitsWt($weight), $color);
615 imagestring($im, 2, ($datatable_x+$datatable_height_offset), $datatable_y, unitsDist($height), $color);
616 imagestring($im, 2, ($datatable_x+$datatable_hc_offset), $datatable_y, unitsDist($head_circ), $color);
617 $datatable_y = $datatable_y + $datatable_y_increment; // increment the datatable "row pointer"
620 // 2 to 20 year-old chart has 7 rows to fill.
621 if ($count < 7 && $charttype == "2-20") {
622 imagestring($im, 2, $datatable_x, $datatable_y, $datestr, $color);
623 imagestring($im, 2, ($datatable_x+$datatable_age_offset), $datatable_y, $ageinYMD, $color);
624 imagestring($im, 2, ($datatable_x+$datatable_weight_offset), $datatable_y, unitsWt($weight), $color);
625 imagestring($im, 2, ($datatable_x+$datatable_height_offset), $datatable_y, unitsDist($height), $color);
626 imagestring($im, 2, ($datatable_x+$datatable_bmi_offset), $datatable_y, substr($bmi,0,5), $color);
627 $datatable_y = $datatable_y + $datatable_y_increment; // increment the datatable "row pointer"
630 // Head Circumference chart has 5 rows to fill in
631 if ($count < 5 && $charttype == "birth") {
632 imagestring($im, 2, $datatable2_x, $datatable2_y, $datestr, $color);
633 imagestring($im, 2, ($datatable2_x+$datatable2_age_offset), $datatable2_y, $ageinYMD, $color);
634 imagestring($im, 2, ($datatable2_x+$datatable2_weight_offset), $datatable2_y, unitsWt($weight), $color);
635 imagestring($im, 2, ($datatable2_x+$datatable2_height_offset), $datatable2_y, unitsDist($height), $color);
636 imagestring($im, 2, ($datatable2_x+$datatable2_hc_offset), $datatable2_y, unitsDist($head_circ), $color);
637 $datatable2_y = $datatable2_y + $datatable2_y_increment; // increment the datatable2 "row pointer"
640 // BMI chart has 14 rows to fill in.
641 if ($count < 14 && $charttype == "2-20") {
642 imagestring($im, 2, $datatable2_x, $datatable2_y, $datestr, $color);
643 imagestring($im, 2, ($datatable2_x+$datatable2_age_offset), $datatable2_y, $ageinYMD, $color);
644 imagestring($im, 2, ($datatable2_x+$datatable2_weight_offset), $datatable2_y, unitsWt($weight), $color);
645 imagestring($im, 2, ($datatable2_x+$datatable2_height_offset), $datatable2_y, unitsDist($height), $color);
646 imagestring($im, 2, ($datatable2_x+$datatable2_bmi_offset), $datatable2_y, substr($bmi,0,5), $color);
647 $datatable2_y = $datatable2_y + $datatable2_y_increment; // increment the datatable2 "row pointer"
650 $count++;
653 if ($_GET['pdf'] == 1) {
654 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
655 $pdf =& new Cezpdf("LETTER");
656 $pdf->ezSetMargins(0,0,0,0);
658 // we start with one large image, break it into two pages
659 $page1 = imagecreate((imagesx($im)/2),imagesy($im));
660 $page2 = imagecreate((imagesx($im)/2),imagesy($im));
661 imagecopy($page1, $im, 0,0, 0,0,(imagesx($im)/2),imagesy($im));
662 imagecopy($page2, $im, 0,0, (imagesx($im)/2),0,imagesx($im),imagesy($im));
663 imagedestroy($im);
665 // each page is built
666 $tmpfilename = tempnam("/tmp", "oemr");
667 imagepng($page1,$tmpfilename);
668 imagedestroy($page1);
669 $pdf->ezImage($tmpfilename);
670 $pdf->ezNewPage();
671 imagepng($page2,$tmpfilename);
672 imagedestroy($page2);
673 $pdf->ezImage($tmpfilename);
675 // temporary file is removed
676 unlink($tmpfilename);
678 // output the PDF
679 $pdf->ezStream();
681 else {
682 // older style chart that is simply a PNG image
683 header("Content-type: image/png");
684 imagepng($im);
685 imagedestroy($im);