2 // Copyright (C) 2006 Rod Roark <rod@sunsetsystems.com>
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.
12 require_once("../globals.php");
13 require_once("$srcdir/patient.inc");
14 require_once("../drugs/drugs.inc.php");
16 $form_from_date = fixDate($_POST['form_from_date'], date('Y-01-01'));
17 $form_to_date = fixDate($_POST['form_to_date'] , date('Y-m-d'));
18 $form_patient_id = trim($_POST['form_patient_id']);
19 $form_drug_name = trim($_POST['form_drug_name']);
20 $form_lot_number = trim($_POST['form_lot_number']);
21 $form_facility = isset($_POST['form_facility']) ?
$_POST['form_facility'] : '';
25 <?php
html_header_show();?
>
26 <title
><?php
xl('Prescriptions and Dispensations','e'); ?
></title
>
27 <script type
="text/javascript" src
="../../library/overlib_mini.js"></script
>
28 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
29 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
30 <script language
="JavaScript">
32 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
34 // The OnClick handler for receipt display.
35 function show_receipt(payid
) {
36 // dlgopen('../patient_file/front_payment.php?receipt=1&payid=' + payid, '_blank', 550, 400);
42 <link rel
='stylesheet' href
='<?php echo $css_header ?>' type
='text/css'>
43 <style type
="text/css">
45 /* specifically include & exclude from printing */
47 #rxdrugreport_parameters {
51 #rxdrugreport_parameters_daterange {
57 /* specifically exclude some from the screen */
59 #rxdrugreport_parameters_daterange {
65 #rxdrugreport_parameters {
67 background
-color
: #ddf;
69 #rxdrugreport_parameters table {
71 border
-collapse
: collapse
;
73 #rxdrugreport_parameters table td {
77 #rxdrugreport_results {
81 #rxdrugreport_results table {
82 border
: 1px solid black
;
84 border
-collapse
: collapse
;
86 #rxdrugreport_results table thead {
87 display
: table
-header
-group
;
88 background
-color
: #ddd;
90 #rxdrugreport_results table th {
91 border
-bottom
: 1px solid black
;
94 #rxdrugreport_results table td {
97 border
-bottom
: 1px solid
#eee;
100 .rxdrugreport_totals td
{
101 background
-color
: #77ff77;
107 <body
class="body_top">
109 <!-- Required
for the popup date selectors
-->
110 <div id
="overDiv" style
="position:absolute; visibility:hidden; z-index:1000;"></div
>
114 <h2
><?php
xl('Prescriptions and Dispensations','e'); ?
></h2
>
116 <div id
="rxdrugreport_parameters_daterange">
117 <?php
echo date("d F Y", strtotime($form_from_date)) ." to ". date("d F Y", strtotime($form_to_date)); ?
>
120 <div id
="rxdrugreport_parameters">
122 <form name
='theform' method
='post' action
='prescriptions_report.php'>
128 // Build a drop-down list of facilities.
130 $query = "SELECT id, name FROM facility ORDER BY name";
131 $fres = sqlStatement($query);
132 echo " <select name='form_facility'>\n";
133 echo " <option value=''>-- All Facilities --\n";
134 while ($frow = sqlFetchArray($fres)) {
135 $facid = $frow['id'];
136 echo " <option value='$facid'";
137 if ($facid == $form_facility) echo " selected";
138 echo ">" . $frow['name'] . "\n";
140 echo " <option value='0'";
141 if ($form_facility === '0') echo " selected";
142 echo ">-- Unspecified --\n";
145  
;<?php
xl('From','e'); ?
>:
146 <input type
='text' name
='form_from_date' id
="form_from_date" size
='10' value
='<?php echo $form_from_date ?>'
147 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
148 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
149 id
='img_from_date' border
='0' alt
='[?]' style
='cursor:pointer'
150 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
151  
;<?php
xl('To','e'); ?
>:
152 <input type
='text' name
='form_to_date' id
="form_to_date" size
='10' value
='<?php echo $form_to_date ?>'
153 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' title
='yyyy-mm-dd'>
154 <img src
='../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
155 id
='img_to_date' border
='0' alt
='[?]' style
='cursor:pointer'
156 title
='<?php xl('Click here to choose a date
','e
'); ?>'>
157  
;<?php
xl('Patient ID','e'); ?
>:
158 <input type
='text' name
='form_patient_id' size
='6' maxlength
='6' value
='<?php echo $form_patient_id ?>'
159 title
='Optional numeric patient ID' />
160  
;<?php
xl('Drug','e'); ?
>:
161 <input type
='text' name
='form_drug_name' size
='10' maxlength
='250' value
='<?php echo $form_drug_name ?>'
162 title
='Optional drug name, use % as a wildcard' />
163  
;<?php
xl('Lot','e'); ?
>:
164 <input type
='text' name
='form_lot_number' size
='10' maxlength
='20' value
='<?php echo $form_lot_number ?>'
165 title
='Optional lot number, use % as a wildcard' />
167 <input type
='submit' name
='form_refresh' value
=<?php
xl('Refresh','e'); ?
>>
169 <input type
='button' value
='<?php xl('Print','e
'); ?>' onclick
='window.print()' />
173 </div
> <!-- end of parameters
-->
175 <div id
="rxdrugreport_results">
178 <th
> <?php
xl('Patient','e'); ?
> </th
>
179 <th
> <?php
xl('ID','e'); ?
> </th
>
180 <th
> <?php
xl('RX','e'); ?
> </th
>
181 <th
> <?php
xl('Drug Name','e'); ?
> </th
>
182 <th
> <?php
xl('NDC','e'); ?
> </th
>
183 <th
> <?php
xl('Units','e'); ?
> </th
>
184 <th
> <?php
xl('Refills','e'); ?
> </th
>
185 <th
> <?php
xl('Instructed','e'); ?
> </th
>
186 <th
> <?php
xl('Reactions','e'); ?
> </th
>
187 <th
> <?php
xl('Dispensed','e'); ?
> </th
>
188 <th
> <?php
xl('Qty','e'); ?
> </th
>
189 <th
> <?php
xl('Manufacturer','e'); ?
> </th
>
190 <th
> <?php
xl('Lot','e'); ?
> </th
>
194 if ($_POST['form_refresh']) {
195 $where = "r.date_modified >= '$form_from_date' AND " .
196 "r.date_modified <= '$form_to_date'";
197 if ($form_patient_id) $where .= " AND r.patient_id = '$form_patient_id'";
198 if ($form_drug_name ) $where .= " AND d.name LIKE '$form_drug_name'";
199 if ($form_lot_number) $where .= " AND i.lot_number LIKE '$form_lot_number'";
201 $query = "SELECT r.id, r.patient_id, " .
202 "r.date_modified, r.dosage, r.route, r.interval, r.refills, " .
203 "d.name, d.ndc_number, d.form, d.size, d.unit, d.reactions, " .
204 "s.sale_id, s.sale_date, s.quantity, " .
205 "i.manufacturer, i.lot_number, i.expiration, " .
206 "p.fname, p.lname, p.mname, u.facility_id " .
207 "FROM prescriptions AS r " .
208 "LEFT OUTER JOIN drugs AS d ON d.drug_id = r.drug_id " .
209 "LEFT OUTER JOIN drug_sales AS s ON s.prescription_id = r.id " .
210 "LEFT OUTER JOIN drug_inventory AS i ON i.inventory_id = s.inventory_id " .
211 "LEFT OUTER JOIN patient_data AS p ON p.pid = r.patient_id " .
212 "LEFT OUTER JOIN users AS u ON u.id = r.provider_id " .
214 "ORDER BY p.lname, p.fname, r.patient_id, r.id, s.sale_id";
216 // echo "<!-- $query -->\n"; // debugging
217 $res = sqlStatement($query);
219 $last_patient_id = 0;
220 $last_prescription_id = 0;
221 while ($row = sqlFetchArray($res)) {
222 // If a facility is specified, ignore rows that do not match.
223 if ($form_facility !== '') {
224 if ($form_facility) {
225 if ($row['facility_id'] != $form_facility) continue;
228 if (!empty($row['facility_id'])) continue;
231 $patient_name = $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'];
232 $patient_id = $row['patient_id'];
233 $prescription_id = $row['id'];
234 $drug_name = $row['name'];
235 $ndc_number = $row['ndc_number'];
236 $drug_units = $row['size'] . ' ' . $unit_array[$row['unit']];
237 $refills = $row['refills'];
238 $reactions = $row['reactions'];
239 $instructed = $row['dosage'] . ' ' . $form_array[$row['form']] . ' ' .
240 $interval_array[$row['interval']];
241 if ($row['patient_id'] == $last_patient_id) {
242 $patient_name = ' ';
243 $patient_id = ' ';
244 if ($row['id'] == $last_prescription_id) {
245 $prescription_id = ' ';
246 $drug_name = ' ';
247 $ndc_number = ' ';
248 $drug_units = ' ';
250 $reactions = ' ';
251 $instructed = ' ';
257 <?php
echo $patient_name ?
>
260 <?php
echo $patient_id ?
>
263 <?php
echo $prescription_id ?
>
266 <?php
echo $drug_name ?
>
269 <?php
echo $ndc_number ?
>
272 <?php
echo $drug_units ?
>
275 <?php
echo $refills ?
>
278 <?php
echo $instructed ?
>
281 <?php
echo $reactions ?
>
284 <a href
='../drugs/dispense_drug.php?sale_id=<?php echo $row['sale_id
'] ?>'
285 style
='color:#0000ff' target
='_blank'>
286 <?php
echo $row['sale_date'] ?
>
290 <?php
echo $row['quantity'] ?
>
293 <?php
echo $row['manufacturer'] ?
>
296 <?php
echo $row['lot_number'] ?
>
300 $last_prescription_id = $row['id'];
301 $last_patient_id = $row['patient_id'];
307 </div
> <!-- end of results
-->
312 <!-- stuff
for the popup calendar
-->
313 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
314 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
315 <script type
="text/javascript" src
="../../library/dynarch_calendar_en.js"></script
>
316 <script type
="text/javascript" src
="../../library/dynarch_calendar_setup.js"></script
>
317 <script language
="Javascript">
318 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
319 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});