6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2010 Rod Roark <rod@sunsetsystems.com>
10 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("../../library/patient.inc");
17 require_once("../../library/acl.inc");
18 require_once("../../custom/code_types.inc.php");
20 use OpenEMR\Services\FacilityService
;
22 $facilityService = new FacilityService();
24 function thisLineItem($row, $codetype, $code)
28 $provname = $row['provider_lname'];
29 if (!empty($row['provider_fname'])) {
30 $provname .= ', ' . $row['provider_fname'];
31 if (!empty($row['provider_mname'])) {
32 $provname .= ' ' . $row['provider_mname'];
36 $crow = sqlQuery("SELECT code_text FROM codes WHERE " .
37 "code_type = ? AND " .
38 "code = ? LIMIT 1", array($code_types[$codetype]['id'], $code));
39 $code_text = $crow['code_text'];
41 if ($_POST['form_csvexport']) {
42 echo '"' . addslashes($row['patient_name' ]) . '",';
43 echo '"' . addslashes($row['pubpid' ]) . '",';
44 echo '"' . addslashes($row['date_ordered' ]) . '",';
45 echo '"' . addslashes($row['procedure_name']) . '",';
46 echo '"' . addslashes($provname) . '",';
47 echo '"' . addslashes($code) . '",';
48 echo '"' . addslashes($code_text) . '"' . "\n";
52 <td
class="detail"><?php
echo text($row['patient_name' ]); ?
></td
>
53 <td
class="detail"><?php
echo text($row['pubpid' ]); ?
></td
>
54 <td
class="detail"><?php
echo text($row['date_ordered' ]); ?
></td
>
55 <td
class="detail"><?php
echo text($row['procedure_name']); ?
></td
>
56 <td
class="detail"><?php
echo text($provname); ?
></td
>
57 <td
class="detail"><?php
echo text($code); ?
></td
>
58 <td
class="detail"><?php
echo text($code_text); ?
></td
>
61 } // End not csv export
64 if (! acl_check('acct', 'rep')) {
65 die(xl("Unauthorized access."));
68 $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
69 $form_to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
70 $form_facility = $_POST['form_facility'];
72 if ($_POST['form_csvexport']) {
73 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
77 header("Pragma: public");
79 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
80 header("Content-Type: application/force-download");
81 header("Content-Disposition: attachment; filename=pending_followup.csv");
82 header("Content-Description: File Transfer");
84 echo '"' . xl('Patient') . '",';
85 echo '"' . xl('ID') . '",';
86 echo '"' . xl('Ordered') . '",';
87 echo '"' . xl('Procedure') . '",';
88 echo '"' . xl('Provider') . '",';
89 echo '"' . xl('Code') . '",';
90 echo '"' . xl('Service') . '"' . "\n";
91 } else { // not export
95 <?php
html_header_show();?
>
97 <link rel
="stylesheet" href
="<?php echo $css_header; ?>" type
="text/css">
98 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.min.css">
100 <title
><?php
echo xlt('Pending Followup from Results') ?
></title
>
102 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-1-9-1/jquery.min.js"></script
>
103 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js"></script
>
106 <script language
="JavaScript">
107 $
(document
).ready(function() {
108 var win
= top
.printLogSetup ? top
: opener
.top
;
109 win
.printLogSetup(document
.getElementById('printbutton'));
111 $
('.datepicker').datetimepicker({
112 <?php
$datetimepicker_timepicker = false; ?
>
113 <?php
$datetimepicker_showseconds = false; ?
>
114 <?php
$datetimepicker_formatInput = false; ?
>
115 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
116 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
123 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
126 <h2
><?php
echo xlt('Pending Followup from Results')?
></h2
>
128 <form method
='post' action
='pending_followup.php' onsubmit
='return top.restoreSession()'>
129 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(collectCsrfToken()); ?>" />
131 <table border
='0' cellpadding
='3'>
136 // Build a drop-down list of facilities.
138 $fres = $facilityService->getAll();
139 echo " <select name='form_facility'>\n";
140 echo " <option value=''>-- All Facilities --\n";
141 foreach ($fres as $frow) {
142 $facid = $frow['id'];
143 echo " <option value='" . attr($facid) . "'";
144 if ($facid == $form_facility) {
148 echo ">" . text($frow['name']) . "\n";
153  
;<?php
echo xlt('From:'); ?
>
154 <input type
='text' class='datepicker' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo attr($form_from_date); ?>'
157  
;<?php
echo xlt('To'); ?
>:
158 <input type
='text' class='datepicker' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo attr($form_to_date); ?>'
161 <input type
='submit' name
='form_refresh' value
="<?php echo xla('Refresh') ?>">
163 <input type
='submit' name
='form_csvexport' value
="<?php echo xla('Export to CSV') ?>">
165 <input type
='button' value
='<?php echo xla('Print'); ?>' id
='printbutton' />
176 <table border
='0' cellpadding
='1' cellspacing
='2' width
='98%'>
177 <tr bgcolor
="#dddddd">
178 <td
class="dehead"><?php
echo xlt('Patient') ?
></td
>
179 <td
class="dehead"><?php
echo xlt('ID') ?
></td
>
180 <td
class="dehead"><?php
echo xlt('Ordered') ?
></td
>
181 <td
class="dehead"><?php
echo xlt('Procedure') ?
></td
>
182 <td
class="dehead"><?php
echo xlt('Provider') ?
></td
>
183 <td
class="dehead"><?php
echo xlt('Code') ?
></td
>
184 <td
class="dehead"><?php
echo xlt('Service') ?
></td
>
189 // If generating a report.
191 if ($_POST['form_refresh'] ||
$_POST['form_csvexport']) {
192 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
196 $sqlBindArray = array();
198 $from_date = $form_from_date;
199 $to_date = $form_to_date;
201 $query = "SELECT po.patient_id, po.encounter_id, po.date_ordered, " .
203 "CONCAT(pd.lname, ', ', pd.fname, ' ', pd.mname) AS patient_name, " .
204 "pto.name AS procedure_name, " .
205 "pts.related_code, " .
206 "u1.lname AS provider_lname, u1.fname AS provider_fname, u1.mname AS provider_mname, " .
207 "pr.procedure_report_id, pr.date_report, pr.report_status " .
208 "FROM procedure_order AS po " .
209 "JOIN form_encounter AS fe ON fe.pid = po.patient_id AND fe.encounter = po.encounter_id " .
210 "JOIN patient_data AS pd ON pd.pid = po.patient_id " .
211 "JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id " .
212 "JOIN procedure_result AS ps ON ps.procedure_report_id = pr.procedure_report_id " .
213 "AND ps.abnormal != '' AND ps.abnormal != 'no' " .
214 "JOIN procedure_type AS pto ON pto.procedure_type_id = po.procedure_type_id " .
215 "JOIN procedure_type AS pts ON pts.procedure_type_id = ps.procedure_type_id " .
216 "AND pts.related_code != '' " .
217 "LEFT JOIN users AS u1 ON u1.id = po.provider_id " .
219 "po.date_ordered >= ? AND po.date_ordered <= ?";
221 array_push($sqlBindArray, $from_date, $to_date);
223 if ($form_facility) {
224 $query .= " AND fe.facility_id = ?";
225 array_push($sqlBindArray, $form_facility);
228 $query .= " ORDER BY pd.lname, pd.fname, pd.mname, po.patient_id, " .
229 "po.date_ordered, po.procedure_order_id";
231 $res = sqlStatement($query, $sqlBindArray);
232 while ($row = sqlFetchArray($res)) {
233 $patient_id = $row['patient_id'];
234 $date_ordered = $row['date_ordered'];
236 $relcodes = explode(';', $row['related_code']);
237 foreach ($relcodes as $codestring) {
238 if ($codestring === '') {
242 list($codetype, $code) = explode(':', $codestring);
244 $brow = sqlQuery("SELECT count(*) AS count " .
245 "FROM billing AS b, form_encounter AS fe WHERE " .
247 "b.code_type = ? AND " .
249 "b.activity = 1 AND " .
250 "fe.pid = b.pid AND fe.encounter = b.encounter AND " .
251 "fe.date >= ?", array($patient_id, $codetype, $code, $date_ordered.' 00:00:00'));
253 // If there was such a service, then this followup is not pending.
254 if (!empty($brow['count'])) {
258 thisLineItem($row, $codetype, $code);
261 } // end report generation
263 if (! $_POST['form_csvexport']) {
272 } // End not csv export