bug fix march continued (#1921)
[openemr.git] / interface / forms / CAMOS / rx_print.php
blob46e038a6e7d101274afa830e5ff8f4f4c33c0137
1 <?php
2 require_once('../../globals.php');
3 require_once('../../../library/classes/Prescription.class.php');
4 //practice data
5 $physician_name = '';
6 $practice_fname = '';
7 $practice_lname = '';
8 $practice_title = '';
9 $practice_address = '';
10 $practice_city = '';
11 $practice_state = '';
12 $practice_zip = '';
13 $practice_phone = '';
14 $practice_fax = '';
15 $practice_license = '';
16 $practice_dea = '';
17 //patient data
18 $patient_name = '';
19 $patient_address = '';
20 $patient_city = '';
21 $patient_state = '';
22 $patient_zip = '';
23 $patient_phone = '';
24 $patient_dob = '';
25 $sigline = array();
26 $sigline['plain'] =
27 "<div class='signature'>"
28 . " ______________________________________________<br/>"
29 . "</div>\n";
30 $sigline['embossed'] =
31 "<div class='signature'>"
32 . " _____________________________________________________<br/>"
33 # . "Signature - Valid for three days and in Broward County only."
34 . "Signature"
35 . "</div>\n";
36 $sigline['signed'] =
37 "<div class='sig'>"
38 . "<img src='./sig.jpg'>"
39 . "</div>\n";
40 $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 =?", array($_SESSION['pid']));
41 if ($result = sqlFetchArray($query)) {
42 $patient_name = $result['fname'] . ' ' . $result['lname'];
43 $patient_address = $result['street'];
44 $patient_city = $result['city'];
45 $patient_state = $result['state'];
46 $patient_zip = $result['postal_code'];
47 $patient_phone = $result['phone_home'];
48 $patient_dob = $result['DOB'];
51 //update user information if selected from form
52 if ($_POST['update']) { // OPTION update practice inf
53 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
54 csrfNotVerified();
57 $query = "update users set " .
58 "fname = '" . add_escape_custom($_POST['practice_fname']) . "', " .
59 "lname = '" . add_escape_custom($_POST['practice_lname']) . "', " .
60 "title = '" . add_escape_custom($_POST['practice_title']) . "', " .
61 "street = '" . add_escape_custom($_POST['practice_address']) . "', " .
62 "city = '" . add_escape_custom($_POST['practice_city']) . "', " .
63 "state = '" . add_escape_custom($_POST['practice_state']) . "', " .
64 "zip = '" . add_escape_custom($_POST['practice_zip']) . "', " .
65 "phone = '" . add_escape_custom($_POST['practice_phone']) . "', " .
66 "fax = '" . add_escape_custom($_POST['practice_fax']) . "', " .
67 "federaldrugid = '" . add_escape_custom($_POST['practice_dea']) . "' " .
68 "where id ='" . add_escape_custom($_SESSION['authUserID']) ."'";
69 sqlInsert($query);
72 //get user information
73 $query = sqlStatement("select * from users where id =?", array($_SESSION['authUserID']));
74 if ($result = sqlFetchArray($query)) {
75 $physician_name = $result['fname'] . ' ' . $result['lname'] . ', ' . $result['title'];
76 $practice_fname = $result['fname'];
77 $practice_lname = $result['lname'];
78 $practice_title = $result['title'];
79 $practice_address = $result['street'];
80 $practice_city = $result['city'];
81 $practice_state = $result['state'];
82 $practice_zip = $result['zip'];
83 $practice_phone = $result['phone'];
84 $practice_fax = $result['fax'];
85 $practice_dea = $result['federaldrugid'];
88 if ($_POST['print_pdf'] || $_POST['print_html']) {
89 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
90 csrfNotVerified();
93 $camos_content = array();
94 foreach ($_POST as $key => $val) {
95 if (substr($key, 0, 3) == 'ch_') {
96 $query = sqlStatement("select content from ".mitigateSqlTableUpperCase("form_CAMOS")." where id =?", array(substr($key, 3)));
97 if ($result = sqlFetchArray($query)) {
98 if ($_POST['print_html']) { //do this change to formatting only for html output
99 $content = preg_replace('|\n|', '<br/>', text($result['content']));
100 $content = preg_replace('|<br/><br/>|', '<br/>', $content);
101 } else {
102 $content = $result['content'];
105 array_push($camos_content, $content);
109 if (substr($key, 0, 5) == 'chrx_') {
110 $rx = new Prescription(substr($key, 5));
111 //$content = $rx->drug.' '.$rx->form.' '.$rx->dosage;
112 $content = ''
113 . text($rx->drug) . ' '
114 . text($rx->size) . ''
115 . text($rx->unit_array[$rx->unit]) . '<br/>'
116 . text($rx->quantity). ' '
117 . text($rx->form_array[$rx->form]). '<br/>'
118 . text($rx->dosage) . ' '
119 . text($rx->form_array[$rx->form]). ' '
120 . text($rx->route_array[$rx->route]) . ' '
121 . text($rx->interval_array[$rx->interval]) . '<br/>'
122 . text($rx->note) . '<br/>'
123 . 'refills:' . text($rx->refills) . '';
124 // . $rx->substitute_array[$rx->substitute]. ''
125 // . $rx->per_refill . '';
126 array_push($camos_content, $content);
130 if (!$_GET['letterhead']) { //OPTION print a prescription with css formatting
132 <html>
133 <head>
134 <?php html_header_show();?>
135 <title>
136 <?php echo xlt('CAMOS'); ?>
137 </title>
138 <link rel="stylesheet" type="text/css" href="./rx.css" />
139 </head>
140 <body onload='init()'>
141 <img src='./hline.jpg' id='hline'>
142 <img src='./vline.jpg' id='vline'>
143 <?php
144 if ($camos_content[0]) { //decide if we are printing this rx
146 <?php
147 function topHeaderRx()
149 global $physician_name,$practice_address,$practice_city,$practice_state,$practice_zip,$practice_phone,$practice_fax,$practice_dea;
150 print text($physician_name) . "<br/>\n";
151 print text($practice_address) . "<br/>\n";
152 print text($practice_city) . ", ";
153 print text($practice_state) . " ";
154 print text($practice_zip) . "<br/>\n";
155 print xlt('Voice') . ': ' . text($practice_phone) . ' / ' . xlt('Fax') . ': ' . text($practice_fax) . "<br/>\n";
156 print xlt('DEA') . ': ' . text($practice_dea);
158 function bottomHeaderRx()
160 global $patient_name,$patient_address,$patient_city,$patient_state,$patient_zip,$patient_phone,$patient_dob;
161 print "<span class='mytagname'> " . xlt('Name') . ":</span>\n";
162 print "<span class='mydata'> " . text($patient_name) . " </span>\n";
163 print "<span class='mytagname'> " . xlt('Address') . ": </span>\n";
164 print "<span class='mydata'> " . text($patient_address) . ", " . text($patient_city) . ", " .
165 text($patient_state) . " " . text($patient_zip) . " </span><br/>\n";
166 print "<span class='mytagname'>" . xlt('Phone') . ":</span>\n";
167 print "<span class='mydata'>" . text($patient_phone) . "</span>\n";
168 print "<span class='mytagname'>" . xlt('DOB') . ":</span>\n";
169 print "<span class='mydata'> " . text($patient_dob) . " </span>\n";
170 print "<span class='mytagname'>" . xlt('Date') . ":</span>\n";
171 print "<span class='mydata'>" . date("F d, Y") . "</span><br/><br/>\n";
172 print "<div class='symbol'>" . xlt('Rx') . "</div><br/>\n";
175 <div id='rx1' class='rx' >
176 <div class='topheader'>
177 <?php
178 topHeaderRx();
180 </div>
181 <hr/>
182 <div class='bottomheader'>
183 <?php
184 bottomHeaderRx();
186 </div>
187 <div class='content'>
188 <?php
189 print $camos_content[0];
191 </div>
192 <?php print $sigline[$_GET[sigline]] ?>
193 </div> <!-- end of rx block -->
194 <?php
195 } // end of deciding if we are printing the above rx block
196 else {
197 print "<img src='./xout.jpg' id='rx1'>\n";
200 <?php
202 if ($camos_content[1]) { //decide if we are printing this rx
204 <div id='rx2' class='rx' >
205 <div class='topheader'>
206 <?php
208 topHeaderRx();
210 </div>
211 <hr/>
212 <div class='bottomheader'>
213 <?php
215 bottomHeaderRx();
217 </div>
218 <div class='content'>
219 <?php
221 print $camos_content[1];
223 </div>
224 <?php print $sigline[$_GET[sigline]] ?>
225 </div> <!-- end of rx block -->
226 <?php
227 } // end of deciding if we are printing the above rx block
228 else {
229 print "<img src='./xout.jpg' id='rx2'>\n";
232 <?php
234 if ($camos_content[2]) { //decide if we are printing this rx
236 <div id='rx3' class='rx' >
237 <div class='topheader'>
238 <?php
240 topHeaderRx();
242 </div>
243 <hr/>
244 <div class='bottomheader'>
245 <?php
247 bottomHeaderRx();
249 </div>
250 <div class='content'>
251 <?php
253 print $camos_content[2];
255 </div>
256 <?php print $sigline[$_GET[sigline]] ?>
257 </div> <!-- end of rx block -->
258 <?php
259 } // end of deciding if we are printing the above rx block
260 else {
261 print "<img src='./xout.jpg' id='rx3'>\n";
264 <?php
266 if ($camos_content[3]) { //decide if we are printing this rx
268 <div id='rx4' class='rx' >
269 <div class='topheader'>
270 <?php
272 topHeaderRx();
274 </div>
275 <hr/>
276 <div class='bottomheader'>
277 <?php
279 bottomHeaderRx();
281 </div>
282 <div class='content'>
283 <?php
285 print $camos_content[3];
287 </div>
288 <?php print $sigline[$_GET[sigline]] ?>
289 </div> <!-- end of rx block -->
290 <?php
291 } // end of deciding if we are printing the above rx block
292 else {
293 print "<img src='./xout.jpg' id='rx4'>\n";
296 </body>
297 </html>
298 <?php
299 } //end of printing to rx not letterhead
300 elseif ($_GET['letterhead']) { //OPTION print to letterhead
301 $content = preg_replace('/PATIENTNAME/i', $patient_name, $camos_content[0]);
302 if ($_POST['print_html']) { //print letterhead to html
304 <html>
305 <head>
306 <style>
307 body {
308 font-family: sans-serif;
309 font-weight: normal;
310 font-size: 12pt;
311 background: white;
312 color: black;
314 .paddingdiv {
315 width: 524pt;
316 padding: 0pt;
317 margin-top: 50pt;
319 .navigate {
320 margin-top: 2.5em;
322 @media print {
323 .navigate {
324 display: none;
327 </style>
328 <title><?php echo xlt('Letter'); ?></title>
329 </head>
330 <body>
331 <div class='paddingdiv'>
332 <?php
333 //bold
334 print "<div style='font-weight:bold;'>";
335 print text($physician_name) . "<br/>\n";
336 print text($practice_address) . "<br/>\n";
337 print text($practice_city).', '.text($practice_state).' '.text($practice_zip) . "<br/>\n";
338 print text($practice_phone) . ' (' . xlt('Voice') . ')' . "<br/>\n";
339 print text($practice_phone) . ' ('. xlt('Fax') . ')' . "<br/>\n";
340 print "<br/>\n";
341 print date("l, F jS, Y") . "<br/>\n";
342 print "<br/>\n";
343 print "</div>";
344 //not bold
345 print "<div style='font-size:90%;'>";
346 print $content;
347 print "</div>";
348 //bold
349 print "<div style='font-weight:bold;'>";
350 print "<br/>\n";
351 print "<br/>\n";
352 if ($_GET['signer'] == 'patient') {
353 print "__________________________________________________________________________________" . "<br/>\n";
354 print xlt("Print name, sign and date.") . "<br/>\n";
355 } elseif ($_GET['signer'] == 'doctor') {
356 print xlt('Sincerely,') . "<br/>\n";
357 print "<br/>\n";
358 print "<br/>\n";
359 print text($physician_name) . "<br/>\n";
362 print "</div>";
364 <script language='JavaScript'>
365 var win = top.printLogPrint ? top : opener.top;
366 win.printLogPrint(window);
367 </script>
368 </div>
369 </body>
370 </html>
371 <?php
372 exit;
373 } else { //print letterhead to pdf
374 $pdf = new Cezpdf();
375 $pdf->selectFont('Times-Bold');
376 $pdf->ezSetCmMargins(3, 1, 1, 1);
377 $pdf->ezText($physician_name, 12);
378 $pdf->ezText($practice_address, 12);
379 $pdf->ezText($practice_city.', '.$practice_state.' '.$practice_zip, 12);
380 $pdf->ezText($practice_phone . ' (' . xl('Voice') . ')', 12);
381 $pdf->ezText($practice_phone . ' ('. xl('Fax') . ')', 12);
382 $pdf->ezText('', 12);
383 $pdf->ezText(date("l, F jS, Y"), 12);
384 $pdf->ezText('', 12);
385 $pdf->selectFont('Helvetica');
386 $pdf->ezText($content, 10);
387 $pdf->selectFont('Times-Bold');
388 $pdf->ezText('', 12);
389 $pdf->ezText('', 12);
390 if ($_GET['signer'] == 'patient') {
391 $pdf->ezText("__________________________________________________________________________________", 12);
392 $pdf->ezText(xl("Print name, sign and date."), 12);
393 } elseif ($_GET['signer'] == 'doctor') {
394 $pdf->ezText(xl('Sincerely,'), 12);
395 $pdf->ezText('', 12);
396 $pdf->ezText('', 12);
397 $pdf->ezText($physician_name, 12);
400 $pdf->ezStream();
401 } //end of html vs pdf print
403 } //end of if print
404 else { //OPTION selection of what to print
406 <html>
407 <head>
408 <?php html_header_show();?>
409 <title>
410 <?php echo xlt('CAMOS'); ?>
411 </title>
412 <script type="text/javascript">
413 //below init function just to demonstrate how to do it.
414 //now need to create 'cycle' function triggered by button to go by fours
415 //through selected types of subcategories.
416 //this is to be very very cool.
417 function init() {}
418 function checkall(){
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 = true;
428 function uncheckall(){
429 var f = document.forms[0];
430 var x = f.elements.length;
431 var i;
432 for(i=0;i<x;i++) {
433 if (f.elements[i].type == 'checkbox') {
434 f.elements[i].checked = false;
438 function cycle() {
439 var log = document.getElementById('log');
440 var cboxes = document.getElementById('checkboxes');
441 var cb = cboxes.getElementsByTagName('div');
442 if (cycle_engine(cb,0) == 0) {cycle_engine(cb,1);}
444 function cycle_engine(cb,seed) {
445 //seed determines if we should turn on up to first 4
446 var count_turnon = 0;
447 var count_turnoff = 0;
448 for (var i=0;i<cb.length;i++) {
449 cbc = cb[i].childNodes;
450 if (cbc[2].innerHTML == 'prescriptions') {
451 if (cbc[1].checked == true) {
452 cbc[1].checked = false;
453 count_turnoff++;
454 } else {
455 if ((count_turnoff > 0 || seed == 1) && count_turnon < 4) {
456 cbc[1].checked = true;
457 count_turnon++;
462 return count_turnoff;
465 </script>
466 <link rel="stylesheet" type="text/css" href="./rx.css" />
467 </head>
468 <h1><?php echo xlt('Select CAMOS Entries for Printing'); ?></h1>
469 <form method=POST name='pick_items' target=_new>
470 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
471 <input type=button name=cyclerx value='<?php echo xla('Cycle'); ?>' onClick='cycle()'><br/>
472 <input type='button' value='<?php echo xla('Select All'); ?>' onClick='checkall()'>
473 <input type='button' value='<?php echo xla('Unselect All'); ?>' onClick='uncheckall()'>
475 <?php if ($_GET['letterhead']) { ?>
476 <input type=submit name='print_pdf' value='<?php echo xla('Print (PDF)'); ?>'>
477 <?php } ?>
479 <input type=submit name='print_html' value='<?php echo xla('Print (HTML)'); ?>'>
480 <?php
482 //check if an encounter is set
483 if ($_SESSION['encounter'] == null) {
484 $query = sqlStatement("select x.id as id, x.category, x.subcategory, x.item from " .
485 mitigateSqlTableUpperCase("form_CAMOS")." as x join forms as y on (x.id = y.form_id) " .
486 "where y.pid = ?" .
487 " and y.form_name like 'CAMOS%'" .
488 " and x.activity = 1", array($_SESSION['pid']));
489 } else {
490 $query = sqlStatement("select x.id as id, x.category, x.subcategory, x.item from " .
491 mitigateSqlTableUpperCase("form_CAMOS")." as x join forms as y on (x.id = y.form_id) " .
492 "where y.encounter = ?" .
493 " and y.pid = ?" .
494 " and y.form_name like 'CAMOS%'" .
495 " and x.activity = 1", array($_SESSION['encounter'], $_SESSION['pid']));
498 $results = array();
499 echo "<div id='checkboxes'>\n";
500 $count = 0;
501 while ($result = sqlFetchArray($query)) {
502 $checked = '';
503 if ($result['category'] == 'prescriptions' && $count < 4) {
504 $count++;
505 $checked = 'checked';
508 echo "<div>\n";
509 echo "<input type=checkbox name='ch_" . attr($result['id']) . "' $checked><span>" .
510 text($result['category']) . '</span>:' . text($result['subcategory']) . ':' . text($result['item']) . "<br/>\n";
511 echo "</div>\n";
514 echo "</div>\n";
515 echo "<div id='log'>\n";//temp for debugging
516 echo "</div>\n";
517 //create Prescription object for the purpose of drawing data from the Prescription
518 //table for those who wish to do so
519 $rxarray = Prescription::prescriptions_factory($_SESSION['pid']);
520 //now give a choice of drugs from the Prescription table
521 foreach ($rxarray as $val) {
522 echo "<input type=checkbox name='chrx_" . attr($val->id) . "'>" .
523 text($val->drug) . ':' . text($val->start_date) . "<br/>\n";
527 <?php if ($_GET['letterhead']) { ?>
528 <input type=submit name='print_pdf' value='<?php echo xla('Print (PDF)'); ?>'>
529 <?php } ?>
531 <input type=submit name='print_html' value='<?php echo xla('Print (HTML)'); ?>'>
532 </form>
533 <h1><?php echo xlt('Update User Information'); ?></h1>
534 <form method=POST name='pick_items'>
535 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
536 <table>
537 <tr>
538 <td> <?php echo xlt('First Name'); ?>: </td>
539 <td> <input type=text name=practice_fname value ='<?php echo attr($practice_fname); ?>'> </td>
540 </tr>
541 <tr>
542 <td> <?php echo xlt('Last Name'); ?>: </td>
543 <td> <input type=text name=practice_lname value ='<?php echo attr($practice_lname); ?>'> </td>
544 </tr>
545 <tr>
546 <td> <?php echo xlt('Title'); ?>: </td>
547 <td> <input type=text name=practice_title value ='<?php echo attr($practice_title); ?>'> </td>
548 </tr>
549 <tr>
550 <td> <?php echo xlt('Street Address'); ?>: </td>
551 <td> <input type=text name=practice_address value ='<?php echo attr($practice_address); ?>'> </td>
552 </tr>
553 <tr>
554 <td> <?php echo xlt('City'); ?>: </td>
555 <td> <input type=text name=practice_city value ='<?php echo attr($practice_city); ?>'> </td>
556 </tr>
557 <tr>
558 <td> <?php echo xlt('State'); ?>: </td>
559 <td> <input type=text name=practice_state value ='<?php echo attr($practice_state); ?>'> </td>
560 </tr>
561 <tr>
562 <td> <?php echo xlt('Zip'); ?>: </td>
563 <td> <input type=text name=practice_zip value ='<?php echo attr($practice_zip); ?>'> </td>
564 </tr>
565 <tr>
566 <td> <?php echo xlt('Phone'); ?>: </td>
567 <td> <input type=text name=practice_phone value ='<?php echo attr($practice_phone); ?>'> </td>
568 </tr>
569 <tr>
570 <td> <?php echo xlt('Fax'); ?>: </td>
571 <td> <input type=text name=practice_fax value ='<?php echo attr($practice_fax); ?>'> </td>
572 </tr>
573 <tr>
574 <td> <?php echo xlt('DEA'); ?>: </td>
575 <td> <input type=text name=practice_dea value ='<?php echo attr($practice_dea); ?>'> </td>
576 </tr>
577 </table>
578 <input type=submit name=update value='<?php echo xla('Update'); ?>'>
579 </form>
580 <?php
581 } //end of else statement
583 </body>
584 </html>