Immunization_information_(MU2) changes, take 5.
[openemr.git] / interface / patient_file / report / custom_report.php
blob87975f3e72f3d69e4ee1f451efe19aaf39c68b1c
1 <?php
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 require_once("../../globals.php");
8 require_once("$srcdir/forms.inc");
9 require_once("$srcdir/billing.inc");
10 require_once("$srcdir/pnotes.inc");
11 require_once("$srcdir/patient.inc");
12 require_once("$srcdir/options.inc.php");
13 require_once("$srcdir/acl.inc");
14 require_once("$srcdir/lists.inc");
15 require_once("$srcdir/report.inc");
16 require_once("$srcdir/classes/Document.class.php");
17 require_once("$srcdir/classes/Note.class.php");
18 require_once("$srcdir/formatting.inc.php");
19 require_once("$srcdir/htmlspecialchars.inc.php");
20 require_once("$srcdir/formdata.inc.php");
21 require_once(dirname(__file__) . "/../../../custom/code_types.inc.php");
23 // For those who care that this is the patient report.
24 $GLOBALS['PATIENT_REPORT_ACTIVE'] = true;
26 $PDF_OUTPUT = empty($_POST['pdf']) ? false : true;
28 if ($PDF_OUTPUT) {
29 require_once("$srcdir/html2pdf/html2pdf.class.php");
30 $pdf = new HTML2PDF('P', 'Letter', 'en');
31 ob_start();
34 // get various authorization levels
35 $auth_notes_a = acl_check('encounters', 'notes_a');
36 $auth_notes = acl_check('encounters', 'notes');
37 $auth_coding_a = acl_check('encounters', 'coding_a');
38 $auth_coding = acl_check('encounters', 'coding');
39 $auth_relaxed = acl_check('encounters', 'relaxed');
40 $auth_med = acl_check('patients' , 'med');
41 $auth_demo = acl_check('patients' , 'demo');
43 $printable = empty($_GET['printable']) ? false : true;
44 if ($PDF_OUTPUT) $printable = true;
45 unset($_GET['printable']);
47 // Number of columns in tables for insurance and encounter forms.
48 $N = $PDF_OUTPUT ? 4 : 6;
50 $first_issue = 1;
52 function getContent() {
53 global $web_root, $webserver_root;
54 $content = ob_get_clean();
55 // Fix a nasty html2pdf bug - it ignores document root!
56 $i = 0;
57 $wrlen = strlen($web_root);
58 $wsrlen = strlen($webserver_root);
59 while (true) {
60 $i = stripos($content, " src='/", $i + 1);
61 if ($i === false) break;
62 if (substr($content, $i+6, $wrlen) === $web_root &&
63 substr($content, $i+6, $wsrlen) !== $webserver_root)
65 $content = substr($content, 0, $i + 6) . $webserver_root . substr($content, $i + 6 + $wrlen);
68 return $content;
71 function postToGet($arin) {
72 $getstring="";
73 foreach ($arin as $key => $val) {
74 if (is_array($val)) {
75 foreach ($val as $k => $v) {
76 $getstring .= urlencode($key . "[]") . "=" . urlencode($v) . "&";
79 else {
80 $getstring .= urlencode($key) . "=" . urlencode($val) . "&";
83 return $getstring;
87 <?php if ($PDF_OUTPUT) { ?>
88 <link rel="stylesheet" href="<?php echo $webserver_root; ?>/interface/themes/style_pdf.css" type="text/css">
89 <?php } else {?>
90 <html>
91 <head>
92 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
93 <?php } ?>
95 <?php // do not show stuff from report.php in forms that is encaspulated
96 // by div of navigateLink class. Specifically used for CAMOS, but
97 // can also be used by other forms that require output in the
98 // encounter listings output, but not in the custom report. ?>
99 <style>
100 div.navigateLink {display:none;}
101 .hilite {background-color: #FFFF00;}
102 .hilite2 {background-color: transparent;}
103 mark {background-color: #FFFF00;}
104 .css_button{cursor:pointer;}
105 .next {background-color: #FFFF00;}
106 #search_options{
107 position:fixed;
108 left:0px;
109 top:0px;
110 z-index:10;
111 border-bottom: solid thin #6D6D6D;
112 padding:0% 2% 0% 2.5%;
114 </style>
116 <?php if (!$PDF_OUTPUT) { ?>
118 <script type="text/javascript" src="<?php echo $GLOBALS['web_root']?>/library/js/jquery-1.5.js"></script>
119 <script type="text/javascript" src="<?php echo $GLOBALS['web_root']?>/library/js/SearchHighlight.js"></script>
120 <script type="text/javascript">var $j = jQuery.noConflict();</script>
122 <script type="text/javascript">
124 // Code for search & Highlight
125 function reset_highlight(form_id,form_dir,class_name) { // Removes <span class='hilite' id=''>VAL</span> with VAL
126 $j("."+class_name).each(function(){
127 val = document.getElementById(this.id).innerHTML;
128 $j("#"+this.id).replaceWith(val);
132 var res_id = 0;
133 function doSearch(form_id,form_dir,exact,class_name,keys,case_sensitive) { // Uses jquery SearchHighlight Plug in
134 var options ={};
135 var keys = keys.replace(/^\s+|\s+$/g, '') ;
136 options = {
137 exact :exact,
138 style_name :class_name,
139 style_name_suffix:false,
140 highlight:'#search_div_'+form_id+'_'+form_dir,
141 keys :keys,
142 set_case_sensitive:case_sensitive
144 $j(document).SearchHighlight(options);
145 $j('.'+class_name).each(function(){
146 res_id = res_id+1;
147 $j(this).attr("id",'result_'+res_id);
151 function remove_mark(form_id,form_dir){ // Removes all <mark> and </mark> tags
152 var match1 = null;
153 var src_str = document.getElementById('search_div_'+form_id+'_'+form_dir).innerHTML;
154 var re = new RegExp('<mark>',"gi");
155 var match2 = src_str.match(re);
156 if(match2){
157 src_str = src_str.replace(re,'');
159 var match2 = null;
160 re = new RegExp('</mark>',"gi");
161 if(match2){
162 src_str = src_str.replace(re,'');
164 document.getElementById('search_div_'+form_id+'_'+form_dir).innerHTML=src_str;
166 function mark_hilight(form_id,form_dir,keys,case_sensitive){ // Adds <mark>match_val</mark> tags
167 keys = keys.replace(/^\s+|\s+$/g, '') ;
168 if(keys == '') return;
169 var src_str = $j('#search_div_'+form_id+'_'+form_dir).html();
170 var term = keys;
171 if((/\s+/).test(term) == true || (/['""-]{1,}/).test(term) == true){
172 term = term.replace(/(\s+)/g,"(<[^>]+>)*$1(<[^>]+>)*");
173 if(case_sensitive == true){
174 var pattern = new RegExp("("+term+")", "g");
176 else{
177 var pattern = new RegExp("("+term+")", "ig");
179 src_str = src_str.replace(/[\s\r\n]{1,}/g, ' '); // Replace text area newline or multiple spaces with single space
180 src_str = src_str.replace(pattern, "<mark class='hilite'>$1</mark>");
181 src_str = src_str.replace(/(<mark class=\'hilite\'>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/g,"$1</mark>$2<mark class='hilite'>$4");
182 $j('#search_div_'+form_id+'_'+form_dir).html(src_str);
183 $j('.hilite').each(function(){
184 res_id = res_id+1;
185 $j(this).attr("id",'result_'+res_id);
187 }else{
188 if(case_sensitive == true)
189 doSearch(form_id,form_dir,'partial','hilite',keys,'true');
190 else
191 doSearch(form_id,form_dir,'partial','hilite',keys,'false');
195 var forms_array;
196 var res_array = Array();
197 function find_all(){ // for each report the function mark_hilight() is called
198 case_sensitive = false;
199 if ($j('#search_case').attr('checked')) {
200 case_sensitive = true;
202 var keys = document.getElementById('search_element').value;
203 var match = null;
204 match = keys.match(/[\^\$\.\|\?\+\(\)\\~`\!@#%&\+={}<>]{1,}/);
205 if(match){
206 document.getElementById('alert_msg').innerHTML='<?php echo xla('Special characters are not allowed');?>..!';
207 return;
209 else{
210 document.getElementById('alert_msg').innerHTML='';
213 forms_arr = document.getElementById('forms_to_search');
214 for (var i = 0; i < forms_arr.options.length; i++) {
215 if(forms_arr.options[i].selected ==true){
216 $j('.class_'+forms_arr.options[i].value).each(function(){
217 id_arr = this.id.split('search_div_');
218 var re = new RegExp('_','i');
219 new_id = id_arr[1].replace(re, "|");
220 new_id_arr = new_id.split('|');
221 form_id = new_id_arr[0];
222 form_dir = new_id_arr[1];
223 mark_hilight(form_id,form_dir,keys,case_sensitive);
228 if($j('.hilite').length <1){
229 if(keys != '')
230 document.getElementById('alert_msg').innerHTML='<?php echo xla('No results found');?>..!';
232 else{
233 document.getElementById('alert_msg').innerHTML='';
234 f_id = $j('.hilite:first').attr('id');
235 element = document.getElementById(f_id);
236 element.scrollIntoView(false);
241 function remove_mark_all(){ // clears previous search results if exists
242 $j('.report_search_div').each(function(){
243 var id_arr = this.id.split('search_div_');
244 var re = new RegExp('_','i');
245 var new_id = id_arr[1].replace(re, "|");
246 var new_id_arr = new_id.split('|');
247 var form_id = new_id_arr[0];
248 var form_dir = new_id_arr[1];
249 reset_highlight(form_id,form_dir,'hilite');
250 reset_highlight(form_id,form_dir,'hilite2');
251 remove_mark(form_id,form_dir);
252 res_id = 0;
253 res_array =[];
257 var last_visited = -1;
258 var last_clicked = "";
259 var cur_res =0;
260 function next(w_count){
261 cur_res++;
262 remove_mark_all();
263 find_all();
264 var index = -1;
265 if(!($j(".hilite")[0])) {
266 return;
268 $j('.hilite').each(function(){
269 if($j(this).is(":visible")){
270 index = index+1;
271 res_array[index] = this.id;
274 $j('.hilite').addClass("hilite2");
275 $j('.hilite').removeClass("hilite");
276 var array_count = res_array.length;
277 if(last_clicked == "prev"){
278 last_visited = last_visited + (w_count-1);
280 last_clicked = "next";
281 for(k=0;k<w_count;k++){
282 last_visited ++;
283 if(last_visited == array_count){
284 cur_res = 0;
285 last_visited = -1;
286 next(w_count);
287 return;
289 $j("#"+res_array[last_visited]).addClass("next");
291 element = document.getElementById(res_array[last_visited]);
292 element.scrollIntoView(false);
296 function prev(w_count){
297 cur_res--;
298 remove_mark_all();
299 find_all();
300 var index = -1;
301 if(!($j(".hilite")[0])) {
302 return;
304 $j('.hilite').each(function(){
305 if($j(this).is(":visible")){
306 index = index+1;
307 res_array[index] = this.id;
310 $j('.hilite').addClass("hilite2");
311 $j('.hilite').removeClass("hilite");
312 var array_count = res_array.length;
313 if(last_clicked == "next"){
314 last_visited = last_visited - (w_count-1);
316 last_clicked = "prev";
317 for(k=0;k<w_count;k++){
318 last_visited --;
319 if(last_visited < 0){
320 cur_res = (array_count/w_count) + 1;
321 last_visited = array_count;
322 prev(w_count);
323 return;
325 $j("#"+res_array[last_visited]).addClass("next");
329 element = document.getElementById(res_array[last_visited]);
330 element.scrollIntoView(false);
332 function clear_last_visit(){
333 last_visited = -1;
334 cur_res = 0;
335 res_array = [];
336 last_clicked = "";
339 function get_word_count(form_id,form_dir,keys,case_sensitive){
340 keys = keys.replace(/^\s+|\s+$/g, '') ;
341 if(keys == '') return;
342 var src_str = $j('#search_div_'+form_id+'_'+form_dir).html();
343 var term = keys;
344 if((/\s+/).test(term) == true){
345 term = term.replace(/(\s+)/g,"(<[^>]+>)*$1(<[^>]+>)*");
346 if(case_sensitive == true){
347 var pattern = new RegExp("("+term+")", "");
349 else{
350 var pattern = new RegExp("("+term+")", "i");
352 src_str = src_str.replace(/[\s\r\n]{1,}/g, ' '); // Replace text area newline or multiple spaces with single space
353 src_str = src_str.replace(pattern, "<mark class='hilite'>$1</mark>");
354 src_str = src_str.replace(/(<mark class=\'hilite\'>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/,"$1</mark>$2<mark class='hilite'>$4");
355 var res =[];
356 res = src_str.match(/<mark class=\'hilite\'>/g);
357 if(res != null){
358 return res.length;
360 }else{
361 return 1;
365 function next_prev(action){
366 var w_count =0;
367 case_sensitive = false;
368 if ($j('#search_case').attr('checked')) {
369 case_sensitive = true;
371 var keys = document.getElementById('search_element').value;
372 var match = null;
373 match = keys.match(/[\^\$\.\|\?\+\(\)\\~`\!@#%&\+={}<>]{1,}/);
374 if(match){
375 document.getElementById('alert_msg').innerHTML='<?php echo xla('Special characters are not allowed');?>..!';
376 return;
378 else{
379 document.getElementById('alert_msg').innerHTML='';
381 forms_arr = document.getElementById('forms_to_search');
382 for (var i = 0; i < forms_arr.options.length; i++) {
383 if(forms_arr.options[i].selected ==true){
384 $j('.class_'+forms_arr.options[i].value).each(function(){
385 id_arr = this.id.split('search_div_');
386 var re = new RegExp('_','i');
387 new_id = id_arr[1].replace(re, "|");
388 new_id_arr = new_id.split('|');
389 form_id = new_id_arr[0];
390 form_dir = new_id_arr[1];
391 w_count = get_word_count(form_id,form_dir,keys,case_sensitive);
393 if(!isNaN(w_count)){
394 break;
398 if(w_count <1){
399 if(keys != '')
400 document.getElementById('alert_msg').innerHTML='<?php echo xla('No results found');?>..!';
402 else{
403 document.getElementById('alert_msg').innerHTML='';
404 if(action == 'next'){
405 next(w_count);
407 else if (action == 'prev'){
408 prev(w_count);
410 var tot_res = res_array.length/w_count;
411 if(tot_res > 0){
412 document.getElementById('alert_msg').innerHTML='<?php echo xla('Showing result');?> '+cur_res+' <?php echo xla('of');?> '+tot_res;
417 </script>
418 </head>
419 <body class="body_top" style="padding-top:95px;">
420 <?php } ?>
421 <div id="report_custom" style="width:100%;"> <!-- large outer DIV -->
423 <?php
424 if (sizeof($_GET) > 0) { $ar = $_GET; }
425 else { $ar = $_POST; }
427 if ($printable) {
428 /*******************************************************************
429 $titleres = getPatientData($pid, "fname,lname,providerID");
430 $sql = "SELECT * FROM facility ORDER BY billing_location DESC LIMIT 1";
431 *******************************************************************/
432 $titleres = getPatientData($pid, "fname,lname,providerID,DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS");
433 if ($_SESSION['pc_facility']) {
434 $sql = "select * from facility where id=" . $_SESSION['pc_facility'];
435 } else {
436 $sql = "SELECT * FROM facility ORDER BY billing_location DESC LIMIT 1";
438 /******************************************************************/
439 $db = $GLOBALS['adodb']['db'];
440 $results = $db->Execute($sql);
441 $facility = array();
442 if (!$results->EOF) {
443 $facility = $results->fields;
445 $practice_logo = "../../../custom/practice_logo.gif";
446 if (file_exists($practice_logo)) {
447 echo "<img src='$practice_logo' align='left'>\n";
450 <h2><?php echo $facility['name'] ?></h2>
451 <?php echo $facility['street'] ?><br>
452 <?php echo $facility['city'] ?>, <?php echo $facility['state'] ?> <?php echo $facility['postal_code'] ?><br clear='all'>
453 <?php echo $facility['phone'] ?><br>
455 <a href="javascript:window.close();"><span class='title'><?php echo $titleres['fname'] . " " . $titleres['lname']; ?></span></a><br>
456 <span class='text'><?php xl('Generated on','e'); ?>: <?php echo oeFormatShortDate(); ?></span>
457 <br><br>
459 <?php
462 else { // not printable
465 <a href="patient_report.php">
466 <span class='title'><?php xl('Patient Report','e'); ?></span>
467 <span class='back'><?php echo $tback;?></span>
468 </a><br><br>
469 <a href="custom_report.php?printable=1&<?php print postToGet($ar); ?>" class='link_submit' target='new'>
470 [<?php xl('Printable Version','e'); ?>]
471 </a><br>
472 <div class="report_search_bar" style="width:100%;" id="search_options">
473 <table style="width:100%;">
474 <tr>
475 <td>
476 <input type="text" onKeyUp="clear_last_visit();remove_mark_all();find_all();" name="search_element" id="search_element" style="width:180px;"/>
477 </td>
478 <td>
479 <a class="css_button" onClick="clear_last_visit();remove_mark_all();find_all();" ><span><?php echo xlt('Find'); ?></span></a>
480 </td>
481 <td>
482 <a class="css_button" onClick="next_prev('prev');" ><span><?php echo xlt('Prev'); ?></span></a>
483 </td>
484 <td>
485 <a class="css_button" onClick="next_prev('next');" ><span><?php echo xlt('Next'); ?></span></a>
486 </td>
487 <td>
488 <input type="checkbox" onClick="clear_last_visit();remove_mark_all();find_all();" name="search_case" id="search_case" />
489 </td>
490 <td>
491 <span><?php echo xlt('Match case'); ?></span>
492 </td>
493 <td style="padding-left:10px;">
494 <span class="text"><b><?php echo xlt('Search In'); ?>:</b></span>
495 <br>
496 <?php
497 $form_id_arr = array();
498 $form_dir_arr = array();
499 $last_key ='';
500 //ksort($ar);
501 foreach ($ar as $key_search => $val_search) {
502 if ($key_search == 'pdf' || $key_search == '' ) continue;
503 if (($auth_notes_a || $auth_notes || $auth_coding_a || $auth_coding || $auth_med || $auth_relaxed)) {
504 preg_match('/^(.*)_(\d+)$/', $key_search, $res_search);
505 $form_id_arr[] = add_escape_custom($res_search[2]);
506 $form_dir_arr[] = add_escape_custom($res_search[1]);
509 //echo json_encode(json_encode($array_key_id));
510 if(sizeof($form_id_arr)>0){
511 $query = "SELECT DISTINCT(form_name),formdir FROM forms WHERE form_id IN ( '".implode("','",$form_id_arr)."') AND formdir IN ( '".implode("','",$form_dir_arr)."')";
512 $arr = sqlStatement($query);
513 echo "<select multiple size='4' style='width:300px;' id='forms_to_search' onchange='clear_last_visit();remove_mark_all();find_all();' >";
514 while($res_forms_ids = sqlFetchArray($arr)){
515 echo "<option value='".attr($res_forms_ids['formdir'])."' selected>".text($res_forms_ids['form_name'])."</option>";
517 echo "</select>";
520 </td>
521 <td style="padding-left:10px;;width:30%;">
522 <span id ='alert_msg' style='color:red;'></span>
523 </td>
524 </tr>
525 </table>
526 </div>
527 <?php
528 } // end not printable ?>
530 <?php
532 // include ALL form's report.php files
533 $inclookupres = sqlStatement("select distinct formdir from forms where pid = '$pid' AND deleted=0");
534 while($result = sqlFetchArray($inclookupres)) {
535 // include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
536 $formdir = $result['formdir'];
537 if (substr($formdir,0,3) == 'LBF')
538 include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
539 else
540 include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
543 // For each form field from patient_report.php...
545 foreach ($ar as $key => $val) {
546 if ($key == 'pdf') continue;
548 // These are the top checkboxes (demographics, allergies, etc.).
550 if (stristr($key,"include_")) {
552 if ($val == "demographics") {
554 echo "<hr />";
555 echo "<div class='text demographics' id='DEM'>\n";
556 print "<h1>".xl('Patient Data').":</h1>";
557 // printRecDataOne($patient_data_array, getRecPatientData ($pid), $N);
558 $result1 = getPatientData($pid);
559 $result2 = getEmployerData($pid);
560 echo " <table>\n";
561 display_layout_rows('DEM', $result1, $result2);
562 echo " </table>\n";
563 echo "</div>\n";
565 } elseif ($val == "history") {
567 echo "<hr />";
568 echo "<div class='text history' id='HIS'>\n";
569 if (acl_check('patients', 'med')) {
570 print "<h1>".xl('History Data').":</h1>";
571 // printRecDataOne($history_data_array, getRecHistoryData ($pid), $N);
572 $result1 = getHistoryData($pid);
573 echo " <table>\n";
574 display_layout_rows('HIS', $result1);
575 echo " </table>\n";
577 echo "</div>";
579 // } elseif ($val == "employer") {
580 // print "<br><span class='bold'>".xl('Employer Data').":</span><br>";
581 // printRecDataOne($employer_data_array, getRecEmployerData ($pid), $N);
583 } elseif ($val == "insurance") {
585 echo "<hr />";
586 echo "<div class='text insurance'>";
587 echo "<h1>".xl('Insurance Data').":</h1>";
588 print "<br><span class=bold>".xl('Primary Insurance Data').":</span><br>";
589 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"primary"), $N);
590 print "<span class=bold>".xl('Secondary Insurance Data').":</span><br>";
591 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"secondary"), $N);
592 print "<span class=bold>".xl('Tertiary Insurance Data').":</span><br>";
593 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"tertiary"), $N);
594 echo "</div>";
596 } elseif ($val == "billing") {
598 echo "<hr />";
599 echo "<div class='text billing'>";
600 print "<h1>".xl('Billing Information').":</h1>";
601 if (count($ar['newpatient']) > 0) {
602 $billings = array();
603 echo "<table>";
604 echo "<tr><td width='400' class='bold'>Code</td><td class='bold'>".xl('Fee')."</td></tr>\n";
605 $total = 0.00;
606 $copays = 0.00;
607 foreach ($ar['newpatient'] as $be) {
608 $ta = split(":",$be);
609 $billing = getPatientBillingEncounter($pid,$ta[1]);
610 $billings[] = $billing;
611 foreach ($billing as $b) {
612 echo "<tr>\n";
613 echo "<td class=text>";
614 echo $b['code_type'] . ":\t" . $b['code'] . "&nbsp;". $b['modifier'] . "&nbsp;&nbsp;&nbsp;" . $b['code_text'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
615 echo "</td>\n";
616 echo "<td class=text>";
617 echo oeFormatMoney($b['fee']);
618 echo "</td>\n";
619 echo "</tr>\n";
620 $total += $b['fee'];
621 if ($b['code_type'] == "COPAY") {
622 $copays += $b['fee'];
626 echo "<tr><td>&nbsp;</td></tr>";
627 echo "<tr><td class=bold>".xl('Sub-Total')."</td><td class=text>" . oeFormatMoney($total + abs($copays)) . "</td></tr>";
628 echo "<tr><td class=bold>".xl('Paid')."</td><td class=text>" . oeFormatMoney(abs($copays)) . "</td></tr>";
629 echo "<tr><td class=bold>".xl('Total')."</td><td class=text>" . oeFormatMoney($total) . "</td></tr>";
630 echo "</table>";
631 echo "<pre>";
632 //print_r($billings);
633 echo "</pre>";
634 } else {
635 printPatientBilling($pid);
637 echo "</div>\n"; // end of billing DIV
639 /****
641 } elseif ($val == "allergies") {
643 print "<span class=bold>Patient Allergies:</span><br>";
644 printListData($pid, "allergy", "1");
646 } elseif ($val == "medications") {
648 print "<span class=bold>Patient Medications:</span><br>";
649 printListData($pid, "medication", "1");
651 } elseif ($val == "medical_problems") {
653 print "<span class=bold>Patient Medical Problems:</span><br>";
654 printListData($pid, "medical_problem", "1");
656 ****/
658 } elseif ($val == "immunizations") {
660 if (acl_check('patients', 'med')) {
661 echo "<hr />";
662 echo "<div class='text immunizations'>\n";
663 print "<h1>".xl('Patient Immunization').":</h1>";
664 $sql = "select i1.immunization_id, i1.administered_date, substring(i1.note,1,20) as immunization_note, c.code_text_short ".
665 " from immunizations i1 ".
666 " left join code_types ct on ct.ct_key = 'CVX' ".
667 " left join codes c on c.code_type = ct.ct_id AND i1.cvx_code = c.code ".
668 " where i1.patient_id = '$pid' and i1.added_erroneously = 0 ".
669 " order by administered_date desc";
670 $result = sqlStatement($sql);
671 while ($row=sqlFetchArray($result)) {
672 // Figure out which name to use (ie. from cvx list or from the custom list)
673 if ($GLOBALS['use_custom_immun_list']) {
674 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
676 else {
677 if (!empty($row['code_text_short'])) {
678 $vaccine_display = htmlspecialchars( xl($row['code_text_short']), ENT_NOQUOTES);
680 else {
681 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
684 echo $row['administered_date'] . " - " . $vaccine_display;
685 if ($row['immunization_note']) {
686 echo " - " . $row['immunization_note'];
688 echo "<br>\n";
690 echo "</div>\n";
693 // communication report
694 } elseif ($val == "batchcom") {
696 echo "<hr />";
697 echo "<div class='text transactions'>\n";
698 print "<h1>".xl('Patient Communication sent').":</h1>";
699 $sql="SELECT concat( 'Messsage Type: ', batchcom.msg_type, ', Message Subject: ', batchcom.msg_subject, ', Sent on:', batchcom.msg_date_sent ) AS batchcom_data, batchcom.msg_text, concat( users.fname, users.lname ) AS user_name FROM `batchcom` JOIN `users` ON users.id = batchcom.sent_by WHERE batchcom.patient_id='$pid'";
700 // echo $sql;
701 $result = sqlStatement($sql);
702 while ($row=sqlFetchArray($result)) {
703 echo $row{'batchcom_data'}.", By: ".$row{'user_name'}."<br>Text:<br> ".$row{'msg_txt'}."<br>\n";
705 echo "</div>\n";
707 } elseif ($val == "notes") {
709 echo "<hr />";
710 echo "<div class='text notes'>\n";
711 print "<h1>".xl('Patient Notes').":</h1>";
712 printPatientNotes($pid);
713 echo "</div>";
715 } elseif ($val == "transactions") {
717 echo "<hr />";
718 echo "<div class='text transactions'>\n";
719 print "<h1>".xl('Patient Transactions').":</h1>";
720 printPatientTransactions($pid);
721 echo "</div>";
725 } else {
727 // Documents is an array of checkboxes whose values are document IDs.
729 if ($key == "documents") {
731 echo "<hr />";
732 echo "<div class='text documents'>";
733 foreach($val as $valkey => $valvalue) {
734 $document_id = $valvalue;
735 if (!is_numeric($document_id)) continue;
736 $d = new Document($document_id);
737 $fname = basename($d->get_url());
738 $couch_docid = $d->get_couch_docid();
739 $couch_revid = $d->get_couch_revid();
740 $extension = substr($fname, strrpos($fname,"."));
741 echo "<h1>" . xl('Document') . " '" . $fname ."'</h1>";
742 $notes = Note::notes_factory($d->get_id());
743 if (!empty($notes)) echo "<table>";
744 foreach ($notes as $note) {
745 echo '<tr>';
746 echo '<td>' . xl('Note') . ' #' . $note->get_id() . '</td>';
747 echo '</tr>';
748 echo '<tr>';
749 echo '<td>' . xl('Date') . ': ' . oeFormatShortDate($note->get_date()) . '</td>';
750 echo '</tr>';
751 echo '<tr>';
752 echo '<td>'.$note->get_note().'<br><br></td>';
753 echo '</tr>';
755 if (!empty($notes)) echo "</table>";
757 $url_file = $d->get_url_filepath();
758 if($couch_docid && $couch_revid){
759 $url_file = $d->get_couch_url($pid,$encounter);
761 // just grab the last two levels, which contain filename and patientid
762 $from_all = explode("/",$url_file);
763 $from_filename = array_pop($from_all);
764 $from_patientid = array_pop($from_all);
765 if($couch_docid && $couch_revid) {
766 $from_file = $GLOBALS['OE_SITE_DIR'] . '/documents/temp/' . $from_filename;
767 $to_file = substr($from_file, 0, strrpos($from_file, '.')) . '_converted.jpg';
769 else {
770 $from_file = $GLOBALS["fileroot"] . "/sites/" . $_SESSION['site_id'] .
771 '/documents/' . $from_patientid . '/' . $from_filename;
772 $to_file = substr($from_file, 0, strrpos($from_file, '.')) . '_converted.jpg';
775 if ($extension == ".png" || $extension == ".jpg" || $extension == ".jpeg" || $extension == ".gif") {
776 if ($PDF_OUTPUT) {
777 // OK to link to the image file because it will be accessed by the
778 // HTML2PDF parser and not the browser.
779 $from_rel = $web_root . substr($from_file, strlen($webserver_root));
780 echo "<img src='$from_rel'";
781 // Flag images with excessive width for possible stylesheet action.
782 $asize = getimagesize($from_file);
783 if ($asize[0] > 750) echo " class='bigimage'";
784 echo " /><br><br>";
786 else {
787 echo "<img src='" . $GLOBALS['webroot'] .
788 "/controller.php?document&retrieve&patient_id=&document_id=" .
789 $document_id . "&as_file=false'><br><br>";
792 else {
794 // Most clinic documents are expected to be PDFs, and in that happy case
795 // we can avoid the lengthy image conversion process.
796 if ($PDF_OUTPUT && $extension == ".pdf") {
797 // HTML to PDF conversion will fail if there are open tags.
798 echo "</div></div>\n";
799 $content = getContent();
800 // $pdf->setDefaultFont('Arial');
801 $pdf->writeHTML($content, false);
802 $pagecount = $pdf->pdf->setSourceFile($from_file);
803 for($i = 0; $i < $pagecount; ++$i){
804 $pdf->pdf->AddPage();
805 $itpl = $pdf->pdf->importPage($i + 1, '/MediaBox');
806 $pdf->pdf->useTemplate($itpl);
808 // Make sure whatever follows is on a new page.
809 $pdf->pdf->AddPage();
810 // Resume output buffering and the above-closed tags.
811 ob_start();
812 echo "<div><div class='text documents'>\n";
814 else {
815 if (! is_file($to_file)) exec("convert -density 200 \"$from_file\" -append -resize 850 \"$to_file\"");
816 if (is_file($to_file)) {
817 if ($PDF_OUTPUT) {
818 // OK to link to the image file because it will be accessed by the
819 // HTML2PDF parser and not the browser.
820 echo "<img src='$to_file'><br><br>";
822 else {
823 echo "<img src='" . $GLOBALS['webroot'] .
824 "/controller.php?document&retrieve&patient_id=&document_id=" .
825 $document_id . "&as_file=false&original_file=false'><br><br>";
827 } else {
828 echo "<b>NOTE</b>: " . xl('Document') . "'" . $fname . "' " .
829 xl('cannot be converted to JPEG. Perhaps ImageMagick is not installed?') . "<br><br>";
830 if($couch_docid && $couch_revid) {
831 unlink($from_file);
836 } // end if-else
837 } // end Documents loop
838 echo "</div>";
840 } else if (strpos($key, "issue_") === 0) {
841 // display patient Issues
843 if ($first_issue) {
844 $prevIssueType = 'asdf1234!@#$'; // random junk so as to not match anything
845 $first_issue = 0;
846 echo "<hr />";
847 echo "<h1>".xl("Issues")."</h1>";
849 preg_match('/^(.*)_(\d+)$/', $key, $res);
850 $rowid = $res[2];
851 $irow = sqlQuery("SELECT type, title, comments, diagnosis " .
852 "FROM lists WHERE id = '$rowid'");
853 $diagnosis = $irow['diagnosis'];
854 if ($prevIssueType != $irow['type']) {
855 // output a header for each Issue Type we encounter
856 $disptype = $ISSUE_TYPES[$irow['type']][0];
857 echo "<div class='issue_type'>" . $disptype . ":</div>\n";
858 $prevIssueType = $irow['type'];
860 echo "<div class='text issue'>";
861 echo "<span class='issue_title'>" . $irow['title'] . ":</span>";
862 echo "<span class='issue_comments'> " . $irow['comments'] . "</span>\n";
863 // Show issue's chief diagnosis and its description:
864 if ($diagnosis) {
865 echo "<div class='text issue_diag'>";
866 echo "<span class='bold'>[".xl('Diagnosis')."]</span><br>";
867 $dcodes = explode(";", $diagnosis);
868 foreach ($dcodes as $dcode) {
869 echo "<span class='italic'>".$dcode."</span>: ";
870 echo lookup_code_descriptions($dcode)."<br>\n";
872 //echo $diagnosis." -- ".lookup_code_descriptions($diagnosis)."\n";
873 echo "</div>";
876 // Supplemental data for GCAC or Contraception issues.
877 if ($irow['type'] == 'ippf_gcac') {
878 echo " <table>\n";
879 display_layout_rows('GCA', sqlQuery("SELECT * FROM lists_ippf_gcac WHERE id = '$rowid'"));
880 echo " </table>\n";
882 else if ($irow['type'] == 'contraceptive') {
883 echo " <table>\n";
884 display_layout_rows('CON', sqlQuery("SELECT * FROM lists_ippf_con WHERE id = '$rowid'"));
885 echo " </table>\n";
888 echo "</div>\n"; //end the issue DIV
890 } else {
891 // we have an "encounter form" form field whose name is like
892 // dirname_formid, with a value which is the encounter ID.
894 // display encounter forms, encoded as a POST variable
895 // in the format: <formdirname_formid>=<encounterID>
897 if (($auth_notes_a || $auth_notes || $auth_coding_a || $auth_coding || $auth_med || $auth_relaxed)) {
898 $form_encounter = $val;
899 preg_match('/^(.*)_(\d+)$/', $key, $res);
900 $form_id = $res[2];
901 $formres = getFormNameByFormdirAndFormid($res[1],$form_id);
902 $dateres = getEncounterDateByEncounter($form_encounter);
904 if ($res[1] == 'newpatient') {
905 echo "<div class='text encounter'>\n";
906 echo "<h1>" . xl($formres["form_name"]) . "</h1>";
908 else {
909 echo "<div class='text encounter_form'>";
910 echo "<h1>" . xl_form_title($formres["form_name"]) . "</h1>";
913 // show the encounter's date
914 echo "(" . oeFormatSDFT(strtotime($dateres["date"])) . ") ";
915 if ($res[1] == 'newpatient') {
916 // display the provider info
917 echo ' '. xl('Provider') . ': ' . text(getProviderName(getProviderIdOfEncounter($form_encounter)));
919 echo "<br>\n";
921 // call the report function for the form
923 <div name="search_div" id="search_div_<?php echo attr($form_id)?>_<?php echo attr($res[1])?>" class="report_search_div class_<?php echo attr($res[1]); ?>">
924 <?php
925 if (substr($res[1],0,3) == 'LBF')
926 call_user_func("lbf_report", $pid, $form_encounter, $N, $form_id, $res[1]);
927 else
928 call_user_func($res[1] . "_report", $pid, $form_encounter, $N, $form_id);
930 </div>
931 <?php
933 if ($res[1] == 'newpatient') {
934 // display billing info
935 $bres = sqlStatement("SELECT b.date, b.code, b.code_text " .
936 "FROM billing AS b, code_types AS ct WHERE " .
937 "b.pid = ? AND " .
938 "b.encounter = ? AND " .
939 "b.activity = 1 AND " .
940 "b.code_type = ct.ct_key AND " .
941 "ct.ct_diag = 0 " .
942 "ORDER BY b.date",
943 array($pid, $form_encounter));
944 while ($brow=sqlFetchArray($bres)) {
945 echo "<span class='bold'>&nbsp;".xl('Procedure').": </span><span class='text'>" .
946 $brow['code'] . " " . $brow['code_text'] . "</span><br>\n";
950 print "</div>";
952 } // end auth-check for encounter forms
954 } // end if('issue_')... else...
956 } // end if('include_')... else...
958 } // end $ar loop
960 if ($printable)
961 echo "<br /><br />" . xl('Signature') . ": _______________________________<br />";
964 </div> <!-- end of report_custom DIV -->
966 <?php
967 if ($PDF_OUTPUT) {
968 $content = getContent();
969 // $pdf->setDefaultFont('Arial');
970 $pdf->writeHTML($content, false);
971 $pdf->Output('report.pdf', 'D'); // D = Download, I = Inline
973 else {
975 </body>
976 </html>
977 <?php } ?>