removal of overlib_mini.js and calendar.js (#640)
[openemr.git] / interface / reports / prescriptions_report.php
blobc2d61000bc6d20ebb730093f4a90dbb6b7d8e74b
1 <?php
2 /**
3 * This report lists prescriptions and their dispensations according
4 * to various input selection criteria.
6 * Fix drug name search to work in a broader sense - tony@mi-squared.com 2010
8 * Copyright (C) 2005-2016 Rod Roark <rod@sunsetsystems.com>
9 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * LICENSE: This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
22 * @package OpenEMR
23 * @author Rod Roark <rod@sunsetsystems.com>
24 * @author Brady Miller <brady.g.miller@gmail.com>
25 * @link http://www.open-emr.org
29 require_once("../globals.php");
30 require_once("$srcdir/patient.inc");
31 require_once("$srcdir/options.inc.php");
32 require_once("../drugs/drugs.inc.php");
34 $form_from_date = (!empty($_POST['form_from_date'])) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-01-01');
35 $form_to_date = (!empty($_POST['form_to_date'])) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
36 $form_patient_id = trim($_POST['form_patient_id']);
37 $form_drug_name = trim($_POST['form_drug_name']);
38 $form_lot_number = trim($_POST['form_lot_number']);
39 $form_facility = isset($_POST['form_facility']) ? $_POST['form_facility'] : '';
41 <html>
42 <head>
43 <?php html_header_show();?>
44 <title><?php xl('Prescriptions and Dispensations','e'); ?></title>
45 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
46 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
47 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
48 <script type="text/javascript" src="../../library/js/report_helper.js?v=<?php echo $v_js_includes; ?>"></script>
49 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
51 <script language="JavaScript">
53 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
55 $(document).ready(function() {
56 oeFixedHeaderSetup(document.getElementById('mymaintable'));
57 var win = top.printLogSetup ? top : opener.top;
58 win.printLogSetup(document.getElementById('printbutton'));
60 $('.datepicker').datetimepicker({
61 <?php $datetimepicker_timepicker = false; ?>
62 <?php $datetimepicker_showseconds = false; ?>
63 <?php $datetimepicker_formatInput = true; ?>
64 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
65 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
66 });
68 });
70 // The OnClick handler for receipt display.
71 function show_receipt(payid) {
72 // dlgopen('../patient_file/front_payment.php?receipt=1&payid=' + payid, '_blank', 550, 400);
73 return false;
76 </script>
78 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
79 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
81 <style type="text/css">
83 /* specifically include & exclude from printing */
84 @media print {
85 #report_parameters {
86 visibility: hidden;
87 display: none;
89 #report_parameters_daterange {
90 visibility: visible;
91 display: inline;
93 #report_results table {
94 margin-top: 0px;
98 /* specifically exclude some from the screen */
99 @media screen {
100 #report_parameters_daterange {
101 visibility: hidden;
102 display: none;
106 </style>
107 </head>
109 <body class="body_top">
111 <!-- Required for the popup date selectors -->
112 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
114 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Prescriptions and Dispensations','e'); ?></span>
116 <div id="report_parameters_daterange">
117 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
118 </div>
120 <form name='theform' id='theform' method='post' action='prescriptions_report.php'>
122 <div id="report_parameters">
124 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
125 <table>
126 <tr>
127 <td width='640px'>
128 <div style='float:left'>
130 <table class='text'>
131 <tr>
132 <td class='label_custom'>
133 <?php xl('Facility','e'); ?>:
134 </td>
135 <td>
136 <?php dropdown_facility(strip_escape_custom($form_facility), 'form_facility', true); ?>
137 </td>
138 <td class='label_custom'>
139 <?php xl('From','e'); ?>:
140 </td>
141 <td>
142 <input type='text' class='datepicker' name='form_from_date' id="form_from_date" size='10' value='<?php echo oeFormatShortDate($form_from_date) ?>'>
143 </td>
144 <td class='label_custom'>
145 <?php xl('To','e'); ?>:
146 </td>
147 <td>
148 <input type='text' class='datepicker' name='form_to_date' id="form_to_date" size='10' value='<?php echo oeFormatShortDate($form_to_date) ?>'>
149 </td>
150 </tr>
151 <tr>
152 <td class='label_custom'>
153 <?php xl('Patient ID','e'); ?>:
154 </td>
155 <td>
156 <input type='text' name='form_patient_id' size='10' maxlength='20' value='<?php echo $form_patient_id ?>'
157 title=<?php xl('Optional numeric patient ID','e','\'','\''); ?> />
158 </td>
159 <td class='label_custom'>
160 <?php xl('Drug','e'); ?>:
161 </td>
162 <td>
163 <input type='text' name='form_drug_name' size='10' maxlength='250' value='<?php echo $form_drug_name ?>'
164 title=<?php xl('Optional drug name, use % as a wildcard','e','\'','\''); ?> />
165 </td>
166 <td class='label_custom'>
167 <?php xl('Lot','e'); ?>:
168 </td>
169 <td>
170 <input type='text' name='form_lot_number' size='10' maxlength='20' value='<?php echo $form_lot_number ?>'
171 title=<?php xl('Optional lot number, use % as a wildcard','e','\'','\''); ?> />
172 </td>
173 </tr>
174 </table>
176 </div>
178 </td>
179 <td align='left' valign='middle' height="100%">
180 <table style='border-left:1px solid; width:100%; height:100%' >
181 <tr>
182 <td>
183 <div style='margin-left:15px'>
184 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
185 <span>
186 <?php xl('Submit','e'); ?>
187 </span>
188 </a>
190 <?php if ($_POST['form_refresh']) { ?>
191 <a href='#' class='css_button' id='printbutton'>
192 <span>
193 <?php xl('Print','e'); ?>
194 </span>
195 </a>
196 <?php } ?>
197 </div>
198 </td>
199 </tr>
200 </table>
201 </td>
202 </tr>
203 </table>
204 </div> <!-- end of parameters -->
206 <?php
207 if ($_POST['form_refresh']) {
209 <div id="report_results">
210 <table id='mymaintable'>
211 <thead>
212 <th> <?php xl('Patient','e'); ?> </th>
213 <th> <?php xl('ID','e'); ?> </th>
214 <th> <?php xl('RX','e'); ?> </th>
215 <th> <?php xl('Drug Name','e'); ?> </th>
216 <th> <?php xl('NDC','e'); ?> </th>
217 <th> <?php xl('Units','e'); ?> </th>
218 <th> <?php xl('Refills','e'); ?> </th>
219 <th> <?php xl('Instructed','e'); ?> </th>
220 <th> <?php xl('Reactions','e'); ?> </th>
221 <th> <?php xl('Dispensed','e'); ?> </th>
222 <th> <?php xl('Qty','e'); ?> </th>
223 <th> <?php xl('Manufacturer','e'); ?> </th>
224 <th> <?php xl('Lot','e'); ?> </th>
225 </thead>
226 <tbody>
227 <?php
228 if ($_POST['form_refresh']) {
229 $where = "r.date_modified >= '$form_from_date' AND " .
230 "r.date_modified <= '$form_to_date'";
231 //if ($form_patient_id) $where .= " AND r.patient_id = '$form_patient_id'";
232 if ($form_patient_id) $where .= " AND p.pubpid = '$form_patient_id'";
233 if ($form_drug_name ) $where .= " AND (d.name LIKE '$form_drug_name' OR r.drug LIKE '$form_drug_name')";
234 if ($form_lot_number) $where .= " AND i.lot_number LIKE '$form_lot_number'";
236 $query = "SELECT r.id, r.patient_id, " .
237 "r.date_modified, r.dosage, r.route, r.interval, r.refills, r.drug, " .
238 "d.name, d.ndc_number, d.form, d.size, d.unit, d.reactions, " .
239 "s.sale_id, s.sale_date, s.quantity, " .
240 "i.manufacturer, i.lot_number, i.expiration, " .
241 "p.pubpid, ".
242 "p.fname, p.lname, p.mname, u.facility_id " .
243 "FROM prescriptions AS r " .
244 "LEFT OUTER JOIN drugs AS d ON d.drug_id = r.drug_id " .
245 "LEFT OUTER JOIN drug_sales AS s ON s.prescription_id = r.id " .
246 "LEFT OUTER JOIN drug_inventory AS i ON i.inventory_id = s.inventory_id " .
247 "LEFT OUTER JOIN patient_data AS p ON p.pid = r.patient_id " .
248 "LEFT OUTER JOIN users AS u ON u.id = r.provider_id " .
249 "WHERE $where " .
250 //"ORDER BY p.lname, p.fname, r.patient_id, r.id, s.sale_id";
251 "ORDER BY p.lname, p.fname, p.pubpid, r.id, s.sale_id";
253 // echo "<!-- $query -->\n"; // debugging
254 $res = sqlStatement($query);
256 $last_patient_id = 0;
257 $last_prescription_id = 0;
258 while ($row = sqlFetchArray($res)) {
259 // If a facility is specified, ignore rows that do not match.
260 if ($form_facility !== '') {
261 if ($form_facility) {
262 if ($row['facility_id'] != $form_facility) continue;
264 else {
265 if (!empty($row['facility_id'])) continue;
268 $patient_name = $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'];
269 //$patient_id = $row['patient_id'];
270 $patient_id = $row['pubpid'];
271 $prescription_id = $row['id'];
272 $drug_name = empty($row['name']) ? $row['drug'] : $row['name'];
273 $ndc_number = $row['ndc_number'];
274 $drug_units = $row['size'] . ' ' .
275 generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'), $row['unit']);
276 $refills = $row['refills'];
277 $reactions = $row['reactions'];
278 $instructed = $row['dosage'] . ' ' .
279 generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'), $row['form']) .
280 ' ' .
281 generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'), $row['interval']);
282 //if ($row['patient_id'] == $last_patient_id) {
283 if (strcmp($row['pubpid'], $last_patient_id) == 0) {
284 $patient_name = '&nbsp;';
285 $patient_id = '&nbsp;';
286 if ($row['id'] == $last_prescription_id) {
287 $prescription_id = '&nbsp;';
288 $drug_name = '&nbsp;';
289 $ndc_number = '&nbsp;';
290 $drug_units = '&nbsp;';
291 $refills = '&nbsp;';
292 $reactions = '&nbsp;';
293 $instructed = '&nbsp;';
297 <tr>
298 <td>
299 <?php echo $patient_name ?>
300 </td>
301 <td>
302 <?php echo $patient_id ?>
303 </td>
304 <td>
305 <?php echo $prescription_id ?>
306 </td>
307 <td>
308 <?php echo $drug_name ?>
309 </td>
310 <td>
311 <?php echo $ndc_number ?>
312 </td>
313 <td>
314 <?php echo $drug_units ?>
315 </td>
316 <td>
317 <?php echo $refills ?>
318 </td>
319 <td>
320 <?php echo $instructed ?>
321 </td>
322 <td>
323 <?php echo $reactions ?>
324 </td>
325 <td>
326 <a href='../drugs/dispense_drug.php?sale_id=<?php echo $row['sale_id'] ?>'
327 style='color:#0000ff' target='_blank'>
328 <?php echo oeFormatShortDate($row['sale_date']) ?>
329 </a>
330 </td>
331 <td>
332 <?php echo $row['quantity'] ?>
333 </td>
334 <td>
335 <?php echo $row['manufacturer'] ?>
336 </td>
337 <td>
338 <?php echo $row['lot_number'] ?>
339 </td>
340 </tr>
341 <?php
342 $last_prescription_id = $row['id'];
343 //$last_patient_id = $row['patient_id'];
344 $last_patient_id = $row['pubpid'];
345 } // end while
346 } // end if
348 </tbody>
349 </table>
350 </div> <!-- end of results -->
351 <?php } else { ?>
352 <div class='text'>
353 <?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
354 </div>
355 <?php } ?>
356 </form>
357 </body>
359 </html>