Highway to PSR2
[openemr.git] / interface / forms / CAMOS / rx_print.php
blob84deabe4419ba8ca4a226b5f0c29cb7e80ea6013
1 <?php
2 include_once('../../globals.php');
3 include_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 =" . $_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 $query = "update users set " .
54 "fname = '" . formData('practice_fname') . "', " .
55 "lname = '" . formData('practice_lname') . "', " .
56 "title = '" . formData('practice_title') . "', " .
57 "street = '" . formData('practice_address') . "', " .
58 "city = '" . formData('practice_city') . "', " .
59 "state = '" . formData('practice_state') . "', " .
60 "zip = '" . formData('practice_zip') . "', " .
61 "phone = '" . formData('practice_phone') . "', " .
62 "fax = '" . formData('practice_fax') . "', " .
63 "federaldrugid = '" . formData('practice_dea') . "' " .
64 "where id =" . $_SESSION['authUserID'];
65 sqlInsert($query);
68 //get user information
69 $query = sqlStatement("select * from users where id =" . $_SESSION['authUserID']);
70 if ($result = sqlFetchArray($query)) {
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'];
84 if ($_POST['print_pdf'] || $_POST['print_html']) {
85 $camos_content = array();
86 foreach ($_POST as $key => $val) {
87 if (substr($key, 0, 3) == 'ch_') {
88 $query = sqlStatement("select content from ".mitigateSqlTableUpperCase("form_CAMOS")." where id =" .
89 substr($key, 3));
90 if ($result = sqlFetchArray($query)) {
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'];
98 array_push($camos_content, $content);
102 if (substr($key, 0, 5) == 'chrx_') {
103 $rx = new Prescription(substr($key, 5));
104 //$content = $rx->drug.' '.$rx->form.' '.$rx->dosage;
105 $content = ''
106 . text($rx->drug) . ' '
107 . text($rx->size) . ''
108 . text($rx->unit_array[$rx->unit]) . '<br/>'
109 . text($rx->quantity). ' '
110 . text($rx->form_array[$rx->form]). '<br/>'
111 . text($rx->dosage) . ' '
112 . text($rx->form_array[$rx->form]). ' '
113 . text($rx->route_array[$rx->route]) . ' '
114 . text($rx->interval_array[$rx->interval]) . '<br/>'
115 . text($rx->note) . '<br/>'
116 . 'refills:' . $rx->refills . '';
117 // . $rx->substitute_array[$rx->substitute]. ''
118 // . $rx->per_refill . '';
119 array_push($camos_content, $content);
123 if (!$_GET['letterhead']) { //OPTION print a prescription with css formatting
125 <html>
126 <head>
127 <?php html_header_show();?>
128 <title>
129 <?php xl('CAMOS', 'e'); ?>
130 </title>
131 <link rel="stylesheet" type="text/css" href="./rx.css" />
132 </head>
133 <body onload='init()'>
134 <img src='./hline.jpg' id='hline'>
135 <img src='./vline.jpg' id='vline'>
136 <?php
137 if ($camos_content[0]) { //decide if we are printing this rx
139 <?php
140 function topHeaderRx()
142 global $physician_name,$practice_address,$practice_city,$practice_state,$practice_zip,$practice_phone,$practice_fax,$practice_dea;
143 print $physician_name . "<br/>\n";
144 print $practice_address . "<br/>\n";
145 print $practice_city . ", ";
146 print $practice_state . " ";
147 print $practice_zip . "<br/>\n";
148 print xl('Voice') . ': ' . $practice_phone . ' / ' . xl('Fax') . ': ' . $practice_fax . "<br/>\n";
149 print xl('DEA') . ': ' . $practice_dea;
151 function bottomHeaderRx()
153 global $patient_name,$patient_address,$patient_city,$patient_state,$patient_zip,$patient_phone,$patient_dob;
154 print "<span class='mytagname'> " . xl('Name') . ":</span>\n";
155 print "<span class='mydata'> $patient_name </span>\n";
156 print "<span class='mytagname'> " . xl('Address') . ": </span>\n";
157 print "<span class='mydata'> $patient_address, $patient_city, " .
158 "$patient_state $patient_zip </span><br/>\n";
159 print "<span class='mytagname'>" . xl('Phone') . ":</span>\n";
160 print "<span class='mydata'>$patient_phone</span>\n";
161 print "<span class='mytagname'>" . xl('DOB') . ":</span>\n";
162 print "<span class='mydata'> $patient_dob </span>\n";
163 print "<span class='mytagname'>" . xl('Date') . ":</span>\n";
164 print "<span class='mydata'>" . date("F d, Y") . "</span><br/><br/>\n";
165 print "<div class='symbol'>" . xl('Rx') . "</div><br/>\n";
168 <div id='rx1' class='rx' >
169 <div class='topheader'>
170 <?php
171 topHeaderRx();
173 </div>
174 <hr/>
175 <div class='bottomheader'>
176 <?php
177 bottomHeaderRx();
179 </div>
180 <div class='content'>
181 <?php
182 print $camos_content[0];
184 </div>
185 <?php print $sigline[$_GET[sigline]] ?>
186 </div> <!-- end of rx block -->
187 <?php
188 } // end of deciding if we are printing the above rx block
189 else {
190 print "<img src='./xout.jpg' id='rx1'>\n";
193 <?php
195 if ($camos_content[1]) { //decide if we are printing this rx
197 <div id='rx2' class='rx' >
198 <div class='topheader'>
199 <?php
201 topHeaderRx();
203 </div>
204 <hr/>
205 <div class='bottomheader'>
206 <?php
208 bottomHeaderRx();
210 </div>
211 <div class='content'>
212 <?php
214 print $camos_content[1];
216 </div>
217 <?php print $sigline[$_GET[sigline]] ?>
218 </div> <!-- end of rx block -->
219 <?php
220 } // end of deciding if we are printing the above rx block
221 else {
222 print "<img src='./xout.jpg' id='rx2'>\n";
225 <?php
227 if ($camos_content[2]) { //decide if we are printing this rx
229 <div id='rx3' class='rx' >
230 <div class='topheader'>
231 <?php
233 topHeaderRx();
235 </div>
236 <hr/>
237 <div class='bottomheader'>
238 <?php
240 bottomHeaderRx();
242 </div>
243 <div class='content'>
244 <?php
246 print $camos_content[2];
248 </div>
249 <?php print $sigline[$_GET[sigline]] ?>
250 </div> <!-- end of rx block -->
251 <?php
252 } // end of deciding if we are printing the above rx block
253 else {
254 print "<img src='./xout.jpg' id='rx3'>\n";
257 <?php
259 if ($camos_content[3]) { //decide if we are printing this rx
261 <div id='rx4' class='rx' >
262 <div class='topheader'>
263 <?php
265 topHeaderRx();
267 </div>
268 <hr/>
269 <div class='bottomheader'>
270 <?php
272 bottomHeaderRx();
274 </div>
275 <div class='content'>
276 <?php
278 print $camos_content[3];
280 </div>
281 <?php print $sigline[$_GET[sigline]] ?>
282 </div> <!-- end of rx block -->
283 <?php
284 } // end of deciding if we are printing the above rx block
285 else {
286 print "<img src='./xout.jpg' id='rx4'>\n";
289 </body>
290 </html>
291 <?php
292 } //end of printing to rx not letterhead
293 elseif ($_GET['letterhead']) { //OPTION print to letterhead
294 $content = preg_replace('/PATIENTNAME/i', $patient_name, $camos_content[0]);
295 if ($_POST['print_html']) { //print letterhead to html
297 <html>
298 <head>
299 <style>
300 body {
301 font-family: sans-serif;
302 font-weight: normal;
303 font-size: 12pt;
304 background: white;
305 color: black;
307 .paddingdiv {
308 width: 524pt;
309 padding: 0pt;
310 margin-top: 50pt;
312 .navigate {
313 margin-top: 2.5em;
315 @media print {
316 .navigate {
317 display: none;
320 </style>
321 <title><?php xl('Letter', 'e'); ?></title>
322 </head>
323 <body>
324 <div class='paddingdiv'>
325 <?php
326 //bold
327 print "<div style='font-weight:bold;'>";
328 print $physician_name . "<br/>\n";
329 print $practice_address . "<br/>\n";
330 print $practice_city.', '.$practice_state.' '.$practice_zip . "<br/>\n";
331 print $practice_phone . ' (' . xl('Voice') . ')' . "<br/>\n";
332 print $practice_phone . ' ('. xl('Fax') . ')' . "<br/>\n";
333 print "<br/>\n";
334 print date("l, F jS, Y") . "<br/>\n";
335 print "<br/>\n";
336 print "</div>";
337 //not bold
338 print "<div style='font-size:90%;'>";
339 print $content;
340 print "</div>";
341 //bold
342 print "<div style='font-weight:bold;'>";
343 print "<br/>\n";
344 print "<br/>\n";
345 if ($_GET['signer'] == 'patient') {
346 print "__________________________________________________________________________________" . "<br/>\n";
347 print xl("Print name, sign and date.") . "<br/>\n";
348 } elseif ($_GET['signer'] == 'doctor') {
349 print xl('Sincerely,') . "<br/>\n";
350 print "<br/>\n";
351 print "<br/>\n";
352 print $physician_name . "<br/>\n";
355 print "</div>";
357 <script language='JavaScript'>
358 var win = top.printLogPrint ? top : opener.top;
359 win.printLogPrint(window);
360 </script>
361 </div>
362 </body>
363 </html>
364 <?php
365 exit;
366 } else { //print letterhead to pdf
367 $pdf = new Cezpdf();
368 $pdf->selectFont('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('Helvetica');
379 $pdf->ezText($content, 10);
380 $pdf->selectFont('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);
386 } elseif ($_GET['signer'] == 'doctor') {
387 $pdf->ezText(xl('Sincerely,'), 12);
388 $pdf->ezText('', 12);
389 $pdf->ezText('', 12);
390 $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");
481 } else {
482 $query = sqlStatement("select x.id as id, x.category, x.subcategory, x.item from " .
483 mitigateSqlTableUpperCase("form_CAMOS")." as x join forms as y on (x.id = y.form_id) " .
484 "where y.encounter = " . $_SESSION['encounter'] .
485 " and y.pid = " . $_SESSION['pid'] .
486 " and y.form_name like 'CAMOS%'" .
487 " and x.activity = 1");
490 $results = array();
491 echo "<div id='checkboxes'>\n";
492 $count = 0;
493 while ($result = sqlFetchArray($query)) {
494 $checked = '';
495 if ($result['category'] == 'prescriptions' && $count < 4) {
496 $count++;
497 $checked = 'checked';
500 echo "<div>\n";
501 echo "<input type=checkbox name='ch_" . $result['id'] . "' $checked><span>" .
502 $result['category'] . '</span>:' . $result['subcategory'] . ':' . $result['item'] . "<br/>\n";
503 echo "</div>\n";
506 echo "</div>\n";
507 echo "<div id='log'>\n";//temp for debugging
508 echo "</div>\n";
509 //create Prescription object for the purpose of drawing data from the Prescription
510 //table for those who wish to do so
511 $rxarray = Prescription::prescriptions_factory($_SESSION['pid']);
512 //now give a choice of drugs from the Prescription table
513 foreach ($rxarray as $val) {
514 echo "<input type=checkbox name='chrx_" . $val->id . "'>" .
515 $val->drug . ':' . $val->start_date . "<br/>\n";
519 <?php if ($_GET['letterhead']) { ?>
520 <input type=submit name='print_pdf' value='<?php xl('Print (PDF)', 'e'); ?>'>
521 <?php } ?>
523 <input type=submit name='print_html' value='<?php xl('Print (HTML)', 'e'); ?>'>
524 </form>
525 <h1><?php xl('Update User Information', 'e'); ?></h1>
526 <form method=POST name='pick_items'>
527 <table>
528 <tr>
529 <td> <?php xl('First Name', 'e'); ?>: </td>
530 <td> <input type=text name=practice_fname value ='<?php echo htmlspecialchars($practice_fname, ENT_QUOTES); ?>'> </td>
531 </tr>
532 <tr>
533 <td> <?php xl('Last Name', 'e'); ?>: </td>
534 <td> <input type=text name=practice_lname value ='<?php echo htmlspecialchars($practice_lname, ENT_QUOTES); ?>'> </td>
535 </tr>
536 <tr>
537 <td> <?php xl('Title', 'e'); ?>: </td>
538 <td> <input type=text name=practice_title value ='<?php echo htmlspecialchars($practice_title, ENT_QUOTES); ?>'> </td>
539 </tr>
540 <tr>
541 <td> <?php xl('Street Address', 'e'); ?>: </td>
542 <td> <input type=text name=practice_address value ='<?php echo htmlspecialchars($practice_address, ENT_QUOTES); ?>'> </td>
543 </tr>
544 <tr>
545 <td> <?php xl('City', 'e'); ?>: </td>
546 <td> <input type=text name=practice_city value ='<?php echo htmlspecialchars($practice_city, ENT_QUOTES); ?>'> </td>
547 </tr>
548 <tr>
549 <td> <?php xl('State', 'e'); ?>: </td>
550 <td> <input type=text name=practice_state value ='<?php echo htmlspecialchars($practice_state, ENT_QUOTES); ?>'> </td>
551 </tr>
552 <tr>
553 <td> <?php xl('Zip', 'e'); ?>: </td>
554 <td> <input type=text name=practice_zip value ='<?php echo htmlspecialchars($practice_zip, ENT_QUOTES); ?>'> </td>
555 </tr>
556 <tr>
557 <td> <?php xl('Phone', 'e'); ?>: </td>
558 <td> <input type=text name=practice_phone value ='<?php echo htmlspecialchars($practice_phone, ENT_QUOTES); ?>'> </td>
559 </tr>
560 <tr>
561 <td> <?php xl('Fax', 'e'); ?>: </td>
562 <td> <input type=text name=practice_fax value ='<?php echo htmlspecialchars($practice_fax, ENT_QUOTES); ?>'> </td>
563 </tr>
564 <tr>
565 <td> <?php xl('DEA', 'e'); ?>: </td>
566 <td> <input type=text name=practice_dea value ='<?php echo htmlspecialchars($practice_dea, ENT_QUOTES); ?>'> </td>
567 </tr>
568 </table>
569 <input type=submit name=update value='<?php xl('Update', 'e'); ?>'>
570 </form>
571 <?php
572 } //end of else statement
574 </body>
575 </html>