added new datepicker to amendments gui
[openemr.git] / interface / reports / prescriptions_report.php
blobeaf14d87c5bc2efcd76b533d61d6ff6c8539206c
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");
33 require_once("$srcdir/formatting.inc.php");
35 $form_from_date = fixDate($_POST['form_from_date'], date('Y-01-01'));
36 $form_to_date = fixDate($_POST['form_to_date'] , date('Y-m-d'));
37 $form_patient_id = trim($_POST['form_patient_id']);
38 $form_drug_name = trim($_POST['form_drug_name']);
39 $form_lot_number = trim($_POST['form_lot_number']);
40 $form_facility = isset($_POST['form_facility']) ? $_POST['form_facility'] : '';
42 <html>
43 <head>
44 <?php html_header_show();?>
45 <title><?php xl('Prescriptions and Dispensations','e'); ?></title>
46 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
47 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
48 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
49 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
50 <script type="text/javascript" src="../../library/js/report_helper.js?v=<?php echo $v_js_includes; ?>"></script>
51 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
53 <script language="JavaScript">
55 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
57 $(document).ready(function() {
58 oeFixedHeaderSetup(document.getElementById('mymaintable'));
59 var win = top.printLogSetup ? top : opener.top;
60 win.printLogSetup(document.getElementById('printbutton'));
62 $('.datepicker').datetimepicker({
63 <?php $datetimepicker_timepicker = false; ?>
64 <?php $datetimepicker_formatInput = false; ?>
65 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
66 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
67 });
69 });
71 // The OnClick handler for receipt display.
72 function show_receipt(payid) {
73 // dlgopen('../patient_file/front_payment.php?receipt=1&payid=' + payid, '_blank', 550, 400);
74 return false;
77 </script>
79 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
80 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
82 <style type="text/css">
84 /* specifically include & exclude from printing */
85 @media print {
86 #report_parameters {
87 visibility: hidden;
88 display: none;
90 #report_parameters_daterange {
91 visibility: visible;
92 display: inline;
94 #report_results table {
95 margin-top: 0px;
99 /* specifically exclude some from the screen */
100 @media screen {
101 #report_parameters_daterange {
102 visibility: hidden;
103 display: none;
107 </style>
108 </head>
110 <body class="body_top">
112 <!-- Required for the popup date selectors -->
113 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
115 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Prescriptions and Dispensations','e'); ?></span>
117 <div id="report_parameters_daterange">
118 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
119 </div>
121 <form name='theform' id='theform' method='post' action='prescriptions_report.php'>
123 <div id="report_parameters">
125 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
126 <table>
127 <tr>
128 <td width='640px'>
129 <div style='float:left'>
131 <table class='text'>
132 <tr>
133 <td class='label'>
134 <?php xl('Facility','e'); ?>:
135 </td>
136 <td>
137 <?php dropdown_facility(strip_escape_custom($form_facility), 'form_facility', true); ?>
138 </td>
139 <td class='label'>
140 <?php xl('From','e'); ?>:
141 </td>
142 <td>
143 <input type='text' class='datepicker' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
144 title='yyyy-mm-dd'>
145 </td>
146 <td class='label'>
147 <?php xl('To','e'); ?>:
148 </td>
149 <td>
150 <input type='text' class='datepicker' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
151 title='yyyy-mm-dd'>
152 </td>
153 </tr>
154 <tr>
155 <td class='label'>
156 <?php xl('Patient ID','e'); ?>:
157 </td>
158 <td>
159 <input type='text' name='form_patient_id' size='10' maxlength='20' value='<?php echo $form_patient_id ?>'
160 title=<?php xl('Optional numeric patient ID','e','\'','\''); ?> />
161 </td>
162 <td class='label'>
163 <?php xl('Drug','e'); ?>:
164 </td>
165 <td>
166 <input type='text' name='form_drug_name' size='10' maxlength='250' value='<?php echo $form_drug_name ?>'
167 title=<?php xl('Optional drug name, use % as a wildcard','e','\'','\''); ?> />
168 </td>
169 <td class='label'>
170 <?php xl('Lot','e'); ?>:
171 </td>
172 <td>
173 <input type='text' name='form_lot_number' size='10' maxlength='20' value='<?php echo $form_lot_number ?>'
174 title=<?php xl('Optional lot number, use % as a wildcard','e','\'','\''); ?> />
175 </td>
176 </tr>
177 </table>
179 </div>
181 </td>
182 <td align='left' valign='middle' height="100%">
183 <table style='border-left:1px solid; width:100%; height:100%' >
184 <tr>
185 <td>
186 <div style='margin-left:15px'>
187 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
188 <span>
189 <?php xl('Submit','e'); ?>
190 </span>
191 </a>
193 <?php if ($_POST['form_refresh']) { ?>
194 <a href='#' class='css_button' id='printbutton'>
195 <span>
196 <?php xl('Print','e'); ?>
197 </span>
198 </a>
199 <?php } ?>
200 </div>
201 </td>
202 </tr>
203 </table>
204 </td>
205 </tr>
206 </table>
207 </div> <!-- end of parameters -->
209 <?php
210 if ($_POST['form_refresh']) {
212 <div id="report_results">
213 <table id='mymaintable'>
214 <thead>
215 <th> <?php xl('Patient','e'); ?> </th>
216 <th> <?php xl('ID','e'); ?> </th>
217 <th> <?php xl('RX','e'); ?> </th>
218 <th> <?php xl('Drug Name','e'); ?> </th>
219 <th> <?php xl('NDC','e'); ?> </th>
220 <th> <?php xl('Units','e'); ?> </th>
221 <th> <?php xl('Refills','e'); ?> </th>
222 <th> <?php xl('Instructed','e'); ?> </th>
223 <th> <?php xl('Reactions','e'); ?> </th>
224 <th> <?php xl('Dispensed','e'); ?> </th>
225 <th> <?php xl('Qty','e'); ?> </th>
226 <th> <?php xl('Manufacturer','e'); ?> </th>
227 <th> <?php xl('Lot','e'); ?> </th>
228 </thead>
229 <tbody>
230 <?php
231 if ($_POST['form_refresh']) {
232 $where = "r.date_modified >= '$form_from_date' AND " .
233 "r.date_modified <= '$form_to_date'";
234 //if ($form_patient_id) $where .= " AND r.patient_id = '$form_patient_id'";
235 if ($form_patient_id) $where .= " AND p.pubpid = '$form_patient_id'";
236 if ($form_drug_name ) $where .= " AND (d.name LIKE '$form_drug_name' OR r.drug LIKE '$form_drug_name')";
237 if ($form_lot_number) $where .= " AND i.lot_number LIKE '$form_lot_number'";
239 $query = "SELECT r.id, r.patient_id, " .
240 "r.date_modified, r.dosage, r.route, r.interval, r.refills, r.drug, " .
241 "d.name, d.ndc_number, d.form, d.size, d.unit, d.reactions, " .
242 "s.sale_id, s.sale_date, s.quantity, " .
243 "i.manufacturer, i.lot_number, i.expiration, " .
244 "p.pubpid, ".
245 "p.fname, p.lname, p.mname, u.facility_id " .
246 "FROM prescriptions AS r " .
247 "LEFT OUTER JOIN drugs AS d ON d.drug_id = r.drug_id " .
248 "LEFT OUTER JOIN drug_sales AS s ON s.prescription_id = r.id " .
249 "LEFT OUTER JOIN drug_inventory AS i ON i.inventory_id = s.inventory_id " .
250 "LEFT OUTER JOIN patient_data AS p ON p.pid = r.patient_id " .
251 "LEFT OUTER JOIN users AS u ON u.id = r.provider_id " .
252 "WHERE $where " .
253 //"ORDER BY p.lname, p.fname, r.patient_id, r.id, s.sale_id";
254 "ORDER BY p.lname, p.fname, p.pubpid, r.id, s.sale_id";
256 // echo "<!-- $query -->\n"; // debugging
257 $res = sqlStatement($query);
259 $last_patient_id = 0;
260 $last_prescription_id = 0;
261 while ($row = sqlFetchArray($res)) {
262 // If a facility is specified, ignore rows that do not match.
263 if ($form_facility !== '') {
264 if ($form_facility) {
265 if ($row['facility_id'] != $form_facility) continue;
267 else {
268 if (!empty($row['facility_id'])) continue;
271 $patient_name = $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'];
272 //$patient_id = $row['patient_id'];
273 $patient_id = $row['pubpid'];
274 $prescription_id = $row['id'];
275 $drug_name = empty($row['name']) ? $row['drug'] : $row['name'];
276 $ndc_number = $row['ndc_number'];
277 $drug_units = $row['size'] . ' ' .
278 generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'), $row['unit']);
279 $refills = $row['refills'];
280 $reactions = $row['reactions'];
281 $instructed = $row['dosage'] . ' ' .
282 generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'), $row['form']) .
283 ' ' .
284 generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'), $row['interval']);
285 //if ($row['patient_id'] == $last_patient_id) {
286 if (strcmp($row['pubpid'], $last_patient_id) == 0) {
287 $patient_name = '&nbsp;';
288 $patient_id = '&nbsp;';
289 if ($row['id'] == $last_prescription_id) {
290 $prescription_id = '&nbsp;';
291 $drug_name = '&nbsp;';
292 $ndc_number = '&nbsp;';
293 $drug_units = '&nbsp;';
294 $refills = '&nbsp;';
295 $reactions = '&nbsp;';
296 $instructed = '&nbsp;';
300 <tr>
301 <td>
302 <?php echo $patient_name ?>
303 </td>
304 <td>
305 <?php echo $patient_id ?>
306 </td>
307 <td>
308 <?php echo $prescription_id ?>
309 </td>
310 <td>
311 <?php echo $drug_name ?>
312 </td>
313 <td>
314 <?php echo $ndc_number ?>
315 </td>
316 <td>
317 <?php echo $drug_units ?>
318 </td>
319 <td>
320 <?php echo $refills ?>
321 </td>
322 <td>
323 <?php echo $instructed ?>
324 </td>
325 <td>
326 <?php echo $reactions ?>
327 </td>
328 <td>
329 <a href='../drugs/dispense_drug.php?sale_id=<?php echo $row['sale_id'] ?>'
330 style='color:#0000ff' target='_blank'>
331 <?php echo oeFormatShortDate($row['sale_date']) ?>
332 </a>
333 </td>
334 <td>
335 <?php echo $row['quantity'] ?>
336 </td>
337 <td>
338 <?php echo $row['manufacturer'] ?>
339 </td>
340 <td>
341 <?php echo $row['lot_number'] ?>
342 </td>
343 </tr>
344 <?php
345 $last_prescription_id = $row['id'];
346 //$last_patient_id = $row['patient_id'];
347 $last_patient_id = $row['pubpid'];
348 } // end while
349 } // end if
351 </tbody>
352 </table>
353 </div> <!-- end of results -->
354 <?php } else { ?>
355 <div class='text'>
356 <?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
357 </div>
358 <?php } ?>
359 </form>
360 </body>
362 </html>