ongoing internationalization of date widget
[openemr.git] / interface / reports / appointments_report.php
blob3d82f895a536e1d2cb44edb0d8e48cc68817cad2
1 <?php
2 /**
3 * This report shows upcoming appointments with filtering and
4 * sorting by patient, practitioner, appointment type, and date.
5 * 2012-01-01 - Added display of home and cell phone and fixed header
6 * 2015-06-19 - brought up to security standards terry@lillysystems.com
8 * Copyright (C) 2005-2016 Rod Roark <rod@sunsetsystems.com>
9 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * LICENSE: This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
22 * @package OpenEMR
23 * @author Rod Roark <rod@sunsetsystems.com>
24 * @author Brady Miller <brady.g.miller@gmail.com>
25 * @link http://www.open-emr.org
31 use OpenEMR\Core\Header;
33 require_once("../globals.php");
34 require_once("../../library/patient.inc");
35 require_once "$srcdir/options.inc.php";
36 require_once "$srcdir/appointments.inc.php";
37 require_once "$srcdir/clinical_rules.php";
39 # Clear the pidList session whenever load this page.
40 # This session will hold array of patients that are listed in this
41 # report, which is then used by the 'Superbills' and 'Address Labels'
42 # features on this report.
43 unset($_SESSION['pidList']);
45 $alertmsg = ''; // not used yet but maybe later
46 $patient = $_REQUEST['patient'];
48 if ($patient && ! $_POST['form_from_date']) {
49 // If a specific patient, default to 2 years ago.
50 $tmp = date('Y') - 2;
51 $from_date = date("$tmp-m-d");
52 } else {
53 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
54 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
57 $show_available_times = false;
58 if ($_POST['form_show_available']) {
59 $show_available_times = true;
62 $chk_with_out_provider = false;
63 if ($_POST['with_out_provider']) {
64 $chk_with_out_provider = true;
67 $chk_with_out_facility = false;
68 if ($_POST['with_out_facility']) {
69 $chk_with_out_facility = true;
72 //$to_date = fixDate($_POST['form_to_date'], '');
73 $provider = $_POST['form_provider'];
74 $facility = $_POST['form_facility']; //(CHEMED) facility filter
75 $form_orderby = getComparisonOrder($_REQUEST['form_orderby']) ? $_REQUEST['form_orderby'] : 'date';
77 // Reminders related stuff
78 $incl_reminders = isset($_POST['incl_reminders']) ? 1 : 0;
79 function fetch_rule_txt($list_id, $option_id)
81 $rs = sqlQuery(
82 'SELECT title, seq from list_options WHERE list_id = ? AND option_id = ? AND activity = 1',
83 array($list_id, $option_id)
85 $rs['title'] = xl_list_label($rs['title']);
86 return $rs;
88 function fetch_reminders($pid, $appt_date)
90 $rems = test_rules_clinic('', 'passive_alert', $appt_date, 'reminders-due', $pid);
91 $seq_due = array();
92 $seq_cat = array();
93 $seq_act = array();
94 foreach ($rems as $ix => $rem) {
95 $rem_out = array();
96 $rule_txt = fetch_rule_txt('rule_reminder_due_opt', $rem['due_status']);
97 $seq_due[$ix] = $rule_txt['seq'];
98 $rem_out['due_txt'] = $rule_txt['title'];
99 $rule_txt = fetch_rule_txt('rule_action_category', $rem['category']);
100 $seq_cat[$ix] = $rule_txt['seq'];
101 $rem_out['cat_txt'] = $rule_txt['title'];
102 $rule_txt = fetch_rule_txt('rule_action', $rem['item']);
103 $seq_act[$ix] = $rule_txt['seq'];
104 $rem_out['act_txt'] = $rule_txt['title'];
105 $rems_out[$ix] = $rem_out;
108 array_multisort($seq_due, SORT_DESC, $seq_cat, SORT_ASC, $seq_act, SORT_ASC, $rems_out);
109 $rems = array();
110 foreach ($rems_out as $ix => $rem) {
111 $rems[$rem['due_txt']] .= (isset($rems[$rem['due_txt']]) ? ', ':'').
112 $rem['act_txt'].' '.$rem['cat_txt'];
115 return $rems;
119 <html>
121 <head>
123 <title><?php echo xlt('Appointments Report'); ?></title>
125 <?php Header::setupHeader(["datetime-picker","report-helper"]); ?>
127 <script type="text/javascript">
129 var mypcc = '<?php echo $GLOBALS['phone_country_code'] ?>';
131 $(document).ready(function() {
132 var win = top.printLogSetup ? top : opener.top;
133 win.printLogSetup(document.getElementById('printbutton'));
135 $('.datepicker').datetimepicker({
136 <?php $datetimepicker_timepicker = false; ?>
137 <?php $datetimepicker_showseconds = false; ?>
138 <?php $datetimepicker_formatInput = false; ?>
139 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
140 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
145 function dosort(orderby) {
146 var f = document.forms[0];
147 f.form_orderby.value = orderby;
148 f.submit();
149 return false;
152 function oldEvt(eventid) {
153 dlgopen('../main/calendar/add_edit_event.php?eid=' + eventid, 'blank', 775, 500);
156 function refreshme() {
157 // location.reload();
158 document.forms[0].submit();
161 </script>
163 <style type="text/css">
164 /* specifically include & exclude from printing */
165 @media print {
166 #report_parameters {
167 visibility: hidden;
168 display: none;
170 #report_parameters_daterange {
171 visibility: visible;
172 display: inline;
174 #report_results table {
175 margin-top: 0px;
179 /* specifically exclude some from the screen */
180 @media screen {
181 #report_parameters_daterange {
182 visibility: hidden;
183 display: none;
186 </style>
187 </head>
189 <body class="body_top">
191 <!-- Required for the popup date selectors -->
192 <div id="overDiv"
193 style="position: absolute; visibility: hidden; z-index: 1000;"></div>
195 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Appointments'); ?></span>
197 <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 ?>
198 </div>
200 <form method='post' name='theform' id='theform' action='appointments_report.php' onsubmit='return top.restoreSession()'>
202 <div id="report_parameters">
204 <table>
205 <tr>
206 <td width='650px'>
207 <div style='float: left'>
209 <table class='text'>
210 <tr>
211 <td class='control-label'><?php echo xlt('Facility'); ?>:</td>
212 <td><?php dropdown_facility($facility, 'form_facility'); ?>
213 </td>
214 <td class='control-label'><?php echo xlt('Provider'); ?>:</td>
215 <td><?php
217 // Build a drop-down list of providers.
220 $query = "SELECT id, lname, fname FROM users WHERE ".
221 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
223 $ures = sqlStatement($query);
225 echo " <select name='form_provider' class='form-control'>\n";
226 echo " <option value=''>-- " . xlt('All') . " --\n";
228 while ($urow = sqlFetchArray($ures)) {
229 $provid = $urow['id'];
230 echo " <option value='" . attr($provid) . "'";
231 if ($provid == $_POST['form_provider']) {
232 echo " selected";
235 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
238 echo " </select>\n";
240 </td>
241 </tr>
242 <tr>
243 <td class='control-label'><?php echo xlt('From'); ?>:</td>
244 <td><input type='text' name='form_from_date' id="form_from_date"
245 class='datepicker form-control'
246 size='10' value='<?php echo attr($from_date) ?>'
247 title='yyyy-mm-dd'>
248 </td>
249 <td class='control-label'><?php echo xlt('To'); ?>:</td>
250 <td><input type='text' name='form_to_date' id="form_to_date"
251 class='datepicker form-control'
252 size='10' value='<?php echo attr($to_date) ?>'
253 title='yyyy-mm-dd'>
254 </td>
255 </tr>
257 <tr>
258 <td class='control-label'><?php echo xlt('Status'); # status code drop down creation ?>:</td>
259 <td><?php generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'All'), $_POST['form_apptstatus']);?></td>
260 <td><?php echo xlt('Category') #category drop down creation ?>:</td>
261 <td>
262 <select id="form_apptcat" name="form_apptcat" class="form-control">
263 <?php
264 $categories=fetchAppointmentCategories();
265 echo "<option value='ALL'>".xlt("All")."</option>";
266 while ($cat=sqlFetchArray($categories)) {
267 echo "<option value='".attr($cat['id'])."'";
268 if ($cat['id']==$_POST['form_apptcat']) {
269 echo " selected='true' ";
272 echo ">".text(xl_appt_category($cat['category']))."</option>";
275 </select>
276 </td>
277 </tr>
278 <tr>
279 <td></td>
280 <td>
281 <div class="checkbox">
282 <label><input type='checkbox' name='form_show_available'
283 <?php if ($show_available_times) {
284 echo ' checked';
285 } ?>> <?php echo xlt('Show Available Times'); # check this to show available times on the report ?>
286 </label>
287 </div>
288 </td>
289 <td></td>
290 <td>
291 <div class="checkbox">
292 <label><input type="checkbox" name="incl_reminders" id="incl_reminders"
293 <?php echo ($incl_reminders ? ' checked':''); # This will include the reminder for the patients on the report ?>>
294 <?php echo xlt('Show Reminders'); ?>
295 </label>
296 </div>
297 </td>
299 <tr>
300 <td></td>
301 <?php # these two selects will show entries that do not have a facility or a provider ?>
302 <td>
303 <div class="checkbox">
304 <label><input type="checkbox" name="with_out_provider" id="with_out_provider" <?php if ($chk_with_out_provider) {
305 echo "checked";
306 }?>><?php echo xlt('Without Provider'); ?>
307 </label>
308 </div>
309 </td>
310 <td></td>
311 <td>
312 <div class="checkbox">
313 <label><input type="checkbox" name="with_out_facility" id="with_out_facility" <?php if ($chk_with_out_facility) {
314 echo "checked";
315 }?>>&nbsp;<?php echo xlt('Without Facility'); ?>
316 </label>
317 </div>
318 </td>
319 </tr>
321 </table>
323 </div>
325 </td>
326 <td align='left' valign='middle' height="100%">
327 <table style='border-left: 1px solid; width: 100%; height: 100%'>
328 <tr>
329 <td>
330 <div class="text-center">
331 <div class="btn-group" role="group">
332 <a href='#' class='btn btn-default btn-save' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
333 <?php echo xlt('Submit'); ?>
334 </a>
335 <?php if ($_POST['form_refresh'] || $_POST['form_orderby']) { ?>
336 <a href='#' class='btn btn-default btn-print' id='printbutton'>
337 <?php echo xlt('Print'); ?>
338 </a>
339 <a href='#' class='btn btn-default btn-transmit' onclick='window.open("../patient_file/printed_fee_sheet.php?fill=2","_blank")' onsubmit='return top.restoreSession()'>
340 <?php echo xlt('Superbills'); ?>
341 </a>
342 <a href='#' class='btn btn-default btn-transmit' onclick='window.open("../patient_file/addr_appt_label.php","_blank")' onsubmit='return top.restoreSession()'>
343 <?php echo xlt('Address Labels'); ?>
344 </a>
345 <?php } ?>
346 </div>
347 </div>
348 </td>
349 </tr>
350 <tr>&nbsp;&nbsp;<?php echo xlt('Most column headers can be clicked to change sort order') ?></tr>
351 </table>
352 </td>
353 </tr>
354 </table>
356 </div>
357 <!-- end of search parameters --> <?php
358 if ($_POST['form_refresh'] || $_POST['form_orderby']) {
359 $showDate = ($from_date != $to_date) || (!$to_date);
361 <div id="report_results">
362 <table>
364 <thead>
365 <th><a href="nojs.php" onclick="return dosort('doctor')"
366 <?php if ($form_orderby == "doctor") {
367 echo " style=\"color:#00cc00\"";
368 } ?>><?php echo xlt('Provider'); ?>
369 </a></th>
371 <th <?php echo $showDate ? '' : 'style="display:none;"' ?>><a href="nojs.php" onclick="return dosort('date')"
372 <?php if ($form_orderby == "date") {
373 echo " style=\"color:#00cc00\"";
374 } ?>><?php echo xlt('Date'); ?></a>
375 </th>
377 <th><a href="nojs.php" onclick="return dosort('time')"
378 <?php if ($form_orderby == "time") {
379 echo " style=\"color:#00cc00\"";
380 } ?>><?php echo xlt('Time'); ?></a>
381 </th>
383 <th><a href="nojs.php" onclick="return dosort('patient')"
384 <?php if ($form_orderby == "patient") {
385 echo " style=\"color:#00cc00\"";
386 } ?>><?php echo xlt('Patient'); ?></a>
387 </th>
389 <th><a href="nojs.php" onclick="return dosort('pubpid')"
390 <?php if ($form_orderby == "pubpid") {
391 echo " style=\"color:#00cc00\"";
392 } ?>><?php echo xlt('ID'); ?></a>
393 </th>
395 <th><?php echo xlt('Home'); //Sorting by phone# not really useful ?></th>
397 <th><?php echo xlt('Cell'); //Sorting by phone# not really useful ?></th>
399 <th><a href="nojs.php" onclick="return dosort('type')"
400 <?php if ($form_orderby == "type") {
401 echo " style=\"color:#00cc00\"";
402 } ?>><?php echo xlt('Type'); ?></a>
403 </th>
405 <th><a href="nojs.php" onclick="return dosort('status')"
406 <?php if ($form_orderby == "status") {
407 echo " style=\"color:#00cc00\"";
408 } ?>><?php echo xlt('Status'); ?></a>
409 </th>
410 </thead>
411 <tbody>
412 <!-- added for better print-ability -->
413 <?php
415 $lastdocname = "";
416 //Appointment Status Checking
417 $form_apptstatus = $_POST['form_apptstatus'];
418 $form_apptcat=null;
419 if (isset($_POST['form_apptcat'])) {
420 if ($form_apptcat!="ALL") {
421 $form_apptcat=intval($_POST['form_apptcat']);
425 //Without provider and facility data checking
426 $with_out_provider = null;
427 $with_out_facility = null;
429 if (isset($_POST['with_out_provider'])) {
430 $with_out_provider = $_POST['with_out_provider'];
433 if (isset($_POST['with_out_facility'])) {
434 $with_out_facility = $_POST['with_out_facility'];
437 $appointments = fetchAppointments($from_date, $to_date, $patient, $provider, $facility, $form_apptstatus, $with_out_provider, $with_out_facility, $form_apptcat);
439 if ($show_available_times) {
440 $availableSlots = getAvailableSlots($from_date, $to_date, $provider, $facility);
441 $appointments = array_merge($appointments, $availableSlots);
444 $appointments = sortAppointments($appointments, $form_orderby);
445 $pid_list = array(); // Initialize list of PIDs for Superbill option
446 $totalAppontments = count($appointments);
448 foreach ($appointments as $appointment) {
449 array_push($pid_list, $appointment['pid']);
450 $patient_id = $appointment['pid'];
451 $docname = $appointment['ulname'] . ', ' . $appointment['ufname'] . ' ' . $appointment['umname'];
453 $errmsg = "";
454 $pc_apptstatus = $appointment['pc_apptstatus'];
458 <tr valign='top' id='p1.<?php echo attr($patient_id) ?>' bgcolor='<?php echo $bgcolor ?>'>
459 <td class="detail">&nbsp;<?php echo ($docname == $lastdocname) ? "" : text($docname) ?>
460 </td>
462 <td class="detail" <?php echo $showDate ? '' : 'style="display:none;"' ?>><?php echo text(oeFormatShortDate($appointment['pc_eventDate'])) ?>
463 </td>
465 <td class="detail"><?php echo text(oeFormatTime($appointment['pc_startTime'])) ?>
466 </td>
468 <td class="detail">&nbsp;<?php echo text($appointment['fname'] . " " . $appointment['lname']) ?>
469 </td>
471 <td class="detail">&nbsp;<?php echo text($appointment['pubpid']) ?></td>
473 <td class="detail">&nbsp;<?php echo text($appointment['phone_home']) ?></td>
475 <td class="detail">&nbsp;<?php echo text($appointment['phone_cell']) ?></td>
477 <td class="detail">&nbsp;<?php echo text(xl_appt_category($appointment['pc_catname'])) ?></td>
479 <td class="detail">&nbsp;
480 <?php
481 //Appointment Status
482 if ($pc_apptstatus != "") {
483 $frow['data_type']=1;
484 $frow['list_id']='apptstat';
485 generate_print_field($frow, $pc_apptstatus);
488 </td>
489 </tr>
491 <?php if ($patient_id && $incl_reminders) {
492 // collect reminders first, so can skip it if empty
493 $rems = fetch_reminders($patient_id, $appointment['pc_eventDate']);
494 } ?>
495 <?php if ($patient_id && (!empty($rems) || !empty($appointment['pc_hometext']))) { // Not display of available slot or not showing reminders and comments empty ?>
496 <tr valign='top' id='p2.<?php echo attr($patient_id) ?>' >
497 <td colspan=<?php echo $showDate ? '"3"' : '"2"' ?> class="detail" />
498 <td colspan=<?php echo ($incl_reminders ? "3":"6") ?> class="detail" align='left'>
499 <?php
500 if (trim($appointment['pc_hometext'])) {
501 echo '<b>'.xlt('Comments') .'</b>: '.attr($appointment['pc_hometext']);
504 if ($incl_reminders) {
505 echo "<td class='detail' colspan='3' align='left'>";
506 $new_line = '';
507 foreach ($rems as $rem_due => $rem_items) {
508 echo "$new_line<b>$rem_due</b>: ".attr($rem_items);
509 $new_line = '<br>';
512 echo "</td>";
515 </td>
516 </tr>
517 <?php
518 } // End of row 2 display
520 $lastdocname = $docname;
523 // assign the session key with the $pid_list array - note array might be empty -- handle on the printed_fee_sheet.php page.
524 $_SESSION['pidList'] = $pid_list;
526 <tr>
527 <td colspan="10" align="left"><?php echo xlt('Total number of appointments'); ?>:&nbsp;<?php echo text($totalAppontments);?></td>
528 </tr>
529 </tbody>
530 </table>
531 </div>
532 <!-- end of search results --> <?php } else { ?>
533 <div class='text'><?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?>
534 </div>
535 <?php } ?> <input type="hidden" name="form_orderby"
536 value="<?php echo attr($form_orderby) ?>" /> <input type="hidden"
537 name="patient" value="<?php echo attr($patient) ?>" /> <input type='hidden'
538 name='form_refresh' id='form_refresh' value='' /></form>
540 <script type="text/javascript">
542 <?php
543 if ($alertmsg) {
544 echo " alert('$alertmsg');\n";
548 </script>
550 </body>
552 </html>