Merge branch 'master' of git://github.com/openemr/openemr
[openemr.git] / interface / reports / referrals_report.php
blob4b9624d4cad2b5572cab3d285815ba5cec4813f2
1 <?php
2 // Copyright (C) 2008, 2010 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 require_once("../globals.php");
12 require_once("$srcdir/patient.inc");
13 require_once("$srcdir/formatting.inc.php");
14 require_once "$srcdir/options.inc.php";
15 require_once "$srcdir/formdata.inc.php";
17 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
18 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
19 $form_facility = isset($_POST['form_facility']) ? $_POST['form_facility'] : '';
21 <html>
22 <head>
23 <?php html_header_show();?>
24 <title><?php xl('Referrals','e'); ?></title>
26 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
28 <script type="text/javascript" src="../../library/dialog.js"></script>
29 <script type="text/javascript" src="../../library/textformat.js"></script>
30 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
31 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
32 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
33 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
35 <script language="JavaScript">
37 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
39 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
41 // The OnClick handler for referral display.
42 function show_referral(transid) {
43 dlgopen('../patient_file/transaction/print_referral.php?transid=' + transid,
44 '_blank', 550, 400);
45 return false;
48 </script>
50 <link rel='stylesheet' href='<?php echo $css_header ?>' type='text/css'>
51 <style type="text/css">
53 /* specifically include & exclude from printing */
54 @media print {
55 #report_parameters {
56 visibility: hidden;
57 display: none;
59 #report_parameters_daterange {
60 visibility: visible;
61 display: inline;
63 #report_results table {
64 margin-top: 0px;
68 /* specifically exclude some from the screen */
69 @media screen {
70 #report_parameters_daterange {
71 visibility: hidden;
72 display: none;
76 </style>
77 </head>
79 <body class="body_top">
81 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Referrals','e'); ?></span>
83 <div id="report_parameters_daterange">
84 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
85 </div>
87 <form name='theform' id='theform' method='post' action='referrals_report.php'>
89 <div id="report_parameters">
90 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
91 <table>
92 <tr>
93 <td width='640px'>
94 <div style='float:left'>
96 <table class='text'>
97 <tr>
98 <td class='label'>
99 <?php xl('Facility','e'); ?>:
100 </td>
101 <td>
102 <?php dropdown_facility(strip_escape_custom($form_facility), 'form_facility', true); ?>
103 </td>
104 <td class='label'>
105 <?php xl('From','e'); ?>:
106 </td>
107 <td>
108 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
109 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
110 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
111 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
112 title='<?php xl('Click here to choose a date','e'); ?>'>
113 </td>
114 <td class='label'>
115 <?php xl('To','e'); ?>:
116 </td>
117 <td>
118 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
119 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
120 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
121 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
122 title='<?php xl('Click here to choose a date','e'); ?>'>
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 style='margin-left:15px'>
135 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
136 <span>
137 <?php xl('Submit','e'); ?>
138 </span>
139 </a>
141 <?php if ($_POST['form_refresh']) { ?>
142 <a href='#' class='css_button' onclick='window.print()'>
143 <span>
144 <?php xl('Print','e'); ?>
145 </span>
146 </a>
147 <?php } ?>
148 </div>
149 </td>
150 </tr>
151 </table>
152 </td>
153 </tr>
154 </table>
155 </div> <!-- end of parameters -->
158 <?php
159 if ($_POST['form_refresh']) {
161 <div id="report_results">
162 <table>
163 <thead>
164 <th> <?php xl('Refer To','e'); ?> </th>
165 <th> <?php xl('Refer Date','e'); ?> </th>
166 <th> <?php xl('Reply Date','e'); ?> </th>
167 <th> <?php xl('Patient','e'); ?> </th>
168 <th> <?php xl('ID','e'); ?> </th>
169 <th> <?php xl('Reason','e'); ?> </th>
170 </thead>
171 <tbody>
172 <?php
173 if ($_POST['form_refresh']) {
174 $query = "SELECT t.id, t.refer_date, t.reply_date, t.body, " .
175 "ut.organization, uf.facility_id, p.pubpid, " .
176 "CONCAT(uf.fname,' ', uf.lname) AS referer_name, " .
177 "CONCAT(p.fname,' ', p.lname) AS patient_name " .
178 "FROM transactions AS t " .
179 "LEFT OUTER JOIN patient_data AS p ON p.pid = t.pid " .
180 "LEFT OUTER JOIN users AS ut ON ut.id = t.refer_to " .
181 "LEFT OUTER JOIN users AS uf ON uf.id = t.refer_from " .
182 "WHERE t.title = 'Referral' AND " .
183 "t.refer_date >= '$from_date' AND t.refer_date <= '$to_date' " .
184 "ORDER BY ut.organization, t.refer_date, t.id";
186 // echo "<!-- $query -->\n"; // debugging
187 $res = sqlStatement($query);
189 while ($row = sqlFetchArray($res)) {
190 // If a facility is specified, ignore rows that do not match.
191 if ($form_facility !== '') {
192 if ($form_facility) {
193 if ($row['facility_id'] != $form_facility) continue;
195 else {
196 if (!empty($row['facility_id'])) continue;
200 <tr>
201 <td>
202 <?php echo $row['organization'] ?>
203 </td>
204 <td>
205 <a href='#' onclick="return show_referral(<?php echo $row['id']; ?>)">
206 <?php echo oeFormatShortDate($row['refer_date']); ?>&nbsp;
207 </a>
208 </td>
209 <td>
210 <?php echo oeFormatShortDate($row['reply_date']) ?>
211 </td>
212 <td>
213 <?php echo $row['patient_name'] ?>
214 </td>
215 <td>
216 <?php echo $row['pubpid'] ?>
217 </td>
218 <td>
219 <?php echo $row['body'] ?>
220 </td>
221 </tr>
222 <?php
226 </tbody>
227 </table>
228 </div> <!-- end of results -->
229 <?php } else { ?>
230 <div class='text'>
231 <?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
232 </div>
233 <?php } ?>
234 </form>
236 <script language='JavaScript'>
237 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
238 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
239 </script>
241 </body>
242 </html>