Fixed bug: https://sourceforge.net/p/openemr/bugs/416/
[openemr.git] / interface / reports / referrals_report.php
blobc146980e743d4bafc876679e357c2a8d5daa4bfa
1 <?php
2 /**
3 * This report lists referrals for a given date range.
5 * Copyright (C) 2008, 2010 Rod Roark <rod@sunsetsystems.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author Rod Roark <rod@sunsetsystems.com>
20 * @author Roberto Vasquez <robertogagliotta@gmail.com>
21 * @link http://www.open-emr.org
24 require_once("../globals.php");
25 require_once("$srcdir/patient.inc");
26 require_once("$srcdir/formatting.inc.php");
27 require_once "$srcdir/options.inc.php";
28 require_once "$srcdir/formdata.inc.php";
30 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
31 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
32 $form_facility = isset($_POST['form_facility']) ? $_POST['form_facility'] : '';
34 <html>
35 <head>
36 <?php html_header_show();?>
37 <title><?php xl('Referrals','e'); ?></title>
39 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
41 <script type="text/javascript" src="../../library/dialog.js"></script>
42 <script type="text/javascript" src="../../library/textformat.js"></script>
43 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
44 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
45 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
46 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
48 <script language="JavaScript">
50 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
52 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
54 $(document).ready(function() {
55 var win = top.printLogSetup ? top : opener.top;
56 win.printLogSetup(document.getElementById('printbutton'));
57 });
59 // The OnClick handler for referral display.
60 function show_referral(transid) {
61 dlgopen('../patient_file/transaction/print_referral.php?transid=' + transid,
62 '_blank', 550, 400);
63 return false;
66 </script>
68 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
69 <style type="text/css">
71 /* specifically include & exclude from printing */
72 @media print {
73 #report_parameters {
74 visibility: hidden;
75 display: none;
77 #report_parameters_daterange {
78 visibility: visible;
79 display: inline;
81 #report_results table {
82 margin-top: 0px;
86 /* specifically exclude some from the screen */
87 @media screen {
88 #report_parameters_daterange {
89 visibility: hidden;
90 display: none;
94 </style>
95 </head>
97 <body class="body_top">
99 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Referrals','e'); ?></span>
101 <div id="report_parameters_daterange">
102 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
103 </div>
105 <form name='theform' id='theform' method='post' action='referrals_report.php'>
107 <div id="report_parameters">
108 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
109 <table>
110 <tr>
111 <td width='640px'>
112 <div style='float:left'>
114 <table class='text'>
115 <tr>
116 <td class='label'>
117 <?php xl('Facility','e'); ?>:
118 </td>
119 <td>
120 <?php dropdown_facility(strip_escape_custom($form_facility), 'form_facility', true); ?>
121 </td>
122 <td class='label'>
123 <?php xl('From','e'); ?>:
124 </td>
125 <td>
126 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
127 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
128 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
129 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
130 title='<?php xl('Click here to choose a date','e'); ?>'>
131 </td>
132 <td class='label'>
133 <?php xl('To','e'); ?>:
134 </td>
135 <td>
136 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
137 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
138 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
139 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
140 title='<?php xl('Click here to choose a date','e'); ?>'>
141 </td>
142 </tr>
143 </table>
145 </div>
147 </td>
148 <td align='left' valign='middle' height="100%">
149 <table style='border-left:1px solid; width:100%; height:100%' >
150 <tr>
151 <td>
152 <div style='margin-left:15px'>
153 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
154 <span>
155 <?php xl('Submit','e'); ?>
156 </span>
157 </a>
159 <?php if ($_POST['form_refresh']) { ?>
160 <a href='#' class='css_button' id='printbutton'>
161 <span>
162 <?php xl('Print','e'); ?>
163 </span>
164 </a>
165 <?php } ?>
166 </div>
167 </td>
168 </tr>
169 </table>
170 </td>
171 </tr>
172 </table>
173 </div> <!-- end of parameters -->
176 <?php
177 if ($_POST['form_refresh']) {
179 <div id="report_results">
180 <table>
181 <thead>
182 <th> <?php xl('Refer To','e'); ?> </th>
183 <th> <?php xl('Refer Date','e'); ?> </th>
184 <th> <?php xl('Reply Date','e'); ?> </th>
185 <th> <?php xl('Patient','e'); ?> </th>
186 <th> <?php xl('ID','e'); ?> </th>
187 <th> <?php xl('Reason','e'); ?> </th>
188 </thead>
189 <tbody>
190 <?php
191 if ($_POST['form_refresh']) {
192 $query = "SELECT t.id, t.refer_date, t.reply_date, t.body, " .
193 "ut.organization, uf.facility_id, p.pubpid, " .
194 "CONCAT(uf.fname,' ', uf.lname) AS referer_name, " .
195 "CONCAT(ut.fname,' ', ut.lname) AS referer_to, " .
196 "CONCAT(p.fname,' ', p.lname) AS patient_name " .
197 "FROM transactions AS t " .
198 "LEFT OUTER JOIN patient_data AS p ON p.pid = t.pid " .
199 "LEFT OUTER JOIN users AS ut ON ut.id = t.refer_to " .
200 "LEFT OUTER JOIN users AS uf ON uf.id = t.refer_from " .
201 "WHERE t.title = 'Referral' AND " .
202 "t.refer_date >= '$from_date' AND t.refer_date <= '$to_date' " .
203 "ORDER BY ut.organization, t.refer_date, t.id";
205 // echo "<!-- $query -->\n"; // debugging
206 $res = sqlStatement($query);
208 while ($row = sqlFetchArray($res)) {
209 // If a facility is specified, ignore rows that do not match.
210 if ($form_facility !== '') {
211 if ($form_facility) {
212 if ($row['facility_id'] != $form_facility) continue;
214 else {
215 if (!empty($row['facility_id'])) continue;
220 <tr>
221 <td>
222 <?php if($row['organization']!=NULL || $row['organization']!='') {
223 echo $row['organization'];
225 else {
226 echo text($row['referer_to']);
230 </td>
231 <td>
232 <a href='#' onclick="return show_referral(<?php echo $row['id']; ?>)">
233 <?php echo oeFormatShortDate($row['refer_date']); ?>&nbsp;
234 </a>
235 </td>
236 <td>
237 <?php echo oeFormatShortDate($row['reply_date']) ?>
238 </td>
239 <td>
240 <?php echo $row['patient_name'] ?>
241 </td>
242 <td>
243 <?php echo $row['pubpid'] ?>
244 </td>
245 <td>
246 <?php echo text($row['body']) ?>
247 </td>
248 </tr>
249 <?php
253 </tbody>
254 </table>
255 </div> <!-- end of results -->
256 <?php } else { ?>
257 <div class='text'>
258 <?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
259 </div>
260 <?php } ?>
261 </form>
263 <script language='JavaScript'>
264 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
265 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
266 </script>
268 </body>
269 </html>