Changes to support electronic lab ordering and results.
[openemr.git] / interface / orders / pending_orders.php
blob4fa6856f61e77aba9dcbc7f7758c06b6a39ab2c9
1 <?php
2 // Copyright (C) 2010-2013 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($provname ) . '",';
31 echo '"' . addslashes($row['priority_name' ]) . '",';
32 echo '"' . addslashes($row['status_name' ]) . '"' . "\n";
34 else {
36 <tr>
37 <td class="detail"><?php echo $row['patient_name' ]; ?></td>
38 <td class="detail"><?php echo $row['pubpid' ]; ?></td>
39 <td class="detail"><?php echo oeFormatShortDate($row['date_ordered' ]); ?></td>
40 <td class="detail"><?php echo $row['organization' ]; ?></td>
41 <td class="detail"><?php echo $provname; ?></td>
42 <td class="detail"><?php echo $row['priority_name' ]; ?></td>
43 <td class="detail"><?php echo $row['status_name' ]; ?></td>
44 </tr>
45 <?php
46 } // End not csv export
49 if (! acl_check('acct', 'rep')) die(xl("Unauthorized access."));
51 $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
52 $form_to_date = fixDate($_POST['form_to_date'] , date('Y-m-d'));
53 $form_facility = $_POST['form_facility'];
55 if ($_POST['form_csvexport']) {
56 header("Pragma: public");
57 header("Expires: 0");
58 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
59 header("Content-Type: application/force-download");
60 header("Content-Disposition: attachment; filename=pending_orders.csv");
61 header("Content-Description: File Transfer");
62 // CSV headers:
63 echo '"' . xl('Patient') . '",';
64 echo '"' . xl('ID') . '",';
65 echo '"' . xl('Ordered') . '",';
66 echo '"' . xl('From') . '",';
67 echo '"' . xl('Procedure') . '",';
68 echo '"' . xl('Provider') . '",';
69 echo '"' . xl('Priority') . '",';
70 echo '"' . xl('Status') . '"' . "\n";
72 else { // not export
74 <html>
75 <head>
76 <?php html_header_show();?>
77 <title><?php xl('Pending Orders','e') ?></title>
78 </head>
80 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
81 <center>
83 <h2><?php xl('Pending Orders','e')?></h2>
85 <form method='post' action='pending_orders.php'>
87 <table border='0' cellpadding='3'>
89 <tr>
90 <td>
91 <?php dropdown_facility(strip_escape_custom($form_facility), 'form_facility', false); ?>
92 &nbsp;<?xl('From:','e')?>
93 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
94 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
95 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
96 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
97 title='<?php xl('Click here to choose a date','e'); ?>'>
98 &nbsp;To:
99 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
100 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
101 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
102 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
103 title='<?php xl('Click here to choose a date','e'); ?>'>
104 &nbsp;
105 <input type='submit' name='form_refresh' value="<?php xl('Refresh','e') ?>">
106 &nbsp;
107 <input type='submit' name='form_csvexport' value="<?php xl('Export to CSV','e') ?>">
108 &nbsp;
109 <input type='button' value='<?php xl('Print','e'); ?>' onclick='window.print()' />
110 </td>
111 </tr>
113 <tr>
114 <td height="1">
115 </td>
116 </tr>
118 </table>
120 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
121 <tr bgcolor="#dddddd">
122 <td class="dehead"><?php xl('Patient','e' ) ?></td>
123 <td class="dehead"><?php xl('ID','e' ) ?></td>
124 <td class="dehead"><?php xl('Ordered','e' ) ?></td>
125 <td class="dehead"><?php xl('From','e' ) ?></td>
126 <td class="dehead"><?php xl('Provider','e' ) ?></td>
127 <td class="dehead"><?php xl('Priority','e' ) ?></td>
128 <td class="dehead"><?php xl('Status','e' ) ?></td>
129 </tr>
130 <?php
131 } // end not export
133 // If generating a report.
135 if ($_POST['form_refresh'] || $_POST['form_csvexport']) {
136 $from_date = $form_from_date;
137 $to_date = $form_to_date;
139 $query = "SELECT po.patient_id, po.date_ordered, " .
140 "pd.pubpid, " .
141 "CONCAT(pd.lname, ', ', pd.fname, ' ', pd.mname) AS patient_name, " .
142 "u1.lname AS provider_lname, u1.fname AS provider_fname, u1.mname AS provider_mname, " .
143 "pp.name AS organization, " .
144 "lop.title AS priority_name, " .
145 "los.title AS status_name, " .
146 "pr.procedure_report_id, pr.date_report, pr.report_status " .
147 "FROM procedure_order AS po " .
148 "JOIN form_encounter AS fe ON fe.pid = po.patient_id AND fe.encounter = po.encounter_id " .
149 "JOIN patient_data AS pd ON pd.pid = po.patient_id " .
150 "LEFT JOIN users AS u1 ON u1.id = po.provider_id " .
151 "LEFT JOIN procedure_providers AS pp ON pp.ppid = po.lab_id " .
152 "LEFT JOIN list_options AS lop ON lop.list_id = 'ord_priority' AND lop.option_id = po.order_priority " .
153 "LEFT JOIN list_options AS los ON los.list_id = 'ord_status' AND los.option_id = po.order_status " .
154 "LEFT JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id " .
155 "WHERE " .
156 "po.date_ordered >= '$from_date' AND po.date_ordered <= '$to_date' AND " .
157 "( pr.report_status IS NULL OR pr.report_status = 'prelim' )";
159 // TBD: What if preliminary and final reports for the same order?
161 if ($form_facility) {
162 $query .= " AND fe.facility_id = '$form_facility'";
164 $query .= " ORDER BY pd.lname, pd.fname, pd.mname, po.patient_id, " .
165 "po.date_ordered, po.procedure_order_id";
167 $res = sqlStatement($query);
168 while ($row = sqlFetchArray($res)) {
169 thisLineItem($row);
172 } // end report generation
174 if (! $_POST['form_csvexport']) {
177 </table>
178 </form>
179 </center>
180 </body>
182 <!-- stuff for the popup calendar -->
183 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
184 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
185 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
186 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
187 <script language="Javascript">
188 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
189 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
190 </script>
192 </html>
193 <?php
194 } // End not csv export