Support for using pounds and ounces on the vitals form.
[openemr.git] / interface / reports / prescriptions_report.php
blob3e442c5ce84b23b9b65c8a7d4b65d802a8c8c4eb
1 <?php
2 // Copyright (C) 2006, 2010 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.
11 //
12 // Fix drug name search to work in a broader sense - tony@mi-squared.com 2010
14 require_once("../globals.php");
15 require_once("$srcdir/patient.inc");
16 require_once("$srcdir/options.inc.php");
17 require_once("../drugs/drugs.inc.php");
18 require_once("$srcdir/formatting.inc.php");
19 require_once "$srcdir/formdata.inc.php";
21 $form_from_date = fixDate($_POST['form_from_date'], date('Y-01-01'));
22 $form_to_date = fixDate($_POST['form_to_date'] , date('Y-m-d'));
23 $form_patient_id = trim($_POST['form_patient_id']);
24 $form_drug_name = trim($_POST['form_drug_name']);
25 $form_lot_number = trim($_POST['form_lot_number']);
26 $form_facility = isset($_POST['form_facility']) ? $_POST['form_facility'] : '';
28 <html>
29 <head>
30 <?php html_header_show();?>
31 <title><?php xl('Prescriptions and Dispensations','e'); ?></title>
32 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
33 <script type="text/javascript" src="../../library/textformat.js"></script>
34 <script type="text/javascript" src="../../library/dialog.js"></script>
35 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
37 <script language="JavaScript">
39 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
41 // The OnClick handler for receipt display.
42 function show_receipt(payid) {
43 // dlgopen('../patient_file/front_payment.php?receipt=1&payid=' + payid, '_blank', 550, 400);
44 return false;
47 </script>
49 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
50 <style type="text/css">
52 /* specifically include & exclude from printing */
53 @media print {
54 #report_parameters {
55 visibility: hidden;
56 display: none;
58 #report_parameters_daterange {
59 visibility: visible;
60 display: inline;
62 #report_results table {
63 margin-top: 0px;
67 /* specifically exclude some from the screen */
68 @media screen {
69 #report_parameters_daterange {
70 visibility: hidden;
71 display: none;
75 </style>
76 </head>
78 <body class="body_top">
80 <!-- Required for the popup date selectors -->
81 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
83 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Prescriptions and Dispensations','e'); ?></span>
85 <div id="report_parameters_daterange">
86 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
87 </div>
89 <form name='theform' id='theform' method='post' action='prescriptions_report.php'>
91 <div id="report_parameters">
93 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
94 <table>
95 <tr>
96 <td width='640px'>
97 <div style='float:left'>
99 <table class='text'>
100 <tr>
101 <td class='label'>
102 <?php xl('Facility','e'); ?>:
103 </td>
104 <td>
105 <?php dropdown_facility(strip_escape_custom($form_facility), 'form_facility', true); ?>
106 </td>
107 <td class='label'>
108 <?php xl('From','e'); ?>:
109 </td>
110 <td>
111 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
112 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
113 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
114 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
115 title='<?php xl('Click here to choose a date','e'); ?>'>
116 </td>
117 <td class='label'>
118 <?php xl('To','e'); ?>:
119 </td>
120 <td>
121 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
122 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
123 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
124 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
125 title='<?php xl('Click here to choose a date','e'); ?>'>
126 </td>
127 </tr>
128 <tr>
129 <td class='label'>
130 <?php xl('Patient ID','e'); ?>:
131 </td>
132 <td>
133 <input type='text' name='form_patient_id' size='10' maxlength='20' value='<?php echo $form_patient_id ?>'
134 title=<?php xl('Optional numeric patient ID','e','\'','\''); ?> />
135 </td>
136 <td class='label'>
137 <?php xl('Drug','e'); ?>:
138 </td>
139 <td>
140 <input type='text' name='form_drug_name' size='10' maxlength='250' value='<?php echo $form_drug_name ?>'
141 title=<?php xl('Optional drug name, use % as a wildcard','e','\'','\''); ?> />
142 </td>
143 <td class='label'>
144 <?php xl('Lot','e'); ?>:
145 </td>
146 <td>
147 <input type='text' name='form_lot_number' size='10' maxlength='20' value='<?php echo $form_lot_number ?>'
148 title=<?php xl('Optional lot number, use % as a wildcard','e','\'','\''); ?> />
149 </td>
150 </tr>
151 </table>
153 </div>
155 </td>
156 <td align='left' valign='middle' height="100%">
157 <table style='border-left:1px solid; width:100%; height:100%' >
158 <tr>
159 <td>
160 <div style='margin-left:15px'>
161 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
162 <span>
163 <?php xl('Submit','e'); ?>
164 </span>
165 </a>
167 <?php if ($_POST['form_refresh']) { ?>
168 <a href='#' class='css_button' onclick='window.print()'>
169 <span>
170 <?php xl('Print','e'); ?>
171 </span>
172 </a>
173 <?php } ?>
174 </div>
175 </td>
176 </tr>
177 </table>
178 </td>
179 </tr>
180 </table>
181 </div> <!-- end of parameters -->
183 <?php
184 if ($_POST['form_refresh']) {
186 <div id="report_results">
187 <table>
188 <thead>
189 <th> <?php xl('Patient','e'); ?> </th>
190 <th> <?php xl('ID','e'); ?> </th>
191 <th> <?php xl('RX','e'); ?> </th>
192 <th> <?php xl('Drug Name','e'); ?> </th>
193 <th> <?php xl('NDC','e'); ?> </th>
194 <th> <?php xl('Units','e'); ?> </th>
195 <th> <?php xl('Refills','e'); ?> </th>
196 <th> <?php xl('Instructed','e'); ?> </th>
197 <th> <?php xl('Reactions','e'); ?> </th>
198 <th> <?php xl('Dispensed','e'); ?> </th>
199 <th> <?php xl('Qty','e'); ?> </th>
200 <th> <?php xl('Manufacturer','e'); ?> </th>
201 <th> <?php xl('Lot','e'); ?> </th>
202 </thead>
203 <tbody>
204 <?php
205 if ($_POST['form_refresh']) {
206 $where = "r.date_modified >= '$form_from_date' AND " .
207 "r.date_modified <= '$form_to_date'";
208 //if ($form_patient_id) $where .= " AND r.patient_id = '$form_patient_id'";
209 if ($form_patient_id) $where .= " AND p.pubpid = '$form_patient_id'";
210 if ($form_drug_name ) $where .= " AND (d.name LIKE '$form_drug_name' OR r.drug LIKE '$form_drug_name')";
211 if ($form_lot_number) $where .= " AND i.lot_number LIKE '$form_lot_number'";
213 $query = "SELECT r.id, r.patient_id, " .
214 "r.date_modified, r.dosage, r.route, r.interval, r.refills, r.drug, " .
215 "d.name, d.ndc_number, d.form, d.size, d.unit, d.reactions, " .
216 "s.sale_id, s.sale_date, s.quantity, " .
217 "i.manufacturer, i.lot_number, i.expiration, " .
218 "p.pubpid, ".
219 "p.fname, p.lname, p.mname, u.facility_id " .
220 "FROM prescriptions AS r " .
221 "LEFT OUTER JOIN drugs AS d ON d.drug_id = r.drug_id " .
222 "LEFT OUTER JOIN drug_sales AS s ON s.prescription_id = r.id " .
223 "LEFT OUTER JOIN drug_inventory AS i ON i.inventory_id = s.inventory_id " .
224 "LEFT OUTER JOIN patient_data AS p ON p.pid = r.patient_id " .
225 "LEFT OUTER JOIN users AS u ON u.id = r.provider_id " .
226 "WHERE $where " .
227 //"ORDER BY p.lname, p.fname, r.patient_id, r.id, s.sale_id";
228 "ORDER BY p.lname, p.fname, p.pubpid, r.id, s.sale_id";
230 // echo "<!-- $query -->\n"; // debugging
231 $res = sqlStatement($query);
233 $last_patient_id = 0;
234 $last_prescription_id = 0;
235 while ($row = sqlFetchArray($res)) {
236 // If a facility is specified, ignore rows that do not match.
237 if ($form_facility !== '') {
238 if ($form_facility) {
239 if ($row['facility_id'] != $form_facility) continue;
241 else {
242 if (!empty($row['facility_id'])) continue;
245 $patient_name = $row['lname'] . ', ' . $row['fname'] . ' ' . $row['mname'];
246 //$patient_id = $row['patient_id'];
247 $patient_id = $row['pubpid'];
248 $prescription_id = $row['id'];
249 $drug_name = empty($row['name']) ? $row['drug'] : $row['name'];
250 $ndc_number = $row['ndc_number'];
251 $drug_units = $row['size'] . ' ' .
252 generate_display_field(array('data_type'=>'1','list_id'=>'drug_units'), $row['unit']);
253 $refills = $row['refills'];
254 $reactions = $row['reactions'];
255 $instructed = $row['dosage'] . ' ' .
256 generate_display_field(array('data_type'=>'1','list_id'=>'drug_form'), $row['form']) .
257 ' ' .
258 generate_display_field(array('data_type'=>'1','list_id'=>'drug_interval'), $row['interval']);
259 //if ($row['patient_id'] == $last_patient_id) {
260 if (strcmp($row['pubpid'], $last_patient_id) == 0) {
261 $patient_name = '&nbsp;';
262 $patient_id = '&nbsp;';
263 if ($row['id'] == $last_prescription_id) {
264 $prescription_id = '&nbsp;';
265 $drug_name = '&nbsp;';
266 $ndc_number = '&nbsp;';
267 $drug_units = '&nbsp;';
268 $refills = '&nbsp;';
269 $reactions = '&nbsp;';
270 $instructed = '&nbsp;';
274 <tr>
275 <td>
276 <?php echo $patient_name ?>
277 </td>
278 <td>
279 <?php echo $patient_id ?>
280 </td>
281 <td>
282 <?php echo $prescription_id ?>
283 </td>
284 <td>
285 <?php echo $drug_name ?>
286 </td>
287 <td>
288 <?php echo $ndc_number ?>
289 </td>
290 <td>
291 <?php echo $drug_units ?>
292 </td>
293 <td>
294 <?php echo $refills ?>
295 </td>
296 <td>
297 <?php echo $instructed ?>
298 </td>
299 <td>
300 <?php echo $reactions ?>
301 </td>
302 <td>
303 <a href='../drugs/dispense_drug.php?sale_id=<?php echo $row['sale_id'] ?>'
304 style='color:#0000ff' target='_blank'>
305 <?php echo oeFormatShortDate($row['sale_date']) ?>
306 </a>
307 </td>
308 <td>
309 <?php echo $row['quantity'] ?>
310 </td>
311 <td>
312 <?php echo $row['manufacturer'] ?>
313 </td>
314 <td>
315 <?php echo $row['lot_number'] ?>
316 </td>
317 </tr>
318 <?php
319 $last_prescription_id = $row['id'];
320 //$last_patient_id = $row['patient_id'];
321 $last_patient_id = $row['pubpid'];
322 } // end while
323 } // end if
325 </tbody>
326 </table>
327 </div> <!-- end of results -->
328 <?php } else { ?>
329 <div class='text'>
330 <?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
331 </div>
332 <?php } ?>
333 </form>
334 </body>
336 <!-- stuff for the popup calendar -->
337 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
338 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
339 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
340 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
341 <script language="Javascript">
342 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
343 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
344 </script>
345 </html>