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>;.
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
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'];
37 header('Location: '.$landingpage.'&w');
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']);
70 require_once("$srcdir/html2pdf/vendor/autoload.php");
71 $pdf = new HTML2PDF ($GLOBALS['pdf_layout'],
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'])
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;
101 function getContent() {
102 global $web_root, $webserver_root;
103 $content = ob_get_clean();
104 // Fix a nasty html2pdf bug - it ignores document root!
106 $wrlen = strlen($web_root);
107 $wsrlen = strlen($webserver_root);
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);
120 function postToGet($arin) {
122 foreach ($arin as $key => $val) {
123 if (is_array($val)) {
124 foreach ($val as $k => $v) {
125 $getstring .= urlencode($key . "[]") . "=" . urlencode($v) . "&";
129 $getstring .= urlencode($key) . "=" . urlencode($val) . "&";
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; ?>" />
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. ?>
156 font
-size
: 20px
!important
;
165 input
[type
="checkbox"], input
[type
="radio"] {
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">
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
);
194 function doSearch(form_id
,form_dir
,exact
,class_name
,keys
,case_sensitive
) { // Uses jquery SearchHighlight Plug in
196 var keys
= keys
.replace(/^\s+|\s+$
/g
, '') ;
199 style_name
:class_name
,
200 style_name_suffix
:false,
201 highlight
:'#search_div_'+form_id+
'_'+form_dir
,
203 set_case_sensitive
:case_sensitive
205 $j(document
).SearchHighlight(options
);
206 $j('.'+class_name
).each(function(){
208 $j(this
).attr("id",'result_'+res_id
);
212 function remove_mark(form_id
,form_dir
){ // Removes all <mark> and </mark> tags
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
);
218 src_str
= src_str
.replace(re
,'');
221 re
= new RegExp('</mark>',"gi");
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();
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");
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(){
246 $j(this
).attr("id",'result_'+res_id
);
249 if(case_sensitive
== true)
250 doSearch(form_id
,form_dir
,'partial','hilite',keys
,'true');
252 doSearch(form_id
,form_dir
,'partial','hilite',keys
,'false');
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
;
265 match
= keys
.match(/[\^\$\
.\|\?\+\
(\
)\\~`\
!@#%&\+={}<>]{1,}/);
267 document
.getElementById('alert_msg').innerHTML
='<?php echo xla('Special characters are not allowed
');?>..!';
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){
291 document
.getElementById('alert_msg').innerHTML
='<?php echo xla('No results found
');?>..!';
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
);
318 var last_visited
= -1;
319 var last_clicked
= "";
321 function next(w_count
){
326 if(!($j(".hilite")[0])) {
329 $j('.hilite').each(function(){
330 if($j(this
).is(":visible")){
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++
){
344 if(last_visited
== array_count
){
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
){
362 if(!($j(".hilite")[0])) {
365 $j('.hilite').each(function(){
366 if($j(this
).is(":visible")){
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++
){
380 if(last_visited
< 0){
381 cur_res
= (array_count
/w_count
) +
1;
382 last_visited
= array_count
;
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(){
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();
405 if((/\s+
/).test(term
) == true){
406 term
= term
.replace(/(\s+
)/g
,"(<[^>]+>)*$1(<[^>]+>)*");
407 if(case_sensitive
== true){
408 var pattern
= new RegExp("("+term+
")", "");
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");
417 res
= src_str
.match(/<mark
class=\'hilite\'
>/g
);
426 function next_prev(action
){
428 case_sensitive
= false;
429 if ($j('#search_case').attr('checked')) {
430 case_sensitive
= true;
432 var keys
= document
.getElementById('search_element').value
;
434 match
= keys
.match(/[\^\$\
.\|\?\+\
(\
)\\~`\
!@#%&\+={}<>]{1,}/);
436 document
.getElementById('alert_msg').innerHTML
='<?php echo xla('Special characters are not allowed
');?>..!';
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
);
461 document
.getElementById('alert_msg').innerHTML
='<?php echo xla('No results found
');?>..!';
464 document
.getElementById('alert_msg').innerHTML
='';
465 if(action
== 'next'){
468 else if (action
== 'prev'){
471 var tot_res
= res_array
.length
/w_count
;
473 document
.getElementById('alert_msg').innerHTML
='<?php echo xla('Showing result
');?> '+cur_res+
' <?php echo xla('of
');?> '+tot_res
;
480 <body
class="body_top" style
="padding-top:95px;">
482 <div id
="report_custom" style
="width:100%;"> <!-- large outer DIV
-->
485 if (sizeof($_GET) > 0) { $ar = $_GET; }
486 else { $ar = $_POST; }
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'];
497 $sql = "SELECT * FROM facility ORDER BY billing_location DESC LIMIT 1";
499 /******************************************************************/
500 $db = $GLOBALS['adodb']['db'];
501 $results = $db->Execute($sql);
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
>
530 else { // not printable
533 <!-- old href was here
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
>
539 <!--<div
class="report_search_bar" style
="width:100%;" id
="search_options">
540 <table style
="width:100%;">
543 <input type
="text" onKeyUp
="clear_last_visit();remove_mark_all();find_all();" name
="search_element" id
="search_element" style
="width:180px;"/>
546 <a
class="css_button" onClick
="clear_last_visit();remove_mark_all();find_all();" ><span
><?php
//echo xlt('Find'); ?></span></a>
549 <a
class="css_button" onClick
="next_prev('prev');" ><span
><?php
//echo xlt('Prev'); ?></span></a>
552 <a
class="css_button" onClick
="next_prev('next');" ><span
><?php
//echo xlt('Next'); ?></span></a>
555 <input type
="checkbox" onClick
="clear_last_visit();remove_mark_all();find_all();" name
="search_case" id
="search_case" />
558 <span
><?php
//echo xlt('Match case'); ?></span>
560 <td style
="padding-left:10px;">
561 <span
class="text"><b
><?php
//echo xlt('Search In'); ?>:</b></span>
564 /* $form_id_arr = array();
565 $form_dir_arr = array();
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>";
588 <td style
="padding-left:10px;;width:30%;">
589 <span id
='alert_msg' style
='color:red;'></span
>
595 } // end not printable ?>
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");
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") {
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);
628 display_layout_rows('DEM', $result1, $result2);
632 } elseif ($val == "history") {
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);
641 display_layout_rows('HIS', $result1);
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") {
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);
663 } elseif ($val == "billing") {
666 echo "<div class='text billing'>";
667 print "<h1>".xl('Billing Information').":</h1>";
668 if (count($ar['newpatient']) > 0) {
671 echo "<tr><td width='400' class='bold'>Code</td><td class='bold'>".xl('Fee')."</td></tr>\n";
674 foreach ($ar['newpatient'] as $be) {
675 $ta = explode(":",$be);
676 $billing = getPatientBillingEncounter($pid,$ta[1]);
677 $billings[] = $billing;
678 foreach ($billing as $b) {
680 echo "<td class=text>";
681 echo $b['code_type'] . ":\t" . $b['code'] . " ". $b['modifier'] . " " . $b['code_text'] . " ";
683 echo "<td class=text>";
684 echo oeFormatMoney($b['fee']);
688 if ($b['code_type'] == "COPAY") {
689 $copays +
= $b['fee'];
693 echo "<tr><td> </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>";
699 //print_r($billings);
702 printPatientBilling($pid);
704 echo "</div>\n"; // end of billing DIV
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");
725 } elseif ($val == "immunizations") {
727 //if (acl_check('patients', 'med')) {
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']);
744 if (!empty($row['code_text_short'])) {
745 $vaccine_display = htmlspecialchars( xl($row['code_text_short']), ENT_NOQUOTES
);
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'];
760 // communication report
761 } elseif ($val == "batchcom") {
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'";
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";
774 } elseif ($val == "notes") {
777 echo "<div class='text notes'>\n";
778 print "<h1>".xl('Patient Notes').":</h1>";
779 printPatientNotes($pid);
782 } elseif ($val == "transactions") {
785 echo "<div class='text transactions'>\n";
786 print "<h1>".xl('Patient Transactions').":</h1>";
787 printPatientTransactions($pid);
794 // Documents is an array of checkboxes whose values are document IDs.
796 if ($key == "documents") {
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>";
810 $notes = $n->notes_factory($d->get_id());
811 if (!empty($notes)) echo "<table>";
812 foreach ($notes as $note) {
814 echo '<td>' . xl('Note') . ' #' . $note->get_id() . '</td>';
817 echo '<td>' . xl('Date') . ': ' . oeFormatShortDate($note->get_date()) . '</td>';
820 echo '<td>'.$note->get_note().'<br><br></td>';
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';
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") {
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'";
861 echo "<img src='" . $GLOBALS['webroot'] .
862 "/controller.php?document&retrieve&patient_id=&document_id=" .
863 $document_id . "&as_file=false'><br><br>";
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.
886 echo "<div><div class='text documents'>\n";
889 if (! is_file($to_file)) exec("convert -density 200 \"$from_file\" -append -resize 850 \"$to_file\"");
890 if (is_file($to_file)) {
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>";
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>";
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) {
910 } // end Documents loop
914 // Procedures is an array of checkboxes whose values are procedure order IDs.
916 else if ($key == "procedures") {
919 echo "<div class='text documents'>";
920 foreach($val as $valkey => $poid) {
921 echo "<h1>" . xlt('Procedure Order') . ":</h1>";
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);
932 else if (strpos($key, "issue_") === 0) {
933 // display patient Issues
936 $prevIssueType = 'asdf1234!@#$'; // random junk so as to not match anything
939 echo "<h1>".xl("Issues")."</h1>";
941 preg_match('/^(.*)_(\d+)$/', $key, $res);
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:
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";
968 // Supplemental data for GCAC or Contraception issues.
969 if ($irow['type'] == 'ippf_gcac') {
971 display_layout_rows('GCA', sqlQuery("SELECT * FROM lists_ippf_gcac WHERE id = '$rowid'"));
974 else if ($irow['type'] == 'contraceptive') {
976 display_layout_rows('CON', sqlQuery("SELECT * FROM lists_ippf_con WHERE id = '$rowid'"));
980 echo "</div>\n"; //end the issue DIV
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);
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>";
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)));
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]); ?>">
1018 if (substr($res[1],0,3) == 'LBF')
1019 call_user_func("lbf_report", $pid, $form_encounter, $N, $form_id, $res[1]);
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();
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 " .
1037 "b.encounter = ? AND " .
1038 "b.activity = 1 AND " .
1039 "b.code_type = ct.ct_key AND " .
1042 array($pid, $form_encounter));
1043 while ($brow=sqlFetchArray($bres)) {
1044 echo "<span class='bold'> ".xl('Procedure').": </span><span class='text'>" .
1045 $brow['code'] . " " . $brow['code_text'] . "</span><br>\n";
1051 } // end auth-check for encounter forms
1053 } // end if('issue_')... else...
1055 } // end if('include_')... else...
1060 echo "<br /><br />" . xl('Signature') . ": _______________________________<br />";
1063 </div
> <!-- end of report_custom DIV
-->
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
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";