Changes by Joe Holzer
[openemr.git] / interface / reports / referrals_report.php
blob681502c1adf62ffb6b1d49b879024855299bf563
1 <?php
2 // Copyright (C) 2008 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This report lists referrals for a given date range.
11 include_once("../globals.php");
12 include_once("$srcdir/patient.inc");
14 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
15 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
16 $form_facility = isset($_POST['form_facility']) ? $_POST['form_facility'] : '';
18 <html>
19 <head>
20 <?php html_header_show();?>
21 <title><?php xl('Referrals','e'); ?></title>
23 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
25 <script type="text/javascript" src="../../library/dialog.js"></script>
26 <script type="text/javascript" src="../../library/textformat.js"></script>
27 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
28 <script type="text/javascript" src="../../library/dynarch_calendar_en.js"></script>
29 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
30 <script language="JavaScript">
32 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
34 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
36 // The OnClick handler for referral display.
37 function show_referral(transid) {
38 dlgopen('../patient_file/transaction/print_referral.php?transid=' + transid,
39 '_blank', 550, 400);
40 return false;
43 </script>
45 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
46 <style type="text/css">
48 /* specifically include & exclude from printing */
49 @media print {
50 #referreport_parameters {
51 visibility: hidden;
52 display: none;
54 #referreport_parameters_daterange {
55 visibility: visible;
56 display: inline;
60 /* specifically exclude some from the screen */
61 @media screen {
62 #referreport_parameters_daterange {
63 visibility: hidden;
64 display: none;
68 #referreport_parameters {
69 width: 100%;
70 background-color: #ddf;
72 #referreport_parameters table {
73 border: none;
74 border-collapse: collapse;
76 #referreport_parameters table td {
77 padding: 3px;
80 #referreport_results {
81 width: 100%;
82 margin-top: 10px;
84 #referreport_results table {
85 border: 1px solid black;
86 width: 98%;
87 border-collapse: collapse;
89 #referreport_results table thead {
90 display: table-header-group;
91 background-color: #ddd;
93 #referreport_results table th {
94 border-bottom: 1px solid black;
95 font-size: 0.7em;
97 #referreport_results table td {
98 padding: 1px;
99 margin: 2px;
100 border-bottom: 1px solid #eee;
101 font-size: 0.7em;
103 .referreport_totals td {
104 background-color: #77ff77;
105 font-weight: bold;
107 </style>
108 </head>
110 <body class="body_top">
112 <center>
114 <h2><?php xl('Referrals','e'); ?></h2>
116 <div id="referreport_parameters_daterange">
117 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
118 </div>
120 <div id="referreport_parameters">
121 <form name='theform' method='post' action='referrals_report.php'>
122 <table>
123 <tr>
124 <td>
125 <?php
126 // Build a drop-down list of facilities.
128 $query = "SELECT id, name FROM facility ORDER BY name";
129 $fres = sqlStatement($query);
130 echo " <select name='form_facility'>\n";
131 echo " <option value=''>-- " . xl('All Facilities') . " --\n";
132 while ($frow = sqlFetchArray($fres)) {
133 $facid = $frow['id'];
134 echo " <option value='$facid'";
135 if ($facid == $form_facility) echo " selected";
136 echo ">" . $frow['name'] . "\n";
138 echo " <option value='0'";
139 if ($form_facility === '0') echo " selected";
140 echo ">-- " . xl('Unspecified') . " --\n";
141 echo " </select>\n";
143 &nbsp;<?php xl('From','e'); ?>:
144 <input type='text' size='10' name='form_from_date' id='form_from_date'
145 value='<?php echo $from_date ?>'
146 title='<?php xl('yyyy-mm-dd','e'); ?>'
147 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
148 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
149 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
150 title='<?php xl('Click here to choose a date','e'); ?>' />
151 &nbsp;<?php xl('To','e'); ?>:
152 <input type='text' size='10' name='form_to_date' id='form_to_date'
153 value='<?php echo $to_date ?>'
154 title='<?php xl('yyyy-mm-dd','e'); ?>'
155 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />
156 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
157 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
158 title='<?php xl('Click here to choose a date','e'); ?>' />
159 &nbsp;
160 <input type='submit' name='form_refresh' value=<?php xl('Refresh','e'); ?>>
161 &nbsp;
162 <input type='button' value='<?php xl('Print','e'); ?>' onclick='window.print()' />
163 </td>
164 </tr>
165 </table>
166 </div> <!-- end of parameters -->
169 <div id="referreport_results">
170 <table>
171 <thead>
172 <th> <?php xl('Refer To','e'); ?> </th>
173 <th> <?php xl('Refer Date','e'); ?> </th>
174 <th> <?php xl('Reply Date','e'); ?> </th>
175 <th> <?php xl('Patient','e'); ?> </th>
176 <th> <?php xl('ID','e'); ?> </th>
177 <th> <?php xl('Reason','e'); ?> </th>
178 </thead>
179 <tbody>
180 <?php
181 if ($_POST['form_refresh']) {
182 $query = "SELECT t.id, t.refer_date, t.reply_date, t.body, " .
183 "ut.organization, uf.facility_id, p.pubpid, " .
184 "CONCAT(uf.fname,' ', uf.lname) AS referer_name, " .
185 "CONCAT(p.fname,' ', p.lname) AS patient_name " .
186 "FROM transactions AS t " .
187 "LEFT OUTER JOIN patient_data AS p ON p.pid = t.pid " .
188 "LEFT OUTER JOIN users AS ut ON ut.id = t.refer_to " .
189 "LEFT OUTER JOIN users AS uf ON uf.id = t.refer_from " .
190 "WHERE t.title = 'Referral' AND " .
191 "t.refer_date >= '$from_date' AND t.refer_date <= '$to_date' " .
192 "ORDER BY ut.organization, t.refer_date, t.id";
194 // echo "<!-- $query -->\n"; // debugging
195 $res = sqlStatement($query);
197 while ($row = sqlFetchArray($res)) {
198 // If a facility is specified, ignore rows that do not match.
199 if ($form_facility !== '') {
200 if ($form_facility) {
201 if ($row['facility_id'] != $form_facility) continue;
203 else {
204 if (!empty($row['facility_id'])) continue;
208 <tr>
209 <td>
210 <?php echo $row['organization'] ?>
211 </td>
212 <td>
213 <a href='#' onclick="return show_referral(<?php echo $row['id']; ?>)">
214 <?php echo $row['refer_date']; ?>&nbsp;
215 </a>
216 </td>
217 <td>
218 <?php echo $row['reply_date'] ?>
219 </td>
220 <td>
221 <?php echo $row['patient_name'] ?>
222 </td>
223 <td>
224 <?php echo $row['pubpid'] ?>
225 </td>
226 <td>
227 <?php echo $row['body'] ?>
228 </td>
229 </tr>
230 <?php
234 </tbody>
235 </table>
236 </div> <!-- end of results -->
237 </form>
238 </center>
240 <script language='JavaScript'>
241 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
242 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
243 </script>
245 </body>
246 </html>