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>;.
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'] : '';
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 ?>
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);
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 */
90 #report_parameters_daterange {
94 #report_results table {
99 /* specifically exclude some from the screen */
101 #report_parameters_daterange {
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)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
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
=''/>
129 <div style
='float:left'>
134 <?php
xl('Facility','e'); ?
>:
137 <?php
dropdown_facility(strip_escape_custom($form_facility), 'form_facility', true); ?
>
140 <?php
xl('From','e'); ?
>:
143 <input type
='text' class='datepicker' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
147 <?php
xl('To','e'); ?
>:
150 <input type
='text' class='datepicker' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
156 <?php
xl('Patient ID','e'); ?
>:
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','\'','\''); ?
> />
163 <?php
xl('Drug','e'); ?
>:
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','\'','\''); ?
> />
170 <?php
xl('Lot','e'); ?
>:
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','\'','\''); ?
> />
182 <td align
='left' valign
='middle' height
="100%">
183 <table style
='border-left:1px solid; width:100%; height:100%' >
186 <div style
='margin-left:15px'>
187 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
189 <?php
xl('Submit','e'); ?
>
193 <?php
if ($_POST['form_refresh']) { ?
>
194 <a href
='#' class='css_button' id
='printbutton'>
196 <?php
xl('Print','e'); ?
>
207 </div
> <!-- end of parameters
-->
210 if ($_POST['form_refresh']) {
212 <div id
="report_results">
213 <table id
='mymaintable'>
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
>
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, " .
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 " .
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;
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']) .
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 = ' ';
288 $patient_id = ' ';
289 if ($row['id'] == $last_prescription_id) {
290 $prescription_id = ' ';
291 $drug_name = ' ';
292 $ndc_number = ' ';
293 $drug_units = ' ';
295 $reactions = ' ';
296 $instructed = ' ';
302 <?php
echo $patient_name ?
>
305 <?php
echo $patient_id ?
>
308 <?php
echo $prescription_id ?
>
311 <?php
echo $drug_name ?
>
314 <?php
echo $ndc_number ?
>
317 <?php
echo $drug_units ?
>
320 <?php
echo $refills ?
>
323 <?php
echo $instructed ?
>
326 <?php
echo $reactions ?
>
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']) ?
>
335 <?php
echo $row['quantity'] ?
>
338 <?php
echo $row['manufacturer'] ?
>
341 <?php
echo $row['lot_number'] ?
>
345 $last_prescription_id = $row['id'];
346 //$last_patient_id = $row['patient_id'];
347 $last_patient_id = $row['pubpid'];
353 </div
> <!-- end of results
-->
356 <?php
echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?
>