a355532fa87725843aaa367df01f4902fb4d2c7a
[openemr.git] / interface / orders / pending_orders.php
bloba355532fa87725843aaa367df01f4902fb4d2c7a
1 <?php
2 // Copyright (C) 2010 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 require_once("../globals.php");
10 require_once("$srcdir/patient.inc");
11 require_once("$srcdir/acl.inc");
12 require_once("$srcdir/formatting.inc.php");
13 require_once "$srcdir/options.inc.php";
14 require_once "$srcdir/formdata.inc.php";
16 function thisLineItem($row) {
17 $provname = $row['provider_lname'];
18 if (!empty($row['provider_fname'])) {
19 $provname .= ', ' . $row['provider_fname'];
20 if (!empty($row['provider_mname'])) {
21 $provname .= ' ' . $row['provider_mname'];
25 if ($_POST['form_csvexport']) {
26 echo '"' . addslashes($row['patient_name' ]) . '",';
27 echo '"' . addslashes($row['pubpid' ]) . '",';
28 echo '"' . addslashes(oeFormatShortDate($row['date_ordered' ])) . '",';
29 echo '"' . addslashes($row['organization' ]) . '",';
30 echo '"' . addslashes($row['procedure_name']) . '",';
31 echo '"' . addslashes($provname ) . '",';
32 echo '"' . addslashes($row['priority_name' ]) . '",';
33 echo '"' . addslashes($row['status_name' ]) . '"' . "\n";
35 else {
37 <tr>
38 <td class="detail"><?php echo $row['patient_name' ]; ?></td>
39 <td class="detail"><?php echo $row['pubpid' ]; ?></td>
40 <td class="detail"><?php echo oeFormatShortDate($row['date_ordered' ]); ?></td>
41 <td class="detail"><?php echo $row['organization' ]; ?></td>
42 <td class="detail"><?php echo $row['procedure_name']; ?></td>
43 <td class="detail"><?php echo $provname; ?></td>
44 <td class="detail"><?php echo $row['priority_name' ]; ?></td>
45 <td class="detail"><?php echo $row['status_name' ]; ?></td>
46 </tr>
47 <?php
48 } // End not csv export
51 if (! acl_check('acct', 'rep')) die(xl("Unauthorized access."));
53 $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
54 $form_to_date = fixDate($_POST['form_to_date'] , date('Y-m-d'));
55 $form_facility = $_POST['form_facility'];
57 if ($_POST['form_csvexport']) {
58 header("Pragma: public");
59 header("Expires: 0");
60 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
61 header("Content-Type: application/force-download");
62 header("Content-Disposition: attachment; filename=pending_orders.csv");
63 header("Content-Description: File Transfer");
64 // CSV headers:
65 echo '"' . xl('Patient') . '",';
66 echo '"' . xl('ID') . '",';
67 echo '"' . xl('Ordered') . '",';
68 echo '"' . xl('From') . '",';
69 echo '"' . xl('Procedure') . '",';
70 echo '"' . xl('Provider') . '",';
71 echo '"' . xl('Priority') . '",';
72 echo '"' . xl('Status') . '"' . "\n";
74 else { // not export
76 <html>
77 <head>
78 <?php html_header_show();?>
79 <title><?php xl('Pending Orders','e') ?></title>
80 </head>
82 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
83 <center>
85 <h2><?php xl('Pending Orders','e')?></h2>
87 <form method='post' action='pending_orders.php'>
89 <table border='0' cellpadding='3'>
91 <tr>
92 <td>
93 <?php dropdown_facility(strip_escape_custom($form_facility), 'form_facility', false); ?>
94 &nbsp;<?xl('From:','e')?>
95 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
96 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
97 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
98 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
99 title='<?php xl('Click here to choose a date','e'); ?>'>
100 &nbsp;To:
101 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
102 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
103 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
104 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
105 title='<?php xl('Click here to choose a date','e'); ?>'>
106 &nbsp;
107 <input type='submit' name='form_refresh' value="<?php xl('Refresh','e') ?>">
108 &nbsp;
109 <input type='submit' name='form_csvexport' value="<?php xl('Export to CSV','e') ?>">
110 &nbsp;
111 <input type='button' value='<?php xl('Print','e'); ?>' onclick='window.print()' />
112 </td>
113 </tr>
115 <tr>
116 <td height="1">
117 </td>
118 </tr>
120 </table>
122 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
123 <tr bgcolor="#dddddd">
124 <td class="dehead"><?php xl('Patient','e' ) ?></td>
125 <td class="dehead"><?php xl('ID','e' ) ?></td>
126 <td class="dehead"><?php xl('Ordered','e' ) ?></td>
127 <td class="dehead"><?php xl('From','e' ) ?></td>
128 <td class="dehead"><?php xl('Procedure','e') ?></td>
129 <td class="dehead"><?php xl('Provider','e' ) ?></td>
130 <td class="dehead"><?php xl('Priority','e' ) ?></td>
131 <td class="dehead"><?php xl('Status','e' ) ?></td>
132 </tr>
133 <?php
134 } // end not export
136 // If generating a report.
138 if ($_POST['form_refresh'] || $_POST['form_csvexport']) {
139 $from_date = $form_from_date;
140 $to_date = $form_to_date;
142 $query = "SELECT po.patient_id, po.date_ordered, " .
143 "pd.pubpid, " .
144 "CONCAT(pd.lname, ', ', pd.fname, ' ', pd.mname) AS patient_name, " .
145 "pt1.name AS procedure_name, " .
146 "u1.lname AS provider_lname, u1.fname AS provider_fname, u1.mname AS provider_mname, " .
147 "u2.organization, " .
148 "lop.title AS priority_name, " .
149 "los.title AS status_name, " .
150 "pr.procedure_report_id, pr.date_report, pr.report_status " .
151 "FROM procedure_order AS po " .
152 "JOIN form_encounter AS fe ON fe.pid = po.patient_id AND fe.encounter = po.encounter_id " .
153 "JOIN patient_data AS pd ON pd.pid = po.patient_id " .
154 "LEFT JOIN users AS u1 ON u1.id = po.provider_id " .
155 "LEFT JOIN procedure_type AS pt1 ON pt1.procedure_type_id = po.procedure_type_id " .
156 "LEFT JOIN users AS u2 ON u2.id = pt1.lab_id " .
157 "LEFT JOIN list_options AS lop ON lop.list_id = 'ord_priority' AND lop.option_id = po.order_priority " .
158 "LEFT JOIN list_options AS los ON los.list_id = 'ord_status' AND los.option_id = po.order_status " .
159 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id " .
160 "WHERE " .
161 "po.date_ordered >= '$from_date' AND po.date_ordered <= '$to_date' AND " .
162 "( pr.report_status IS NULL OR pr.report_status = 'prelim' )";
164 // TBD: What if preliminary and final reports for the same order?
166 if ($form_facility) {
167 $query .= " AND fe.facility_id = '$form_facility'";
169 $query .= " ORDER BY pd.lname, pd.fname, pd.mname, po.patient_id, " .
170 "po.date_ordered, po.procedure_order_id";
172 $res = sqlStatement($query);
173 while ($row = sqlFetchArray($res)) {
174 thisLineItem($row);
177 } // end report generation
179 if (! $_POST['form_csvexport']) {
182 </table>
183 </form>
184 </center>
185 </body>
187 <!-- stuff for the popup calendar -->
188 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
189 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
190 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
191 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
192 <script language="Javascript">
193 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
194 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
195 </script>
197 </html>
198 <?php
199 } // End not csv export