Merge branch 'master' of git://github.com/openemr/openemr
[openemr.git] / interface / reports / appointments_report.php
blob4b8040e0bb8f639b47f3b90f95c6c0eb44de38ea
1 <?php
2 // Copyright (C) 2005-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 shows upcoming appointments with filtering and
10 // sorting by patient, practitioner, appointment type, and date.
12 require_once("../globals.php");
13 require_once("../../library/patient.inc");
14 require_once("$srcdir/formatting.inc.php");
15 require_once "$srcdir/options.inc.php";
16 require_once "$srcdir/formdata.inc.php";
18 $alertmsg = ''; // not used yet but maybe later
20 // For each sorting option, specify the ORDER BY argument.
23 $ORDERHASH = array(
24 'doctor' => 'lower(u.lname), lower(u.fname), pc_eventDate, pc_startTime',
25 'patient' => 'lower(p.lname), lower(p.fname), pc_eventDate, pc_startTime',
26 'pubpid' => 'lower(p.pubpid), pc_eventDate, pc_startTime',
27 'time' => 'pc_eventDate, pc_startTime, lower(u.lname), lower(u.fname)',
28 'type' => 'pc_catname, pc_eventDate, pc_startTime, lower(u.lname), lower(u.fname)'
31 $patient = $_REQUEST['patient'];
33 if ($patient && ! $_POST['form_from_date']) {
34 // If a specific patient, default to 2 years ago.
35 $tmp = date('Y') - 2;
36 $from_date = date("$tmp-m-d");
37 } else {
38 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
39 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
42 //$to_date = fixDate($_POST['form_to_date'], '');
43 $provider = $_POST['form_provider'];
44 $facility = $_POST['form_facility']; //(CHEMED) facility filter
46 $form_orderby = $ORDERHASH[$_REQUEST['form_orderby']] ? $_REQUEST['form_orderby'] : 'time';
48 $orderby = $ORDERHASH[$form_orderby];
50 $where = "e.pc_pid != '' AND e.pc_eventDate >= '$from_date'";
52 if ($to_date ) $where .= " AND e.pc_eventDate <= '$to_date'";
53 if ($provider) $where .= " AND e.pc_aid = '$provider'";
55 //(CHEMED) facility filter
56 $facility_filter = '';
57 if ($facility) {
58 $event_facility_filter = " AND e.pc_facility = '$facility'";
59 $provider_facility_filter = " AND users.facility_id = '$facility'";
61 //END (CHEMED)
63 if ($patient ) $where .= " AND e.pc_pid = '$patient'";
65 // Get the info.
68 $query = "SELECT " .
69 "e.pc_eventDate, e.pc_startTime, e.pc_catid, e.pc_eid, " .
70 "p.fname, p.mname, p.lname, p.pid, p.pubpid, " .
71 "u.fname AS ufname, u.mname AS umname, u.lname AS ulname, " .
72 "c.pc_catname " .
73 "FROM openemr_postcalendar_events AS e " .
74 "LEFT OUTER JOIN patient_data AS p ON p.pid = e.pc_pid " .
75 "LEFT OUTER JOIN users AS u ON u.id = e.pc_aid " .
76 "LEFT OUTER JOIN openemr_postcalendar_categories AS c ON c.pc_catid = e.pc_catid " .
77 "WHERE $where $event_facility_filter ORDER BY $orderby"; //(CHEMED) facility filter
79 $res = sqlStatement($query);
83 <html>
85 <head>
86 <?php html_header_show();?>
88 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
90 <title><?php xl('Appointments Report','e'); ?></title>
92 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
93 <script type="text/javascript" src="../../library/textformat.js"></script>
94 <script type="text/javascript" src="../../library/dialog.js"></script>
95 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
97 <script LANGUAGE="JavaScript">
99 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
101 function dosort(orderby) {
102 var f = document.forms[0];
103 f.form_orderby.value = orderby;
104 f.submit();
105 return false;
108 function oldEvt(eventid) {
109 dlgopen('../main/calendar/add_edit_event.php?eid=' + eventid, 'blank', 550, 270);
112 function refreshme() {
113 // location.reload();
114 document.forms[0].submit();
117 </script>
119 <style type="text/css">
121 /* specifically include & exclude from printing */
122 @media print {
123 #report_parameters {
124 visibility: hidden;
125 display: none;
127 #report_parameters_daterange {
128 visibility: visible;
129 display: inline;
131 #report_results table {
132 margin-top: 0px;
136 /* specifically exclude some from the screen */
137 @media screen {
138 #report_parameters_daterange {
139 visibility: hidden;
140 display: none;
144 </style>
145 </head>
147 <body class="body_top">
149 <!-- Required for the popup date selectors -->
150 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
152 <span class='title'><?php xl('Report','e'); ?> - <?php xl('Appointments','e'); ?></span>
154 <div id="report_parameters_daterange">
155 <?php echo date("d F Y", strtotime($form_from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($form_to_date)); ?>
156 </div>
158 <form method='post' name='theform' id='theform' action='appointments_report.php'>
159 <form name='theform' id='theform' method='post' action='referrals_report.php'>
161 <div id="report_parameters">
163 <table>
164 <tr>
165 <td width='470px'>
166 <div style='float:left'>
168 <table class='text'>
169 <tr>
170 <td class='label'>
171 <?php xl('Facility','e'); ?>:
172 </td>
173 <td>
174 <?php dropdown_facility(strip_escape_custom($facility), 'form_facility'); ?>
175 </td>
176 <td class='label'>
177 <?php xl('Provider','e'); ?>:
178 </td>
179 <td>
180 <?php
182 // Build a drop-down list of providers.
185 $query = "SELECT id, lname, fname FROM users WHERE ".
186 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
188 $ures = sqlStatement($query);
190 echo " <select name='form_provider'>\n";
191 echo " <option value=''>-- " . xl('All') . " --\n";
193 while ($urow = sqlFetchArray($ures)) {
194 $provid = $urow['id'];
195 echo " <option value='$provid'";
196 if ($provid == $_POST['form_provider']) echo " selected";
197 echo ">" . $urow['lname'] . ", " . $urow['fname'] . "\n";
200 echo " </select>\n";
203 </td>
204 </tr>
205 <tr>
206 <td class='label'>
207 <?php xl('From','e'); ?>:
208 </td>
209 <td>
210 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $form_from_date ?>'
211 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
212 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
213 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
214 title='<?php xl('Click here to choose a date','e'); ?>'>
215 </td>
216 <td class='label'>
217 <?php xl('To','e'); ?>:
218 </td>
219 <td>
220 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $form_to_date ?>'
221 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
222 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
223 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
224 title='<?php xl('Click here to choose a date','e'); ?>'>
225 </td>
226 </tr>
227 </table>
229 </div>
231 </td>
232 <td align='left' valign='middle' height="100%">
233 <table style='border-left:1px solid; width:100%; height:100%' >
234 <tr>
235 <td>
236 <div style='margin-left:15px'>
237 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
238 <span>
239 <?php xl('Submit','e'); ?>
240 </span>
241 </a>
243 <?php if ($_POST['form_refresh'] || $_POST['form_orderby'] ) { ?>
244 <a href='#' class='css_button' onclick='window.print()'>
245 <span>
246 <?php xl('Print','e'); ?>
247 </span>
248 </a>
249 <?php } ?>
250 </div>
251 </td>
252 </tr>
253 </table>
254 </td>
255 </tr>
256 </table>
258 </div> <!-- end of search parameters -->
260 <?php
261 if ($_POST['form_refresh'] || $_POST['form_orderby']) {
263 <div id="report_results">
264 <table>
266 <thead>
267 <th>
268 <a href="nojs.php" onclick="return dosort('doctor')"
269 <?php if ($form_orderby == "doctor") echo " style=\"color:#00cc00\"" ?>><?php xl('Provider','e'); ?> </a>
270 </th>
272 <th>
273 <a href="nojs.php" onclick="return dosort('time')"
274 <?php if ($form_orderby == "time") echo " style=\"color:#00cc00\"" ?>><?php xl('Time','e'); ?></a>
275 </th>
277 <th>
278 <a href="nojs.php" onclick="return dosort('patient')"
279 <?php if ($form_orderby == "patient") echo " style=\"color:#00cc00\"" ?>><?php xl('Patient','e'); ?></a>
280 </th>
282 <th>
283 <a href="nojs.php" onclick="return dosort('pubpid')"
284 <?php if ($form_orderby == "pubpid") echo " style=\"color:#00cc00\"" ?>><?php xl('ID','e'); ?></a>
285 </th>
287 <th>
288 <a href="nojs.php" onclick="return dosort('type')"
289 <?php if ($form_orderby == "type") echo " style=\"color:#00cc00\"" ?>><?php xl('Type','e'); ?></a>
290 </th>
292 </thead>
293 <tbody> <!-- added for better print-ability -->
294 <?php
296 if ($res) {
297 $lastdocname = "";
299 while ($row = sqlFetchArray($res)) {
300 $patient_id = $row['pid'];
301 $docname = $row['ulname'] . ', ' . $row['ufname'] . ' ' . $row['umname'];
302 $errmsg = "";
306 <tr bgcolor='<?php echo $bgcolor ?>'>
307 <td class="detail">
308 &nbsp;<?php echo ($docname == $lastdocname) ? "" : $docname ?>
309 </td>
311 <td class="detail">
312 <?php echo oeFormatShortDate($row['pc_eventDate']) . ' ' . substr($row['pc_startTime'], 0, 5) ?>
313 <!--
314 &nbsp;<a href='javascript:oldEvt(<?php echo $row['pc_eid'] ?>)'>
315 </a>
317 </td>
319 <td class="detail">
320 &nbsp;<?php echo $row['fname'] . " " . $row['lname'] ?>
321 </td>
323 <td class="detail">
324 &nbsp;<?php echo $row['pubpid'] ?>
325 </td>
327 <td class="detail">
328 &nbsp;<?php echo xl_appt_category($row['pc_catname']) ?>
329 </td>
331 </tr>
333 <?php
334 $lastdocname = $docname;
338 </tbody>
339 </table>
340 </div> <!-- end of search results -->
341 <?php } else { ?>
342 <div class='text'>
343 <?php echo xl('Please input search criteria above, and click Submit to view results.', 'e' ); ?>
344 </div>
345 <?php } ?>
347 <input type="hidden" name="form_orderby" value="<?php echo $form_orderby ?>" />
348 <input type="hidden" name="patient" value="<?php echo $patient ?>" />
349 <input type='hidden' name='form_refresh' id='form_refresh' value=''/>
351 </form>
353 <script>
355 <?php
356 if ($alertmsg) { echo " alert('$alertmsg');\n"; }
359 </script>
361 </body>
363 <!-- stuff for the popup calendar -->
364 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
365 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
366 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
367 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
368 <script language="Javascript">
369 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
370 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
371 </script>
373 </html>