drug waste management and ability to reprint a label
[openemr.git] / interface / reports / prescriptions_report.php
blobfa13684a627b049f287fd0511945f0d95091d83d
1 <?
2 // Copyright (C) 2006 Rod Roark <rod@sunsetsystems.com>
3 //
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']);
22 <html>
23 <head>
24 <title><? xl('Prescriptions and Dispensations','e'); ?></title>
25 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
26 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
27 <script type="text/javascript" src="../../library/calendar.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 = '<? 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);
37 return false;
40 </script>
41 </head>
43 <body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
45 <!-- Required for the popup date selectors -->
46 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
48 <center>
50 <h2><? xl('Prescriptions and Dispensations','e'); ?></h2>
52 <form name='theform' method='post' action='prescriptions_report.php'>
54 <table border='0' cellpadding='3'>
56 <tr>
57 <td>
58 <? xl('From','e'); ?>:
59 <input type='text' name='form_from_date' size='10' value='<? echo $form_from_date ?>'
60 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
61 <a href="javascript:show_calendar('theform.form_from_date')"
62 title=".xl('Click here to choose a date')."
63 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a>
64 &nbsp;<? xl('To','e'); ?>:
65 <input type='text' name='form_to_date' size='10' value='<? echo $form_to_date ?>'
66 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
67 <a href="javascript:show_calendar('theform.form_to_date')"
68 title=".xl('Click here to choose a date')."
69 ><img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' border='0'></a>
70 &nbsp;<? xl('Patient ID','e'); ?>:
71 <input type='text' name='form_patient_id' size='6' maxlength='6' value='<? echo $form_patient_id ?>'
72 title='Optional numeric patient ID' />
73 &nbsp;<? xl('Drug','e'); ?>:
74 <input type='text' name='form_drug_name' size='10' maxlength='250' value='<? echo $form_drug_name ?>'
75 title='Optional drug name, use % as a wildcard' />
76 &nbsp;<? xl('Lot','e'); ?>:
77 <input type='text' name='form_lot_number' size='10' maxlength='20' value='<? echo $form_lot_number ?>'
78 title='Optional lot number, use % as a wildcard' />
79 &nbsp;
80 <input type='submit' name='form_refresh' value=<? xl('Refresh','e'); ?>>
81 </td>
82 </tr>
84 <tr>
85 <td height="1">
86 </td>
87 </tr>
89 </table>
91 <table border='0' cellpadding='1' cellspacing='2' width='98%'>
93 <tr bgcolor="#dddddd">
94 <td class='dehead'>
95 <? xl('Patient','e'); ?>
96 </td>
97 <td class='dehead'>
98 <? xl('ID','e'); ?>
99 </td>
100 <td class='dehead'>
101 <? xl('RX','e'); ?>
102 </td>
103 <td class='dehead'>
104 <? xl('Drug Name','e'); ?>
105 </td>
106 <td class='dehead'>
107 <? xl('NDC','e'); ?>
108 </td>
109 <td class='dehead'>
110 <? xl('Units','e'); ?>
111 </td>
112 <td class='dehead'>
113 <? xl('Refills','e'); ?>
114 </td>
115 <td class='dehead'>
116 <? xl('Instructed','e'); ?>
117 </td>
118 <td class='dehead'>
119 <? xl('Reactions','e'); ?>
120 </td>
121 <td class='dehead'>
122 <? xl('Dispensed','e'); ?>
123 </td>
124 <td class='dehead'>
125 <? xl('Qty','e'); ?>
126 </td>
127 <td class='dehead'>
128 <? xl('Manufacturer','e'); ?>
129 </td>
130 <td class='dehead'>
131 <? xl('Lot','e'); ?>
132 </td>
133 </tr>
135 if ($_POST['form_refresh']) {
136 $where = "r.date_modified >= '$form_from_date' AND " .
137 "r.date_modified <= '$form_to_date'";
138 if ($form_patient_id) $where .= " AND r.patient_id = '$form_patient_id'";
139 if ($form_drug_name ) $where .= " AND d.name LIKE '$form_drug_name'";
140 if ($form_lot_number) $where .= " AND i.lot_number LIKE '$form_lot_number'";
142 $query = "SELECT r.id, r.patient_id, " .
143 "r.date_modified, r.dosage, r.route, r.interval, r.refills, " .
144 "d.name, d.ndc_number, d.form, d.size, d.unit, d.reactions, " .
145 "s.sale_id, s.sale_date, s.quantity, " .
146 "i.manufacturer, i.lot_number, i.expiration, " .
147 "p.fname, p.lname, p.mname " .
148 "FROM prescriptions AS r " .
149 "LEFT OUTER JOIN drugs AS d ON d.drug_id = r.drug_id " .
150 "LEFT OUTER JOIN drug_sales AS s ON s.prescription_id = r.id " .
151 "LEFT OUTER JOIN drug_inventory AS i ON i.inventory_id = s.inventory_id " .
152 "LEFT OUTER JOIN patient_data AS p ON p.pid = r.patient_id " .
153 "WHERE $where " .
154 "ORDER BY p.lname, p.fname, r.patient_id, r.id, s.sale_id";
156 // echo "<!-- $query -->\n"; // debugging
157 $res = sqlStatement($query);
159 $last_patient_id = 0;
160 $last_prescription_id = 0;
161 while ($row = sqlFetchArray($res)) {
162 $patient_name = $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'];
163 $patient_id = $row['patient_id'];
164 $prescription_id = $row['id'];
165 $drug_name = $row['name'];
166 $ndc_number = $row['ndc_number'];
167 $drug_units = $row['size'] . ' ' . $unit_array[$row['unit']];
168 $refills = $row['refills'];
169 $reactions = $row['reactions'];
170 $instructed = $row['dosage'] . ' ' . $form_array[$row['form']] . ' ' .
171 $interval_array[$row['interval']];
172 if ($row['patient_id'] == $last_patient_id) {
173 $patient_name = '&nbsp;';
174 $patient_id = '&nbsp;';
175 if ($row['id'] == $last_prescription_id) {
176 $prescription_id = '&nbsp;';
177 $drug_name = '&nbsp;';
178 $ndc_number = '&nbsp;';
179 $drug_units = '&nbsp;';
180 $refills = '&nbsp;';
181 $reactions = '&nbsp;';
182 $instructed = '&nbsp;';
186 <tr>
187 <td class='detail'>
188 <?php echo $patient_name ?>
189 </td>
190 <td class='detail'>
191 <?php echo $patient_id ?>
192 </td>
193 <td class='detail'>
194 <?php echo $prescription_id ?>
195 </td>
196 <td class='detail'>
197 <?php echo $drug_name ?>
198 </td>
199 <td class='detail'>
200 <?php echo $ndc_number ?>
201 </td>
202 <td class='detail'>
203 <?php echo $drug_units ?>
204 </td>
205 <td class='detail'>
206 <?php echo $refills ?>
207 </td>
208 <td class='detail'>
209 <?php echo $instructed ?>
210 </td>
211 <td class='detail'>
212 <?php echo $reactions ?>
213 </td>
214 <td class='detail'>
215 <a href='../drugs/dispense_drug.php?sale_id=<?php echo $row['sale_id'] ?>'
216 style='color:#0000ff' target='_blank'>
217 <?php echo $row['sale_date'] ?>
218 </a>
219 </td>
220 <td class='detail'>
221 <?php echo $row['quantity'] ?>
222 </td>
223 <td class='detail'>
224 <?php echo $row['manufacturer'] ?>
225 </td>
226 <td class='detail'>
227 <?php echo $row['lot_number'] ?>
228 </td>
229 </tr>
230 <?php
231 $last_prescription_id = $row['id'];
232 $last_patient_id = $row['patient_id'];
233 } // end while
234 } // end if
237 </table>
238 </form>
239 </center>
240 </body>
241 </html>