MU2 for items e2 and f1.
[openemr.git] / interface / reports / referrals_report.php
blob55c52333d414da0b8161e9c534e095686cb65cb6
1 <?php
2 /**
3 * This report lists referrals for a given date range.
5 * Copyright (C) 2008-2016 Rod Roark <rod@sunsetsystems.com>
6 * Copyright (C) 2016 Roberto Vasquez <robertogagliotta@gmail.com>
8 * LICENSE: This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @package OpenEMR
20 * @author Rod Roark <rod@sunsetsystems.com>
21 * @author Roberto Vasquez <robertogagliotta@gmail.com>
22 * @link http://www.open-emr.org
25 $fake_register_globals=false;
26 $sanitize_all_escapes=true;
28 require_once("../globals.php");
29 require_once("$srcdir/patient.inc");
30 require_once("$srcdir/formatting.inc.php");
31 require_once "$srcdir/options.inc.php";
32 require_once "$srcdir/formdata.inc.php";
34 $from_date = (isset($_POST['form_from_date'])) ? fixDate($_POST['form_from_date'], date('Y-m-d')) : '';
35 $form_from_date = $from_date;
36 $to_date = (isset($_POST['form_to_date'])) ? fixDate($_POST['form_to_date'], date('Y-m-d')) : '';;
37 $form_to_date = $to_date;
38 $form_facility = isset($_POST['form_facility']) ? $_POST['form_facility'] : '';
40 <html>
41 <head>
42 <?php html_header_show();?>
43 <title><?php echo xlt('Referrals'); ?></title>
45 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
47 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
48 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
49 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
50 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
51 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
52 <script type="text/javascript" src="../../library/js/jquery-1.9.1.min.js"></script>
53 <script type="text/javascript" src="../../library/js/report_helper.js?v=<?php echo $v_js_includes; ?>"></script>
54 <script language="JavaScript">
56 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
58 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
60 $(document).ready(function() {
61 oeFixedHeaderSetup(document.getElementById('mymaintable'));
62 var win = top.printLogSetup ? top : opener.top;
63 win.printLogSetup(document.getElementById('printbutton'));
64 });
66 // The OnClick handler for referral display.
68 function show_referral(transid) {
69 dlgopen('../patient_file/transaction/print_referral.php?transid=' + transid,
70 '_blank', 550, 400);
71 return false;
74 </script>
76 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
77 <style type="text/css">
79 /* specifically include & exclude from printing */
80 @media print {
81 #report_parameters {
82 visibility: hidden;
83 display: none;
85 #report_parameters_daterange {
86 visibility: visible;
87 display: inline;
89 #report_results table {
90 margin-top: 0px;
94 /* specifically exclude some from the screen */
95 @media screen {
96 #report_parameters_daterange {
97 visibility: hidden;
98 display: none;
102 </style>
104 <script language="JavaScript">
106 </script>
108 </head>
110 <body class="body_top">
112 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Referrals'); ?></span>
114 <div id="report_parameters_daterange">
115 <?php echo text(date("d F Y", strtotime($form_from_date))) ." &nbsp; to &nbsp; ". text(date("d F Y", strtotime($form_to_date))); ?>
116 </div>
118 <form name='theform' id='theform' method='post' action='referrals_report.php'>
120 <div id="report_parameters">
121 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
122 <table>
123 <tr>
124 <td width='640px'>
125 <div style='float:left'>
127 <table class='text'>
128 <tr>
129 <td class='label'>
130 <?php echo xlt('Facility'); ?>:
131 </td>
132 <td>
133 <?php dropdown_facility(($form_facility), 'form_facility', true); ?>
134 </td>
135 <td class='label'>
136 <?php echo xlt('From'); ?>:
137 </td>
138 <td>
139 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo attr($form_from_date) ?>'
140 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='<?php echo xla('yyyy-mm-dd') ?>'>
141 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
142 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
143 title='<?php echo xla('Click here to choose a date'); ?>'>
144 </td>
145 <td class='label'>
146 <?php echo xlt('To'); ?>:
147 </td>
148 <td>
149 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo attr($form_to_date) ?>'
150 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='<?php echo xla('yyyy-mm-dd') ?>'>
151 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
152 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
153 title='<?php echo xla('Click here to choose a date'); ?>'>
154 </td>
155 </tr>
156 </table>
158 </div>
160 </td>
161 <td align='left' valign='middle' height="100%">
162 <table style='border-left:1px solid; width:100%; height:100%' >
163 <tr>
164 <td>
165 <div style='margin-left:15px'>
166 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
167 <span>
168 <?php echo xlt('Submit'); ?>
169 </span>
170 </a>
172 <?php if ($_POST['form_refresh']) { ?>
173 <a href='#' class='css_button' id='printbutton'>
174 <span>
175 <?php echo xlt('Print'); ?>
176 </span>
177 </a>
178 <?php } ?>
179 </div>
180 </td>
181 </tr>
182 </table>
183 </td>
184 </tr>
185 </table>
186 </div> <!-- end of parameters -->
188 <?php
189 if ($_POST['form_refresh']) {
191 <div id="report_results">
192 <table width='98%' id='mymaintable'>
193 <thead>
194 <th> <?php echo xlt('Refer To'); ?> </th>
195 <th> <?php echo xlt('Refer Date'); ?> </th>
196 <th> <?php echo xlt('Reply Date'); ?> </th>
197 <th> <?php echo xlt('Patient'); ?> </th>
198 <th> <?php echo xlt('ID'); ?> </th>
199 <th> <?php echo xlt('Reason'); ?> </th>
200 </thead>
201 <tbody>
202 <?php
203 if ($_POST['form_refresh']) {
204 $query = "SELECT t.id, t.pid, " .
205 "d1.field_value AS refer_date, " .
206 "d3.field_value AS reply_date, " .
207 "d4.field_value AS body, " .
208 "ut.organization, uf.facility_id, p.pubpid, " .
209 "CONCAT(uf.fname,' ', uf.lname) AS referer_name, " .
210 "CONCAT(ut.fname,' ', ut.lname) AS referer_to, " .
211 "CONCAT(p.fname,' ', p.lname) AS patient_name " .
212 "FROM transactions AS t " .
213 "LEFT JOIN patient_data AS p ON p.pid = t.pid " .
214 "JOIN lbt_data AS d1 ON d1.form_id = t.id AND d1.field_id = 'refer_date' " .
215 "LEFT JOIN lbt_data AS d3 ON d3.form_id = t.id AND d3.field_id = 'reply_date' " .
216 "LEFT JOIN lbt_data AS d4 ON d4.form_id = t.id AND d4.field_id = 'body' " .
217 "LEFT JOIN lbt_data AS d7 ON d7.form_id = t.id AND d7.field_id = 'refer_to' " .
218 "LEFT JOIN lbt_data AS d8 ON d8.form_id = t.id AND d8.field_id = 'refer_from' " .
219 "LEFT JOIN users AS ut ON ut.id = d7.field_value " .
220 "LEFT JOIN users AS uf ON uf.id = d8.field_value " .
221 "WHERE t.title = 'LBTref' AND " .
222 "d1.field_value >= ? AND d1.field_value <= ? " .
223 "ORDER BY ut.organization, d1.field_value, t.id";
224 $res = sqlStatement($query, array($from_date, $to_date));
226 while ($row = sqlFetchArray($res)) {
227 // If a facility is specified, ignore rows that do not match.
228 if ($form_facility !== '') {
229 if ($form_facility) {
230 if ($row['facility_id'] != $form_facility) continue;
232 else {
233 if (!empty($row['facility_id'])) continue;
238 <tr>
239 <td>
240 <?php if($row['organization']!=NULL || $row['organization']!='') {
241 echo text($row['organization']);
243 else {
244 echo text($row['referer_to']);
248 </td>
249 <td>
250 <a href='#' onclick="return show_referral(<?php echo attr($row['id']); ?>)">
251 <?php echo text(oeFormatShortDate($row['refer_date'])); ?>&nbsp;
252 </a>
253 </td>
254 <td>
255 <?php echo text(oeFormatShortDate($row['reply_date'])) ?>
256 </td>
257 <td>
258 <?php echo text($row['patient_name']) ?>
259 </td>
260 <td>
261 <?php echo text($row['pubpid']) ?>
262 </td>
263 <td>
264 <?php echo text($row['body']) ?>
265 </td>
266 </tr>
267 <?php
271 </tbody>
272 </table>
273 </div> <!-- end of results -->
274 <?php } else { ?>
275 <div class='text'>
276 <?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?>
277 </div>
278 <?php } ?>
279 </form>
281 <script language='JavaScript'>
282 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
283 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
284 </script>
286 </body>
287 </html>