minor comment fix of prior commit
[openemr.git] / interface / reports / appointments_report.php
blob7c258900b81f617424124bb0c42e5e22774352f8
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.
11 // 2012-01-01 - Added display of home and cell phone and fixed header
12 // 2015-06-19 - brought up to security standards terry@lillysystems.com
14 $fake_register_globals=false;
15 $sanitize_all_escapes=true;
17 require_once("../globals.php");
18 require_once("../../library/patient.inc");
19 require_once("$srcdir/formatting.inc.php");
20 require_once "$srcdir/options.inc.php";
21 require_once "$srcdir/formdata.inc.php";
22 require_once "$srcdir/appointments.inc.php";
23 require_once "$srcdir/clinical_rules.php";
25 # Clear the pidList session whenever load this page.
26 # This session will hold array of patients that are listed in this
27 # report, which is then used by the 'Superbills' and 'Address Labels'
28 # features on this report.
29 unset($_SESSION['pidList']);
31 $alertmsg = ''; // not used yet but maybe later
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 $show_available_times = false;
44 if ( $_POST['form_show_available'] ) {
45 $show_available_times = true;
48 $chk_with_out_provider = false;
49 if ( $_POST['with_out_provider'] ) {
50 $chk_with_out_provider = true;
53 $chk_with_out_facility = false;
54 if ( $_POST['with_out_facility'] ) {
55 $chk_with_out_facility = true;
58 //$to_date = fixDate($_POST['form_to_date'], '');
59 $provider = $_POST['form_provider'];
60 $facility = $_POST['form_facility']; //(CHEMED) facility filter
61 $form_orderby = getComparisonOrder( $_REQUEST['form_orderby'] ) ? $_REQUEST['form_orderby'] : 'date';
63 // Reminders related stuff
64 $incl_reminders = isset($_POST['incl_reminders']) ? 1 : 0;
65 function fetch_rule_txt ($list_id, $option_id) {
66 $rs = sqlQuery('SELECT title, seq from list_options WHERE list_id=? AND option_id=?',
67 array($list_id, $option_id));
68 $rs['title'] = xl_list_label($rs['title']);
69 return $rs;
71 function fetch_reminders($pid, $appt_date) {
72 $rems = test_rules_clinic('','passive_alert',$appt_date,'reminders-due',$pid);
73 $seq_due = array();
74 $seq_cat = array();
75 $seq_act = array();
76 foreach ($rems as $ix => $rem) {
77 $rem_out = array();
78 $rule_txt = fetch_rule_txt ('rule_reminder_due_opt', $rem['due_status']);
79 $seq_due[$ix] = $rule_txt['seq'];
80 $rem_out['due_txt'] = $rule_txt['title'];
81 $rule_txt = fetch_rule_txt ('rule_action_category', $rem['category']);
82 $seq_cat[$ix] = $rule_txt['seq'];
83 $rem_out['cat_txt'] = $rule_txt['title'];
84 $rule_txt = fetch_rule_txt ('rule_action', $rem['item']);
85 $seq_act[$ix] = $rule_txt['seq'];
86 $rem_out['act_txt'] = $rule_txt['title'];
87 $rems_out[$ix] = $rem_out;
89 array_multisort($seq_due, SORT_DESC, $seq_cat, SORT_ASC, $seq_act, SORT_ASC, $rems_out);
90 $rems = array();
91 foreach ($rems_out as $ix => $rem) {
92 $rems[$rem['due_txt']] .= (isset($rems[$rem['due_txt']]) ? ', ':'').
93 $rem['act_txt'].' '.$rem['cat_txt'];
95 return $rems;
99 <html>
101 <head>
102 <?php html_header_show();?>
104 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
106 <title><?php echo xlt('Appointments Report'); ?></title>
108 <script type="text/javascript" src="../../library/overlib_mini.js"></script>
109 <script type="text/javascript" src="../../library/textformat.js"></script>
110 <script type="text/javascript" src="../../library/dialog.js"></script>
111 <script type="text/javascript" src="../../library/js/jquery.1.3.2.js"></script>
113 <script type="text/javascript">
115 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
117 $(document).ready(function() {
118 var win = top.printLogSetup ? top : opener.top;
119 win.printLogSetup(document.getElementById('printbutton'));
122 function dosort(orderby) {
123 var f = document.forms[0];
124 f.form_orderby.value = orderby;
125 f.submit();
126 return false;
129 function oldEvt(eventid) {
130 dlgopen('../main/calendar/add_edit_event.php?eid=' + eventid, 'blank', 550, 270);
133 function refreshme() {
134 // location.reload();
135 document.forms[0].submit();
138 </script>
140 <style type="text/css">
141 /* specifically include & exclude from printing */
142 @media print {
143 #report_parameters {
144 visibility: hidden;
145 display: none;
147 #report_parameters_daterange {
148 visibility: visible;
149 display: inline;
151 #report_results table {
152 margin-top: 0px;
156 /* specifically exclude some from the screen */
157 @media screen {
158 #report_parameters_daterange {
159 visibility: hidden;
160 display: none;
163 </style>
164 </head>
166 <body class="body_top">
168 <!-- Required for the popup date selectors -->
169 <div id="overDiv"
170 style="position: absolute; visibility: hidden; z-index: 1000;"></div>
172 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Appointments'); ?></span>
174 <div id="report_parameters_daterange"><?php echo date("d F Y", strtotime($from_date)) ." &nbsp; to &nbsp; ". date("d F Y", strtotime($to_date)); #sets date range for calendars ?>
175 </div>
177 <form method='post' name='theform' id='theform' action='appointments_report.php' onsubmit='return top.restoreSession()'>
179 <div id="report_parameters">
181 <table>
182 <tr>
183 <td width='650px'>
184 <div style='float: left'>
186 <table class='text'>
187 <tr>
188 <td class='label'><?php echo xlt('Facility'); ?>:</td>
189 <td><?php dropdown_facility($facility , 'form_facility'); ?>
190 </td>
191 <td class='label'><?php echo xlt('Provider'); ?>:</td>
192 <td><?php
194 // Build a drop-down list of providers.
197 $query = "SELECT id, lname, fname FROM users WHERE ".
198 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
200 $ures = sqlStatement($query);
202 echo " <select name='form_provider'>\n";
203 echo " <option value=''>-- " . xlt('All') . " --\n";
205 while ($urow = sqlFetchArray($ures)) {
206 $provid = $urow['id'];
207 echo " <option value='" . attr($provid) . "'";
208 if ($provid == $_POST['form_provider']) echo " selected";
209 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
212 echo " </select>\n";
214 </td>
215 </tr>
216 <tr>
217 <td class='label'><?php echo xlt('From'); ?>:</td>
218 <td><input type='text' name='form_from_date' id="form_from_date"
219 size='10' value='<?php echo attr($from_date) ?>'
220 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
221 title='yyyy-mm-dd'> <img src='../pic/show_calendar.gif'
222 align='absbottom' width='24' height='22' id='img_from_date'
223 border='0' alt='[?]' style='cursor: pointer'
224 title='<?php echo xlt('Click here to choose a date'); ?>'></td>
225 <td class='label'><?php echo xlt('To'); ?>:</td>
226 <td><input type='text' name='form_to_date' id="form_to_date"
227 size='10' value='<?php echo attr($to_date) ?>'
228 onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)'
229 title='yyyy-mm-dd'> <img src='../pic/show_calendar.gif'
230 align='absbottom' width='24' height='22' id='img_to_date'
231 border='0' alt='[?]' style='cursor: pointer'
232 title='<?php echo xlt('Click here to choose a date'); ?>'></td>
233 </tr>
235 <tr>
236 <td class='label'><?php echo xlt('Status'); # status code drop down creation ?>:</td>
237 <td><?php generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'All'),$_POST['form_apptstatus']);?></td>
238 <td><?php echo xlt('Category') #category drop down creation ?>:</td>
239 <td>
240 <select id="form_apptcat" name="form_apptcat">
241 <?php
242 $categories=fetchAppointmentCategories();
243 echo "<option value='ALL'>".xlt("All")."</option>";
244 while($cat=sqlFetchArray($categories))
246 echo "<option value='".attr($cat['id'])."'";
247 if($cat['id']==$_POST['form_apptcat'])
249 echo " selected='true' ";
251 echo ">".text(xl_appt_category($cat['category']))."</option>";
254 </select>
255 </td>
256 </tr>
257 <tr>
258 <td></td>
259 <td><label><input type='checkbox' name='form_show_available'
260 <?php if ( $show_available_times ) echo ' checked'; ?>> <?php echo xlt('Show Available Times'); # check this to show available times on the report ?>
261 </label></td>
262 <td></td>
263 <td><label><input type="checkbox" name="incl_reminders" id="incl_reminders"
264 <?php echo ($incl_reminders ? ' checked':''); # This will include the reminder for the patients on the report ?>>
265 <?php echo xlt('Show Reminders'); ?></label></td>
267 <tr>
268 <td></td>
269 <?php # these two selects will show entries that do not have a facility or a provider ?>
270 <td><label><input type="checkbox" name="with_out_provider" id="with_out_provider" <?php if($chk_with_out_provider) echo "checked";?>>&nbsp;<?php echo xlt('Without Provider'); ?></label></td>
271 <td></td>
272 <td><label><input type="checkbox" name="with_out_facility" id="with_out_facility" <?php if($chk_with_out_facility) echo "checked";?>>&nbsp;<?php echo xlt('Without Facility'); ?></label></td>
273 </tr>
275 </table>
277 </div>
279 </td>
280 <td align='left' valign='middle' height="100%">
281 <table style='border-left: 1px solid; width: 100%; height: 100%'>
282 <tr>
283 <td>
284 <div style='margin-left: 15px'>
285 <a href='#' class='css_button' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
286 <span> <?php echo xlt('Submit'); ?> </span> </a>
287 <?php if ($_POST['form_refresh'] || $_POST['form_orderby'] ) { ?>
288 <a href='#' class='css_button' id='printbutton'>
289 <span> <?php echo xlt('Print'); ?> </span> </a>
290 <a href='#' class='css_button' onclick='window.open("../patient_file/printed_fee_sheet.php?fill=2","_blank")' onsubmit='return top.restoreSession()'>
291 <span> <?php echo xlt('Superbills'); ?> </span> </a>
292 <a href='#' class='css_button' onclick='window.open("../patient_file/addr_appt_label.php","_blank")' onsubmit='return top.restoreSession()'>
293 <span> <?php echo xlt('Address Labels'); ?> </span> </a>
294 <?php } ?></div>
295 </td>
296 </tr>
297 <tr>&nbsp;&nbsp;<?php echo xlt('Most column headers can be clicked to change sort order') ?></tr>
298 </table>
299 </td>
300 </tr>
301 </table>
303 </div>
304 <!-- end of search parameters --> <?php
305 if ($_POST['form_refresh'] || $_POST['form_orderby']) {
306 $showDate = ($from_date != $to_date) || (!$to_date);
308 <div id="report_results">
309 <table>
311 <thead>
312 <th><a href="nojs.php" onclick="return dosort('doctor')"
313 <?php if ($form_orderby == "doctor") echo " style=\"color:#00cc00\"" ?>><?php echo xlt('Provider'); ?>
314 </a></th>
316 <th <?php echo $showDate ? '' : 'style="display:none;"' ?>><a href="nojs.php" onclick="return dosort('date')"
317 <?php if ($form_orderby == "date") echo " style=\"color:#00cc00\"" ?>><?php echo xlt('Date'); ?></a>
318 </th>
320 <th><a href="nojs.php" onclick="return dosort('time')"
321 <?php if ($form_orderby == "time") echo " style=\"color:#00cc00\"" ?>><?php echo xlt('Time'); ?></a>
322 </th>
324 <th><a href="nojs.php" onclick="return dosort('patient')"
325 <?php if ($form_orderby == "patient") echo " style=\"color:#00cc00\"" ?>><?php echo xlt('Patient'); ?></a>
326 </th>
328 <th><a href="nojs.php" onclick="return dosort('pubpid')"
329 <?php if ($form_orderby == "pubpid") echo " style=\"color:#00cc00\"" ?>><?php echo xlt('ID'); ?></a>
330 </th>
332 <th><?php echo xlt('Home'); //Sorting by phone# not really useful ?></th>
334 <th><?php echo xlt('Cell'); //Sorting by phone# not really useful ?></th>
336 <th><a href="nojs.php" onclick="return dosort('type')"
337 <?php if ($form_orderby == "type") echo " style=\"color:#00cc00\"" ?>><?php echo xlt('Type'); ?></a>
338 </th>
340 <th><a href="nojs.php" onclick="return dosort('status')"
341 <?php if ($form_orderby == "status") echo " style=\"color:#00cc00\"" ?>><?php echo xlt('Status'); ?></a>
342 </th>
343 </thead>
344 <tbody>
345 <!-- added for better print-ability -->
346 <?php
348 $lastdocname = "";
349 //Appointment Status Checking
350 $form_apptstatus = $_POST['form_apptstatus'];
351 $form_apptcat=null;
352 if(isset($_POST['form_apptcat']))
354 if($form_apptcat!="ALL")
356 $form_apptcat=intval($_POST['form_apptcat']);
360 //Without provider and facility data checking
361 $with_out_provider = null;
362 $with_out_facility = null;
364 if( isset($_POST['with_out_provider']) ){
365 $with_out_provider = $_POST['with_out_provider'];
368 if( isset($_POST['with_out_facility']) ){
369 $with_out_facility = $_POST['with_out_facility'];
371 $appointments = fetchAppointments( $from_date, $to_date, $patient, $provider, $facility, $form_apptstatus, $with_out_provider, $with_out_facility,$form_apptcat );
373 if ( $show_available_times ) {
374 $availableSlots = getAvailableSlots( $from_date, $to_date, $provider, $facility );
375 $appointments = array_merge( $appointments, $availableSlots );
378 $appointments = sortAppointments( $appointments, $form_orderby );
379 $pid_list = array(); // Initialize list of PIDs for Superbill option
380 $totalAppontments = count($appointments);
382 foreach ( $appointments as $appointment ) {
383 array_push($pid_list,$appointment['pid']);
384 $patient_id = $appointment['pid'];
385 $docname = $appointment['ulname'] . ', ' . $appointment['ufname'] . ' ' . $appointment['umname'];
387 $errmsg = "";
388 $pc_apptstatus = $appointment['pc_apptstatus'];
392 <tr valign='top' id='p1.<?php echo attr($patient_id) ?>' bgcolor='<?php echo $bgcolor ?>'>
393 <td class="detail">&nbsp;<?php echo ($docname == $lastdocname) ? "" : text($docname) ?>
394 </td>
396 <td class="detail" <?php echo $showDate ? '' : 'style="display:none;"' ?>><?php echo text(oeFormatShortDate($appointment['pc_eventDate'])) ?>
397 </td>
399 <td class="detail"><?php echo text(oeFormatTime($appointment['pc_startTime'])) ?>
400 </td>
402 <td class="detail">&nbsp;<?php echo text($appointment['fname'] . " " . $appointment['lname']) ?>
403 </td>
405 <td class="detail">&nbsp;<?php echo text($appointment['pubpid']) ?></td>
407 <td class="detail">&nbsp;<?php echo text($appointment['phone_home']) ?></td>
409 <td class="detail">&nbsp;<?php echo text($appointment['phone_cell']) ?></td>
411 <td class="detail">&nbsp;<?php echo text(xl_appt_category($appointment['pc_catname'])) ?></td>
413 <td class="detail">&nbsp;
414 <?php
415 //Appointment Status
416 if($pc_apptstatus != ""){
417 $frow['data_type']=1;
418 $frow['list_id']='apptstat';
419 generate_print_field($frow, $pc_apptstatus);
422 </td>
423 </tr>
425 <?php if ($patient_id && $incl_reminders) {
426 // collect reminders first, so can skip it if empty
427 $rems = fetch_reminders ($patient_id, $appointment['pc_eventDate']);
428 } ?>
429 <?php if ($patient_id && (!empty($rems) || !empty($appointment['pc_hometext']))) { // Not display of available slot or not showing reminders and comments empty ?>
430 <tr valign='top' id='p2.<?php echo attr($patient_id) ?>' >
431 <td colspan=<?php echo $showDate ? '"3"' : '"2"' ?> class="detail" />
432 <td colspan=<?php echo ($incl_reminders ? "3":"6") ?> class="detail" align='left'>
433 <?php
434 if (trim($appointment['pc_hometext'])) {
435 echo '<b>'.xlt('Comments') .'</b>: '.attr($appointment['pc_hometext']);
437 if ($incl_reminders) {
438 echo "<td class='detail' colspan='3' align='left'>";
439 $new_line = '';
440 foreach ($rems as $rem_due => $rem_items) {
441 echo "$new_line<b>$rem_due</b>: ".attr($rem_items);
442 $new_line = '<br>';
444 echo "</td>";
447 </td>
448 </tr>
449 <?php
450 } // End of row 2 display
452 $lastdocname = $docname;
454 // assign the session key with the $pid_list array - note array might be empty -- handle on the printed_fee_sheet.php page.
455 $_SESSION['pidList'] = $pid_list;
457 <tr>
458 <td colspan="10" align="left"><?php echo xlt('Total number of appointments'); ?>:&nbsp;<?php echo text($totalAppontments);?></td>
459 </tr>
460 </tbody>
461 </table>
462 </div>
463 <!-- end of search results --> <?php } else { ?>
464 <div class='text'><?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?>
465 </div>
466 <?php } ?> <input type="hidden" name="form_orderby"
467 value="<?php echo attr($form_orderby) ?>" /> <input type="hidden"
468 name="patient" value="<?php echo attr($patient) ?>" /> <input type='hidden'
469 name='form_refresh' id='form_refresh' value='' /></form>
471 <script type="text/javascript">
473 <?php
474 if ($alertmsg) { echo " alert('$alertmsg');\n"; }
477 </script>
479 </body>
481 <!-- stuff for the popup calendar -->
482 <style type="text/css">
483 @import url(../../library/dynarch_calendar.css);
484 </style>
485 <script type="text/javascript" src="../../library/dynarch_calendar.js"></script>
486 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
487 <script type="text/javascript"
488 src="../../library/dynarch_calendar_setup.js"></script>
489 <script type="text/javascript">
490 Calendar.setup({inputField:"form_from_date", ifFormat:"%Y-%m-%d", button:"img_from_date"});
491 Calendar.setup({inputField:"form_to_date", ifFormat:"%Y-%m-%d", button:"img_to_date"});
492 </script>
494 </html>