minor documentation fix
[openemr.git] / interface / orders / pending_orders.php
blob1e83ca5aa51d6f59298ebfa81d598e923a8891eb
1 <?php
2 /**
3 * Pending orders.
5 * @package OpenEMR
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-2013 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("$srcdir/patient.inc");
17 require_once("$srcdir/acl.inc");
18 require_once "$srcdir/options.inc.php";
20 use OpenEMR\Core\Header;
22 function thisLineItem($row)
24 $provname = $row['provider_lname'];
25 if (!empty($row['provider_fname'])) {
26 $provname .= ', ' . $row['provider_fname'];
27 if (!empty($row['provider_mname'])) {
28 $provname .= ' ' . $row['provider_mname'];
32 if ($_POST['form_csvexport']) {
33 echo '"' . addslashes($row['patient_name' ]) . '",';
34 echo '"' . addslashes($row['pubpid' ]) . '",';
35 echo '"' . addslashes(oeFormatShortDate($row['date_ordered' ])) . '",';
36 echo '"' . addslashes($row['organization' ]) . '",';
37 echo '"' . addslashes($provname) . '",';
38 echo '"' . addslashes($row['priority_name' ]) . '",';
39 echo '"' . addslashes($row['status_name' ]) . '"' . "\n";
40 } else {
42 <tr>
43 <td class="detail"><?php echo text($row['patient_name' ]); ?></td>
44 <td class="detail"><?php echo text($row['pubpid' ]); ?></td>
45 <td class="detail"><?php echo text(oeFormatShortDate($row['date_ordered' ])); ?></td>
46 <td class="detail"><?php echo text($row['organization' ]); ?></td>
47 <td class="detail"><?php echo text($provname); ?></td>
48 <td class="detail"><?php echo text($row['priority_name' ]); ?></td>
49 <td class="detail"><?php echo text($row['status_name' ]); ?></td>
50 </tr>
51 <?php
52 } // End not csv export
55 if (! acl_check('acct', 'rep')) {
56 die(xlt("Unauthorized access."));
59 $form_from_date = isset($_POST['form_from_date']) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-m-d');
60 $form_to_date = isset($_POST['form_to_date']) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
61 $form_facility = $_POST['form_facility'];
63 if ($_POST['form_csvexport']) {
64 header("Pragma: public");
65 header("Expires: 0");
66 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
67 header("Content-Type: application/force-download");
68 header("Content-Disposition: attachment; filename=pending_orders.csv");
69 header("Content-Description: File Transfer");
70 // CSV headers:
71 echo '"' . xl('Patient') . '",';
72 echo '"' . xl('ID') . '",';
73 echo '"' . xl('Ordered') . '",';
74 echo '"' . xl('From') . '",';
75 echo '"' . xl('Procedure') . '",';
76 echo '"' . xl('Provider') . '",';
77 echo '"' . xl('Priority') . '",';
78 echo '"' . xl('Status') . '"' . "\n";
79 } else { // not export
81 <html>
82 <head>
83 <title><?php echo xlt('Pending Orders') ?></title>
85 <?php Header::setupHeader('datetime-picker'); ?>
87 <script language="JavaScript">
89 $(document).ready(function() {
90 var win = top.printLogSetup ? top : opener.top;
91 win.printLogSetup(document.getElementById('printbutton'));
93 $('.datepicker').datetimepicker({
94 <?php $datetimepicker_timepicker = false; ?>
95 <?php $datetimepicker_showseconds = false; ?>
96 <?php $datetimepicker_formatInput = true; ?>
97 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
98 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
99 });
101 </script>
102 </head>
104 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
105 <center>
107 <h2><?php echo xlt('Pending Orders')?></h2>
109 <form method='post' action='pending_orders.php'>
111 <table border='0' cellpadding='3'>
113 <tr>
114 <td>
115 <?php dropdown_facility($form_facility, 'form_facility', false); ?>
116 </td>
117 <td class='control-label'>
118 &nbsp;<?php echo xlt('From')?>:
119 </td>
120 <td>
121 <input type='text' class='datepicker form-control' name='form_from_date' id="form_from_date" size='10' value='<?php echo attr(oeFormatShortDate($form_from_date)); ?>'>
122 </td>
123 <td class='control-label'>
124 &nbsp;<?php echo xlt('To')?>:
125 </td>
126 <td>
127 <input type='text' class='datepicker form-control' name='form_to_date' id="form_to_date" size='10' value='<?php echo attr(oeFormatShortDate($form_to_date)); ?>'>
128 </td>
129 </tr>
130 <tr>
131 <td>
132 <div class="btn-group" role="group">
133 <button type='submit' class='btn btn-default btn-refresh' name='form_refresh'><?php echo xlt('Refresh'); ?></button>
134 <button type='submit' class='btn btn-default btn-transmit' name='form_csvexport'><?php echo xlt('Export to CSV'); ?></button>
135 <button type='button' class='btn btn-default btn-print' id='printbutton'><?php echo xlt('Print'); ?></button>
136 </div>
137 </td>
138 </tr>
140 <tr>
141 <td height="1">
142 </td>
143 </tr>
145 </table>
147 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
148 <tr bgcolor="#dddddd">
149 <td class="dehead"><?php echo xlt('Patient'); ?></td>
150 <td class="dehead"><?php echo xlt('ID'); ?></td>
151 <td class="dehead"><?php echo xlt('Ordered'); ?></td>
152 <td class="dehead"><?php echo xlt('From'); ?></td>
153 <td class="dehead"><?php echo xlt('Provider'); ?></td>
154 <td class="dehead"><?php echo xlt('Priority'); ?></td>
155 <td class="dehead"><?php echo xlt('Status'); ?></td>
156 </tr>
157 <?php
158 } // end not export
160 // If generating a report.
162 if ($_POST['form_refresh'] || $_POST['form_csvexport']) {
163 $sqlBindArray = array();
164 $query = "SELECT po.patient_id, po.date_ordered, " .
165 "pd.pubpid, " .
166 "CONCAT(pd.lname, ', ', pd.fname, ' ', pd.mname) AS patient_name, " .
167 "u1.lname AS provider_lname, u1.fname AS provider_fname, u1.mname AS provider_mname, " .
168 "pp.name AS organization, " .
169 "lop.title AS priority_name, " .
170 "los.title AS status_name, " .
171 "pr.procedure_report_id, pr.date_report, pr.report_status " .
172 "FROM procedure_order AS po " .
173 "JOIN form_encounter AS fe ON fe.pid = po.patient_id AND fe.encounter = po.encounter_id " .
174 "JOIN patient_data AS pd ON pd.pid = po.patient_id " .
175 "LEFT JOIN users AS u1 ON u1.id = po.provider_id " .
176 "LEFT JOIN procedure_providers AS pp ON pp.ppid = po.lab_id " .
177 "LEFT JOIN list_options AS lop ON lop.list_id = 'ord_priority' AND lop.option_id = po.order_priority AND lop.activity = 1 " .
178 "LEFT JOIN list_options AS los ON los.list_id = 'ord_status' AND los.option_id = po.order_status AND los.activity = 1 " .
179 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id " .
180 "WHERE " .
181 "po.date_ordered >= ? AND po.date_ordered <= ? AND " .
182 "( pr.report_status IS NULL OR pr.report_status = 'prelim' )";
183 array_push($sqlBindArray, $form_from_date, $form_to_date);
185 // TBD: What if preliminary and final reports for the same order?
187 if ($form_facility) {
188 $query .= " AND fe.facility_id = ?";
189 array_push($sqlBindArray, $form_facility);
192 $query .= " ORDER BY pd.lname, pd.fname, pd.mname, po.patient_id, " .
193 "po.date_ordered, po.procedure_order_id";
195 $res = sqlStatement($query, $sqlBindArray);
196 while ($row = sqlFetchArray($res)) {
197 thisLineItem($row);
199 } // end report generation
201 if (! $_POST['form_csvexport']) {
204 </table>
205 </form>
206 </center>
207 </body>
209 </html>
210 <?php
211 } // End not csv export