leaned down jquery versions
[openemr.git] / portal / report / portal_custom_report.php
blob92f9b8e017792ec07d86b6b1ef8869a246efecb6
1 <?php
2 use ESign\Api;
3 /**
5 * Patient custom report.
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author Brady Miller <brady@sparmy.com>
20 * @author Ken Chapple <ken@mi-squared.com>
21 * @author Tony McCormick <tony@mi-squared.com>
22 * @link http://www.open-emr.org
24 session_start();
26 //landing page definition -- where to go if something goes wrong
27 $landingpage = "../index.php?site=".$_SESSION['site_id'];
30 // kick out if patient not authenticated
31 if ( isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two']) ) {
32 $pid = $_SESSION['pid'];
33 $user = $_SESSION['sessionUser'];
35 else {
36 session_destroy();
37 header('Location: '.$landingpage.'&w');
38 exit;
40 $ignoreAuth = true;
41 global $ignoreAuth;
43 require_once('../../interface/globals.php');
44 require_once("$srcdir/forms.inc");
45 require_once("$srcdir/billing.inc");
46 require_once("$srcdir/pnotes.inc");
47 require_once("$srcdir/patient.inc");
48 require_once("$srcdir/options.inc.php");
49 require_once("$srcdir/acl.inc");
50 require_once("$srcdir/lists.inc");
51 require_once("$srcdir/report.inc");
52 require_once("$srcdir/classes/Document.class.php");
53 require_once("$srcdir/classes/Note.class.php");
54 require_once("$srcdir/formatting.inc.php");
55 require_once("$srcdir/htmlspecialchars.inc.php");
56 require_once("$srcdir/formdata.inc.php");
57 require_once(dirname(__file__) . "/../../custom/code_types.inc.php");
58 require_once $GLOBALS['srcdir'].'/ESign/Api.php';
59 require_once($GLOBALS["include_root"] . "/orders/single_order_results.inc.php");
60 if ($GLOBALS['gbl_portal_cms_enable']) {
61 require_once($GLOBALS["include_root"] . "/cmsportal/portal.inc.php");
64 // For those who care that this is the patient report.
65 $GLOBALS['PATIENT_REPORT_ACTIVE'] = true;
67 $PDF_OUTPUT = empty($_POST['pdf']) ? 0 : intval($_POST['pdf']);
69 if ($PDF_OUTPUT) {
70 require_once("$srcdir/html2pdf/vendor/autoload.php");
71 $pdf = new HTML2PDF ($GLOBALS['pdf_layout'],
72 $GLOBALS['pdf_size'],
73 $GLOBALS['pdf_language'],
74 true, // default unicode setting is true
75 'UTF-8', // default encoding setting is UTF-8
76 array($GLOBALS['pdf_left_margin'],$GLOBALS['pdf_top_margin'],$GLOBALS['pdf_right_margin'],$GLOBALS['pdf_bottom_margin'])
78 ob_start();
81 // get various authorization levels
82 $auth_notes_a = true; //acl_check('encounters', 'notes_a');
83 $auth_notes = true; //acl_check('encounters', 'notes');
84 $auth_coding_a = true; //acl_check('encounters', 'coding_a');
85 $auth_coding = true; //acl_check('encounters', 'coding');
86 $auth_relaxed = true; //acl_check('encounters', 'relaxed');
87 $auth_med = true; //acl_check('patients' , 'med');
88 $auth_demo = true; //acl_check('patients' , 'demo');
90 $esignApi = new Api();
92 $printable = empty($_GET['printable']) ? false : true;
93 if ($PDF_OUTPUT) { $printable = true; }
94 unset($_GET['printable']);
96 // Number of columns in tables for insurance and encounter forms.
97 $N = $PDF_OUTPUT ? 4 : 6;
99 $first_issue = 1;
101 function getContent() {
102 global $web_root, $webserver_root;
103 $content = ob_get_clean();
104 // Fix a nasty html2pdf bug - it ignores document root!
105 $i = 0;
106 $wrlen = strlen($web_root);
107 $wsrlen = strlen($webserver_root);
108 while (true) {
109 $i = stripos($content, " src='/", $i + 1);
110 if ($i === false) break;
111 if (substr($content, $i+6, $wrlen) === $web_root &&
112 substr($content, $i+6, $wsrlen) !== $webserver_root)
114 $content = substr($content, 0, $i + 6) . $webserver_root . substr($content, $i + 6 + $wrlen);
117 return $content;
120 function postToGet($arin) {
121 $getstring="";
122 foreach ($arin as $key => $val) {
123 if (is_array($val)) {
124 foreach ($val as $k => $v) {
125 $getstring .= urlencode($key . "[]") . "=" . urlencode($v) . "&";
128 else {
129 $getstring .= urlencode($key) . "=" . urlencode($val) . "&";
132 return $getstring;
136 <?php if ($PDF_OUTPUT) { ?>
137 <link rel="stylesheet" href="<?php echo $webserver_root; ?>/interface/themes/style_pdf.css?v=<?php echo $v_js_includes; ?>" type="text/css">
138 <link rel="stylesheet" type="text/css" href="<?php echo $webserver_root; ?>/library/ESign/css/esign_report.css?v=<?php echo $v_js_includes; ?>" />
139 <?php } else {?>
140 <html>
141 <head>
143 <?php } ?>
145 <?php // do not show stuff from report.php in forms that is encaspulated
146 // by div of navigateLink class. Specifically used for CAMOS, but
147 // can also be used by other forms that require output in the
148 // encounter listings output, but not in the custom report. ?>
150 <style>
152 .h3, h3 {
153 font-size: 20px;
155 .report_search_div{
156 font-size: 20px !important;
157 font-style:bold;
159 .label {
160 color:black;
162 .groupname {
163 color:green;
165 input[type="checkbox"], input[type="radio"] {
166 margin: 0 5px 5px;
167 line-height: normal;
169 </style>
171 <?php if (!$PDF_OUTPUT) { ?>
172 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
173 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['webroot'] ?>/library/ESign/css/esign_report.css?v=<?php echo $v_js_includes; ?>" />
174 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
175 <script type="text/javascript" src="<?php echo $GLOBALS['web_root']?>/library/js/SearchHighlight.js?v=<?php echo $v_js_includes; ?>"></script>
176 <script type="text/javascript">var $j = jQuery.noConflict();</script>
178 <?php // if the track_anything form exists, then include the styling
179 if (file_exists(dirname(__FILE__) . "/../../forms/track_anything/style.css")) { ?>
180 <link rel="stylesheet" href="<?php echo $GLOBALS['web_root']?>/interface/forms/track_anything/style.css?v=<?php echo $v_js_includes; ?>" type="text/css">
181 <?php } ?>
183 <script type="text/javascript">
185 // Code for search & Highlight
186 function reset_highlight(form_id,form_dir,class_name) { // Removes <span class='hilite' id=''>VAL</span> with VAL
187 $j("."+class_name).each(function(){
188 val = document.getElementById(this.id).innerHTML;
189 $j("#"+this.id).replaceWith(val);
193 var res_id = 0;
194 function doSearch(form_id,form_dir,exact,class_name,keys,case_sensitive) { // Uses jquery SearchHighlight Plug in
195 var options ={};
196 var keys = keys.replace(/^\s+|\s+$/g, '') ;
197 options = {
198 exact :exact,
199 style_name :class_name,
200 style_name_suffix:false,
201 highlight:'#search_div_'+form_id+'_'+form_dir,
202 keys :keys,
203 set_case_sensitive:case_sensitive
205 $j(document).SearchHighlight(options);
206 $j('.'+class_name).each(function(){
207 res_id = res_id+1;
208 $j(this).attr("id",'result_'+res_id);
212 function remove_mark(form_id,form_dir){ // Removes all <mark> and </mark> tags
213 var match1 = null;
214 var src_str = document.getElementById('search_div_'+form_id+'_'+form_dir).innerHTML;
215 var re = new RegExp('<mark>',"gi");
216 var match2 = src_str.match(re);
217 if(match2){
218 src_str = src_str.replace(re,'');
220 var match2 = null;
221 re = new RegExp('</mark>',"gi");
222 if(match2){
223 src_str = src_str.replace(re,'');
225 document.getElementById('search_div_'+form_id+'_'+form_dir).innerHTML=src_str;
227 function mark_hilight(form_id,form_dir,keys,case_sensitive){ // Adds <mark>match_val</mark> tags
228 keys = keys.replace(/^\s+|\s+$/g, '') ;
229 if(keys == '') return;
230 var src_str = $j('#search_div_'+form_id+'_'+form_dir).html();
231 var term = keys;
232 if((/\s+/).test(term) == true || (/['""-]{1,}/).test(term) == true){
233 term = term.replace(/(\s+)/g,"(<[^>]+>)*$1(<[^>]+>)*");
234 if(case_sensitive == true){
235 var pattern = new RegExp("("+term+")", "g");
237 else{
238 var pattern = new RegExp("("+term+")", "ig");
240 src_str = src_str.replace(/[\s\r\n]{1,}/g, ' '); // Replace text area newline or multiple spaces with single space
241 src_str = src_str.replace(pattern, "<mark class='hilite'>$1</mark>");
242 src_str = src_str.replace(/(<mark class=\'hilite\'>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/g,"$1</mark>$2<mark class='hilite'>$4");
243 $j('#search_div_'+form_id+'_'+form_dir).html(src_str);
244 $j('.hilite').each(function(){
245 res_id = res_id+1;
246 $j(this).attr("id",'result_'+res_id);
248 }else{
249 if(case_sensitive == true)
250 doSearch(form_id,form_dir,'partial','hilite',keys,'true');
251 else
252 doSearch(form_id,form_dir,'partial','hilite',keys,'false');
256 var forms_array;
257 var res_array = Array();
258 function find_all(){ // for each report the function mark_hilight() is called
259 case_sensitive = false;
260 if ($j('#search_case').attr('checked')) {
261 case_sensitive = true;
263 var keys = document.getElementById('search_element').value;
264 var match = null;
265 match = keys.match(/[\^\$\.\|\?\+\(\)\\~`\!@#%&\+={}<>]{1,}/);
266 if(match){
267 document.getElementById('alert_msg').innerHTML='<?php echo xla('Special characters are not allowed');?>..!';
268 return;
270 else{
271 document.getElementById('alert_msg').innerHTML='';
274 forms_arr = document.getElementById('forms_to_search');
275 for (var i = 0; i < forms_arr.options.length; i++) {
276 if(forms_arr.options[i].selected ==true){
277 $j('.class_'+forms_arr.options[i].value).each(function(){
278 id_arr = this.id.split('search_div_');
279 var re = new RegExp('_','i');
280 new_id = id_arr[1].replace(re, "|");
281 new_id_arr = new_id.split('|');
282 form_id = new_id_arr[0];
283 form_dir = new_id_arr[1];
284 mark_hilight(form_id,form_dir,keys,case_sensitive);
289 if($j('.hilite').length <1){
290 if(keys != '')
291 document.getElementById('alert_msg').innerHTML='<?php echo xla('No results found');?>..!';
293 else{
294 document.getElementById('alert_msg').innerHTML='';
295 f_id = $j('.hilite:first').attr('id');
296 element = document.getElementById(f_id);
297 element.scrollIntoView(false);
302 function remove_mark_all(){ // clears previous search results if exists
303 $j('.report_search_div').each(function(){
304 var id_arr = this.id.split('search_div_');
305 var re = new RegExp('_','i');
306 var new_id = id_arr[1].replace(re, "|");
307 var new_id_arr = new_id.split('|');
308 var form_id = new_id_arr[0];
309 var form_dir = new_id_arr[1];
310 reset_highlight(form_id,form_dir,'hilite');
311 reset_highlight(form_id,form_dir,'hilite2');
312 remove_mark(form_id,form_dir);
313 res_id = 0;
314 res_array =[];
318 var last_visited = -1;
319 var last_clicked = "";
320 var cur_res =0;
321 function next(w_count){
322 cur_res++;
323 remove_mark_all();
324 find_all();
325 var index = -1;
326 if(!($j(".hilite")[0])) {
327 return;
329 $j('.hilite').each(function(){
330 if($j(this).is(":visible")){
331 index = index+1;
332 res_array[index] = this.id;
335 $j('.hilite').addClass("hilite2");
336 $j('.hilite').removeClass("hilite");
337 var array_count = res_array.length;
338 if(last_clicked == "prev"){
339 last_visited = last_visited + (w_count-1);
341 last_clicked = "next";
342 for(k=0;k<w_count;k++){
343 last_visited ++;
344 if(last_visited == array_count){
345 cur_res = 0;
346 last_visited = -1;
347 next(w_count);
348 return;
350 $j("#"+res_array[last_visited]).addClass("next");
352 element = document.getElementById(res_array[last_visited]);
353 element.scrollIntoView(false);
357 function prev(w_count){
358 cur_res--;
359 remove_mark_all();
360 find_all();
361 var index = -1;
362 if(!($j(".hilite")[0])) {
363 return;
365 $j('.hilite').each(function(){
366 if($j(this).is(":visible")){
367 index = index+1;
368 res_array[index] = this.id;
371 $j('.hilite').addClass("hilite2");
372 $j('.hilite').removeClass("hilite");
373 var array_count = res_array.length;
374 if(last_clicked == "next"){
375 last_visited = last_visited - (w_count-1);
377 last_clicked = "prev";
378 for(k=0;k<w_count;k++){
379 last_visited --;
380 if(last_visited < 0){
381 cur_res = (array_count/w_count) + 1;
382 last_visited = array_count;
383 prev(w_count);
384 return;
386 $j("#"+res_array[last_visited]).addClass("next");
390 element = document.getElementById(res_array[last_visited]);
391 element.scrollIntoView(false);
393 function clear_last_visit(){
394 last_visited = -1;
395 cur_res = 0;
396 res_array = [];
397 last_clicked = "";
400 function get_word_count(form_id,form_dir,keys,case_sensitive){
401 keys = keys.replace(/^\s+|\s+$/g, '') ;
402 if(keys == '') return;
403 var src_str = $j('#search_div_'+form_id+'_'+form_dir).html();
404 var term = keys;
405 if((/\s+/).test(term) == true){
406 term = term.replace(/(\s+)/g,"(<[^>]+>)*$1(<[^>]+>)*");
407 if(case_sensitive == true){
408 var pattern = new RegExp("("+term+")", "");
410 else{
411 var pattern = new RegExp("("+term+")", "i");
413 src_str = src_str.replace(/[\s\r\n]{1,}/g, ' '); // Replace text area newline or multiple spaces with single space
414 src_str = src_str.replace(pattern, "<mark class='hilite'>$1</mark>");
415 src_str = src_str.replace(/(<mark class=\'hilite\'>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/,"$1</mark>$2<mark class='hilite'>$4");
416 var res =[];
417 res = src_str.match(/<mark class=\'hilite\'>/g);
418 if(res != null){
419 return res.length;
421 }else{
422 return 1;
426 function next_prev(action){
427 var w_count =0;
428 case_sensitive = false;
429 if ($j('#search_case').attr('checked')) {
430 case_sensitive = true;
432 var keys = document.getElementById('search_element').value;
433 var match = null;
434 match = keys.match(/[\^\$\.\|\?\+\(\)\\~`\!@#%&\+={}<>]{1,}/);
435 if(match){
436 document.getElementById('alert_msg').innerHTML='<?php echo xla('Special characters are not allowed');?>..!';
437 return;
439 else{
440 document.getElementById('alert_msg').innerHTML='';
442 forms_arr = document.getElementById('forms_to_search');
443 for (var i = 0; i < forms_arr.options.length; i++) {
444 if(forms_arr.options[i].selected ==true){
445 $j('.class_'+forms_arr.options[i].value).each(function(){
446 id_arr = this.id.split('search_div_');
447 var re = new RegExp('_','i');
448 new_id = id_arr[1].replace(re, "|");
449 new_id_arr = new_id.split('|');
450 form_id = new_id_arr[0];
451 form_dir = new_id_arr[1];
452 w_count = get_word_count(form_id,form_dir,keys,case_sensitive);
454 if(!isNaN(w_count)){
455 break;
459 if(w_count <1){
460 if(keys != '')
461 document.getElementById('alert_msg').innerHTML='<?php echo xla('No results found');?>..!';
463 else{
464 document.getElementById('alert_msg').innerHTML='';
465 if(action == 'next'){
466 next(w_count);
468 else if (action == 'prev'){
469 prev(w_count);
471 var tot_res = res_array.length/w_count;
472 if(tot_res > 0){
473 document.getElementById('alert_msg').innerHTML='<?php echo xla('Showing result');?> '+cur_res+' <?php echo xla('of');?> '+tot_res;
478 </script>
479 </head>
480 <body class="body_top" style="padding-top:95px;">
481 <?php } ?>
482 <div id="report_custom" style="width:100%;"> <!-- large outer DIV -->
484 <?php
485 if (sizeof($_GET) > 0) { $ar = $_GET; }
486 else { $ar = $_POST; }
488 if ($printable) {
489 /*******************************************************************
490 $titleres = getPatientData($pid, "fname,lname,providerID");
491 $sql = "SELECT * FROM facility ORDER BY billing_location DESC LIMIT 1";
492 *******************************************************************/
493 $titleres = getPatientData($pid, "fname,lname,providerID,DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS");
494 if ($_SESSION['pc_facility']) {
495 $sql = "select * from facility where id=" . $_SESSION['pc_facility'];
496 } else {
497 $sql = "SELECT * FROM facility ORDER BY billing_location DESC LIMIT 1";
499 /******************************************************************/
500 $db = $GLOBALS['adodb']['db'];
501 $results = $db->Execute($sql);
502 $facility = array();
503 if (!$results->EOF) {
504 $facility = $results->fields;
506 // Setup Headers and Footers for html2PDF only Download
507 // in HTML view it's just one line at the top of page 1
508 echo '<page_header style="text-align:right;"> ' . xlt("PATIENT") . ':' . text($titleres['lname']) . ', ' . text($titleres['fname']) . ' - ' . $titleres['DOB_TS'] . '</page_header> ';
509 echo '<page_footer style="text-align:right;">' . xlt('Generated on') . ' ' . oeFormatShortDate() . ' - ' . text($facility['name']) . ' ' . text($facility['phone']) . '</page_footer>';
511 // Use logo if it exists as 'practice_logo.gif' in the site dir
512 // old code used the global custom dir which is no longer a valid
513 $practice_logo = "$OE_SITE_DIR/images/practice_logo.gif";
514 if (file_exists($practice_logo)) {
515 echo "<img src='$practice_logo' align='left'><br />\n";
518 <h2><?php echo $facility['name'] ?></h2>
519 <?php echo $facility['street'] ?><br>
520 <?php echo $facility['city'] ?>, <?php echo $facility['state'] ?> <?php echo $facility['postal_code'] ?><br clear='all'>
521 <?php echo $facility['phone'] ?><br>
523 <a href="javascript:window.close();"><span class='title'><?php echo $titleres['fname'] . " " . $titleres['lname']; ?></span></a><br>
524 <span class='text'><?php xl('Generated on','e'); ?>: <?php echo oeFormatShortDate(); ?></span>
525 <br><br>
527 <?php
530 else { // not printable
533 <!-- old href was here
534 <br><br> -->
536 <a href="./report/portal_custom_report.php?printable=1&<?php print postToGet($ar); ?>" class='link_submit' target='new' onclick='top.restoreSession()'>
537 <button><?php xl('Printable Version','e'); ?></button>
538 </a><br>
539 <!--<div class="report_search_bar" style="width:100%;" id="search_options">
540 <table style="width:100%;">
541 <tr>
542 <td>
543 <input type="text" onKeyUp="clear_last_visit();remove_mark_all();find_all();" name="search_element" id="search_element" style="width:180px;"/>
544 </td>
545 <td>
546 <a class="css_button" onClick="clear_last_visit();remove_mark_all();find_all();" ><span><?php //echo xlt('Find'); ?></span></a>
547 </td>
548 <td>
549 <a class="css_button" onClick="next_prev('prev');" ><span><?php //echo xlt('Prev'); ?></span></a>
550 </td>
551 <td>
552 <a class="css_button" onClick="next_prev('next');" ><span><?php //echo xlt('Next'); ?></span></a>
553 </td>
554 <td>
555 <input type="checkbox" onClick="clear_last_visit();remove_mark_all();find_all();" name="search_case" id="search_case" />
556 </td>
557 <td>
558 <span><?php //echo xlt('Match case'); ?></span>
559 </td>
560 <td style="padding-left:10px;">
561 <span class="text"><b><?php //echo xlt('Search In'); ?>:</b></span>
562 <br>
563 <?php
564 /* $form_id_arr = array();
565 $form_dir_arr = array();
566 $last_key ='';
567 //ksort($ar);
568 foreach ($ar as $key_search => $val_search) {
569 if ($key_search == 'pdf' || $key_search == '' ) continue;
570 if (($auth_notes_a || $auth_notes || $auth_coding_a || $auth_coding || $auth_med || $auth_relaxed)) {
571 preg_match('/^(.*)_(\d+)$/', $key_search, $res_search);
572 $form_id_arr[] = add_escape_custom($res_search[2]);
573 $form_dir_arr[] = add_escape_custom($res_search[1]);
576 //echo json_encode(json_encode($array_key_id));
577 if(sizeof($form_id_arr)>0){
578 $query = "SELECT DISTINCT(form_name),formdir FROM forms WHERE form_id IN ( '".implode("','",$form_id_arr)."') AND formdir IN ( '".implode("','",$form_dir_arr)."')";
579 $arr = sqlStatement($query);
580 echo "<select multiple size='4' style='width:300px;' id='forms_to_search' onchange='clear_last_visit();remove_mark_all();find_all();' >";
581 while($res_forms_ids = sqlFetchArray($arr)){
582 echo "<option value='".attr($res_forms_ids['formdir'])."' selected>".text($res_forms_ids['form_name'])."</option>";
584 echo "</select>";
585 } */
587 </td>
588 <td style="padding-left:10px;;width:30%;">
589 <span id ='alert_msg' style='color:red;'></span>
590 </td>
591 </tr>
592 </table>
593 </div>-->
594 <?php
595 } // end not printable ?>
597 <?php
599 // include ALL form's report.php files
600 $inclookupres = sqlStatement("select distinct formdir from forms where pid = '$pid' AND deleted=0");
601 while($result = sqlFetchArray($inclookupres)) {
602 // include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
603 $formdir = $result['formdir'];
604 if (substr($formdir,0,3) == 'LBF')
605 include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
606 else
607 include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
610 // For each form field from patient_report.php...
612 foreach ($ar as $key => $val) {
613 if ($key == 'pdf') continue;
615 // These are the top checkboxes (demographics, allergies, etc.).
617 if (stristr($key,"include_")) {
619 if ($val == "demographics") {
621 echo "<hr />";
622 echo "<div class='text demographics' id='DEM'>\n";
623 print "<h1>".xl('Patient Data').":</h1>";
624 // printRecDataOne($patient_data_array, getRecPatientData ($pid), $N);
625 $result1 = getPatientData($pid);
626 $result2 = getEmployerData($pid);
627 echo " <table>\n";
628 display_layout_rows('DEM', $result1, $result2);
629 echo " </table>\n";
630 echo "</div>\n";
632 } elseif ($val == "history") {
634 echo "<hr />";
635 echo "<div class='text history' id='HIS'>\n";
636 //if (acl_check('patients', 'med')) {
637 print "<h1>".xl('History Data').":</h1>";
638 // printRecDataOne($history_data_array, getRecHistoryData ($pid), $N);
639 $result1 = getHistoryData($pid);
640 echo " <table>\n";
641 display_layout_rows('HIS', $result1);
642 echo " </table>\n";
644 echo "</div>";
646 // } elseif ($val == "employer") {
647 // print "<br><span class='bold'>".xl('Employer Data').":</span><br>";
648 // printRecDataOne($employer_data_array, getRecEmployerData ($pid), $N);
650 } elseif ($val == "insurance") {
652 echo "<hr />";
653 echo "<div class='text insurance'>";
654 echo "<h1>".xl('Insurance Data').":</h1>";
655 print "<br><span class=bold>".xl('Primary Insurance Data').":</span><br>";
656 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"primary"), $N);
657 print "<span class=bold>".xl('Secondary Insurance Data').":</span><br>";
658 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"secondary"), $N);
659 print "<span class=bold>".xl('Tertiary Insurance Data').":</span><br>";
660 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"tertiary"), $N);
661 echo "</div>";
663 } elseif ($val == "billing") {
665 echo "<hr />";
666 echo "<div class='text billing'>";
667 print "<h1>".xl('Billing Information').":</h1>";
668 if (count($ar['newpatient']) > 0) {
669 $billings = array();
670 echo "<table>";
671 echo "<tr><td width='400' class='bold'>Code</td><td class='bold'>".xl('Fee')."</td></tr>\n";
672 $total = 0.00;
673 $copays = 0.00;
674 foreach ($ar['newpatient'] as $be) {
675 $ta = explode(":",$be);
676 $billing = getPatientBillingEncounter($pid,$ta[1]);
677 $billings[] = $billing;
678 foreach ($billing as $b) {
679 echo "<tr>\n";
680 echo "<td class=text>";
681 echo $b['code_type'] . ":\t" . $b['code'] . "&nbsp;". $b['modifier'] . "&nbsp;&nbsp;&nbsp;" . $b['code_text'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
682 echo "</td>\n";
683 echo "<td class=text>";
684 echo oeFormatMoney($b['fee']);
685 echo "</td>\n";
686 echo "</tr>\n";
687 $total += $b['fee'];
688 if ($b['code_type'] == "COPAY") {
689 $copays += $b['fee'];
693 echo "<tr><td>&nbsp;</td></tr>";
694 echo "<tr><td class=bold>".xl('Sub-Total')."</td><td class=text>" . oeFormatMoney($total + abs($copays)) . "</td></tr>";
695 echo "<tr><td class=bold>".xl('Paid')."</td><td class=text>" . oeFormatMoney(abs($copays)) . "</td></tr>";
696 echo "<tr><td class=bold>".xl('Total')."</td><td class=text>" . oeFormatMoney($total) . "</td></tr>";
697 echo "</table>";
698 echo "<pre>";
699 //print_r($billings);
700 echo "</pre>";
701 } else {
702 printPatientBilling($pid);
704 echo "</div>\n"; // end of billing DIV
706 /****
708 } elseif ($val == "allergies") {
710 print "<span class=bold>Patient Allergies:</span><br>";
711 printListData($pid, "allergy", "1");
713 } elseif ($val == "medications") {
715 print "<span class=bold>Patient Medications:</span><br>";
716 printListData($pid, "medication", "1");
718 } elseif ($val == "medical_problems") {
720 print "<span class=bold>Patient Medical Problems:</span><br>";
721 printListData($pid, "medical_problem", "1");
723 ****/
725 } elseif ($val == "immunizations") {
727 //if (acl_check('patients', 'med')) {
728 echo "<hr />";
729 echo "<div class='text immunizations'>\n";
730 print "<h1>".xl('Patient Immunization').":</h1>";
731 $sql = "select i1.immunization_id, i1.administered_date, substring(i1.note,1,20) as immunization_note, c.code_text_short ".
732 " from immunizations i1 ".
733 " left join code_types ct on ct.ct_key = 'CVX' ".
734 " left join codes c on c.code_type = ct.ct_id AND i1.cvx_code = c.code ".
735 " where i1.patient_id = '$pid' and i1.added_erroneously = 0 ".
736 " order by administered_date desc";
737 $result = sqlStatement($sql);
738 while ($row=sqlFetchArray($result)) {
739 // Figure out which name to use (ie. from cvx list or from the custom list)
740 if ($GLOBALS['use_custom_immun_list']) {
741 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
743 else {
744 if (!empty($row['code_text_short'])) {
745 $vaccine_display = htmlspecialchars( xl($row['code_text_short']), ENT_NOQUOTES);
747 else {
748 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
751 echo $row['administered_date'] . " - " . $vaccine_display;
752 if ($row['immunization_note']) {
753 echo " - " . $row['immunization_note'];
755 echo "<br>\n";
757 echo "</div>\n";
760 // communication report
761 } elseif ($val == "batchcom") {
763 echo "<hr />";
764 echo "<div class='text transactions'>\n";
765 print "<h1>".xl('Patient Communication sent').":</h1>";
766 $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'";
767 // echo $sql;
768 $result = sqlStatement($sql);
769 while ($row=sqlFetchArray($result)) {
770 echo $row{'batchcom_data'}.", By: ".$row{'user_name'}."<br>Text:<br> ".$row{'msg_txt'}."<br>\n";
772 echo "</div>\n";
774 } elseif ($val == "notes") {
776 echo "<hr />";
777 echo "<div class='text notes'>\n";
778 print "<h1>".xl('Patient Notes').":</h1>";
779 printPatientNotes($pid);
780 echo "</div>";
782 } elseif ($val == "transactions") {
784 echo "<hr />";
785 echo "<div class='text transactions'>\n";
786 print "<h1>".xl('Patient Transactions').":</h1>";
787 printPatientTransactions($pid);
788 echo "</div>";
792 } else {
794 // Documents is an array of checkboxes whose values are document IDs.
796 if ($key == "documents") {
798 echo "<hr />";
799 echo "<div class='text documents'>";
800 foreach($val as $valkey => $valvalue) {
801 $document_id = $valvalue;
802 if (!is_numeric($document_id)) continue;
803 $d = new Document($document_id);
804 $fname = basename($d->get_url());
805 $couch_docid = $d->get_couch_docid();
806 $couch_revid = $d->get_couch_revid();
807 $extension = substr($fname, strrpos($fname,"."));
808 echo "<h1>" . xl('Document') . " '" . $fname ."'</h1>";
809 $n = new Note();
810 $notes = $n->notes_factory($d->get_id());
811 if (!empty($notes)) echo "<table>";
812 foreach ($notes as $note) {
813 echo '<tr>';
814 echo '<td>' . xl('Note') . ' #' . $note->get_id() . '</td>';
815 echo '</tr>';
816 echo '<tr>';
817 echo '<td>' . xl('Date') . ': ' . oeFormatShortDate($note->get_date()) . '</td>';
818 echo '</tr>';
819 echo '<tr>';
820 echo '<td>'.$note->get_note().'<br><br></td>';
821 echo '</tr>';
823 if (!empty($notes)) echo "</table>";
825 $url_file = $d->get_url_filepath();
826 if($couch_docid && $couch_revid){
827 $url_file = $d->get_couch_url($pid,$encounter);
829 // Collect filename and path
830 $from_all = explode("/",$url_file);
831 $from_filename = array_pop($from_all);
832 $from_pathname_array = array();
833 for ($i=0;$i<$d->get_path_depth();$i++) {
834 $from_pathname_array[] = array_pop($from_all);
836 $from_pathname_array = array_reverse($from_pathname_array);
837 $from_pathname = implode("/",$from_pathname_array);
839 if($couch_docid && $couch_revid) {
840 $from_file = $GLOBALS['OE_SITE_DIR'] . '/documents/temp/' . $from_filename;
841 $to_file = substr($from_file, 0, strrpos($from_file, '.')) . '_converted.jpg';
843 else {
844 $from_file = $GLOBALS["fileroot"] . "/sites/" . $_SESSION['site_id'] .
845 '/documents/' . $from_pathname . '/' . $from_filename;
846 $to_file = substr($from_file, 0, strrpos($from_file, '.')) . '_converted.jpg';
849 if ($extension == ".png" || $extension == ".jpg" || $extension == ".jpeg" || $extension == ".gif") {
850 if ($PDF_OUTPUT) {
851 // OK to link to the image file because it will be accessed by the
852 // HTML2PDF parser and not the browser.
853 $from_rel = $web_root . substr($from_file, strlen($webserver_root));
854 echo "<img src='$from_rel'";
855 // Flag images with excessive width for possible stylesheet action.
856 $asize = getimagesize($from_file);
857 if ($asize[0] > 750) echo " class='bigimage'";
858 echo " /><br><br>";
860 else {
861 echo "<img src='" . $GLOBALS['webroot'] .
862 "/controller.php?document&retrieve&patient_id=&document_id=" .
863 $document_id . "&as_file=false'><br><br>";
866 else {
868 // Most clinic documents are expected to be PDFs, and in that happy case
869 // we can avoid the lengthy image conversion process.
870 if ($PDF_OUTPUT && $extension == ".pdf") {
871 // HTML to PDF conversion will fail if there are open tags.
872 echo "</div></div>\n";
873 $content = getContent();
874 // $pdf->setDefaultFont('Arial');
875 $pdf->writeHTML($content, false);
876 $pagecount = $pdf->pdf->setSourceFile($from_file);
877 for($i = 0; $i < $pagecount; ++$i){
878 $pdf->pdf->AddPage();
879 $itpl = $pdf->pdf->importPage($i + 1, '/MediaBox');
880 $pdf->pdf->useTemplate($itpl);
882 // Make sure whatever follows is on a new page.
883 $pdf->pdf->AddPage();
884 // Resume output buffering and the above-closed tags.
885 ob_start();
886 echo "<div><div class='text documents'>\n";
888 else {
889 if (! is_file($to_file)) exec("convert -density 200 \"$from_file\" -append -resize 850 \"$to_file\"");
890 if (is_file($to_file)) {
891 if ($PDF_OUTPUT) {
892 // OK to link to the image file because it will be accessed by the
893 // HTML2PDF parser and not the browser.
894 echo "<img src='$to_file'><br><br>";
896 else {
897 echo "<img src='" . $GLOBALS['webroot'] .
898 "/controller.php?document&retrieve&patient_id=&document_id=" .
899 $document_id . "&as_file=false&original_file=false'><br><br>";
901 } else {
902 echo "<b>NOTE</b>: " . xl('Document') . "'" . $fname . "' " .
903 xl('cannot be converted to JPEG. Perhaps ImageMagick is not installed?') . "<br><br>";
904 if($couch_docid && $couch_revid) {
905 unlink($from_file);
909 } // end if-else
910 } // end Documents loop
911 echo "</div>";
914 // Procedures is an array of checkboxes whose values are procedure order IDs.
916 else if ($key == "procedures") {
917 if ($auth_med) {
918 echo "<hr />";
919 echo "<div class='text documents'>";
920 foreach($val as $valkey => $poid) {
921 echo "<h1>" . xlt('Procedure Order') . ":</h1>";
922 echo "<br />\n";
923 // Need to move the inline styles from this function to the stylesheet, but until
924 // then we do it just for PDFs to avoid breaking anything.
925 generate_order_report($poid, false, !$PDF_OUTPUT);
926 echo "<br />\n";
928 echo "</div>";
932 else if (strpos($key, "issue_") === 0) {
933 // display patient Issues
935 if ($first_issue) {
936 $prevIssueType = 'asdf1234!@#$'; // random junk so as to not match anything
937 $first_issue = 0;
938 echo "<hr />";
939 echo "<h1>".xl("Issues")."</h1>";
941 preg_match('/^(.*)_(\d+)$/', $key, $res);
942 $rowid = $res[2];
943 $irow = sqlQuery("SELECT type, title, comments, diagnosis " .
944 "FROM lists WHERE id = '$rowid'");
945 $diagnosis = $irow['diagnosis'];
946 if ($prevIssueType != $irow['type']) {
947 // output a header for each Issue Type we encounter
948 $disptype = $ISSUE_TYPES[$irow['type']][0];
949 echo "<div class='issue_type'>" . $disptype . ":</div>\n";
950 $prevIssueType = $irow['type'];
952 echo "<div class='text issue'>";
953 echo "<span class='issue_title'>" . $irow['title'] . ":</span>";
954 echo "<span class='issue_comments'> " . $irow['comments'] . "</span>\n";
955 // Show issue's chief diagnosis and its description:
956 if ($diagnosis) {
957 echo "<div class='text issue_diag'>";
958 echo "<span class='bold'>[".xl('Diagnosis')."]</span><br>";
959 $dcodes = explode(";", $diagnosis);
960 foreach ($dcodes as $dcode) {
961 echo "<span class='italic'>".$dcode."</span>: ";
962 echo lookup_code_descriptions($dcode)."<br>\n";
964 //echo $diagnosis." -- ".lookup_code_descriptions($diagnosis)."\n";
965 echo "</div>";
968 // Supplemental data for GCAC or Contraception issues.
969 if ($irow['type'] == 'ippf_gcac') {
970 echo " <table>\n";
971 display_layout_rows('GCA', sqlQuery("SELECT * FROM lists_ippf_gcac WHERE id = '$rowid'"));
972 echo " </table>\n";
974 else if ($irow['type'] == 'contraceptive') {
975 echo " <table>\n";
976 display_layout_rows('CON', sqlQuery("SELECT * FROM lists_ippf_con WHERE id = '$rowid'"));
977 echo " </table>\n";
980 echo "</div>\n"; //end the issue DIV
982 } else {
983 // we have an "encounter form" form field whose name is like
984 // dirname_formid, with a value which is the encounter ID.
986 // display encounter forms, encoded as a POST variable
987 // in the format: <formdirname_formid>=<encounterID>
989 if (($auth_notes_a || $auth_notes || $auth_coding_a || $auth_coding || $auth_med || $auth_relaxed)) {
990 $form_encounter = $val;
991 preg_match('/^(.*)_(\d+)$/', $key, $res);
992 $form_id = $res[2];
993 $formres = getFormNameByFormdirAndFormid($res[1],$form_id);
994 $dateres = getEncounterDateByEncounter($form_encounter);
995 $formId = getFormIdByFormdirAndFormid($res[1], $form_id);
997 if ($res[1] == 'newpatient') {
998 echo "<div class='text encounter'>\n";
999 echo "<h1>" . xl($formres["form_name"]) . "</h1>";
1001 else {
1002 echo "<div class='text encounter_form'>";
1003 echo "<h1>" . xl_form_title($formres["form_name"]) . "</h1>";
1006 // show the encounter's date
1007 echo "(" . oeFormatSDFT(strtotime($dateres["date"])) . ") ";
1008 if ($res[1] == 'newpatient') {
1009 // display the provider info
1010 echo ' '. xl('Provider') . ': ' . text(getProviderName(getProviderIdOfEncounter($form_encounter)));
1012 echo "<br>\n";
1014 // call the report function for the form
1016 <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]); ?>">
1017 <?php
1018 if (substr($res[1],0,3) == 'LBF')
1019 call_user_func("lbf_report", $pid, $form_encounter, $N, $form_id, $res[1]);
1020 else
1021 call_user_func($res[1] . "_report", $pid, $form_encounter, $N, $form_id);
1023 $esign = $esignApi->createFormESign( $formId, $res[1], $form_encounter );
1024 if ( $esign->isLogViewable("report") ) {
1025 $esign->renderLog();
1029 </div>
1030 <?php
1032 if ($res[1] == 'newpatient') {
1033 // display billing info
1034 $bres = sqlStatement("SELECT b.date, b.code, b.code_text " .
1035 "FROM billing AS b, code_types AS ct WHERE " .
1036 "b.pid = ? AND " .
1037 "b.encounter = ? AND " .
1038 "b.activity = 1 AND " .
1039 "b.code_type = ct.ct_key AND " .
1040 "ct.ct_diag = 0 " .
1041 "ORDER BY b.date",
1042 array($pid, $form_encounter));
1043 while ($brow=sqlFetchArray($bres)) {
1044 echo "<span class='bold'>&nbsp;".xl('Procedure').": </span><span class='text'>" .
1045 $brow['code'] . " " . $brow['code_text'] . "</span><br>\n";
1049 print "</div>";
1051 } // end auth-check for encounter forms
1053 } // end if('issue_')... else...
1055 } // end if('include_')... else...
1057 } // end $ar loop
1059 if ($printable)
1060 echo "<br /><br />" . xl('Signature') . ": _______________________________<br />";
1063 </div> <!-- end of report_custom DIV -->
1065 <?php
1066 if ($PDF_OUTPUT) {
1067 $content = getContent();
1068 // $pdf->setDefaultFont('Arial');
1069 $pdf->writeHTML($content, false);
1070 if ($PDF_OUTPUT == 1) {
1071 $pdf->Output('report.pdf', $GLOBALS['pdf_output']); // D = Download, I = Inline
1073 else {
1074 // This is the case of writing the PDF as a message to the CMS portal.
1075 $ptdata = getPatientData($pid, 'cmsportal_login');
1076 $contents = $pdf->Output('', true);
1077 echo "<html><head>\n";
1078 echo "<link rel='stylesheet' href='$css_header' type='text/css'>\n";
1079 echo "</head><body class='body_top'>\n";
1080 $result = cms_portal_call(array(
1081 'action' => 'putmessage',
1082 'user' => $ptdata['cmsportal_login'],
1083 'title' => xl('Your Clinical Report'),
1084 'message' => xl('Please see the attached PDF.'),
1085 'filename' => 'report.pdf',
1086 'mimetype' => 'application/pdf',
1087 'contents' => base64_encode($contents),
1089 if ($result['errmsg']) die(text($result['errmsg']));
1090 echo "<p>" . xlt('Report has been sent to the patient.') . "</p>\n";
1091 echo "</body></html>\n";
1094 else {
1096 </body>
1097 </html>
1098 <?php } ?>