Portal Updates for Usability study, UI/UX and bug fixes. (#7556)
[openemr.git] / interface / reports / referrals_report.php
blob3be386d2e0f68730365c64b524797c95edc51a94
1 <?php
3 /**
4 * This report lists referrals for a given date range.
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Roberto Vasquez <robertogagliotta@gmail.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2008-2016 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2016 Roberto Vasquez <robertogagliotta@gmail.com>
13 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once("../globals.php");
18 require_once("$srcdir/patient.inc.php");
19 require_once "$srcdir/options.inc.php";
21 use OpenEMR\Common\Acl\AclMain;
22 use OpenEMR\Common\Csrf\CsrfUtils;
23 use OpenEMR\Common\Twig\TwigContainer;
24 use OpenEMR\Core\Header;
26 if (!AclMain::aclCheckCore('patients', 'med')) {
27 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Referrals")]);
28 exit;
31 if (!empty($_POST)) {
32 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
33 CsrfUtils::csrfNotVerified();
37 $form_from_date = (isset($_POST['form_from_date'])) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-01-01');
38 $form_to_date = (isset($_POST['form_to_date'])) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
39 $form_facility = isset($_POST['form_facility']) ? $_POST['form_facility'] : '';
41 <html>
42 <head>
43 <title><?php echo xlt('Referrals'); ?></title>
45 <?php Header::setupHeader(['datetime-picker', 'report-helper']); ?>
47 <script>
48 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
50 $(function () {
51 oeFixedHeaderSetup(document.getElementById('mymaintable'));
52 var win = top.printLogSetup ? top : opener.top;
53 win.printLogSetup(document.getElementById('printbutton'));
55 $('.datepicker').datetimepicker({
56 <?php $datetimepicker_timepicker = false; ?>
57 <?php $datetimepicker_showseconds = false; ?>
58 <?php $datetimepicker_formatInput = true; ?>
59 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
60 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
61 });
62 });
64 // The OnClick handler for referral display.
66 function show_referral(transid) {
67 dlgopen('../patient_file/transaction/print_referral.php?transid=' + encodeURIComponent(transid),
68 '_blank', 550, 400,true); // Force new window rather than iframe because of the dynamic generation of the content in print_referral.php
69 return false;
71 </script>
73 <style>
74 /* specifically include & exclude from printing */
75 @media print {
76 #report_parameters {
77 visibility: hidden;
78 display: none;
80 #report_parameters_daterange {
81 visibility: visible;
82 display: inline;
84 #report_results table {
85 margin-top: 0px;
89 /* specifically exclude some from the screen */
90 @media screen {
91 #report_parameters_daterange {
92 visibility: hidden;
93 display: none;
96 </style>
97 </head>
99 <body class="body_top">
101 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Referrals'); ?></span>
103 <div id="report_parameters_daterange">
104 <?php echo text(oeFormatShortDate($form_from_date)) . " &nbsp; " . xlt('to{{Range}}') . " &nbsp; " . text(oeFormatShortDate($form_to_date)); ?>
105 </div>
107 <form name='theform' id='theform' method='post' action='referrals_report.php' onsubmit='return top.restoreSession()'>
108 <input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
110 <div id="report_parameters">
111 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
112 <table>
113 <tr>
114 <td width='640px'>
115 <div style='float:left'>
117 <table class='text'>
118 <tr>
119 <td class='col-form-label'>
120 <?php echo xlt('Facility'); ?>:
121 </td>
122 <td>
123 <?php dropdown_facility(($form_facility), 'form_facility', true); ?>
124 </td>
125 <td class='col-form-label'>
126 <?php echo xlt('From'); ?>:
127 </td>
128 <td>
129 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo attr(oeFormatShortDate($form_from_date)); ?>'
130 class='datepicker form-control'>
131 </td>
132 <td class='col-form-label'>
133 <?php echo xlt('To{{Range}}'); ?>:
134 </td>
135 <td>
136 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo attr(oeFormatShortDate($form_to_date)); ?>'
137 class='datepicker form-control'>
138 </td>
139 </tr>
140 </table>
142 </div>
144 </td>
145 <td class='h-100' align='left' valign='middle'>
146 <table class='w-100 h-100' style='border-left:1px solid;'>
147 <tr>
148 <td>
149 <div class="text-center">
150 <div class="btn-group" role="group">
151 <a href='#' class='btn btn-secondary btn-save' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
152 <?php echo xlt('Submit'); ?>
153 </a>
154 <?php if (!empty($_POST['form_refresh'])) { ?>
155 <a href='#' class='btn btn-secondary btn-print' id='printbutton'>
156 <?php echo xlt('Print'); ?>
157 </a>
158 <?php } ?>
159 </div>
160 </div>
161 </td>
162 </tr>
163 </table>
164 </td>
165 </tr>
166 </table>
167 </div> <!-- end of parameters -->
169 <?php
170 if (!empty($_POST['form_refresh'])) {
172 <div id="report_results">
173 <table class='table' width='98%' id='mymaintable'>
174 <thead class='thead-light'>
175 <th> <?php echo xlt('Refer To'); ?> </th>
176 <th> <?php echo xlt('Refer Date'); ?> </th>
177 <th> <?php echo xlt('Reply Date'); ?> </th>
178 <th> <?php echo xlt('Patient'); ?> </th>
179 <th> <?php echo xlt('ID'); ?> </th>
180 <th> <?php echo xlt('Reason'); ?> </th>
181 </thead>
182 <tbody>
183 <?php
184 if ($_POST['form_refresh']) {
185 $query = "SELECT t.id, t.pid, " .
186 "d1.field_value AS refer_date, " .
187 "d3.field_value AS reply_date, " .
188 "d4.field_value AS body, " .
189 "ut.organization, uf.facility_id, p.pubpid, " .
190 "CONCAT(uf.fname,' ', uf.lname) AS referer_name, " .
191 "CONCAT(ut.fname,' ', ut.lname) AS referer_to, " .
192 "CONCAT(p.fname,' ', p.lname) AS patient_name " .
193 "FROM transactions AS t " .
194 "LEFT JOIN patient_data AS p ON p.pid = t.pid " .
195 "JOIN lbt_data AS d1 ON d1.form_id = t.id AND d1.field_id = 'refer_date' " .
196 "LEFT JOIN lbt_data AS d3 ON d3.form_id = t.id AND d3.field_id = 'reply_date' " .
197 "LEFT JOIN lbt_data AS d4 ON d4.form_id = t.id AND d4.field_id = 'body' " .
198 "LEFT JOIN lbt_data AS d7 ON d7.form_id = t.id AND d7.field_id = 'refer_to' " .
199 "LEFT JOIN lbt_data AS d8 ON d8.form_id = t.id AND d8.field_id = 'refer_from' " .
200 "LEFT JOIN users AS ut ON ut.id = d7.field_value " .
201 "LEFT JOIN users AS uf ON uf.id = d8.field_value " .
202 "WHERE t.title = 'LBTref' AND " .
203 "d1.field_value >= ? AND d1.field_value <= ? " .
204 "ORDER BY ut.organization, d1.field_value, t.id";
205 $res = sqlStatement($query, array($form_from_date, $form_to_date));
207 while ($row = sqlFetchArray($res)) {
208 // If a facility is specified, ignore rows that do not match.
209 if ($form_facility !== '') {
210 if ($form_facility) {
211 if ($row['facility_id'] != $form_facility) {
212 continue;
214 } else {
215 if (!empty($row['facility_id'])) {
216 continue;
222 <tr>
223 <td>
224 <?php
225 if ($row['organization'] != null || $row['organization'] != '') {
226 echo text($row['organization']);
227 } else {
228 echo text($row['referer_to']);
231 </td>
232 <td>
233 <a href='#' onclick="return show_referral(<?php echo js_escape($row['id']); ?>)">
234 <?php echo text(oeFormatShortDate($row['refer_date'])); ?>&nbsp;
235 </a>
236 </td>
237 <td>
238 <?php echo text(oeFormatShortDate($row['reply_date'])) ?>
239 </td>
240 <td>
241 <?php echo text($row['patient_name']) ?>
242 </td>
243 <td>
244 <?php echo text($row['pubpid']) ?>
245 </td>
246 <td>
247 <?php echo text($row['body']) ?>
248 </td>
249 </tr>
250 <?php
254 </tbody>
255 </table>
256 </div> <!-- end of results -->
257 <?php } else { ?>
258 <div class='text'>
259 <?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?>
260 </div>
261 <?php } ?>
262 </form>
264 </body>
265 </html>