changed links to https and completed noopener stuff
[openemr.git] / interface / reports / appointments_report.php
blob691608f73c923ab6d58d05d0393b1572d4820b19
1 <?php
2 /**
3 * This report shows upcoming appointments with filtering and
4 * sorting by patient, practitioner, appointment type, and date.
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2005-2016 Rod Roark <rod@sunsetsystems.com>
11 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once("../globals.php");
17 require_once("../../library/patient.inc");
18 require_once "$srcdir/options.inc.php";
19 require_once "$srcdir/appointments.inc.php";
20 require_once "$srcdir/clinical_rules.php";
22 use OpenEMR\Core\Header;
24 if (!empty($_POST)) {
25 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
26 csrfNotVerified();
30 # Clear the pidList session whenever load this page.
31 # This session will hold array of patients that are listed in this
32 # report, which is then used by the 'Superbills' and 'Address Labels'
33 # features on this report.
34 unset($_SESSION['pidList']);
36 $alertmsg = ''; // not used yet but maybe later
37 $patient = $_REQUEST['patient'];
39 if ($patient && !isset($_POST['form_from_date'])) {
40 // If a specific patient, default to 2 years ago.
41 $tmp = date('Y') - 2;
42 $from_date = date("$tmp-m-d");
43 $to_date = date('Y-m-d');
44 } else {
45 $from_date = isset($_POST['form_from_date']) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-m-d');
46 $to_date = isset($_POST['form_to_date']) ? DateToYYYYMMDD($_POST['form_to_date']) : date('Y-m-d');
49 $show_available_times = false;
50 if ($_POST['form_show_available']) {
51 $show_available_times = true;
54 $chk_with_out_provider = false;
55 if ($_POST['with_out_provider']) {
56 $chk_with_out_provider = true;
59 $chk_with_out_facility = false;
60 if ($_POST['with_out_facility']) {
61 $chk_with_out_facility = true;
64 $provider = $_POST['form_provider'];
65 $facility = $_POST['form_facility']; //(CHEMED) facility filter
66 $form_orderby = getComparisonOrder($_REQUEST['form_orderby']) ? $_REQUEST['form_orderby'] : 'date';
68 // Reminders related stuff
69 $incl_reminders = isset($_POST['incl_reminders']) ? 1 : 0;
70 function fetch_rule_txt($list_id, $option_id)
72 $rs = sqlQuery(
73 'SELECT title, seq from list_options WHERE list_id = ? AND option_id = ? AND activity = 1',
74 array($list_id, $option_id)
76 $rs['title'] = xl_list_label($rs['title']);
77 return $rs;
79 function fetch_reminders($pid, $appt_date)
81 $rems = test_rules_clinic('', 'passive_alert', $appt_date, 'reminders-due', $pid);
82 $seq_due = array();
83 $seq_cat = array();
84 $seq_act = array();
85 foreach ($rems as $ix => $rem) {
86 $rem_out = array();
87 $rule_txt = fetch_rule_txt('rule_reminder_due_opt', $rem['due_status']);
88 $seq_due[$ix] = $rule_txt['seq'];
89 $rem_out['due_txt'] = $rule_txt['title'];
90 $rule_txt = fetch_rule_txt('rule_action_category', $rem['category']);
91 $seq_cat[$ix] = $rule_txt['seq'];
92 $rem_out['cat_txt'] = $rule_txt['title'];
93 $rule_txt = fetch_rule_txt('rule_action', $rem['item']);
94 $seq_act[$ix] = $rule_txt['seq'];
95 $rem_out['act_txt'] = $rule_txt['title'];
96 $rems_out[$ix] = $rem_out;
99 array_multisort($seq_due, SORT_DESC, $seq_cat, SORT_ASC, $seq_act, SORT_ASC, $rems_out);
100 $rems = array();
101 foreach ($rems_out as $ix => $rem) {
102 $rems[$rem['due_txt']] .= (isset($rems[$rem['due_txt']]) ? ', ':'').
103 $rem['act_txt'].' '.$rem['cat_txt'];
106 return $rems;
110 <html>
112 <head>
113 <title><?php echo xlt('Appointments Report'); ?></title>
115 <?php Header::setupHeader(["datetime-picker","report-helper"]); ?>
117 <script type="text/javascript">
118 $(document).ready(function() {
119 var win = top.printLogSetup ? top : opener.top;
120 win.printLogSetup(document.getElementById('printbutton'));
122 $('.datepicker').datetimepicker({
123 <?php $datetimepicker_timepicker = false; ?>
124 <?php $datetimepicker_showseconds = false; ?>
125 <?php $datetimepicker_formatInput = true; ?>
126 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
127 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
132 function dosort(orderby) {
133 var f = document.forms[0];
134 f.form_orderby.value = orderby;
135 f.submit();
136 return false;
139 function oldEvt(eventid) {
140 dlgopen('../main/calendar/add_edit_event.php?eid=' + encodeURIComponent(eventid), 'blank', 775, 500);
143 function refreshme() {
144 // location.reload();
145 document.forms[0].submit();
147 </script>
149 <style type="text/css">
150 /* specifically include & exclude from printing */
151 @media print {
152 #report_parameters {
153 visibility: hidden;
154 display: none;
156 #report_parameters_daterange {
157 visibility: visible;
158 display: inline;
160 #report_results table {
161 margin-top: 0px;
165 /* specifically exclude some from the screen */
166 @media screen {
167 #report_parameters_daterange {
168 visibility: hidden;
169 display: none;
172 </style>
173 </head>
175 <body class="body_top">
177 <!-- Required for the popup date selectors -->
178 <div id="overDiv"
179 style="position: absolute; visibility: hidden; z-index: 1000;"></div>
181 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Appointments'); ?></span>
183 <div id="report_parameters_daterange"><?php echo text(oeFormatShortDate($from_date)) ." &nbsp; " . xlt('to') . " &nbsp; ". text(oeFormatShortDate($to_date)); ?>
184 </div>
186 <form method='post' name='theform' id='theform' action='appointments_report.php' onsubmit='return top.restoreSession()'>
187 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
189 <div id="report_parameters">
191 <table>
192 <tr>
193 <td width='650px'>
194 <div style='float: left'>
196 <table class='text'>
197 <tr>
198 <td class='control-label'><?php echo xlt('Facility'); ?>:</td>
199 <td><?php dropdown_facility($facility, 'form_facility'); ?>
200 </td>
201 <td class='control-label'><?php echo xlt('Provider'); ?>:</td>
202 <td><?php
204 // Build a drop-down list of providers.
207 $query = "SELECT id, lname, fname FROM users WHERE ".
208 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
210 $ures = sqlStatement($query);
212 echo " <select name='form_provider' class='form-control'>\n";
213 echo " <option value=''>-- " . xlt('All') . " --\n";
215 while ($urow = sqlFetchArray($ures)) {
216 $provid = $urow['id'];
217 echo " <option value='" . attr($provid) . "'";
218 if ($provid == $_POST['form_provider']) {
219 echo " selected";
222 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
225 echo " </select>\n";
227 </td>
228 </tr>
229 <tr>
230 <td class='control-label'><?php echo xlt('From'); ?>:</td>
231 <td><input type='text' name='form_from_date' id="form_from_date"
232 class='datepicker form-control'
233 size='10' value='<?php echo attr(oeFormatShortDate($from_date)); ?>'>
234 </td>
235 <td class='control-label'><?php echo xlt('To'); ?>:</td>
236 <td><input type='text' name='form_to_date' id="form_to_date"
237 class='datepicker form-control'
238 size='10' value='<?php echo attr(oeFormatShortDate($to_date)); ?>'>
239 </td>
240 </tr>
242 <tr>
243 <td class='control-label'><?php echo xlt('Status'); # status code drop down creation ?>:</td>
244 <td><?php generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'All'), $_POST['form_apptstatus']);?></td>
245 <td><?php echo xlt('Category') #category drop down creation ?>:</td>
246 <td>
247 <select id="form_apptcat" name="form_apptcat" class="form-control">
248 <?php
249 $categories=fetchAppointmentCategories();
250 echo "<option value='ALL'>".xlt("All")."</option>";
251 while ($cat=sqlFetchArray($categories)) {
252 echo "<option value='".attr($cat['id'])."'";
253 if ($cat['id']==$_POST['form_apptcat']) {
254 echo " selected='true' ";
257 echo ">".text(xl_appt_category($cat['category']))."</option>";
260 </select>
261 </td>
262 </tr>
263 <tr>
264 <td></td>
265 <td>
266 <div class="checkbox">
267 <label><input type='checkbox' name='form_show_available'
268 <?php echo ($show_available_times) ? ' checked' : ''; ?>> <?php echo xlt('Show Available Times'); # check this to show available times on the report ?>
269 </label>
270 </div>
271 </td>
272 <td></td>
273 <td>
274 <div class="checkbox">
275 <label><input type="checkbox" name="incl_reminders" id="incl_reminders"
276 <?php echo ($incl_reminders ? ' checked':''); # This will include the reminder for the patients on the report ?>>
277 <?php echo xlt('Show Reminders'); ?>
278 </label>
279 </div>
280 </td>
282 <tr>
283 <td></td>
284 <?php # these two selects will show entries that do not have a facility or a provider ?>
285 <td>
286 <div class="checkbox">
287 <label><input type="checkbox" name="with_out_provider" id="with_out_provider" <?php echo ($chk_with_out_provider) ? "checked" : ""; ?>><?php echo xlt('Without Provider'); ?>
288 </label>
289 </div>
290 </td>
291 <td></td>
292 <td>
293 <div class="checkbox">
294 <label><input type="checkbox" name="with_out_facility" id="with_out_facility" <?php echo ($chk_with_out_facility) ? "checked" : ""; ?>>&nbsp;<?php echo xlt('Without Facility'); ?>
295 </label>
296 </div>
297 </td>
298 </tr>
300 </table>
302 </div>
304 </td>
305 <td align='left' valign='middle' height="100%">
306 <table style='border-left: 1px solid; width: 100%; height: 100%'>
307 <tr>
308 <td>
309 <div class="text-center">
310 <div class="btn-group" role="group">
311 <a href='#' class='btn btn-default btn-save' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
312 <?php echo xlt('Submit'); ?>
313 </a>
314 <?php if ($_POST['form_refresh'] || $_POST['form_orderby']) { ?>
315 <a href='#' class='btn btn-default btn-print' id='printbutton'>
316 <?php echo xlt('Print'); ?>
317 </a>
318 <a href='#' class='btn btn-default btn-transmit' onclick='window.open("../patient_file/printed_fee_sheet.php?fill=2", "_blank").opener = null' onsubmit='return top.restoreSession()'>
319 <?php echo xlt('Superbills'); ?>
320 </a>
321 <a href='#' class='btn btn-default btn-transmit' onclick='window.open("../patient_file/addr_appt_label.php", "_blank").opener = null' onsubmit='return top.restoreSession()'>
322 <?php echo xlt('Address Labels'); ?>
323 </a>
324 <?php } ?>
325 </div>
326 </div>
327 </td>
328 </tr>
329 <tr>&nbsp;&nbsp;<?php echo xlt('Most column headers can be clicked to change sort order') ?></tr>
330 </table>
331 </td>
332 </tr>
333 </table>
335 </div>
336 <!-- end of search parameters --> <?php
337 if ($_POST['form_refresh'] || $_POST['form_orderby']) {
338 $showDate = ($from_date != $to_date) || (!$to_date);
340 <div id="report_results">
341 <table>
343 <thead>
344 <th><a href="nojs.php" onclick="return dosort('doctor')"
345 <?php echo ($form_orderby == "doctor") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('Provider'); ?>
346 </a></th>
348 <th <?php echo $showDate ? '' : 'style="display:none;"' ?>><a href="nojs.php" onclick="return dosort('date')"
349 <?php echo ($form_orderby == "date") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('Date'); ?></a>
350 </th>
352 <th><a href="nojs.php" onclick="return dosort('time')"
353 <?php echo ($form_orderby == "time") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('Time'); ?></a>
354 </th>
356 <th><a href="nojs.php" onclick="return dosort('patient')"
357 <?php echo ($form_orderby == "patient") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('Patient'); ?></a>
358 </th>
360 <th><a href="nojs.php" onclick="return dosort('pubpid')"
361 <?php echo ($form_orderby == "pubpid") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('ID'); ?></a>
362 </th>
364 <th><?php echo xlt('Home'); //Sorting by phone# not really useful ?></th>
366 <th><?php echo xlt('Cell'); //Sorting by phone# not really useful ?></th>
368 <th><a href="nojs.php" onclick="return dosort('type')"
369 <?php echo ($form_orderby == "type") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('Type'); ?></a>
370 </th>
372 <th><a href="nojs.php" onclick="return dosort('status')"
373 <?php echo ($form_orderby == "status") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('Status'); ?></a>
374 </th>
375 </thead>
376 <tbody>
377 <!-- added for better print-ability -->
378 <?php
380 $lastdocname = "";
381 //Appointment Status Checking
382 $form_apptstatus = $_POST['form_apptstatus'];
383 $form_apptcat=null;
384 if (isset($_POST['form_apptcat'])) {
385 if ($form_apptcat!="ALL") {
386 $form_apptcat=intval($_POST['form_apptcat']);
390 //Without provider and facility data checking
391 $with_out_provider = null;
392 $with_out_facility = null;
394 if (isset($_POST['with_out_provider'])) {
395 $with_out_provider = $_POST['with_out_provider'];
398 if (isset($_POST['with_out_facility'])) {
399 $with_out_facility = $_POST['with_out_facility'];
402 $appointments = fetchAppointments($from_date, $to_date, $patient, $provider, $facility, $form_apptstatus, $with_out_provider, $with_out_facility, $form_apptcat);
404 if ($show_available_times) {
405 $availableSlots = getAvailableSlots($from_date, $to_date, $provider, $facility);
406 $appointments = array_merge($appointments, $availableSlots);
409 $appointments = sortAppointments($appointments, $form_orderby);
410 $pid_list = array(); // Initialize list of PIDs for Superbill option
411 $totalAppontments = count($appointments);
413 foreach ($appointments as $appointment) {
414 array_push($pid_list, $appointment['pid']);
415 $patient_id = $appointment['pid'];
416 $docname = $appointment['ulname'] . ', ' . $appointment['ufname'] . ' ' . $appointment['umname'];
418 $errmsg = "";
419 $pc_apptstatus = $appointment['pc_apptstatus'];
423 <tr valign='top' id='p1.<?php echo attr($patient_id) ?>' bgcolor='<?php echo attr($bgcolor); ?>'>
424 <td class="detail">&nbsp;<?php echo ($docname == $lastdocname) ? "" : text($docname) ?>
425 </td>
427 <td class="detail" <?php echo $showDate ? '' : 'style="display:none;"' ?>><?php echo text(oeFormatShortDate($appointment['pc_eventDate'])) ?>
428 </td>
430 <td class="detail"><?php echo text(oeFormatTime($appointment['pc_startTime'])) ?>
431 </td>
433 <td class="detail">&nbsp;<?php echo text($appointment['fname'] . " " . $appointment['lname']) ?>
434 </td>
436 <td class="detail">&nbsp;<?php echo text($appointment['pubpid']) ?></td>
438 <td class="detail">&nbsp;<?php echo text($appointment['phone_home']) ?></td>
440 <td class="detail">&nbsp;<?php echo text($appointment['phone_cell']) ?></td>
442 <td class="detail">&nbsp;<?php echo text(xl_appt_category($appointment['pc_catname'])) ?></td>
444 <td class="detail">&nbsp;
445 <?php
446 //Appointment Status
447 if ($pc_apptstatus != "") {
448 echo text(getListItemTitle('apptstat', $pc_apptstatus));
451 </td>
452 </tr>
454 <?php
455 if ($patient_id && $incl_reminders) {
456 // collect reminders first, so can skip it if empty
457 $rems = fetch_reminders($patient_id, $appointment['pc_eventDate']);
460 <?php
461 if ($patient_id && (!empty($rems) || !empty($appointment['pc_hometext']))) { // Not display of available slot or not showing reminders and comments empty ?>
462 <tr valign='top' id='p2.<?php echo attr($patient_id) ?>' >
463 <td colspan=<?php echo $showDate ? '"3"' : '"2"' ?> class="detail" />
464 <td colspan=<?php echo ($incl_reminders ? "3":"6") ?> class="detail" align='left'>
465 <?php
466 if (trim($appointment['pc_hometext'])) {
467 echo '<b>'.xlt('Comments') .'</b>: '.text($appointment['pc_hometext']);
470 if ($incl_reminders) {
471 echo "<td class='detail' colspan='3' align='left'>";
472 $new_line = '';
473 foreach ($rems as $rem_due => $rem_items) {
474 echo "$new_line<b>$rem_due</b>: ".attr($rem_items);
475 $new_line = '<br>';
478 echo "</td>";
481 </td>
482 </tr>
483 <?php
484 } // End of row 2 display
486 $lastdocname = $docname;
489 // assign the session key with the $pid_list array - note array might be empty -- handle on the printed_fee_sheet.php page.
490 $_SESSION['pidList'] = $pid_list;
492 <tr>
493 <td colspan="10" align="left"><?php echo xlt('Total number of appointments'); ?>:&nbsp;<?php echo text($totalAppontments);?></td>
494 </tr>
495 </tbody>
496 </table>
497 </div>
498 <!-- end of search results -->
499 <?php } else { ?>
500 <div class='text'><?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?>
501 </div>
502 <?php } ?> <input type="hidden" name="form_orderby"
503 value="<?php echo attr($form_orderby) ?>" /> <input type="hidden"
504 name="patient" value="<?php echo attr($patient) ?>" /> <input type='hidden'
505 name='form_refresh' id='form_refresh' value='' /></form>
507 <script type="text/javascript">
509 <?php
510 if ($alertmsg) {
511 echo " alert(" . js_escape($alertmsg) . ");\n";
515 </script>
517 </body>
519 </html>