Feature to add drug-drug interaction checking for the
[openemr.git] / interface / orders / pending_followup.php
blob98448839fa63d35ceb4a5f740d3fde01d972cc3a
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("../../library/patient.inc");
11 require_once("../../library/acl.inc");
12 require_once("../../custom/code_types.inc.php");
14 function thisLineItem($row, $codetype, $code) {
15 global $code_types;
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 $crow = sqlQuery("SELECT code_text FROM codes WHERE " .
26 "code_type = '" . $code_types[$codetype]['id'] . "' AND " .
27 "code = '$code' LIMIT 1");
28 $code_text = $crow['code_text'];
30 if ($_POST['form_csvexport']) {
31 echo '"' . addslashes($row['patient_name' ]) . '",';
32 echo '"' . addslashes($row['pubpid' ]) . '",';
33 echo '"' . addslashes($row['date_ordered' ]) . '",';
34 echo '"' . addslashes($row['procedure_name']) . '",';
35 echo '"' . addslashes($provname ) . '",';
36 echo '"' . addslashes($code ) . '",';
37 echo '"' . addslashes($code_text ) . '"' . "\n";
39 else {
41 <tr>
42 <td class="detail"><?php echo $row['patient_name' ]; ?></td>
43 <td class="detail"><?php echo $row['pubpid' ]; ?></td>
44 <td class="detail"><?php echo $row['date_ordered' ]; ?></td>
45 <td class="detail"><?php echo $row['procedure_name']; ?></td>
46 <td class="detail"><?php echo $provname; ?></td>
47 <td class="detail"><?php echo $code; ?></td>
48 <td class="detail"><?php echo $code_text; ?></td>
49 </tr>
50 <?php
51 } // End not csv export
54 if (! acl_check('acct', 'rep')) die(xl("Unauthorized access."));
56 $form_from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
57 $form_to_date = fixDate($_POST['form_to_date'] , date('Y-m-d'));
58 $form_facility = $_POST['form_facility'];
60 if ($_POST['form_csvexport']) {
61 header("Pragma: public");
62 header("Expires: 0");
63 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
64 header("Content-Type: application/force-download");
65 header("Content-Disposition: attachment; filename=pending_followup.csv");
66 header("Content-Description: File Transfer");
67 // CSV headers:
68 echo '"' . xl('Patient') . '",';
69 echo '"' . xl('ID') . '",';
70 echo '"' . xl('Ordered') . '",';
71 echo '"' . xl('Procedure') . '",';
72 echo '"' . xl('Provider') . '",';
73 echo '"' . xl('Code') . '",';
74 echo '"' . xl('Service') . '"' . "\n";
76 else { // not export
78 <html>
79 <head>
80 <?php html_header_show();?>
81 <title><?php xl('Pending Followup from Results','e') ?></title>
83 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-9-1/index.js"></script>
84 <script language="JavaScript">
85 $(document).ready(function() {
86 var win = top.printLogSetup ? top : opener.top;
87 win.printLogSetup(document.getElementById('printbutton'));
88 });
89 </script>
91 </head>
93 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
94 <center>
96 <h2><?php xl('Pending Followup from Results','e')?></h2>
98 <form method='post' action='pending_followup.php'>
100 <table border='0' cellpadding='3'>
102 <tr>
103 <td>
104 <?php
105 // Build a drop-down list of facilities.
107 $query = "SELECT id, name FROM facility ORDER BY name";
108 $fres = sqlStatement($query);
109 echo " <select name='form_facility'>\n";
110 echo " <option value=''>-- All Facilities --\n";
111 while ($frow = sqlFetchArray($fres)) {
112 $facid = $frow['id'];
113 echo " <option value='$facid'";
114 if ($facid == $form_facility) echo " selected";
115 echo ">" . $frow['name'] . "\n";
117 echo " </select>\n";
119 &nbsp;<?xl('From:','e')?>
120 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
121 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
122 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
123 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
124 title='<?php xl('Click here to choose a date','e'); ?>'>
125 &nbsp;To:
126 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
127 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
128 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
129 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
130 title='<?php xl('Click here to choose a date','e'); ?>'>
131 &nbsp;
132 <input type='submit' name='form_refresh' value="<?php xl('Refresh','e') ?>">
133 &nbsp;
134 <input type='submit' name='form_csvexport' value="<?php xl('Export to CSV','e') ?>">
135 &nbsp;
136 <input type='button' value='<?php echo xla('Print'); ?>' id='printbutton' />
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 xl('Patient','e' ) ?></td>
150 <td class="dehead"><?php xl('ID','e' ) ?></td>
151 <td class="dehead"><?php xl('Ordered','e' ) ?></td>
152 <td class="dehead"><?php xl('Procedure','e') ?></td>
153 <td class="dehead"><?php xl('Provider','e' ) ?></td>
154 <td class="dehead"><?php xl('Code','e' ) ?></td>
155 <td class="dehead"><?php xl('Service','e' ) ?></td>
156 </tr>
157 <?php
158 } // end not export
160 // If generating a report.
162 if ($_POST['form_refresh'] || $_POST['form_csvexport']) {
163 $from_date = $form_from_date;
164 $to_date = $form_to_date;
166 $query = "SELECT po.patient_id, po.encounter_id, po.date_ordered, " .
167 "pd.pubpid, " .
168 "CONCAT(pd.lname, ', ', pd.fname, ' ', pd.mname) AS patient_name, " .
169 "pto.name AS procedure_name, " .
170 "pts.related_code, " .
171 "u1.lname AS provider_lname, u1.fname AS provider_fname, u1.mname AS provider_mname, " .
172 "pr.procedure_report_id, pr.date_report, pr.report_status " .
173 "FROM procedure_order AS po " .
174 "JOIN form_encounter AS fe ON fe.pid = po.patient_id AND fe.encounter = po.encounter_id " .
175 "JOIN patient_data AS pd ON pd.pid = po.patient_id " .
176 "JOIN procedure_report AS pr ON pr.procedure_order_id = po.procedure_order_id " .
177 "JOIN procedure_result AS ps ON ps.procedure_report_id = pr.procedure_report_id " .
178 "AND ps.abnormal != '' AND ps.abnormal != 'no' " .
179 "JOIN procedure_type AS pto ON pto.procedure_type_id = po.procedure_type_id " .
180 "JOIN procedure_type AS pts ON pts.procedure_type_id = ps.procedure_type_id " .
181 "AND pts.related_code != '' " .
182 "LEFT JOIN users AS u1 ON u1.id = po.provider_id " .
183 "WHERE " .
184 "po.date_ordered >= '$from_date' AND po.date_ordered <= '$to_date'";
186 if ($form_facility) {
187 $query .= " AND fe.facility_id = '$form_facility'";
189 $query .= " ORDER BY pd.lname, pd.fname, pd.mname, po.patient_id, " .
190 "po.date_ordered, po.procedure_order_id";
192 $res = sqlStatement($query);
193 while ($row = sqlFetchArray($res)) {
194 $patient_id = $row['patient_id'];
195 $date_ordered = $row['date_ordered'];
197 $relcodes = explode(';', $row['related_code']);
198 foreach ($relcodes as $codestring) {
199 if ($codestring === '') continue;
200 list($codetype, $code) = explode(':', $codestring);
202 $brow = sqlQuery("SELECT count(*) AS count " .
203 "FROM billing AS b, form_encounter AS fe WHERE " .
204 "b.pid = '$patient_id' AND " .
205 "b.code_type = '$codetype' AND " .
206 "b.code = '$code' AND " .
207 "b.activity = 1 AND " .
208 "fe.pid = b.pid AND fe.encounter = b.encounter AND " .
209 "fe.date >= '$date_ordered 00:00:00'");
211 // If there was such a service, then this followup is not pending.
212 if (!empty($brow['count'])) continue;
214 thisLineItem($row, $codetype, $code);
218 } // end report generation
220 if (! $_POST['form_csvexport']) {
223 </table>
224 </form>
225 </center>
226 </body>
228 <!-- stuff for the popup calendar -->
229 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
230 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
231 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
232 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
233 <script language="Javascript">
234 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
235 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
236 </script>
238 </html>
239 <?php
240 } // End not csv export