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']);
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);
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
>
50 <h2
><?
xl('Prescriptions and Dispensations','e'); ?
></h2
>
52 <form name
='theform' method
='post' action
='prescriptions_report.php'>
54 <table border
='0' cellpadding
='3'>
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  
;<?
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  
;<?
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  
;<?
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  
;<?
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' />
80 <input type
='submit' name
='form_refresh' value
=<?
xl('Refresh','e'); ?
>>
91 <table border
='0' cellpadding
='1' cellspacing
='2' width
='98%'>
93 <tr bgcolor
="#dddddd">
95 <?
xl('Patient','e'); ?
>
104 <?
xl('Drug Name','e'); ?
>
110 <?
xl('Units','e'); ?
>
113 <?
xl('Refills','e'); ?
>
116 <?
xl('Instructed','e'); ?
>
119 <?
xl('Reactions','e'); ?
>
122 <?
xl('Dispensed','e'); ?
>
128 <?
xl('Manufacturer','e'); ?
>
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 " .
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 = ' ';
174 $patient_id = ' ';
175 if ($row['id'] == $last_prescription_id) {
176 $prescription_id = ' ';
177 $drug_name = ' ';
178 $ndc_number = ' ';
179 $drug_units = ' ';
181 $reactions = ' ';
182 $instructed = ' ';
188 <?php
echo $patient_name ?
>
191 <?php
echo $patient_id ?
>
194 <?php
echo $prescription_id ?
>
197 <?php
echo $drug_name ?
>
200 <?php
echo $ndc_number ?
>
203 <?php
echo $drug_units ?
>
206 <?php
echo $refills ?
>
209 <?php
echo $instructed ?
>
212 <?php
echo $reactions ?
>
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'] ?
>
221 <?php
echo $row['quantity'] ?
>
224 <?php
echo $row['manufacturer'] ?
>
227 <?php
echo $row['lot_number'] ?
>
231 $last_prescription_id = $row['id'];
232 $last_patient_id = $row['patient_id'];