minor fix in hover for prior commit
[openemr.git] / interface / reports / prescriptions_report.php
blobd13652a0567ef2de95be485c0fd4262aab498b9e
1 <?php
2 // Copyright (C) 2006-2016 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 // This report lists prescriptions and their dispensations according
10 // to various input selection criteria.
11 //
12 // Fix drug name search to work in a broader sense - tony@mi-squared.com 2010
14 require_once("../globals.php");
15 require_once("$srcdir/patient.inc");
16 require_once("$srcdir/options.inc.php");
17 require_once("../drugs/drugs.inc.php");
18 require_once("$srcdir/formatting.inc.php");
19 require_once "$srcdir/formdata.inc.php";
21 $form_from_date = fixDate($_POST['form_from_date'], date('Y-01-01'));
22 $form_to_date = fixDate($_POST['form_to_date'] , date('Y-m-d'));
23 $form_patient_id = trim($_POST['form_patient_id']);
24 $form_drug_name = trim($_POST['form_drug_name']);
25 $form_lot_number = trim($_POST['form_lot_number']);
26 $form_facility = isset($_POST['form_facility']) ? $_POST['form_facility'] : '';
28 <html>
29 <head>
30 <?php html_header_show();?>
31 <title><?php xl('Prescriptions and Dispensations','e'); ?></title>
32 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
33 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
34 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
35 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-9-1/index.js"></script>
36 <script type="text/javascript" src="../../library/js/report_helper.js?v=<?php echo $v_js_includes; ?>"></script>
38 <script language="JavaScript">
40 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
42 $(document).ready(function() {
43 oeFixedHeaderSetup(document.getElementById('mymaintable'));
44 var win = top.printLogSetup ? top : opener.top;
45 win.printLogSetup(document.getElementById('printbutton'));
46 });
48 // The OnClick handler for receipt display.
49 function show_receipt(payid) {
50 // dlgopen('../patient_file/front_payment.php?receipt=1&payid=' + payid, '_blank', 550, 400);
51 return false;
54 </script>
56 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
57 <style type="text/css">
59 /* specifically include & exclude from printing */
60 @media print {
61 #report_parameters {
62 visibility: hidden;
63 display: none;
65 #report_parameters_daterange {
66 visibility: visible;
67 display: inline;
69 #report_results table {
70 margin-top: 0px;
74 /* specifically exclude some from the screen */
75 @media screen {
76 #report_parameters_daterange {
77 visibility: hidden;
78 display: none;
82 </style>
83 </head>
85 <body class="body_top">
87 <!-- Required for the popup date selectors -->
88 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
90 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Prescriptions and Dispensations','e'); ?></span>
92 <div id="report_parameters_daterange">
93 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
94 </div>
96 <form name='theform' id='theform' method='post' action='prescriptions_report.php'>
98 <div id="report_parameters">
100 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
101 <table>
102 <tr>
103 <td width='640px'>
104 <div style='float:left'>
106 <table class='text'>
107 <tr>
108 <td class='label'>
109 <?php xl('Facility','e'); ?>:
110 </td>
111 <td>
112 <?php dropdown_facility(strip_escape_custom($form_facility), 'form_facility', true); ?>
113 </td>
114 <td class='label'>
115 <?php xl('From','e'); ?>:
116 </td>
117 <td>
118 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
119 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
120 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
121 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
122 title='<?php xl('Click here to choose a date','e'); ?>'>
123 </td>
124 <td class='label'>
125 <?php xl('To','e'); ?>:
126 </td>
127 <td>
128 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
129 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
130 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
131 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
132 title='<?php xl('Click here to choose a date','e'); ?>'>
133 </td>
134 </tr>
135 <tr>
136 <td class='label'>
137 <?php xl('Patient ID','e'); ?>:
138 </td>
139 <td>
140 <input type='text' name='form_patient_id' size='10' maxlength='20' value='<?php echo $form_patient_id ?>'
141 title=<?php xl('Optional numeric patient ID','e','\'','\''); ?> />
142 </td>
143 <td class='label'>
144 <?php xl('Drug','e'); ?>:
145 </td>
146 <td>
147 <input type='text' name='form_drug_name' size='10' maxlength='250' value='<?php echo $form_drug_name ?>'
148 title=<?php xl('Optional drug name, use % as a wildcard','e','\'','\''); ?> />
149 </td>
150 <td class='label'>
151 <?php xl('Lot','e'); ?>:
152 </td>
153 <td>
154 <input type='text' name='form_lot_number' size='10' maxlength='20' value='<?php echo $form_lot_number ?>'
155 title=<?php xl('Optional lot number, use % as a wildcard','e','\'','\''); ?> />
156 </td>
157 </tr>
158 </table>
160 </div>
162 </td>
163 <td align='left' valign='middle' height="100%">
164 <table style='border-left:1px solid; width:100%; height:100%' >
165 <tr>
166 <td>
167 <div style='margin-left:15px'>
168 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
169 <span>
170 <?php xl('Submit','e'); ?>
171 </span>
172 </a>
174 <?php if ($_POST['form_refresh']) { ?>
175 <a href='#' class='css_button' id='printbutton'>
176 <span>
177 <?php xl('Print','e'); ?>
178 </span>
179 </a>
180 <?php } ?>
181 </div>
182 </td>
183 </tr>
184 </table>
185 </td>
186 </tr>
187 </table>
188 </div> <!-- end of parameters -->
190 <?php
191 if ($_POST['form_refresh']) {
193 <div id="report_results">
194 <table id='mymaintable'>
195 <thead>
196 <th> <?php xl('Patient','e'); ?> </th>
197 <th> <?php xl('ID','e'); ?> </th>
198 <th> <?php xl('RX','e'); ?> </th>
199 <th> <?php xl('Drug Name','e'); ?> </th>
200 <th> <?php xl('NDC','e'); ?> </th>
201 <th> <?php xl('Units','e'); ?> </th>
202 <th> <?php xl('Refills','e'); ?> </th>
203 <th> <?php xl('Instructed','e'); ?> </th>
204 <th> <?php xl('Reactions','e'); ?> </th>
205 <th> <?php xl('Dispensed','e'); ?> </th>
206 <th> <?php xl('Qty','e'); ?> </th>
207 <th> <?php xl('Manufacturer','e'); ?> </th>
208 <th> <?php xl('Lot','e'); ?> </th>
209 </thead>
210 <tbody>
211 <?php
212 if ($_POST['form_refresh']) {
213 $where = "r.date_modified >= '$form_from_date' AND " .
214 "r.date_modified <= '$form_to_date'";
215 //if ($form_patient_id) $where .= " AND r.patient_id = '$form_patient_id'";
216 if ($form_patient_id) $where .= " AND p.pubpid = '$form_patient_id'";
217 if ($form_drug_name ) $where .= " AND (d.name LIKE '$form_drug_name' OR r.drug LIKE '$form_drug_name')";
218 if ($form_lot_number) $where .= " AND i.lot_number LIKE '$form_lot_number'";
220 $query = "SELECT r.id, r.patient_id, " .
221 "r.date_modified, r.dosage, r.route, r.interval, r.refills, r.drug, " .
222 "d.name, d.ndc_number, d.form, d.size, d.unit, d.reactions, " .
223 "s.sale_id, s.sale_date, s.quantity, " .
224 "i.manufacturer, i.lot_number, i.expiration, " .
225 "p.pubpid, ".
226 "p.fname, p.lname, p.mname, u.facility_id " .
227 "FROM prescriptions AS r " .
228 "LEFT OUTER JOIN drugs AS d ON d.drug_id = r.drug_id " .
229 "LEFT OUTER JOIN drug_sales AS s ON s.prescription_id = r.id " .
230 "LEFT OUTER JOIN drug_inventory AS i ON i.inventory_id = s.inventory_id " .
231 "LEFT OUTER JOIN patient_data AS p ON p.pid = r.patient_id " .
232 "LEFT OUTER JOIN users AS u ON u.id = r.provider_id " .
233 "WHERE $where " .
234 //"ORDER BY p.lname, p.fname, r.patient_id, r.id, s.sale_id";
235 "ORDER BY p.lname, p.fname, p.pubpid, r.id, s.sale_id";
237 // echo "<!-- $query -->\n"; // debugging
238 $res = sqlStatement($query);
240 $last_patient_id = 0;
241 $last_prescription_id = 0;
242 while ($row = sqlFetchArray($res)) {
243 // If a facility is specified, ignore rows that do not match.
244 if ($form_facility !== '') {
245 if ($form_facility) {
246 if ($row['facility_id'] != $form_facility) continue;
248 else {
249 if (!empty($row['facility_id'])) continue;
252 $patient_name = $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'];
253 //$patient_id = $row['patient_id'];
254 $patient_id = $row['pubpid'];
255 $prescription_id = $row['id'];
256 $drug_name = empty($row['name']) ? $row['drug'] : $row['name'];
257 $ndc_number = $row['ndc_number'];
258 $drug_units = $row['size'] . ' ' .
259 generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'), $row['unit']);
260 $refills = $row['refills'];
261 $reactions = $row['reactions'];
262 $instructed = $row['dosage'] . ' ' .
263 generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'), $row['form']) .
264 ' ' .
265 generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'), $row['interval']);
266 //if ($row['patient_id'] == $last_patient_id) {
267 if (strcmp($row['pubpid'], $last_patient_id) == 0) {
268 $patient_name = '&nbsp;';
269 $patient_id = '&nbsp;';
270 if ($row['id'] == $last_prescription_id) {
271 $prescription_id = '&nbsp;';
272 $drug_name = '&nbsp;';
273 $ndc_number = '&nbsp;';
274 $drug_units = '&nbsp;';
275 $refills = '&nbsp;';
276 $reactions = '&nbsp;';
277 $instructed = '&nbsp;';
281 <tr>
282 <td>
283 <?php echo $patient_name ?>
284 </td>
285 <td>
286 <?php echo $patient_id ?>
287 </td>
288 <td>
289 <?php echo $prescription_id ?>
290 </td>
291 <td>
292 <?php echo $drug_name ?>
293 </td>
294 <td>
295 <?php echo $ndc_number ?>
296 </td>
297 <td>
298 <?php echo $drug_units ?>
299 </td>
300 <td>
301 <?php echo $refills ?>
302 </td>
303 <td>
304 <?php echo $instructed ?>
305 </td>
306 <td>
307 <?php echo $reactions ?>
308 </td>
309 <td>
310 <a href='../drugs/dispense_drug.php?sale_id=<?php echo $row['sale_id'] ?>'
311 style='color:#0000ff' target='_blank'>
312 <?php echo oeFormatShortDate($row['sale_date']) ?>
313 </a>
314 </td>
315 <td>
316 <?php echo $row['quantity'] ?>
317 </td>
318 <td>
319 <?php echo $row['manufacturer'] ?>
320 </td>
321 <td>
322 <?php echo $row['lot_number'] ?>
323 </td>
324 </tr>
325 <?php
326 $last_prescription_id = $row['id'];
327 //$last_patient_id = $row['patient_id'];
328 $last_patient_id = $row['pubpid'];
329 } // end while
330 } // end if
332 </tbody>
333 </table>
334 </div> <!-- end of results -->
335 <?php } else { ?>
336 <div class='text'>
337 <?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
338 </div>
339 <?php } ?>
340 </form>
341 </body>
343 <!-- stuff for the popup calendar -->
344 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
345 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
346 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
347 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
348 <script language="Javascript">
349 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
350 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
351 </script>
352 </html>