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