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