added new datepicker to amendments gui
[openemr.git] / interface / reports / referrals_report.php
blobab03cd07dfe0c33298df50ce27543c0a5b14db40
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>
7 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
9 * LICENSE: This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
20 * @package OpenEMR
21 * @author Rod Roark <rod@sunsetsystems.com>
22 * @author Roberto Vasquez <robertogagliotta@gmail.com>
23 * @author Brady Miller <brady.g.miller@gmail.com>
24 * @link http://www.open-emr.org
27 $fake_register_globals=false;
28 $sanitize_all_escapes=true;
30 require_once("../globals.php");
31 require_once("$srcdir/patient.inc");
32 require_once("$srcdir/formatting.inc.php");
33 require_once "$srcdir/options.inc.php";
35 $from_date = (isset($_POST['form_from_date'])) ? fixDate($_POST['form_from_date'], date('Y-m-d')) : '';
36 $form_from_date = $from_date;
37 $to_date = (isset($_POST['form_to_date'])) ? fixDate($_POST['form_to_date'], date('Y-m-d')) : '';;
38 $form_to_date = $to_date;
39 $form_facility = isset($_POST['form_facility']) ? $_POST['form_facility'] : '';
41 <html>
42 <head>
43 <?php html_header_show();?>
44 <title><?php echo xlt('Referrals'); ?></title>
46 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
47 <script type="text/javascript" src="../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
48 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-3-1-1/index.js"></script>
49 <script type="text/javascript" src="../../library/js/report_helper.js?v=<?php echo $v_js_includes; ?>"></script>
50 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
51 <script language="JavaScript">
53 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
55 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
57 $(document).ready(function() {
58 oeFixedHeaderSetup(document.getElementById('mymaintable'));
59 var win = top.printLogSetup ? top : opener.top;
60 win.printLogSetup(document.getElementById('printbutton'));
62 $('.datepicker').datetimepicker({
63 <?php $datetimepicker_timepicker = false; ?>
64 <?php $datetimepicker_formatInput = false; ?>
65 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
66 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
67 });
68 });
70 // The OnClick handler for referral display.
72 function show_referral(transid) {
73 dlgopen('../patient_file/transaction/print_referral.php?transid=' + transid,
74 '_blank', 550, 400,true); // Force new window rather than iframe because of the dynamic generation of the content in print_referral.php
75 return false;
78 </script>
80 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
81 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
82 <style type="text/css">
84 /* specifically include & exclude from printing */
85 @media print {
86 #report_parameters {
87 visibility: hidden;
88 display: none;
90 #report_parameters_daterange {
91 visibility: visible;
92 display: inline;
94 #report_results table {
95 margin-top: 0px;
99 /* specifically exclude some from the screen */
100 @media screen {
101 #report_parameters_daterange {
102 visibility: hidden;
103 display: none;
107 </style>
109 <script language="JavaScript">
111 </script>
113 </head>
115 <body class="body_top">
117 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Referrals'); ?></span>
119 <div id="report_parameters_daterange">
120 <?php echo text(date("d F Y", strtotime($form_from_date))) ." &nbsp; to &nbsp; ". text(date("d F Y", strtotime($form_to_date))); ?>
121 </div>
123 <form name='theform' id='theform' method='post' action='referrals_report.php'>
125 <div id="report_parameters">
126 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
127 <table>
128 <tr>
129 <td width='640px'>
130 <div style='float:left'>
132 <table class='text'>
133 <tr>
134 <td class='label'>
135 <?php echo xlt('Facility'); ?>:
136 </td>
137 <td>
138 <?php dropdown_facility(($form_facility), 'form_facility', true); ?>
139 </td>
140 <td class='label'>
141 <?php echo xlt('From'); ?>:
142 </td>
143 <td>
144 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo attr($form_from_date) ?>'
145 class='datepicker'
146 title='<?php echo xla('yyyy-mm-dd') ?>'>
147 </td>
148 <td class='label'>
149 <?php echo xlt('To'); ?>:
150 </td>
151 <td>
152 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo attr($form_to_date) ?>'
153 class='datepicker'
154 title='<?php echo xla('yyyy-mm-dd') ?>'>
155 </td>
156 </tr>
157 </table>
159 </div>
161 </td>
162 <td align='left' valign='middle' height="100%">
163 <table style='border-left:1px solid; width:100%; height:100%' >
164 <tr>
165 <td>
166 <div style='margin-left:15px'>
167 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
168 <span>
169 <?php echo xlt('Submit'); ?>
170 </span>
171 </a>
173 <?php if ($_POST['form_refresh']) { ?>
174 <a href='#' class='css_button' id='printbutton'>
175 <span>
176 <?php echo xlt('Print'); ?>
177 </span>
178 </a>
179 <?php } ?>
180 </div>
181 </td>
182 </tr>
183 </table>
184 </td>
185 </tr>
186 </table>
187 </div> <!-- end of parameters -->
189 <?php
190 if ($_POST['form_refresh']) {
192 <div id="report_results">
193 <table width='98%' id='mymaintable'>
194 <thead>
195 <th> <?php echo xlt('Refer To'); ?> </th>
196 <th> <?php echo xlt('Refer Date'); ?> </th>
197 <th> <?php echo xlt('Reply Date'); ?> </th>
198 <th> <?php echo xlt('Patient'); ?> </th>
199 <th> <?php echo xlt('ID'); ?> </th>
200 <th> <?php echo xlt('Reason'); ?> </th>
201 </thead>
202 <tbody>
203 <?php
204 if ($_POST['form_refresh']) {
205 $query = "SELECT t.id, t.pid, " .
206 "d1.field_value AS refer_date, " .
207 "d3.field_value AS reply_date, " .
208 "d4.field_value AS body, " .
209 "ut.organization, uf.facility_id, p.pubpid, " .
210 "CONCAT(uf.fname,' ', uf.lname) AS referer_name, " .
211 "CONCAT(ut.fname,' ', ut.lname) AS referer_to, " .
212 "CONCAT(p.fname,' ', p.lname) AS patient_name " .
213 "FROM transactions AS t " .
214 "LEFT JOIN patient_data AS p ON p.pid = t.pid " .
215 "JOIN lbt_data AS d1 ON d1.form_id = t.id AND d1.field_id = 'refer_date' " .
216 "LEFT JOIN lbt_data AS d3 ON d3.form_id = t.id AND d3.field_id = 'reply_date' " .
217 "LEFT JOIN lbt_data AS d4 ON d4.form_id = t.id AND d4.field_id = 'body' " .
218 "LEFT JOIN lbt_data AS d7 ON d7.form_id = t.id AND d7.field_id = 'refer_to' " .
219 "LEFT JOIN lbt_data AS d8 ON d8.form_id = t.id AND d8.field_id = 'refer_from' " .
220 "LEFT JOIN users AS ut ON ut.id = d7.field_value " .
221 "LEFT JOIN users AS uf ON uf.id = d8.field_value " .
222 "WHERE t.title = 'LBTref' AND " .
223 "d1.field_value >= ? AND d1.field_value <= ? " .
224 "ORDER BY ut.organization, d1.field_value, t.id";
225 $res = sqlStatement($query, array($from_date, $to_date));
227 while ($row = sqlFetchArray($res)) {
228 // If a facility is specified, ignore rows that do not match.
229 if ($form_facility !== '') {
230 if ($form_facility) {
231 if ($row['facility_id'] != $form_facility) continue;
233 else {
234 if (!empty($row['facility_id'])) continue;
239 <tr>
240 <td>
241 <?php if($row['organization']!=NULL || $row['organization']!='') {
242 echo text($row['organization']);
244 else {
245 echo text($row['referer_to']);
249 </td>
250 <td>
251 <a href='#' onclick="return show_referral(<?php echo attr($row['id']); ?>)">
252 <?php echo text(oeFormatShortDate($row['refer_date'])); ?>&nbsp;
253 </a>
254 </td>
255 <td>
256 <?php echo text(oeFormatShortDate($row['reply_date'])) ?>
257 </td>
258 <td>
259 <?php echo text($row['patient_name']) ?>
260 </td>
261 <td>
262 <?php echo text($row['pubpid']) ?>
263 </td>
264 <td>
265 <?php echo text($row['body']) ?>
266 </td>
267 </tr>
268 <?php
272 </tbody>
273 </table>
274 </div> <!-- end of results -->
275 <?php } else { ?>
276 <div class='text'>
277 <?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?>
278 </div>
279 <?php } ?>
280 </form>
282 </body>
283 </html>