Support for optional logging of print actions.
[openemr.git] / interface / forms / CAMOS / rx_print.php
blob15c25ca1faa6be5eb7fa9b3d240fd3c42308b7a0
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 ".mitigateSqlTableUpperCase("form_CAMOS")." where id =" .
88 substr($key,3));
89 if ($result = mysql_fetch_array($query, MYSQL_ASSOC)) {
91 if ($_POST['print_html']) { //do this change to formatting only for html output
92 $content = preg_replace('|\n|','<br/>', text($result['content']));
93 $content = preg_replace('|<br/><br/>|','<br/>', $content);
94 } else {
95 $content = $result['content'];
97 array_push($camos_content,$content);
100 if (substr($key,0,5) == 'chrx_') {
101 $rx = new Prescription(substr($key,5));
102 //$content = $rx->drug.' '.$rx->form.' '.$rx->dosage;
103 $content = ''
104 . text($rx->drug) . ' '
105 . text($rx->size) . ''
106 . text($rx->unit_array[$rx->unit]) . '<br/>'
107 . text($rx->quantity). ' '
108 . text($rx->form_array[$rx->form]). '<br/>'
109 . text($rx->dosage) . ' '
110 . text($rx->form_array[$rx->form]). ' '
111 . text($rx->route_array[$rx->route]) . ' '
112 . text($rx->interval_array[$rx->interval]) . '<br/>'
113 . text($rx->note) . '<br/>'
114 . 'refills:' . $rx->refills . '';
115 // . $rx->substitute_array[$rx->substitute]. ''
116 // . $rx->per_refill . '';
117 array_push($camos_content,$content);
120 if (!$_GET['letterhead']) { //OPTION print a prescription with css formatting
122 <html>
123 <head>
124 <?php html_header_show();?>
125 <title>
126 <?php xl('CAMOS','e'); ?>
127 </title>
128 <link rel="stylesheet" type="text/css" href="./rx.css" />
129 </head>
130 <body onload='init()'>
131 <img src='./hline.jpg' id='hline'>
132 <img src='./vline.jpg' id='vline'>
133 <?php
134 if ($camos_content[0]) { //decide if we are printing this rx
136 <?php
137 function topHeaderRx() {
138 global $physician_name,$practice_address,$practice_city,$practice_state,$practice_zip,$practice_phone,$practice_fax,$practice_dea;
139 print $physician_name . "<br/>\n";
140 print $practice_address . "<br/>\n";
141 print $practice_city . ", ";
142 print $practice_state . " ";
143 print $practice_zip . "<br/>\n";
144 print xl('Voice') . ': ' . $practice_phone . ' / ' . xl('Fax') . ': ' . $practice_fax . "<br/>\n";
145 print xl('DEA') . ': ' . $practice_dea;
147 function bottomHeaderRx() {
148 global $patient_name,$patient_address,$patient_city,$patient_state,$patient_zip,$patient_phone,$patient_dob;
149 print "<span class='mytagname'> " . xl('Name') . ":</span>\n";
150 print "<span class='mydata'> $patient_name </span>\n";
151 print "<span class='mytagname'> " . xl('Address') . ": </span>\n";
152 print "<span class='mydata'> $patient_address, $patient_city, " .
153 "$patient_state $patient_zip </span><br/>\n";
154 print "<span class='mytagname'>" . xl('Phone') . ":</span>\n";
155 print "<span class='mydata'>$patient_phone</span>\n";
156 print "<span class='mytagname'>" . xl('DOB') . ":</span>\n";
157 print "<span class='mydata'> $patient_dob </span>\n";
158 print "<span class='mytagname'>" . xl('Date') . ":</span>\n";
159 print "<span class='mydata'>" . date("F d, Y") . "</span><br/><br/>\n";
160 print "<div class='symbol'>" . xl('Rx') . "</div><br/>\n";
163 <div id='rx1' class='rx' >
164 <div class='topheader'>
165 <?php
166 topHeaderRx();
168 </div>
169 <hr/>
170 <div class='bottomheader'>
171 <?php
172 bottomHeaderRx();
174 </div>
175 <div class='content'>
176 <?php
177 print $camos_content[0];
179 </div>
180 <?php print $sigline[$_GET[sigline]] ?>
181 </div> <!-- end of rx block -->
182 <?php
183 } // end of deciding if we are printing the above rx block
184 else {
185 print "<img src='./xout.jpg' id='rx1'>\n";
188 <?php
190 if ($camos_content[1]) { //decide if we are printing this rx
192 <div id='rx2' class='rx' >
193 <div class='topheader'>
194 <?php
196 topHeaderRx();
198 </div>
199 <hr/>
200 <div class='bottomheader'>
201 <?php
203 bottomHeaderRx();
205 </div>
206 <div class='content'>
207 <?php
209 print $camos_content[1];
211 </div>
212 <?php print $sigline[$_GET[sigline]] ?>
213 </div> <!-- end of rx block -->
214 <?php
216 } // end of deciding if we are printing the above rx block
217 else {
218 print "<img src='./xout.jpg' id='rx2'>\n";
221 <?php
223 if ($camos_content[2]) { //decide if we are printing this rx
225 <div id='rx3' class='rx' >
226 <div class='topheader'>
227 <?php
229 topHeaderRx();
231 </div>
232 <hr/>
233 <div class='bottomheader'>
234 <?php
236 bottomHeaderRx();
238 </div>
239 <div class='content'>
240 <?php
242 print $camos_content[2];
244 </div>
245 <?php print $sigline[$_GET[sigline]] ?>
246 </div> <!-- end of rx block -->
247 <?php
249 } // end of deciding if we are printing the above rx block
250 else {
251 print "<img src='./xout.jpg' id='rx3'>\n";
254 <?php
256 if ($camos_content[3]) { //decide if we are printing this rx
258 <div id='rx4' class='rx' >
259 <div class='topheader'>
260 <?php
262 topHeaderRx();
264 </div>
265 <hr/>
266 <div class='bottomheader'>
267 <?php
269 bottomHeaderRx();
271 </div>
272 <div class='content'>
273 <?php
275 print $camos_content[3];
277 </div>
278 <?php print $sigline[$_GET[sigline]] ?>
279 </div> <!-- end of rx block -->
280 <?php
282 } // end of deciding if we are printing the above rx block
283 else {
284 print "<img src='./xout.jpg' id='rx4'>\n";
287 </body>
288 </html>
289 <?php
290 }//end of printing to rx not letterhead
291 elseif ($_GET['letterhead']) { //OPTION print to letterhead
292 $content = preg_replace('/PATIENTNAME/i',$patient_name,$camos_content[0]);
293 if($_POST['print_html']) { //print letterhead to html
295 <html>
296 <head>
297 <style>
298 body {
299 font-family: sans-serif;
300 font-weight: normal;
301 font-size: 12pt;
302 background: white;
303 color: black;
305 .paddingdiv {
306 width: 524pt;
307 padding: 0pt;
308 margin-top: 50pt;
310 .navigate {
311 margin-top: 2.5em;
313 @media print {
314 .navigate {
315 display: none;
318 </style>
319 <title><?php xl('Letter','e'); ?></title>
320 </head>
321 <body>
322 <div class='paddingdiv'>
323 <?php
324 //bold
325 print "<div style='font-weight:bold;'>";
326 print $physician_name . "<br/>\n";
327 print $practice_address . "<br/>\n";
328 print $practice_city.', '.$practice_state.' '.$practice_zip . "<br/>\n";
329 print $practice_phone . ' (' . xl('Voice') . ')' . "<br/>\n";
330 print $practice_phone . ' ('. xl('Fax') . ')' . "<br/>\n";
331 print "<br/>\n";
332 print date("l, F jS, Y") . "<br/>\n";
333 print "<br/>\n";
334 print "</div>";
335 //not bold
336 print "<div style='font-size:90%;'>";
337 print $content;
338 print "</div>";
339 //bold
340 print "<div style='font-weight:bold;'>";
341 print "<br/>\n";
342 print "<br/>\n";
343 if ($_GET['signer'] == 'patient') {
344 print "__________________________________________________________________________________" . "<br/>\n";
345 print xl("Print name, sign and date.") . "<br/>\n";
347 elseif ($_GET['signer'] == 'doctor') {
348 print xl('Sincerely,') . "<br/>\n";
349 print "<br/>\n";
350 print "<br/>\n";
351 print $physician_name . "<br/>\n";
353 print "</div>";
355 <script language='JavaScript'>
356 var win = top.printLogPrint ? top : opener.top;
357 win.printLogPrint(window);
358 </script>
359 </div>
360 </body>
361 </html>
362 <?php
363 exit;
365 else { //print letterhead to pdf
366 include_once('../../../library/classes/class.ezpdf.php');
367 $pdf =& new Cezpdf();
368 $pdf->selectFont('../../../library/fonts/Times-Bold');
369 $pdf->ezSetCmMargins(3,1,1,1);
370 $pdf->ezText($physician_name,12);
371 $pdf->ezText($practice_address,12);
372 $pdf->ezText($practice_city.', '.$practice_state.' '.$practice_zip,12);
373 $pdf->ezText($practice_phone . ' (' . xl('Voice') . ')',12);
374 $pdf->ezText($practice_phone . ' ('. xl('Fax') . ')',12);
375 $pdf->ezText('',12);
376 $pdf->ezText(date("l, F jS, Y"),12);
377 $pdf->ezText('',12);
378 $pdf->selectFont('../../../library/fonts/Helvetica');
379 $pdf->ezText($content,10);
380 $pdf->selectFont('../../../library/fonts/Times-Bold');
381 $pdf->ezText('',12);
382 $pdf->ezText('',12);
383 if ($_GET['signer'] == 'patient') {
384 $pdf->ezText("__________________________________________________________________________________",12);
385 $pdf->ezText(xl("Print name, sign and date."),12);
387 elseif ($_GET['signer'] == 'doctor') {
388 $pdf->ezText(xl('Sincerely,'),12);
389 $pdf->ezText('',12);
390 $pdf->ezText('',12);
391 $pdf->ezText($physician_name,12);
393 $pdf->ezStream();
394 } //end of html vs pdf print
396 } //end of if print
397 else { //OPTION selection of what to print
399 <html>
400 <head>
401 <?php html_header_show();?>
402 <title>
403 <?php xl('CAMOS','e'); ?>
404 </title>
405 <script type="text/javascript">
406 //below init function just to demonstrate how to do it.
407 //now need to create 'cycle' function triggered by button to go by fours
408 //through selected types of subcategories.
409 //this is to be very very cool.
410 function init() {}
411 function checkall(){
412 var f = document.forms[0];
413 var x = f.elements.length;
414 var i;
415 for(i=0;i<x;i++) {
416 if (f.elements[i].type == 'checkbox') {
417 f.elements[i].checked = true;
421 function uncheckall(){
422 var f = document.forms[0];
423 var x = f.elements.length;
424 var i;
425 for(i=0;i<x;i++) {
426 if (f.elements[i].type == 'checkbox') {
427 f.elements[i].checked = false;
431 function cycle() {
432 var log = document.getElementById('log');
433 var cboxes = document.getElementById('checkboxes');
434 var cb = cboxes.getElementsByTagName('div');
435 if (cycle_engine(cb,0) == 0) {cycle_engine(cb,1);}
437 function cycle_engine(cb,seed) {
438 //seed determines if we should turn on up to first 4
439 var count_turnon = 0;
440 var count_turnoff = 0;
441 for (var i=0;i<cb.length;i++) {
442 cbc = cb[i].childNodes;
443 if (cbc[2].innerHTML == 'prescriptions') {
444 if (cbc[1].checked == true) {
445 cbc[1].checked = false;
446 count_turnoff++;
447 } else {
448 if ((count_turnoff > 0 || seed == 1) && count_turnon < 4) {
449 cbc[1].checked = true;
450 count_turnon++;
455 return count_turnoff;
458 </script>
459 <link rel="stylesheet" type="text/css" href="./rx.css" />
460 </head>
461 <h1><?php xl('Select CAMOS Entries for Printing','e'); ?></h1>
462 <form method=POST name='pick_items' target=_new>
463 <input type=button name=cyclerx value='<?php xl('Cycle','e'); ?>' onClick='cycle()'><br/>
464 <input type='button' value='<?php xl('Select All','e'); ?>' onClick='checkall()'>
465 <input type='button' value='<?php xl('Unselect All','e'); ?>' onClick='uncheckall()'>
467 <?php if ($_GET['letterhead']) { ?>
468 <input type=submit name='print_pdf' value='<?php xl('Print (PDF)','e'); ?>'>
469 <?php } ?>
471 <input type=submit name='print_html' value='<?php xl('Print (HTML)','e'); ?>'>
472 <?php
474 //check if an encounter is set
475 if ($_SESSION['encounter'] == NULL) {
476 $query = sqlStatement("select x.id as id, x.category, x.subcategory, x.item from " .
477 mitigateSqlTableUpperCase("form_CAMOS")." as x join forms as y on (x.id = y.form_id) " .
478 "where y.pid = " . $_SESSION['pid'] .
479 " and y.form_name like 'CAMOS%'" .
480 " and x.activity = 1");
482 else {
483 $query = sqlStatement("select x.id as id, x.category, x.subcategory, x.item from " .
484 mitigateSqlTableUpperCase("form_CAMOS")." as x join forms as y on (x.id = y.form_id) " .
485 "where y.encounter = " . $_SESSION['encounter'] .
486 " and y.pid = " . $_SESSION['pid'] .
487 " and y.form_name like 'CAMOS%'" .
488 " and x.activity = 1");
490 $results = array();
491 echo "<div id='checkboxes'>\n";
492 $count = 0;
493 while ($result = mysql_fetch_array($query, MYSQL_ASSOC)) {
494 $checked = '';
495 if ($result['category'] == 'prescriptions' && $count < 4) {
496 $count++;
497 $checked = 'checked';
499 echo "<div>\n";
500 echo "<input type=checkbox name='ch_" . $result['id'] . "' $checked><span>" .
501 $result['category'] . '</span>:' . $result['subcategory'] . ':' . $result['item'] . "<br/>\n";
502 echo "</div>\n";
504 echo "</div>\n";
505 echo "<div id='log'>\n";//temp for debugging
506 echo "</div>\n";
507 //create Prescription object for the purpose of drawing data from the Prescription
508 //table for those who wish to do so
509 $rxarray = Prescription::prescriptions_factory($_SESSION['pid']);
510 //now give a choice of drugs from the Prescription table
511 foreach($rxarray as $val) {
512 echo "<input type=checkbox name='chrx_" . $val->id . "'>" .
513 $val->drug . ':' . $val->start_date . "<br/>\n";
517 <?php if ($_GET['letterhead']) { ?>
518 <input type=submit name='print_pdf' value='<?php xl('Print (PDF)','e'); ?>'>
519 <?php } ?>
521 <input type=submit name='print_html' value='<?php xl('Print (HTML)','e'); ?>'>
522 </form>
523 <h1><?php xl('Update User Information','e'); ?></h1>
524 <form method=POST name='pick_items'>
525 <table>
526 <tr>
527 <td> <?php xl('First Name','e'); ?>: </td>
528 <td> <input type=text name=practice_fname value ='<?php echo htmlspecialchars($practice_fname,ENT_QUOTES); ?>'> </td>
529 </tr>
530 <tr>
531 <td> <?php xl('Last Name','e'); ?>: </td>
532 <td> <input type=text name=practice_lname value ='<?php echo htmlspecialchars($practice_lname,ENT_QUOTES); ?>'> </td>
533 </tr>
534 <tr>
535 <td> <?php xl('Title','e'); ?>: </td>
536 <td> <input type=text name=practice_title value ='<?php echo htmlspecialchars($practice_title,ENT_QUOTES); ?>'> </td>
537 </tr>
538 <tr>
539 <td> <?php xl('Street Address','e'); ?>: </td>
540 <td> <input type=text name=practice_address value ='<?php echo htmlspecialchars($practice_address,ENT_QUOTES); ?>'> </td>
541 </tr>
542 <tr>
543 <td> <?php xl('City','e'); ?>: </td>
544 <td> <input type=text name=practice_city value ='<?php echo htmlspecialchars($practice_city,ENT_QUOTES); ?>'> </td>
545 </tr>
546 <tr>
547 <td> <?php xl('State','e'); ?>: </td>
548 <td> <input type=text name=practice_state value ='<?php echo htmlspecialchars($practice_state,ENT_QUOTES); ?>'> </td>
549 </tr>
550 <tr>
551 <td> <?php xl('Zip','e'); ?>: </td>
552 <td> <input type=text name=practice_zip value ='<?php echo htmlspecialchars($practice_zip,ENT_QUOTES); ?>'> </td>
553 </tr>
554 <tr>
555 <td> <?php xl('Phone','e'); ?>: </td>
556 <td> <input type=text name=practice_phone value ='<?php echo htmlspecialchars($practice_phone,ENT_QUOTES); ?>'> </td>
557 </tr>
558 <tr>
559 <td> <?php xl('Fax','e'); ?>: </td>
560 <td> <input type=text name=practice_fax value ='<?php echo htmlspecialchars($practice_fax,ENT_QUOTES); ?>'> </td>
561 </tr>
562 <tr>
563 <td> <?php xl('DEA','e'); ?>: </td>
564 <td> <input type=text name=practice_dea value ='<?php echo htmlspecialchars($practice_dea,ENT_QUOTES); ?>'> </td>
565 </tr>
566 </table>
567 <input type=submit name=update value='<?php xl('Update','e'); ?>'>
568 </form>
569 <?php
570 } //end of else statement
572 </body>
573 </html>