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");
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'] : '';
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 ?>
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);
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 */
89 #report_parameters_daterange {
93 #report_results table {
98 /* specifically exclude some from the screen */
100 #report_parameters_daterange {
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)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
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
=''/>
128 <div style
='float:left'>
132 <td
class='label_custom'>
133 <?php
xl('Facility','e'); ?
>:
136 <?php
dropdown_facility(strip_escape_custom($form_facility), 'form_facility', true); ?
>
138 <td
class='label_custom'>
139 <?php
xl('From','e'); ?
>:
142 <input type
='text' class='datepicker' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo oeFormatShortDate($form_from_date) ?>'>
144 <td
class='label_custom'>
145 <?php
xl('To','e'); ?
>:
148 <input type
='text' class='datepicker' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo oeFormatShortDate($form_to_date) ?>'>
152 <td
class='label_custom'>
153 <?php
xl('Patient ID','e'); ?
>:
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','\'','\''); ?
> />
159 <td
class='label_custom'>
160 <?php
xl('Drug','e'); ?
>:
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','\'','\''); ?
> />
166 <td
class='label_custom'>
167 <?php
xl('Lot','e'); ?
>:
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','\'','\''); ?
> />
179 <td align
='left' valign
='middle' height
="100%">
180 <table style
='border-left:1px solid; width:100%; height:100%' >
183 <div style
='margin-left:15px'>
184 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
186 <?php
xl('Submit','e'); ?
>
190 <?php
if ($_POST['form_refresh']) { ?
>
191 <a href
='#' class='css_button' id
='printbutton'>
193 <?php
xl('Print','e'); ?
>
204 </div
> <!-- end of parameters
-->
207 if ($_POST['form_refresh']) {
209 <div id
="report_results">
210 <table id
='mymaintable'>
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
>
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, " .
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 " .
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;
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']) .
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 = ' ';
285 $patient_id = ' ';
286 if ($row['id'] == $last_prescription_id) {
287 $prescription_id = ' ';
288 $drug_name = ' ';
289 $ndc_number = ' ';
290 $drug_units = ' ';
292 $reactions = ' ';
293 $instructed = ' ';
299 <?php
echo $patient_name ?
>
302 <?php
echo $patient_id ?
>
305 <?php
echo $prescription_id ?
>
308 <?php
echo $drug_name ?
>
311 <?php
echo $ndc_number ?
>
314 <?php
echo $drug_units ?
>
317 <?php
echo $refills ?
>
320 <?php
echo $instructed ?
>
323 <?php
echo $reactions ?
>
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']) ?
>
332 <?php
echo $row['quantity'] ?
>
335 <?php
echo $row['manufacturer'] ?
>
338 <?php
echo $row['lot_number'] ?
>
342 $last_prescription_id = $row['id'];
343 //$last_patient_id = $row['patient_id'];
344 $last_patient_id = $row['pubpid'];
350 </div
> <!-- end of results
-->
353 <?php
echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?
>