Fixed php open tags
[openemr.git] / interface / forms / CAMOS / rx_print.php
blobe58b1d2bc8379b1adad1861140d2297cdb2c3ef5
1 <?php
2 include_once ('../../globals.php');
3 include_once ('../../../library/sql.inc');
4 include_once ('../../../library/classes/Prescription.class.php');
5 include_once("../../../library/formdata.inc.php");
6 //practice data
7 $physician_name = '';
8 $practice_fname = '';
9 $practice_lname = '';
10 $practice_title = '';
11 $practice_address = '';
12 $practice_city = '';
13 $practice_state = '';
14 $practice_zip = '';
15 $practice_phone = '';
16 $practice_fax = '';
17 $practice_license = '';
18 $practice_dea = '';
19 //patient data
20 $patient_name = '';
21 $patient_address = '';
22 $patient_city = '';
23 $patient_state = '';
24 $patient_zip = '';
25 $patient_phone = '';
26 $patient_dob = '';
27 $sigline = array();
28 $sigline['plain'] =
29 "<div class='signature'>"
30 . " ______________________________________________<br/>"
31 . "</div>\n";
32 $sigline['embossed'] =
33 "<div class='signature'>"
34 . " _____________________________________________________<br/>"
35 # . "Signature - Valid for three days and in Broward County only."
36 . "Signature"
37 . "</div>\n";
38 $sigline['signed'] =
39 "<div class='sig'>"
40 . "<img src='./sig.jpg'>"
41 . "</div>\n";
42 $query = sqlStatement("select fname,lname,street,city,state,postal_code,phone_home,DATE_FORMAT(DOB,'%m/%d/%y') as DOB from patient_data where pid =" . $_SESSION['pid']);
43 if ($result = mysql_fetch_array($query, MYSQL_ASSOC)) {
44 $patient_name = $result['fname'] . ' ' . $result['lname'];
45 $patient_address = $result['street'];
46 $patient_city = $result['city'];
47 $patient_state = $result['state'];
48 $patient_zip = $result['postal_code'];
49 $patient_phone = $result['phone_home'];
50 $patient_dob = $result['DOB'];
52 //update user information if selected from form
53 if ($_POST['update']) { // OPTION update practice inf
54 $query = "update users set " .
55 "fname = '" . formData('practice_fname') . "', " .
56 "lname = '" . formData('practice_lname') . "', " .
57 "title = '" . formData('practice_title') . "', " .
58 "street = '" . formData('practice_address') . "', " .
59 "city = '" . formData('practice_city') . "', " .
60 "state = '" . formData('practice_state') . "', " .
61 "zip = '" . formData('practice_zip') . "', " .
62 "phone = '" . formData('practice_phone') . "', " .
63 "fax = '" . formData('practice_fax') . "', " .
64 "federaldrugid = '" . formData('practice_dea') . "' " .
65 "where id =" . $_SESSION['authUserID'];
66 sqlInsert($query);
68 //get user information
69 $query = sqlStatement("select * from users where id =" . $_SESSION['authUserID']);
70 if ($result = mysql_fetch_array($query, MYSQL_ASSOC)) {
71 $physician_name = $result['fname'] . ' ' . $result['lname'] . ', ' . $result['title'];
72 $practice_fname = $result['fname'];
73 $practice_lname = $result['lname'];
74 $practice_title = $result['title'];
75 $practice_address = $result['street'];
76 $practice_city = $result['city'];
77 $practice_state = $result['state'];
78 $practice_zip = $result['zip'];
79 $practice_phone = $result['phone'];
80 $practice_fax = $result['fax'];
81 $practice_dea = $result['federaldrugid'];
83 if ($_POST['print_pdf'] || $_POST['print_html']) {
84 $camos_content = array();
85 foreach ($_POST as $key => $val) {
86 if (substr($key,0,3) == 'ch_') {
87 $query = sqlStatement("select content from form_CAMOS where id =" .
88 substr($key,3));
89 if ($result = mysql_fetch_array($query, MYSQL_ASSOC)) {
90 if ($_POST['print_html']) { //do this change to formatting only for html output
91 $content = preg_replace('|\n|','<br/>', $result['content']);
92 $content = preg_replace('|<br/><br/>|','<br/>', $content);
93 } else {
94 $content = $result['content'];
96 array_push($camos_content,$content);
99 if (substr($key,0,5) == 'chrx_') {
100 $rx = new Prescription(substr($key,5));
101 //$content = $rx->drug.' '.$rx->form.' '.$rx->dosage;
102 $content = ''
103 . $rx->drug . ' '
104 . $rx->size . ''
105 . $rx->unit_array[$rx->unit] . '<br/>'
106 . $rx->quantity. ' '
107 . $rx->form_array[$rx->form]. '<br/>'
108 . $rx->dosage . ' '
109 . $rx->form_array[$rx->form]. ' '
110 . $rx->route_array[$rx->route] . ' '
111 . $rx->interval_array[$rx->interval] . '<br/>'
112 . 'refills:' . $rx->refills . '';
113 // . $rx->substitute_array[$rx->substitute]. ''
114 // . $rx->per_refill . '';
115 array_push($camos_content,$content);
118 if (!$_GET['letterhead']) { //OPTION print a prescription with css formatting
120 <html>
121 <head>
122 <?php html_header_show();?>
123 <title>
124 <?php xl('CAMOS','e'); ?>
125 </title>
126 <link rel="stylesheet" type="text/css" href="./rx.css" />
127 </head>
128 <body onload='init()'>
129 <img src='./hline.jpg' id='hline'>
130 <img src='./vline.jpg' id='vline'>
131 <?php
132 if ($camos_content[0]) { //decide if we are printing this rx
134 <?php
135 function topHeaderRx() {
136 global $physician_name,$practice_address,$practice_city,$practice_state,$practice_zip,$practice_phone,$practice_fax,$practice_dea;
137 print $physician_name . "<br/>\n";
138 print $practice_address . "<br/>\n";
139 print $practice_city . ", ";
140 print $practice_state . " ";
141 print $practice_zip . "<br/>\n";
142 print xl('Voice') . ': ' . $practice_phone . ' / ' . xl('Fax') . ': ' . $practice_fax . "<br/>\n";
143 print xl('DEA') . ': ' . $practice_dea;
145 function bottomHeaderRx() {
146 global $patient_name,$patient_address,$patient_city,$patient_state,$patient_zip,$patient_phone,$patient_dob;
147 print "<span class='mytagname'> " . xl('Name') . ":</span>\n";
148 print "<span class='mydata'> $patient_name </span>\n";
149 print "<span class='mytagname'> " . xl('Address') . ": </span>\n";
150 print "<span class='mydata'> $patient_address, $patient_city, " .
151 "$patient_state $patient_zip </span><br/>\n";
152 print "<span class='mytagname'>" . xl('Phone') . ":</span>\n";
153 print "<span class='mydata'>$patient_phone</span>\n";
154 print "<span class='mytagname'>" . xl('DOB') . ":</span>\n";
155 print "<span class='mydata'> $patient_dob </span>\n";
156 print "<span class='mytagname'>" . xl('Date') . ":</span>\n";
157 print "<span class='mydata'>" . date("F d, Y") . "</span><br/><br/>\n";
158 print "<div class='symbol'>" . xl('Rx') . "</div><br/>\n";
161 <div id='rx1' class='rx' >
162 <div class='topheader'>
163 <?php
164 topHeaderRx();
166 </div>
167 <hr/>
168 <div class='bottomheader'>
169 <?php
170 bottomHeaderRx();
172 </div>
173 <div class='content'>
174 <?php
175 print $camos_content[0];
177 </div>
178 <?php print $sigline[$_GET[sigline]] ?>
179 </div> <!-- end of rx block -->
180 <?php
181 } // end of deciding if we are printing the above rx block
182 else {
183 print "<img src='./xout.jpg' id='rx1'>\n";
186 <?php
188 if ($camos_content[1]) { //decide if we are printing this rx
190 <div id='rx2' class='rx' >
191 <div class='topheader'>
192 <?php
194 topHeaderRx();
196 </div>
197 <hr/>
198 <div class='bottomheader'>
199 <?php
201 bottomHeaderRx();
203 </div>
204 <div class='content'>
205 <?php
207 print $camos_content[1];
209 </div>
210 <?php print $sigline[$_GET[sigline]] ?>
211 </div> <!-- end of rx block -->
212 <?php
214 } // end of deciding if we are printing the above rx block
215 else {
216 print "<img src='./xout.jpg' id='rx2'>\n";
219 <?php
221 if ($camos_content[2]) { //decide if we are printing this rx
223 <div id='rx3' class='rx' >
224 <div class='topheader'>
225 <?php
227 topHeaderRx();
229 </div>
230 <hr/>
231 <div class='bottomheader'>
232 <?php
234 bottomHeaderRx();
236 </div>
237 <div class='content'>
238 <?php
240 print $camos_content[2];
242 </div>
243 <?php print $sigline[$_GET[sigline]] ?>
244 </div> <!-- end of rx block -->
245 <?php
247 } // end of deciding if we are printing the above rx block
248 else {
249 print "<img src='./xout.jpg' id='rx3'>\n";
252 <?php
254 if ($camos_content[3]) { //decide if we are printing this rx
256 <div id='rx4' class='rx' >
257 <div class='topheader'>
258 <?php
260 topHeaderRx();
262 </div>
263 <hr/>
264 <div class='bottomheader'>
265 <?php
267 bottomHeaderRx();
269 </div>
270 <div class='content'>
271 <?php
273 print $camos_content[3];
275 </div>
276 <?php print $sigline[$_GET[sigline]] ?>
277 </div> <!-- end of rx block -->
278 <?php
280 } // end of deciding if we are printing the above rx block
281 else {
282 print "<img src='./xout.jpg' id='rx4'>\n";
285 </body>
286 </html>
287 <?php
288 }//end of printing to rx not letterhead
289 elseif ($_GET['letterhead']) { //OPTION print to letterhead
290 $content = preg_replace('/PATIENTNAME/i',$patient_name,$camos_content[0]);
291 if($_POST['print_html']) { //print letterhead to html
293 <html>
294 <head>
295 <style>
296 body {
297 font-family: sans-serif;
298 font-weight: normal;
299 font-size: 12pt;
300 background: white;
301 color: black;
303 .paddingdiv {
304 width: 524pt;
305 padding: 0pt;
306 margin-top: 50pt;
308 .navigate {
309 margin-top: 2.5em;
311 @media print {
312 .navigate {
313 display: none;
316 </style>
317 <title><?php xl('Letter','e'); ?></title>
318 </head>
319 <body>
320 <div class='paddingdiv'>
321 <?php
322 //bold
323 print "<div style='font-weight:bold;'>";
324 print $physician_name . "<br/>\n";
325 print $practice_address . "<br/>\n";
326 print $practice_city.', '.$practice_state.' '.$practice_zip . "<br/>\n";
327 print $practice_phone . ' (' . xl('Voice') . ')' . "<br/>\n";
328 print $practice_phone . ' ('. xl('Fax') . ')' . "<br/>\n";
329 print "<br/>\n";
330 print date("l, F jS, Y") . "<br/>\n";
331 print "<br/>\n";
332 print "</div>";
333 //not bold
334 print "<div style='font-size:90%;'>";
335 print $content;
336 print "</div>";
337 //bold
338 print "<div style='font-weight:bold;'>";
339 print "<br/>\n";
340 print "<br/>\n";
341 if ($_GET['signer'] == 'patient') {
342 print "__________________________________________________________________________________" . "<br/>\n";
343 print xl("Print name, sign and date.") . "<br/>\n";
345 elseif ($_GET['signer'] == 'doctor') {
346 print xl('Sincerely,') . "<br/>\n";
347 print "<br/>\n";
348 print "<br/>\n";
349 print $physician_name . "<br/>\n";
351 print "</div>";
353 <script language='JavaScript'>
354 window.print();
355 </script>
356 </div>
357 </body>
358 </html>
359 <?php
360 exit;
362 else { //print letterhead to pdf
363 include_once('../../../library/classes/class.ezpdf.php');
364 $pdf =& new Cezpdf();
365 $pdf->selectFont('../../../library/fonts/Times-Bold');
366 $pdf->ezSetCmMargins(3,1,1,1);
367 $pdf->ezText($physician_name,12);
368 $pdf->ezText($practice_address,12);
369 $pdf->ezText($practice_city.', '.$practice_state.' '.$practice_zip,12);
370 $pdf->ezText($practice_phone . ' (' . xl('Voice') . ')',12);
371 $pdf->ezText($practice_phone . ' ('. xl('Fax') . ')',12);
372 $pdf->ezText('',12);
373 $pdf->ezText(date("l, F jS, Y"),12);
374 $pdf->ezText('',12);
375 $pdf->selectFont('../../../library/fonts/Helvetica');
376 $pdf->ezText($content,10);
377 $pdf->selectFont('../../../library/fonts/Times-Bold');
378 $pdf->ezText('',12);
379 $pdf->ezText('',12);
380 if ($_GET['signer'] == 'patient') {
381 $pdf->ezText("__________________________________________________________________________________",12);
382 $pdf->ezText(xl("Print name, sign and date."),12);
384 elseif ($_GET['signer'] == 'doctor') {
385 $pdf->ezText(xl('Sincerely,'),12);
386 $pdf->ezText('',12);
387 $pdf->ezText('',12);
388 $pdf->ezText($physician_name,12);
390 $pdf->ezStream();
391 } //end of html vs pdf print
393 } //end of if print
394 else { //OPTION selection of what to print
396 <html>
397 <head>
398 <?php html_header_show();?>
399 <title>
400 <?php xl('CAMOS','e'); ?>
401 </title>
402 <script type="text/javascript">
403 //below init function just to demonstrate how to do it.
404 //now need to create 'cycle' function triggered by button to go by fours
405 //through selected types of subcategories.
406 //this is to be very very cool.
407 function init() {}
408 function checkall(){
409 var f = document.forms[0];
410 var x = f.elements.length;
411 var i;
412 for(i=0;i<x;i++) {
413 if (f.elements[i].type == 'checkbox') {
414 f.elements[i].checked = true;
418 function uncheckall(){
419 var f = document.forms[0];
420 var x = f.elements.length;
421 var i;
422 for(i=0;i<x;i++) {
423 if (f.elements[i].type == 'checkbox') {
424 f.elements[i].checked = false;
428 function cycle() {
429 var log = document.getElementById('log');
430 var cboxes = document.getElementById('checkboxes');
431 var cb = cboxes.getElementsByTagName('div');
432 if (cycle_engine(cb,0) == 0) {cycle_engine(cb,1);}
434 function cycle_engine(cb,seed) {
435 //seed determines if we should turn on up to first 4
436 var count_turnon = 0;
437 var count_turnoff = 0;
438 for (var i=0;i<cb.length;i++) {
439 cbc = cb[i].childNodes;
440 if (cbc[2].innerHTML == 'prescriptions') {
441 if (cbc[1].checked == true) {
442 cbc[1].checked = false;
443 count_turnoff++;
444 } else {
445 if ((count_turnoff > 0 || seed == 1) && count_turnon < 4) {
446 cbc[1].checked = true;
447 count_turnon++;
452 return count_turnoff;
455 </script>
456 <link rel="stylesheet" type="text/css" href="./rx.css" />
457 </head>
458 <h1><?php xl('Select CAMOS Entries for Printing','e'); ?></h1>
459 <form method=POST name='pick_items' target=_new>
460 <input type=button name=cyclerx value='<?php xl('Cycle','e'); ?>' onClick='cycle()'><br/>
461 <input type='button' value='<?php xl('Select All','e'); ?>' onClick='checkall()'>
462 <input type='button' value='<?php xl('Unselect All','e'); ?>' onClick='uncheckall()'>
464 <?php if ($_GET['letterhead']) { ?>
465 <input type=submit name='print_pdf' value='<?php xl('Print (PDF)','e'); ?>'>
466 <?php } ?>
468 <input type=submit name='print_html' value='<?php xl('Print (HTML)','e'); ?>'>
469 <?php
471 //check if an encounter is set
472 if ($_SESSION['encounter'] == NULL) {
473 $query = sqlStatement("select x.id as id, x.category, x.subcategory, x.item from " .
474 "form_CAMOS as x join forms as y on (x.id = y.form_id) " .
475 "where y.pid = " . $_SESSION['pid'] .
476 " and y.form_name like 'CAMOS%'" .
477 " and x.activity = 1");
479 else {
480 $query = sqlStatement("select x.id as id, x.category, x.subcategory, x.item from " .
481 "form_CAMOS as x join forms as y on (x.id = y.form_id) " .
482 "where y.encounter = " . $_SESSION['encounter'] .
483 " and y.pid = " . $_SESSION['pid'] .
484 " and y.form_name like 'CAMOS%'" .
485 " and x.activity = 1");
487 $results = array();
488 echo "<div id='checkboxes'>\n";
489 $count = 0;
490 while ($result = mysql_fetch_array($query, MYSQL_ASSOC)) {
491 $checked = '';
492 if ($result['category'] == 'prescriptions' && $count < 4) {
493 $count++;
494 $checked = 'checked';
496 echo "<div>\n";
497 echo "<input type=checkbox name='ch_" . $result['id'] . "' $checked><span>" .
498 $result['category'] . '</span>:' . $result['subcategory'] . ':' . $result['item'] . "<br/>\n";
499 echo "</div>\n";
501 echo "</div>\n";
502 echo "<div id='log'>\n";//temp for debugging
503 echo "</div>\n";
504 //create Prescription object for the purpose of drawing data from the Prescription
505 //table for those who wish to do so
506 $rxarray = Prescription::prescriptions_factory($_SESSION['pid']);
507 //now give a choice of drugs from the Prescription table
508 foreach($rxarray as $val) {
509 echo "<input type=checkbox name='chrx_" . $val->id . "'>" .
510 $val->drug . ':' . $val->start_date . "<br/>\n";
514 <?php if ($_GET['letterhead']) { ?>
515 <input type=submit name='print_pdf' value='<?php xl('Print (PDF)','e'); ?>'>
516 <?php } ?>
518 <input type=submit name='print_html' value='<?php xl('Print (HTML)','e'); ?>'>
519 </form>
520 <h1><?php xl('Update User Information','e'); ?></h1>
521 <form method=POST name='pick_items'>
522 <table>
523 <tr>
524 <td> <?php xl('First Name','e'); ?>: </td>
525 <td> <input type=text name=practice_fname value ='<?php echo htmlspecialchars($practice_fname,ENT_QUOTES); ?>'> </td>
526 </tr>
527 <tr>
528 <td> <?php xl('Last Name','e'); ?>: </td>
529 <td> <input type=text name=practice_lname value ='<?php echo htmlspecialchars($practice_lname,ENT_QUOTES); ?>'> </td>
530 </tr>
531 <tr>
532 <td> <?php xl('Title','e'); ?>: </td>
533 <td> <input type=text name=practice_title value ='<?php echo htmlspecialchars($practice_title,ENT_QUOTES); ?>'> </td>
534 </tr>
535 <tr>
536 <td> <?php xl('Street Address','e'); ?>: </td>
537 <td> <input type=text name=practice_address value ='<?php echo htmlspecialchars($practice_address,ENT_QUOTES); ?>'> </td>
538 </tr>
539 <tr>
540 <td> <?php xl('City','e'); ?>: </td>
541 <td> <input type=text name=practice_city value ='<?php echo htmlspecialchars($practice_city,ENT_QUOTES); ?>'> </td>
542 </tr>
543 <tr>
544 <td> <?php xl('State','e'); ?>: </td>
545 <td> <input type=text name=practice_state value ='<?php echo htmlspecialchars($practice_state,ENT_QUOTES); ?>'> </td>
546 </tr>
547 <tr>
548 <td> <?php xl('Zip','e'); ?>: </td>
549 <td> <input type=text name=practice_zip value ='<?php echo htmlspecialchars($practice_zip,ENT_QUOTES); ?>'> </td>
550 </tr>
551 <tr>
552 <td> <?php xl('Phone','e'); ?>: </td>
553 <td> <input type=text name=practice_phone value ='<?php echo htmlspecialchars($practice_phone,ENT_QUOTES); ?>'> </td>
554 </tr>
555 <tr>
556 <td> <?php xl('Fax','e'); ?>: </td>
557 <td> <input type=text name=practice_fax value ='<?php echo htmlspecialchars($practice_fax,ENT_QUOTES); ?>'> </td>
558 </tr>
559 <tr>
560 <td> <?php xl('DEA','e'); ?>: </td>
561 <td> <input type=text name=practice_dea value ='<?php echo htmlspecialchars($practice_dea,ENT_QUOTES); ?>'> </td>
562 </tr>
563 </table>
564 <input type=submit name=update value='<?php xl('Update','e'); ?>'>
565 </form>
566 <?php
567 } //end of else statement
569 </body>
570 </html>