fix some failures to enforce required fields, and some code refactoring
[openemr.git] / interface / reports / appointments_report.php
blobb59a832e86f56aad2ad6370d3bba06d9d1374087
1 <?php
2 // Copyright (C) 2005-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 shows upcoming appointments with filtering and
10 // sorting by patient, practitioner, appointment type, and date.
12 include_once("../globals.php");
13 include_once("../../library/patient.inc");
15 $alertmsg = ''; // not used yet but maybe later
17 // For each sorting option, specify the ORDER BY argument.
20 $ORDERHASH = array(
21 'doctor' => 'lower(u.lname), lower(u.fname), pc_eventDate, pc_startTime',
22 'patient' => 'lower(p.lname), lower(p.fname), pc_eventDate, pc_startTime',
23 'pubpid' => 'lower(p.pubpid), pc_eventDate, pc_startTime',
24 'time' => 'pc_eventDate, pc_startTime, lower(u.lname), lower(u.fname)',
25 'type' => 'pc_catname, pc_eventDate, pc_startTime, lower(u.lname), lower(u.fname)'
28 function bucks($amount) {
29 if ($amount) printf("%.2f", $amount);
32 $patient = $_REQUEST['patient'];
34 if ($patient && ! $_POST['form_from_date']) {
35 // If a specific patient, default to 2 years ago.
36 $tmp = date('Y') - 2;
37 $from_date = date("$tmp-m-d");
38 } else {
39 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
40 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
43 //$to_date = fixDate($_POST['form_to_date'], '');
44 $provider = $_POST['form_provider'];
45 $facility = $_POST['form_facility']; //(CHEMED) facility filter
47 $form_orderby = $ORDERHASH[$_REQUEST['form_orderby']] ? $_REQUEST['form_orderby'] : 'time';
49 $orderby = $ORDERHASH[$form_orderby];
51 $where = "e.pc_pid != '' AND e.pc_eventDate >= '$from_date'";
53 if ($to_date ) $where .= " AND e.pc_eventDate <= '$to_date'";
54 if ($provider) $where .= " AND e.pc_aid = '$provider'";
56 //(CHEMED) facility filter
57 $facility_filter = '';
58 if ($facility) {
59 $event_facility_filter = " AND e.pc_facility = '$facility'";
60 $provider_facility_filter = " AND users.facility_id = '$facility'";
62 //END (CHEMED)
64 if ($patient ) $where .= " AND e.pc_pid = '$patient'";
66 // Get the info.
69 $query = "SELECT " .
70 "e.pc_eventDate, e.pc_startTime, e.pc_catid, e.pc_eid, " .
71 "p.fname, p.mname, p.lname, p.pid, p.pubpid, " .
72 "u.fname AS ufname, u.mname AS umname, u.lname AS ulname, " .
73 "c.pc_catname " .
74 "FROM openemr_postcalendar_events AS e " .
75 "LEFT OUTER JOIN patient_data AS p ON p.pid = e.pc_pid " .
76 "LEFT OUTER JOIN users AS u ON u.id = e.pc_aid " .
77 "LEFT OUTER JOIN openemr_postcalendar_categories AS c ON c.pc_catid = e.pc_catid " .
78 "WHERE $where $event_facility_filter ORDER BY $orderby"; //(CHEMED) facility filter
80 $res = sqlStatement($query);
84 <html>
86 <head>
87 <?php html_header_show();?>
89 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
91 <title><?php xl('Appointments Report','e'); ?></title>
93 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
94 <script type="text/javascript" src="../../library/textformat.js"></script>
95 <script type="text/javascript" src="../../library/dialog.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>
120 /* specifically include & exclude from printing */
121 @media print {
122 #apptreport_parameters {
123 visibility: hidden;
124 display: none;
126 #apptreport_parameters_daterange {
127 visibility: visible;
128 display: inline;
132 /* specifically exclude some from the screen */
133 @media screen {
134 #apptreport_parameters_daterange {
135 visibility: hidden;
136 display: none;
140 #apptreport_parameters {
141 width: 100%;
142 text-align: center;
143 background-color: #ddf;
145 #apptreport_parameters table {
146 border: none;
147 border-collapse: collapse;
149 #apptreport_parameters table td {
150 padding: 3px;
153 #apptreport_results {
154 width: 100%;
155 margin-top: 10px;
157 #apptreport_results table {
158 border: 1px solid black;
159 width: 98%;
160 border-collapse: collapse;
162 #apptreport_results table thead {
163 display: table-header-group;
164 background-color: #ddd;
166 #apptreport_results table th {
167 border-bottom: 1px solid black;
169 #apptreport_results table td {
170 padding: 1px;
171 margin: 2px;
174 </style>
175 </head>
177 <body class="body_top">
179 <!-- Required for the popup date selectors -->
180 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
182 <center>
184 <h2><?php xl('Appointments Report','e'); ?></h2>
185 <div id="apptreport_parameters_daterange">
186 <?php echo date("d F Y", strtotime($from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($to_date)); ?>
187 </div>
189 <form method='post' name='theform' action='appointments_report.php'>
191 <div id="apptreport_parameters">
192 <table>
193 <tr>
194 <td>
196 <?php //(CHEMED) Facility filter
198 xl('Facility','e');
200 // Build a drop-down list of facilities.
203 $query = "SELECT id, name FROM facility WHERE " .
204 "service_location = 1 ORDER BY name ";
206 $ures = sqlStatement($query);
208 echo " <select name='form_facility' onChange='document.all.theform.submit()'>\n";
209 echo " <option value=''>-- All --\n";
211 while ($urow = sqlFetchArray($ures)) {
212 $fid = $urow['id'];
213 echo " <option value='$fid'";
214 if ($fid == $_POST['form_facility']) echo " selected";
215 echo ">" . $urow['name'] . "\n";
218 echo " </select>\n";
219 //END (CHEMED) Facility filter
222 <?php xl('Provider','e'); ?>:
224 <?php
226 // Build a drop-down list of providers.
229 $query = "SELECT id, lname, fname FROM users WHERE ".
230 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
232 $ures = sqlStatement($query);
234 echo " <select name='form_provider'>\n";
235 echo " <option value=''>-- All --\n";
237 while ($urow = sqlFetchArray($ures)) {
238 $provid = $urow['id'];
239 echo " <option value='$provid'";
240 if ($provid == $_POST['form_provider']) echo " selected";
241 echo ">" . $urow['lname'] . ", " . $urow['fname'] . "\n";
244 echo " </select>\n";
248 &nbsp;<?php xl('From','e'); ?>:
250 <input type='text' name='form_from_date' id="form_from_date" size='10' value='<?php echo $from_date ?>'
251 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
252 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
253 id='img_from_date' border='0' alt='[?]' style='cursor:pointer'
254 title='<?php xl('Click here to choose a date','e'); ?>'>
256 &nbsp;<?php xl('To','e'); ?>:
258 <input type='text' name='form_to_date' id="form_to_date" size='10' value='<?php echo $to_date ?>'
259 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' title='yyyy-mm-dd'>
260 <img src='../pic/show_calendar.gif' align='absbottom' width='24' height='22'
261 id='img_to_date' border='0' alt='[?]' style='cursor:pointer'
262 title='<?php xl('Click here to choose a date','e'); ?>'>
264 &nbsp;
265 <input type='submit' name='form_refresh' value='<?php xl('Refresh','e'); ?>'>
266 &nbsp;
267 <input type='button' value='<?php xl('Print','e'); ?>' onclick='window.print()' />
269 </td>
270 </tr>
272 <tr>
273 <td height="1">
274 </td>
275 </tr>
277 </table>
278 </div> <!-- end of search parameters -->
280 <div id="apptreport_results">
281 <table>
283 <thead>
284 <th>
285 <a href="nojs.php" onclick="return dosort('doctor')"
286 <?php if ($form_orderby == "doctor") echo " style=\"color:#00cc00\"" ?>><?php xl('Provider','e'); ?> </a>
287 </th>
289 <th>
290 <a href="nojs.php" onclick="return dosort('time')"
291 <?php if ($form_orderby == "time") echo " style=\"color:#00cc00\"" ?>><?php xl('Time','e'); ?></a>
292 </th>
294 <th>
295 <a href="nojs.php" onclick="return dosort('patient')"
296 <?php if ($form_orderby == "patient") echo " style=\"color:#00cc00\"" ?>><?php xl('Patient','e'); ?></a>
297 </th>
299 <th>
300 <a href="nojs.php" onclick="return dosort('pubpid')"
301 <?php if ($form_orderby == "pubpid") echo " style=\"color:#00cc00\"" ?>><?php xl('ID','e'); ?></a>
302 </th>
304 <th>
305 <a href="nojs.php" onclick="return dosort('type')"
306 <?php if ($form_orderby == "type") echo " style=\"color:#00cc00\"" ?>><?php xl('Type','e'); ?></a>
307 </th>
309 </thead>
310 <tbody> <!-- added for better print-ability -->
311 <?php
313 if ($res) {
314 $lastdocname = "";
316 while ($row = sqlFetchArray($res)) {
317 $patient_id = $row['pid'];
318 $docname = $row['ulname'] . ', ' . $row['ufname'] . ' ' . $row['umname'];
319 $errmsg = "";
323 <tr bgcolor='<?php echo $bgcolor ?>'>
324 <td class="detail">
325 &nbsp;<?php echo ($docname == $lastdocname) ? "" : $docname ?>
326 </td>
328 <td class="detail">
329 <?php echo $row['pc_eventDate'] . ' ' . substr($row['pc_startTime'], 0, 5) ?>
330 <!--
331 &nbsp;<a href='javascript:oldEvt(<?php echo $row['pc_eid'] ?>)'>
332 </a>
334 </td>
336 <td class="detail">
337 &nbsp;<?php echo $row['fname'] . " " . $row['lname'] ?>
338 </td>
340 <td class="detail">
341 &nbsp;<?php echo $row['pubpid'] ?>
342 </td>
344 <td class="detail">
345 &nbsp;<?php echo $row['pc_catname'] ?>
346 </td>
348 </tr>
350 <?php
351 $lastdocname = $docname;
355 </tbody>
356 </table>
357 </div> <!-- end of search results -->
359 <input type="hidden" name="form_orderby" value="<?php echo $form_orderby ?>" />
360 <input type="hidden" name="patient" value="<?php echo $patient ?>" />
362 </form>
364 </center>
366 <script>
368 <?php
369 if ($alertmsg) { echo " alert('$alertmsg');\n"; }
372 </script>
374 </body>
376 <!-- stuff for the popup calendar -->
377 <style type="text/css">@import url(../../library/dynarch_calendar.css);</style>
378 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
379 <script type="text/javascript" src="../../library/dynarch_calendar_en.js"></script>
380 <script type="text/javascript" src="../../library/dynarch_calendar_setup.js"></script>
381 <script language="Javascript">
382 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
383 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
384 </script>
386 </html>