cleanup referral report
[openemr.git] / interface / reports / referrals_report.php
blob1453a565348f23471704261981492f326b8358aa
1 <?php
2 /**
3 * This report lists referrals for a given date range.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @author Roberto Vasquez <robertogagliotta@gmail.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2008-2016 Rod Roark <rod@sunsetsystems.com>
11 * @copyright Copyright (c) 2016 Roberto Vasquez <robertogagliotta@gmail.com>
12 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
13 * @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");
19 require_once "$srcdir/options.inc.php";
21 use OpenEMR\Core\Header;
23 $form_from_date = (isset($_POST['form_from_date'])) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-01-01');
24 $form_to_date = (isset($_POST['form_to_date'])) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
25 $form_facility = isset($_POST['form_facility']) ? $_POST['form_facility'] : '';
27 <html>
28 <head>
29 <title><?php echo xlt('Referrals'); ?></title>
31 <?php Header::setupHeader(['datetime-picker', 'report-helper']); ?>
33 <script language="JavaScript">
34 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
36 $(document).ready(function() {
37 oeFixedHeaderSetup(document.getElementById('mymaintable'));
38 var win = top.printLogSetup ? top : opener.top;
39 win.printLogSetup(document.getElementById('printbutton'));
41 $('.datepicker').datetimepicker({
42 <?php $datetimepicker_timepicker = false; ?>
43 <?php $datetimepicker_showseconds = false; ?>
44 <?php $datetimepicker_formatInput = true; ?>
45 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
46 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
47 });
48 });
50 // The OnClick handler for referral display.
52 function show_referral(transid) {
53 dlgopen('../patient_file/transaction/print_referral.php?transid=' + transid,
54 '_blank', 550, 400,true); // Force new window rather than iframe because of the dynamic generation of the content in print_referral.php
55 return false;
57 </script>
59 <style type="text/css">
60 /* specifically include & exclude from printing */
61 @media print {
62 #report_parameters {
63 visibility: hidden;
64 display: none;
66 #report_parameters_daterange {
67 visibility: visible;
68 display: inline;
70 #report_results table {
71 margin-top: 0px;
75 /* specifically exclude some from the screen */
76 @media screen {
77 #report_parameters_daterange {
78 visibility: hidden;
79 display: none;
82 </style>
83 </head>
85 <body class="body_top">
87 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Referrals'); ?></span>
89 <div id="report_parameters_daterange">
90 <?php echo oeFormatShortDate($form_from_date) ." &nbsp; " . xlt('to') . " &nbsp; ". oeFormatShortDate($form_to_date); ?>
91 </div>
93 <form name='theform' id='theform' method='post' action='referrals_report.php' onsubmit='return top.restoreSession()'>
95 <div id="report_parameters">
96 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
97 <table>
98 <tr>
99 <td width='640px'>
100 <div style='float:left'>
102 <table class='text'>
103 <tr>
104 <td class='control-label'>
105 <?php echo xlt('Facility'); ?>:
106 </td>
107 <td>
108 <?php dropdown_facility(($form_facility), 'form_facility', true); ?>
109 </td>
110 <td class='control-label'>
111 <?php echo xlt('From'); ?>:
112 </td>
113 <td>
114 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo oeFormatShortDate($form_from_date) ?>'
115 class='datepicker form-control'>
116 </td>
117 <td class='control-label'>
118 <?php echo xlt('To'); ?>:
119 </td>
120 <td>
121 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo oeFormatShortDate($form_to_date) ?>'
122 class='datepicker form-control'>
123 </td>
124 </tr>
125 </table>
127 </div>
129 </td>
130 <td align='left' valign='middle' height="100%">
131 <table style='border-left:1px solid; width:100%; height:100%' >
132 <tr>
133 <td>
134 <div class="text-center">
135 <div class="btn-group" role="group">
136 <a href='#' class='btn btn-default btn-save' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
137 <?php echo xlt('Submit'); ?>
138 </a>
139 <?php if ($_POST['form_refresh']) { ?>
140 <a href='#' class='btn btn-default btn-print' id='printbutton'>
141 <?php echo xlt('Print'); ?>
142 </a>
143 <?php } ?>
144 </div>
145 </div>
146 </td>
147 </tr>
148 </table>
149 </td>
150 </tr>
151 </table>
152 </div> <!-- end of parameters -->
154 <?php
155 if ($_POST['form_refresh']) {
157 <div id="report_results">
158 <table width='98%' id='mymaintable'>
159 <thead>
160 <th> <?php echo xlt('Refer To'); ?> </th>
161 <th> <?php echo xlt('Refer Date'); ?> </th>
162 <th> <?php echo xlt('Reply Date'); ?> </th>
163 <th> <?php echo xlt('Patient'); ?> </th>
164 <th> <?php echo xlt('ID'); ?> </th>
165 <th> <?php echo xlt('Reason'); ?> </th>
166 </thead>
167 <tbody>
168 <?php
169 if ($_POST['form_refresh']) {
170 $query = "SELECT t.id, t.pid, " .
171 "d1.field_value AS refer_date, " .
172 "d3.field_value AS reply_date, " .
173 "d4.field_value AS body, " .
174 "ut.organization, uf.facility_id, p.pubpid, " .
175 "CONCAT(uf.fname,' ', uf.lname) AS referer_name, " .
176 "CONCAT(ut.fname,' ', ut.lname) AS referer_to, " .
177 "CONCAT(p.fname,' ', p.lname) AS patient_name " .
178 "FROM transactions AS t " .
179 "LEFT JOIN patient_data AS p ON p.pid = t.pid " .
180 "JOIN lbt_data AS d1 ON d1.form_id = t.id AND d1.field_id = 'refer_date' " .
181 "LEFT JOIN lbt_data AS d3 ON d3.form_id = t.id AND d3.field_id = 'reply_date' " .
182 "LEFT JOIN lbt_data AS d4 ON d4.form_id = t.id AND d4.field_id = 'body' " .
183 "LEFT JOIN lbt_data AS d7 ON d7.form_id = t.id AND d7.field_id = 'refer_to' " .
184 "LEFT JOIN lbt_data AS d8 ON d8.form_id = t.id AND d8.field_id = 'refer_from' " .
185 "LEFT JOIN users AS ut ON ut.id = d7.field_value " .
186 "LEFT JOIN users AS uf ON uf.id = d8.field_value " .
187 "WHERE t.title = 'LBTref' AND " .
188 "d1.field_value >= ? AND d1.field_value <= ? " .
189 "ORDER BY ut.organization, d1.field_value, t.id";
190 $res = sqlStatement($query, array($form_from_date, $form_to_date));
192 while ($row = sqlFetchArray($res)) {
193 // If a facility is specified, ignore rows that do not match.
194 if ($form_facility !== '') {
195 if ($form_facility) {
196 if ($row['facility_id'] != $form_facility) {
197 continue;
199 } else {
200 if (!empty($row['facility_id'])) {
201 continue;
207 <tr>
208 <td>
209 <?php
210 if ($row['organization']!=null || $row['organization']!='') {
211 echo text($row['organization']);
212 } else {
213 echo text($row['referer_to']);
216 </td>
217 <td>
218 <a href='#' onclick="return show_referral(<?php echo attr($row['id']); ?>)">
219 <?php echo text(oeFormatShortDate($row['refer_date'])); ?>&nbsp;
220 </a>
221 </td>
222 <td>
223 <?php echo text(oeFormatShortDate($row['reply_date'])) ?>
224 </td>
225 <td>
226 <?php echo text($row['patient_name']) ?>
227 </td>
228 <td>
229 <?php echo text($row['pubpid']) ?>
230 </td>
231 <td>
232 <?php echo text($row['body']) ?>
233 </td>
234 </tr>
235 <?php
239 </tbody>
240 </table>
241 </div> <!-- end of results -->
242 <?php } else { ?>
243 <div class='text'>
244 <?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?>
245 </div>
246 <?php } ?>
247 </form>
249 </body>
250 </html>