4 * Copyright (C) 2010-2013 Rod Roark <rod@sunsetsystems.com>
5 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
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 2
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 Rod Roark <rod@sunsetsystems.com>
20 * @author Brady Miller <brady.g.miller@gmail.com>
21 * @link http://www.open-emr.org
24 use OpenEMR\Core\Header
;
26 require_once("../globals.php");
27 require_once("$srcdir/patient.inc");
28 require_once("$srcdir/acl.inc");
29 require_once "$srcdir/options.inc.php";
31 function thisLineItem($row)
33 $provname = $row['provider_lname'];
34 if (!empty($row['provider_fname'])) {
35 $provname .= ', ' . $row['provider_fname'];
36 if (!empty($row['provider_mname'])) {
37 $provname .= ' ' . $row['provider_mname'];
41 if ($_POST['form_csvexport']) {
42 echo '"' . addslashes($row['patient_name' ]) . '",';
43 echo '"' . addslashes($row['pubpid' ]) . '",';
44 echo '"' . addslashes(oeFormatShortDate($row['date_ordered' ])) . '",';
45 echo '"' . addslashes($row['organization' ]) . '",';
46 echo '"' . addslashes($provname) . '",';
47 echo '"' . addslashes($row['priority_name' ]) . '",';
48 echo '"' . addslashes($row['status_name' ]) . '"' . "\n";
52 <td
class="detail"><?php
echo $row['patient_name' ]; ?
></td
>
53 <td
class="detail"><?php
echo $row['pubpid' ]; ?
></td
>
54 <td
class="detail"><?php
echo oeFormatShortDate($row['date_ordered' ]); ?
></td
>
55 <td
class="detail"><?php
echo $row['organization' ]; ?
></td
>
56 <td
class="detail"><?php
echo $provname; ?
></td
>
57 <td
class="detail"><?php
echo $row['priority_name' ]; ?
></td
>
58 <td
class="detail"><?php
echo $row['status_name' ]; ?
></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 header("Pragma: public");
75 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
76 header("Content-Type: application/force-download");
77 header("Content-Disposition: attachment; filename=pending_orders.csv");
78 header("Content-Description: File Transfer");
80 echo '"' . xl('Patient') . '",';
81 echo '"' . xl('ID') . '",';
82 echo '"' . xl('Ordered') . '",';
83 echo '"' . xl('From') . '",';
84 echo '"' . xl('Procedure') . '",';
85 echo '"' . xl('Provider') . '",';
86 echo '"' . xl('Priority') . '",';
87 echo '"' . xl('Status') . '"' . "\n";
88 } else { // not export
93 <title
><?php
xl('Pending Orders', 'e') ?
></title
>
95 <?php Header
::setupHeader('datetime-picker'); ?
>
97 <script language
="JavaScript">
99 $
(document
).ready(function() {
100 var win
= top
.printLogSetup ? top
: opener
.top
;
101 win
.printLogSetup(document
.getElementById('printbutton'));
103 $
('.datepicker').datetimepicker({
104 <?php
$datetimepicker_timepicker = false; ?
>
105 <?php
$datetimepicker_showseconds = false; ?
>
106 <?php
$datetimepicker_formatInput = false; ?
>
107 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
108 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
116 <body leftmargin
='0' topmargin
='0' marginwidth
='0' marginheight
='0'>
119 <h2
><?php
xl('Pending Orders', 'e')?
></h2
>
121 <form method
='post' action
='pending_orders.php'>
123 <table border
='0' cellpadding
='3'>
127 <?php
dropdown_facility(strip_escape_custom($form_facility), 'form_facility', false); ?
>
129 <td
class='control-label'>
130  
;<?php
echo xlt('From')?
>:
133 <input type
='text' class='datepicker form-control' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
136 <td
class='control-label'>
137  
;<?php
echo xlt('To')?
>:
140 <input type
='text' class='datepicker form-control' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
146 <div
class="btn-group" role
="group">
147 <button type
='submit' class='btn btn-default btn-refresh' name
='form_refresh'><?php
echo xlt('Refresh'); ?
></button
>
148 <button type
='submit' class='btn btn-default btn-transmit' name
='form_csvexport'><?php
echo xlt('Export to CSV'); ?
></button
>
149 <button type
='button' class='btn btn-default btn-print' id
='printbutton'><?php
echo xlt('Print'); ?
></button
>
161 <table border
='0' cellpadding
='1' cellspacing
='2' width
='98%'>
162 <tr bgcolor
="#dddddd">
163 <td
class="dehead"><?php
xl('Patient', 'e') ?
></td
>
164 <td
class="dehead"><?php
xl('ID', 'e') ?
></td
>
165 <td
class="dehead"><?php
xl('Ordered', 'e') ?
></td
>
166 <td
class="dehead"><?php
xl('From', 'e') ?
></td
>
167 <td
class="dehead"><?php
xl('Provider', 'e') ?
></td
>
168 <td
class="dehead"><?php
xl('Priority', 'e') ?
></td
>
169 <td
class="dehead"><?php
xl('Status', 'e') ?
></td
>
174 // If generating a report.
176 if ($_POST['form_refresh'] ||
$_POST['form_csvexport']) {
177 $from_date = $form_from_date;
178 $to_date = $form_to_date;
180 $query = "SELECT po.patient_id, po.date_ordered, " .
182 "CONCAT(pd.lname, ', ', pd.fname, ' ', pd.mname) AS patient_name, " .
183 "u1.lname AS provider_lname, u1.fname AS provider_fname, u1.mname AS provider_mname, " .
184 "pp.name AS organization, " .
185 "lop.title AS priority_name, " .
186 "los.title AS status_name, " .
187 "pr.procedure_report_id, pr.date_report, pr.report_status " .
188 "FROM procedure_order AS po " .
189 "JOIN form_encounter AS fe ON fe.pid = po.patient_id AND fe.encounter = po.encounter_id " .
190 "JOIN patient_data AS pd ON pd.pid = po.patient_id " .
191 "LEFT JOIN users AS u1 ON u1.id = po.provider_id " .
192 "LEFT JOIN procedure_providers AS pp ON pp.ppid = po.lab_id " .
193 "LEFT JOIN list_options AS lop ON lop.list_id = 'ord_priority' AND lop.option_id = po.order_priority AND lop.activity = 1 " .
194 "LEFT JOIN list_options AS los ON los.list_id = 'ord_status' AND los.option_id = po.order_status AND los.activity = 1 " .
195 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id " .
197 "po.date_ordered >= '$from_date' AND po.date_ordered <= '$to_date' AND " .
198 "( pr.report_status IS NULL OR pr.report_status = 'prelim' )";
200 // TBD: What if preliminary and final reports for the same order?
202 if ($form_facility) {
203 $query .= " AND fe.facility_id = '$form_facility'";
206 $query .= " ORDER BY pd.lname, pd.fname, pd.mname, po.patient_id, " .
207 "po.date_ordered, po.procedure_order_id";
209 $res = sqlStatement($query);
210 while ($row = sqlFetchArray($res)) {
213 } // end report generation
215 if (! $_POST['form_csvexport']) {
225 } // End not csv export