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
25 require_once("../../globals.php");
26 require_once("$srcdir/forms.inc");
27 require_once("$srcdir/billing.inc");
28 require_once("$srcdir/pnotes.inc");
29 require_once("$srcdir/patient.inc");
30 require_once("$srcdir/options.inc.php");
31 require_once("$srcdir/acl.inc");
32 require_once("$srcdir/lists.inc");
33 require_once("$srcdir/report.inc");
34 require_once("$srcdir/formatting.inc.php");
35 require_once(dirname(__file__
) . "/../../../custom/code_types.inc.php");
36 require_once $GLOBALS['srcdir'].'/ESign/Api.php';
37 require_once($GLOBALS["include_root"] . "/orders/single_order_results.inc.php");
38 if ($GLOBALS['gbl_portal_cms_enable']) {
39 require_once($GLOBALS["include_root"] . "/cmsportal/portal.inc.php");
41 require_once("$srcdir/appointments.inc.php");
42 // For those who care that this is the patient report.
43 $GLOBALS['PATIENT_REPORT_ACTIVE'] = true;
45 $PDF_OUTPUT = empty($_POST['pdf']) ?
0 : intval($_POST['pdf']);
48 require_once("$srcdir/html2pdf/vendor/autoload.php");
49 $pdf = new HTML2PDF ($GLOBALS['pdf_layout'],
51 $GLOBALS['pdf_language'],
52 true, // default unicode setting is true
53 'UTF-8', // default encoding setting is UTF-8
54 array($GLOBALS['pdf_left_margin'],$GLOBALS['pdf_top_margin'],$GLOBALS['pdf_right_margin'],$GLOBALS['pdf_bottom_margin']),
55 $_SESSION['language_direction'] == 'rtl' ?
true : false
57 //set 'dejavusans' for now. which is supported by a lot of languages - http://dejavu-fonts.org/wiki/Main_Page
58 //TODO: can have this selected as setting in globals after we have more experience with this to fully support internationalization.
59 $pdf->setDefaultFont('dejavusans');
64 // get various authorization levels
65 $auth_notes_a = acl_check('encounters', 'notes_a');
66 $auth_notes = acl_check('encounters', 'notes');
67 $auth_coding_a = acl_check('encounters', 'coding_a');
68 $auth_coding = acl_check('encounters', 'coding');
69 $auth_relaxed = acl_check('encounters', 'relaxed');
70 $auth_med = acl_check('patients' , 'med');
71 $auth_demo = acl_check('patients' , 'demo');
73 $esignApi = new Api();
75 $printable = empty($_GET['printable']) ?
false : true;
76 if ($PDF_OUTPUT) { $printable = true; }
77 unset($_GET['printable']);
79 // Number of columns in tables for insurance and encounter forms.
80 $N = $PDF_OUTPUT ?
4 : 6;
84 function getContent() {
85 global $web_root, $webserver_root;
86 $content = ob_get_clean();
87 // Fix a nasty html2pdf bug - it ignores document root!
89 $wrlen = strlen($web_root);
90 $wsrlen = strlen($webserver_root);
92 $i = stripos($content, " src='/", $i +
1);
93 if ($i === false) break;
94 if (substr($content, $i+
6, $wrlen) === $web_root &&
95 substr($content, $i+
6, $wsrlen) !== $webserver_root)
97 $content = substr($content, 0, $i +
6) . $webserver_root . substr($content, $i +
6 +
$wrlen);
103 function postToGet($arin) {
105 foreach ($arin as $key => $val) {
106 if (is_array($val)) {
107 foreach ($val as $k => $v) {
108 $getstring .= urlencode($key . "[]") . "=" . urlencode($v) . "&";
112 $getstring .= urlencode($key) . "=" . urlencode($val) . "&";
119 <?php
if ($PDF_OUTPUT) { ?
>
120 <link rel
="stylesheet" href
="<?php echo $webserver_root . '/interface/themes/style_pdf.css' ?>" type
="text/css">
121 <link rel
="stylesheet" type
="text/css" href
="<?php echo $webserver_root; ?>/library/ESign/css/esign_report.css" />
125 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
126 <link rel
="stylesheet" type
="text/css" href
="<?php echo $GLOBALS['webroot'] ?>/library/ESign/css/esign_report.css" />
129 <?php
// do not show stuff from report.php in forms that is encaspulated
130 // by div of navigateLink class. Specifically used for CAMOS, but
131 // can also be used by other forms that require output in the
132 // encounter listings output, but not in the custom report. ?>
134 div
.navigateLink
{display
:none
;}
135 .hilite
{background
-color
: #FFFF00;}
136 .hilite2
{background
-color
: transparent
;}
137 mark
{background
-color
: #FFFF00;}
138 .css_button
{cursor
:pointer
;}
139 .next
{background
-color
: #FFFF00;}
145 border
-bottom
: solid thin
#6D6D6D;
146 padding
:0%
2%
0%
2.5%
;
148 img
{ max
-width
:700px
; }
151 <?php
if (!$PDF_OUTPUT) { ?
>
153 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script
>
154 <script type
="text/javascript" src
="<?php echo $GLOBALS['web_root']?>/library/js/SearchHighlight.js"></script
>
155 <script type
="text/javascript">var $j = jQuery
.noConflict();</script
>
157 <?php
// if the track_anything form exists, then include the styling
158 if (file_exists(dirname(__FILE__
) . "/../../forms/track_anything/style.css")) { ?
>
159 <link rel
="stylesheet" href
="<?php echo $GLOBALS['web_root']?>/interface/forms/track_anything/style.css" type
="text/css">
164 // remove blank header for printable version to conserve space
165 // adjust this if you are printing to letterhead to appropriate height
166 ($printable) ?
($style = ''):($style='padding-top:95px;');
168 <body
class="body_top" style
="<?php echo $style; ?>">
170 <div id
="report_custom" style
="width:100%;"> <!-- large outer DIV
-->
173 if (sizeof($_GET) > 0) { $ar = $_GET; }
174 else { $ar = $_POST; }
176 /*******************************************************************
177 $titleres = getPatientData($pid, "fname,lname,providerID");
178 $sql = "SELECT * FROM facility ORDER BY billing_location DESC LIMIT 1";
179 *******************************************************************/
180 $titleres = getPatientData($pid, "fname,lname,providerID,DATE_FORMAT(DOB,'%m/%d/%Y') as DOB_TS");
181 if ($_SESSION['pc_facility']) {
182 $sql = "select * from facility where id=" . $_SESSION['pc_facility'];
184 $sql = "SELECT * FROM facility ORDER BY billing_location DESC LIMIT 1";
186 /******************************************************************/
187 $db = $GLOBALS['adodb']['db'];
188 $results = $db->Execute($sql);
190 if (!$results->EOF
) {
191 $facility = $results->fields
;
193 // Setup Headers and Footers for html2PDF only Download
194 // in HTML view it's just one line at the top of page 1
195 echo '<page_header style="text-align:right;" class="custom-tag"> ' . xlt("PATIENT") . ':' . text($titleres['lname']) . ', ' . text($titleres['fname']) . ' - ' . $titleres['DOB_TS'] . '</page_header> ';
196 echo '<page_footer style="text-align:right;" class="custom-tag">' . xlt('Generated on') . ' ' . oeFormatShortDate() . ' - ' . text($facility['name']) . ' ' . text($facility['phone']) . '</page_footer>';
198 // Use logo if it exists as 'practice_logo.gif' in the site dir
199 // old code used the global custom dir which is no longer a valid
200 $practice_logo = "$OE_SITE_DIR/images/practice_logo.gif";
201 if (file_exists($practice_logo)) {
202 echo "<img src='$practice_logo' align='left'><br />\n";
205 <h2
><?php
echo $facility['name'] ?
></h2
>
206 <?php
echo $facility['street'] ?
><br
>
207 <?php
echo $facility['city'] ?
>, <?php
echo $facility['state'] ?
> <?php
echo $facility['postal_code'] ?
><br clear
='all'>
208 <?php
echo $facility['phone'] ?
><br
>
210 <a href
="javascript:window.close();"><span
class='title'><?php
echo $titleres['fname'] . " " . $titleres['lname']; ?
></span
></a
><br
>
211 <span
class='text'><?php
xl('Generated on','e'); ?
>: <?php
echo oeFormatShortDate(); ?
></span
>
217 else { // not printable
220 <a href
="patient_report.php" onclick
='top.restoreSession()'>
221 <span
class='title'><?php
xl('Patient Report','e'); ?
></span
>
222 <span
class='back'><?php
echo $tback;?
></span
>
224 <a href
="custom_report.php?printable=1&<?php print postToGet($ar); ?>" class='link_submit' target
='new' onclick
='top.restoreSession()'>
225 [<?php
xl('Printable Version','e'); ?
>]
227 <div
class="report_search_bar" style
="width:100%;" id
="search_options">
228 <table style
="width:100%;">
231 <input type
="text" onKeyUp
="clear_last_visit();remove_mark_all();find_all();" name
="search_element" id
="search_element" style
="width:180px;"/>
234 <a
class="css_button" onClick
="clear_last_visit();remove_mark_all();find_all();" ><span
><?php
echo xlt('Find'); ?
></span
></a
>
237 <a
class="css_button" onClick
="next_prev('prev');" ><span
><?php
echo xlt('Prev'); ?
></span
></a
>
240 <a
class="css_button" onClick
="next_prev('next');" ><span
><?php
echo xlt('Next'); ?
></span
></a
>
243 <input type
="checkbox" onClick
="clear_last_visit();remove_mark_all();find_all();" name
="search_case" id
="search_case" />
246 <span
><?php
echo xlt('Match case'); ?
></span
>
248 <td style
="padding-left:10px;">
249 <span
class="text"><b
><?php
echo xlt('Search In'); ?
>:</b
></span
>
252 $form_id_arr = array();
253 $form_dir_arr = array();
256 foreach ($ar as $key_search => $val_search) {
257 if ($key_search == 'pdf' ||
$key_search == '' ) continue;
258 if (($auth_notes_a ||
$auth_notes ||
$auth_coding_a ||
$auth_coding ||
$auth_med ||
$auth_relaxed)) {
259 preg_match('/^(.*)_(\d+)$/', $key_search, $res_search);
260 $form_id_arr[] = add_escape_custom($res_search[2]);
261 $form_dir_arr[] = add_escape_custom($res_search[1]);
264 //echo json_encode(json_encode($array_key_id));
265 if(sizeof($form_id_arr)>0){
266 $query = "SELECT DISTINCT(form_name),formdir FROM forms WHERE form_id IN ( '".implode("','",$form_id_arr)."') AND formdir IN ( '".implode("','",$form_dir_arr)."')";
267 $arr = sqlStatement($query);
268 echo "<select multiple size='4' style='width:300px;' id='forms_to_search' onchange='clear_last_visit();remove_mark_all();find_all();' >";
269 while($res_forms_ids = sqlFetchArray($arr)){
270 echo "<option value='".attr($res_forms_ids['formdir'])."' selected>".text($res_forms_ids['form_name'])."</option>";
276 <td style
="padding-left:10px;;width:30%;">
277 <span id
='alert_msg' style
='color:red;'></span
>
283 } // end not printable ?>
287 // include ALL form's report.php files
288 $inclookupres = sqlStatement("select distinct formdir from forms where pid = '$pid' AND deleted=0");
289 while($result = sqlFetchArray($inclookupres)) {
290 // include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
291 $formdir = $result['formdir'];
292 if (substr($formdir,0,3) == 'LBF')
293 include_once($GLOBALS['incdir'] . "/forms/LBF/report.php");
295 include_once($GLOBALS['incdir'] . "/forms/$formdir/report.php");
298 // For each form field from patient_report.php...
300 foreach ($ar as $key => $val) {
301 if ($key == 'pdf') continue;
303 // These are the top checkboxes (demographics, allergies, etc.).
305 if (stristr($key,"include_")) {
307 if($val == "recurring_days"){
309 /// label/header for recurring days
311 echo "<div class='text' id='appointments'>\n";
312 print "<h1>".xlt('Recurrent Appointments').":</h1>";
314 //fetch the data of the recurring days
315 $recurrences = fetchRecurrences($pid);
317 //print the recurring days to screen
318 if($recurrences[0] == false){ //if there are no recurrent appointments:
319 echo "<div class='text' >";
320 echo "<span>" . xlt('None') . "</span>";
325 foreach ($recurrences as $row) {
326 //checks if there are recurrences and if they are current (git didn't end yet)
327 if ($row == false ||
!recurrence_is_current($row['pc_endDate']))
329 echo "<div class='text' >";
330 echo "<span>" . xlt('Appointment Category') . ': ' . xlt($row['pc_catname']) . "</span>";
332 echo "<span>" . xlt('Recurrence') . ': ' .text($row['pc_recurrspec']) . "</span>";
334 $red_text = ""; //if ends in a week, make font red
335 if (ends_in_a_week($row['pc_endDate'])) {
336 $red_text = " style=\"color:red;\" ";
338 echo "<span" . $red_text . ">" . xlt('End Date') . ': ' . text($row['pc_endDate']) . "</span>";
344 elseif ($val == "demographics") {
347 echo "<div class='text demographics' id='DEM'>\n";
348 print "<h1>".xl('Patient Data').":</h1>";
349 // printRecDataOne($patient_data_array, getRecPatientData ($pid), $N);
350 $result1 = getPatientData($pid);
351 $result2 = getEmployerData($pid);
353 display_layout_rows('DEM', $result1, $result2);
357 } elseif ($val == "history") {
360 echo "<div class='text history' id='HIS'>\n";
361 if (acl_check('patients', 'med')) {
362 print "<h1>".xl('History Data').":</h1>";
363 // printRecDataOne($history_data_array, getRecHistoryData ($pid), $N);
364 $result1 = getHistoryData($pid);
366 display_layout_rows('HIS', $result1);
371 // } elseif ($val == "employer") {
372 // print "<br><span class='bold'>".xl('Employer Data').":</span><br>";
373 // printRecDataOne($employer_data_array, getRecEmployerData ($pid), $N);
375 } elseif ($val == "insurance") {
378 echo "<div class='text insurance'>";
379 echo "<h1>".xl('Insurance Data').":</h1>";
380 print "<br><span class=bold>".xl('Primary Insurance Data').":</span><br>";
381 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"primary"), $N);
382 print "<span class=bold>".xl('Secondary Insurance Data').":</span><br>";
383 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"secondary"), $N);
384 print "<span class=bold>".xl('Tertiary Insurance Data').":</span><br>";
385 printRecDataOne($insurance_data_array, getRecInsuranceData ($pid,"tertiary"), $N);
388 } elseif ($val == "billing") {
391 echo "<div class='text billing'>";
392 print "<h1>".xl('Billing Information').":</h1>";
393 if (count($ar['newpatient']) > 0) {
396 echo "<tr><td width='400' class='bold'>Code</td><td class='bold'>".xl('Fee')."</td></tr>\n";
399 foreach ($ar['newpatient'] as $be) {
400 $ta = explode(":",$be);
401 $billing = getPatientBillingEncounter($pid,$ta[1]);
402 $billings[] = $billing;
403 foreach ($billing as $b) {
405 echo "<td class=text>";
406 echo $b['code_type'] . ":\t" . $b['code'] . " ". $b['modifier'] . " " . $b['code_text'] . " ";
408 echo "<td class=text>";
409 echo oeFormatMoney($b['fee']);
413 if ($b['code_type'] == "COPAY") {
414 $copays +
= $b['fee'];
418 echo "<tr><td> </td></tr>";
419 echo "<tr><td class=bold>".xl('Sub-Total')."</td><td class=text>" . oeFormatMoney($total +
abs($copays)) . "</td></tr>";
420 echo "<tr><td class=bold>".xl('Paid')."</td><td class=text>" . oeFormatMoney(abs($copays)) . "</td></tr>";
421 echo "<tr><td class=bold>".xl('Total')."</td><td class=text>" . oeFormatMoney($total) . "</td></tr>";
424 //print_r($billings);
427 printPatientBilling($pid);
429 echo "</div>\n"; // end of billing DIV
433 } elseif ($val == "allergies") {
435 print "<span class=bold>Patient Allergies:</span><br>";
436 printListData($pid, "allergy", "1");
438 } elseif ($val == "medications") {
440 print "<span class=bold>Patient Medications:</span><br>";
441 printListData($pid, "medication", "1");
443 } elseif ($val == "medical_problems") {
445 print "<span class=bold>Patient Medical Problems:</span><br>";
446 printListData($pid, "medical_problem", "1");
450 } elseif ($val == "immunizations") {
452 if (acl_check('patients', 'med')) {
454 echo "<div class='text immunizations'>\n";
455 print "<h1>".xl('Patient Immunization').":</h1>";
456 $sql = "select i1.immunization_id, i1.administered_date, substring(i1.note,1,20) as immunization_note, c.code_text_short ".
457 " from immunizations i1 ".
458 " left join code_types ct on ct.ct_key = 'CVX' ".
459 " left join codes c on c.code_type = ct.ct_id AND i1.cvx_code = c.code ".
460 " where i1.patient_id = '$pid' and i1.added_erroneously = 0 ".
461 " order by administered_date desc";
462 $result = sqlStatement($sql);
463 while ($row=sqlFetchArray($result)) {
464 // Figure out which name to use (ie. from cvx list or from the custom list)
465 if ($GLOBALS['use_custom_immun_list']) {
466 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
469 if (!empty($row['code_text_short'])) {
470 $vaccine_display = htmlspecialchars( xl($row['code_text_short']), ENT_NOQUOTES
);
473 $vaccine_display = generate_display_field(array('data_type'=>'1','list_id'=>'immunizations'), $row['immunization_id']);
476 echo $row['administered_date'] . " - " . $vaccine_display;
477 if ($row['immunization_note']) {
478 echo " - " . $row['immunization_note'];
485 // communication report
486 } elseif ($val == "batchcom") {
489 echo "<div class='text transactions'>\n";
490 print "<h1>".xl('Patient Communication sent').":</h1>";
491 $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'";
493 $result = sqlStatement($sql);
494 while ($row=sqlFetchArray($result)) {
495 echo $row{'batchcom_data'}.", By: ".$row{'user_name'}."<br>Text:<br> ".$row{'msg_txt'}."<br>\n";
499 } elseif ($val == "notes") {
502 echo "<div class='text notes'>\n";
503 print "<h1>".xl('Patient Notes').":</h1>";
504 printPatientNotes($pid);
507 } elseif ($val == "transactions") {
510 echo "<div class='text transactions'>\n";
511 print "<h1>".xl('Patient Transactions').":</h1>";
512 printPatientTransactions($pid);
519 // Documents is an array of checkboxes whose values are document IDs.
521 if ($key == "documents") {
524 echo "<div class='text documents'>";
525 foreach($val as $valkey => $valvalue) {
526 $document_id = $valvalue;
527 if (!is_numeric($document_id)) continue;
528 $d = new Document($document_id);
529 $fname = basename($d->get_url());
530 $couch_docid = $d->get_couch_docid();
531 $couch_revid = $d->get_couch_revid();
532 echo "<h1>" . xl('Document') . " '" . $fname ."'</h1>";
534 $notes = $n->notes_factory($d->get_id());
535 if (!empty($notes)) echo "<table>";
536 foreach ($notes as $note) {
538 echo '<td>' . xl('Note') . ' #' . $note->get_id() . '</td>';
541 echo '<td>' . xl('Date') . ': ' . oeFormatShortDate($note->get_date()) . '</td>';
544 echo '<td>'.$note->get_note().'<br><br></td>';
547 if (!empty($notes)) echo "</table>";
549 $url_file = $d->get_url_filepath();
550 if($couch_docid && $couch_revid){
551 $url_file = $d->get_couch_url($pid,$encounter);
553 // Collect filename and path
554 $from_all = explode("/",$url_file);
555 $from_filename = array_pop($from_all);
556 $from_pathname_array = array();
557 for ($i=0;$i<$d->get_path_depth();$i++
) {
558 $from_pathname_array[] = array_pop($from_all);
560 $from_pathname_array = array_reverse($from_pathname_array);
561 $from_pathname = implode("/",$from_pathname_array);
563 if($couch_docid && $couch_revid) {
564 $from_file = $GLOBALS['OE_SITE_DIR'] . '/documents/temp/' . $from_filename;
565 $to_file = substr($from_file, 0, strrpos($from_file, '.')) . '_converted.jpg';
568 $from_file = $GLOBALS["fileroot"] . "/sites/" . $_SESSION['site_id'] .
569 '/documents/' . $from_pathname . '/' . $from_filename;
570 $to_file = substr($from_file, 0, strrpos($from_file, '.')) . '_converted.jpg';
573 //Extract the extension by the mime/type and not the file name extension
574 // -There is an exception. Need to manually see if it a pdf since
575 // the image_type_to_extension() is not working to identify pdf.
576 $extension = substr($fname, strrpos($fname,"."));
577 if ($extension != ".pdf") {
578 $image_data = getimagesize($from_file);
579 $extension = image_type_to_extension($image_data[2]);
582 if ($extension == ".png" ||
$extension == ".jpg" ||
$extension == ".jpeg" ||
$extension == ".gif") {
584 // OK to link to the image file because it will be accessed by the
585 // HTML2PDF parser and not the browser.
586 $from_rel = $web_root . substr($from_file, strlen($webserver_root));
587 echo "<img src='$from_rel'";
588 // Flag images with excessive width for possible stylesheet action.
589 $asize = getimagesize($from_file);
590 if ($asize[0] > 750) echo " class='bigimage'";
594 echo "<img src='" . $GLOBALS['webroot'] .
595 "/controller.php?document&retrieve&patient_id=&document_id=" .
596 $document_id . "&as_file=false&original_file=true&disable_exit=false&show_original=true'><br><br>";
601 // Most clinic documents are expected to be PDFs, and in that happy case
602 // we can avoid the lengthy image conversion process.
603 if ($PDF_OUTPUT && $extension == ".pdf") {
604 // HTML to PDF conversion will fail if there are open tags.
605 echo "</div></div>\n";
606 $content = getContent();
607 // $pdf->setDefaultFont('Arial');
608 $pdf->writeHTML($content, false);
609 $pagecount = $pdf->pdf
->setSourceFile($from_file);
610 for($i = 0; $i < $pagecount; ++
$i){
611 $pdf->pdf
->AddPage();
612 $itpl = $pdf->pdf
->importPage($i +
1, '/MediaBox');
613 $pdf->pdf
->useTemplate($itpl);
615 // Make sure whatever follows is on a new page.
616 $pdf->pdf
->AddPage();
617 // Resume output buffering and the above-closed tags.
619 echo "<div><div class='text documents'>\n";
622 if (! is_file($to_file)) exec("convert -density 200 \"$from_file\" -append -resize 850 \"$to_file\"");
623 if (is_file($to_file)) {
625 // OK to link to the image file because it will be accessed by the
626 // HTML2PDF parser and not the browser.
627 echo "<img src='$to_file'><br><br>";
630 echo "<img src='" . $GLOBALS['webroot'] .
631 "/controller.php?document&retrieve&patient_id=&document_id=" .
632 $document_id . "&as_file=false&original_file=false'><br><br>";
635 echo "<b>NOTE</b>: " . xl('Document') . "'" . $fname . "' " .
636 xl('cannot be converted to JPEG. Perhaps ImageMagick is not installed?') . "<br><br>";
637 if($couch_docid && $couch_revid) {
643 } // end Documents loop
647 // Procedures is an array of checkboxes whose values are procedure order IDs.
649 else if ($key == "procedures") {
652 echo "<div class='text documents'>";
653 foreach($val as $valkey => $poid) {
654 echo "<h1>" . xlt('Procedure Order') . ":</h1>";
656 // Need to move the inline styles from this function to the stylesheet, but until
657 // then we do it just for PDFs to avoid breaking anything.
658 generate_order_report($poid, false, !$PDF_OUTPUT);
665 else if (strpos($key, "issue_") === 0) {
666 // display patient Issues
669 $prevIssueType = 'asdf1234!@#$'; // random junk so as to not match anything
672 echo "<h1>".xl("Issues")."</h1>";
674 preg_match('/^(.*)_(\d+)$/', $key, $res);
676 $irow = sqlQuery("SELECT type, title, comments, diagnosis " .
677 "FROM lists WHERE id = '$rowid'");
678 $diagnosis = $irow['diagnosis'];
679 if ($prevIssueType != $irow['type']) {
680 // output a header for each Issue Type we encounter
681 $disptype = $ISSUE_TYPES[$irow['type']][0];
682 echo "<div class='issue_type'>" . $disptype . ":</div>\n";
683 $prevIssueType = $irow['type'];
685 echo "<div class='text issue'>";
686 echo "<span class='issue_title'>" . $irow['title'] . ":</span>";
687 echo "<span class='issue_comments'> " . $irow['comments'] . "</span>\n";
688 // Show issue's chief diagnosis and its description:
690 echo "<div class='text issue_diag'>";
691 echo "<span class='bold'>[".xl('Diagnosis')."]</span><br>";
692 $dcodes = explode(";", $diagnosis);
693 foreach ($dcodes as $dcode) {
694 echo "<span class='italic'>".$dcode."</span>: ";
695 echo lookup_code_descriptions($dcode)."<br>\n";
697 //echo $diagnosis." -- ".lookup_code_descriptions($diagnosis)."\n";
701 // Supplemental data for GCAC or Contraception issues.
702 if ($irow['type'] == 'ippf_gcac') {
704 display_layout_rows('GCA', sqlQuery("SELECT * FROM lists_ippf_gcac WHERE id = '$rowid'"));
707 else if ($irow['type'] == 'contraceptive') {
709 display_layout_rows('CON', sqlQuery("SELECT * FROM lists_ippf_con WHERE id = '$rowid'"));
713 echo "</div>\n"; //end the issue DIV
716 // we have an "encounter form" form field whose name is like
717 // dirname_formid, with a value which is the encounter ID.
719 // display encounter forms, encoded as a POST variable
720 // in the format: <formdirname_formid>=<encounterID>
722 if (($auth_notes_a ||
$auth_notes ||
$auth_coding_a ||
$auth_coding ||
$auth_med ||
$auth_relaxed)) {
723 $form_encounter = $val;
724 preg_match('/^(.*)_(\d+)$/', $key, $res);
726 $formres = getFormNameByFormdirAndFormid($res[1],$form_id);
727 $dateres = getEncounterDateByEncounter($form_encounter);
728 $formId = getFormIdByFormdirAndFormid($res[1], $form_id);
730 if ($res[1] == 'newpatient') {
731 echo "<div class='text encounter'>\n";
732 echo "<h1>" . xl($formres["form_name"]) . "</h1>";
735 echo "<div class='text encounter_form'>";
736 echo "<h1>" . xl_form_title($formres["form_name"]) . "</h1>";
739 // show the encounter's date
740 echo "(" . oeFormatSDFT(strtotime($dateres["date"])) . ") ";
741 if ($res[1] == 'newpatient') {
742 // display the provider info
743 echo ' '. xl('Provider') . ': ' . text(getProviderName(getProviderIdOfEncounter($form_encounter)));
747 // call the report function for the form
749 <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]); ?>">
751 if (substr($res[1],0,3) == 'LBF')
752 call_user_func("lbf_report", $pid, $form_encounter, $N, $form_id, $res[1]);
754 call_user_func($res[1] . "_report", $pid, $form_encounter, $N, $form_id);
756 $esign = $esignApi->createFormESign( $formId, $res[1], $form_encounter );
757 if ( $esign->isLogViewable("report") ) {
765 if ($res[1] == 'newpatient') {
766 // display billing info
767 $bres = sqlStatement("SELECT b.date, b.code, b.code_text " .
768 "FROM billing AS b, code_types AS ct WHERE " .
770 "b.encounter = ? AND " .
771 "b.activity = 1 AND " .
772 "b.code_type = ct.ct_key AND " .
775 array($pid, $form_encounter));
776 while ($brow=sqlFetchArray($bres)) {
777 echo "<span class='bold'> ".xl('Procedure').": </span><span class='text'>" .
778 $brow['code'] . " " . $brow['code_text'] . "</span><br>\n";
784 } // end auth-check for encounter forms
786 } // end if('issue_')... else...
788 } // end if('include_')... else...
793 echo "<br /><br />" . xl('Signature') . ": _______________________________<br />";
796 </div
> <!-- end of report_custom DIV
-->
800 $content = getContent();
801 // $pdf->setDefaultFont('Arial');
802 $pdf->writeHTML($content, false);
803 if ($PDF_OUTPUT == 1) {
804 $pdf->Output('report.pdf', $GLOBALS['pdf_output']); // D = Download, I = Inline
807 // This is the case of writing the PDF as a message to the CMS portal.
808 $ptdata = getPatientData($pid, 'cmsportal_login');
809 $contents = $pdf->Output('', true);
810 echo "<html><head>\n";
811 echo "<link rel='stylesheet' href='$css_header' type='text/css'>\n";
812 echo "</head><body class='body_top'>\n";
813 $result = cms_portal_call(array(
814 'action' => 'putmessage',
815 'user' => $ptdata['cmsportal_login'],
816 'title' => xl('Your Clinical Report'),
817 'message' => xl('Please see the attached PDF.'),
818 'filename' => 'report.pdf',
819 'mimetype' => 'application/pdf',
820 'contents' => base64_encode($contents),
822 if ($result['errmsg']) die(text($result['errmsg']));
823 echo "<p>" . xlt('Report has been sent to the patient.') . "</p>\n";
824 echo "</body></html>\n";
830 <?php
if (!$printable) { // Set up translated strings for use by interactive search ?>
831 <script type
="text/javascript">
832 var xl_string
= <?php
echo json_encode( array(
833 'spcl_chars' => xla('Special characters are not allowed').'.',
834 'not_found' => xla('No results found').'.',
835 'results' => xla('Showing result'),
836 'literal_of' => xla('of'),
840 <script type
="text/javascript" src
="<?php echo $GLOBALS['web_root']?>/interface/patient_file/report/custom_report.js?v=<?php echo $v_js_includes; ?>"></script
>