Revert "1. add edit event fails when save edited single provider recurring events...
[openemr.git] / interface / reports / appointments_report.php
blobd4acfcc74114da251c03b85c46bfece6cf9a23b4
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 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 # Clear the pidList session whenever load this page.
25 # This session will hold array of patients that are listed in this
26 # report, which is then used by the 'Superbills' and 'Address Labels'
27 # features on this report.
28 unset($_SESSION['pidList']);
30 $alertmsg = ''; // not used yet but maybe later
31 $patient = $_REQUEST['patient'];
33 if ($patient && !isset($_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 $to_date = date('Y-m-d');
38 } else {
39 $from_date = isset($_POST['form_from_date']) ? DateToYYYYMMDD($_POST['form_from_date']) : date('Y-m-d');
40 $to_date = isset($_POST['form_to_date']) ? DateToYYYYMMDD($_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 $provider = $_POST['form_provider'];
59 $facility = $_POST['form_facility']; //(CHEMED) facility filter
60 $form_orderby = getComparisonOrder($_REQUEST['form_orderby']) ? $_REQUEST['form_orderby'] : 'date';
62 // Reminders related stuff
63 $incl_reminders = isset($_POST['incl_reminders']) ? 1 : 0;
64 function fetch_rule_txt($list_id, $option_id)
66 $rs = sqlQuery(
67 'SELECT title, seq from list_options WHERE list_id = ? AND option_id = ? AND activity = 1',
68 array($list_id, $option_id)
70 $rs['title'] = xl_list_label($rs['title']);
71 return $rs;
73 function fetch_reminders($pid, $appt_date)
75 $rems = test_rules_clinic('', 'passive_alert', $appt_date, 'reminders-due', $pid);
76 $seq_due = array();
77 $seq_cat = array();
78 $seq_act = array();
79 foreach ($rems as $ix => $rem) {
80 $rem_out = array();
81 $rule_txt = fetch_rule_txt('rule_reminder_due_opt', $rem['due_status']);
82 $seq_due[$ix] = $rule_txt['seq'];
83 $rem_out['due_txt'] = $rule_txt['title'];
84 $rule_txt = fetch_rule_txt('rule_action_category', $rem['category']);
85 $seq_cat[$ix] = $rule_txt['seq'];
86 $rem_out['cat_txt'] = $rule_txt['title'];
87 $rule_txt = fetch_rule_txt('rule_action', $rem['item']);
88 $seq_act[$ix] = $rule_txt['seq'];
89 $rem_out['act_txt'] = $rule_txt['title'];
90 $rems_out[$ix] = $rem_out;
93 array_multisort($seq_due, SORT_DESC, $seq_cat, SORT_ASC, $seq_act, SORT_ASC, $rems_out);
94 $rems = array();
95 foreach ($rems_out as $ix => $rem) {
96 $rems[$rem['due_txt']] .= (isset($rems[$rem['due_txt']]) ? ', ':'').
97 $rem['act_txt'].' '.$rem['cat_txt'];
100 return $rems;
104 <html>
106 <head>
107 <title><?php echo xlt('Appointments Report'); ?></title>
109 <?php Header::setupHeader(["datetime-picker","report-helper"]); ?>
111 <script type="text/javascript">
112 $(document).ready(function() {
113 var win = top.printLogSetup ? top : opener.top;
114 win.printLogSetup(document.getElementById('printbutton'));
116 $('.datepicker').datetimepicker({
117 <?php $datetimepicker_timepicker = false; ?>
118 <?php $datetimepicker_showseconds = false; ?>
119 <?php $datetimepicker_formatInput = true; ?>
120 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
121 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
126 function dosort(orderby) {
127 var f = document.forms[0];
128 f.form_orderby.value = orderby;
129 f.submit();
130 return false;
133 function oldEvt(eventid) {
134 dlgopen('../main/calendar/add_edit_event.php?eid=' + eventid, 'blank', 775, 500);
137 function refreshme() {
138 // location.reload();
139 document.forms[0].submit();
141 </script>
143 <style type="text/css">
144 /* specifically include & exclude from printing */
145 @media print {
146 #report_parameters {
147 visibility: hidden;
148 display: none;
150 #report_parameters_daterange {
151 visibility: visible;
152 display: inline;
154 #report_results table {
155 margin-top: 0px;
159 /* specifically exclude some from the screen */
160 @media screen {
161 #report_parameters_daterange {
162 visibility: hidden;
163 display: none;
166 </style>
167 </head>
169 <body class="body_top">
171 <!-- Required for the popup date selectors -->
172 <div id="overDiv"
173 style="position: absolute; visibility: hidden; z-index: 1000;"></div>
175 <span class='title'><?php echo xlt('Report'); ?> - <?php echo xlt('Appointments'); ?></span>
177 <div id="report_parameters_daterange"><?php echo text(oeFormatShortDate($from_date)) ." &nbsp; " . xlt('to') . " &nbsp; ". text(oeFormatShortDate($to_date)); ?>
178 </div>
180 <form method='post' name='theform' id='theform' action='appointments_report.php' onsubmit='return top.restoreSession()'>
182 <div id="report_parameters">
184 <table>
185 <tr>
186 <td width='650px'>
187 <div style='float: left'>
189 <table class='text'>
190 <tr>
191 <td class='control-label'><?php echo xlt('Facility'); ?>:</td>
192 <td><?php dropdown_facility($facility, 'form_facility'); ?>
193 </td>
194 <td class='control-label'><?php echo xlt('Provider'); ?>:</td>
195 <td><?php
197 // Build a drop-down list of providers.
200 $query = "SELECT id, lname, fname FROM users WHERE ".
201 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
203 $ures = sqlStatement($query);
205 echo " <select name='form_provider' class='form-control'>\n";
206 echo " <option value=''>-- " . xlt('All') . " --\n";
208 while ($urow = sqlFetchArray($ures)) {
209 $provid = $urow['id'];
210 echo " <option value='" . attr($provid) . "'";
211 if ($provid == $_POST['form_provider']) {
212 echo " selected";
215 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
218 echo " </select>\n";
220 </td>
221 </tr>
222 <tr>
223 <td class='control-label'><?php echo xlt('From'); ?>:</td>
224 <td><input type='text' name='form_from_date' id="form_from_date"
225 class='datepicker form-control'
226 size='10' value='<?php echo attr(oeFormatShortDate($from_date)); ?>'>
227 </td>
228 <td class='control-label'><?php echo xlt('To'); ?>:</td>
229 <td><input type='text' name='form_to_date' id="form_to_date"
230 class='datepicker form-control'
231 size='10' value='<?php echo attr(oeFormatShortDate($to_date)); ?>'>
232 </td>
233 </tr>
235 <tr>
236 <td class='control-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" class="form-control">
241 <?php
242 $categories=fetchAppointmentCategories();
243 echo "<option value='ALL'>".xlt("All")."</option>";
244 while ($cat=sqlFetchArray($categories)) {
245 echo "<option value='".attr($cat['id'])."'";
246 if ($cat['id']==$_POST['form_apptcat']) {
247 echo " selected='true' ";
250 echo ">".text(xl_appt_category($cat['category']))."</option>";
253 </select>
254 </td>
255 </tr>
256 <tr>
257 <td></td>
258 <td>
259 <div class="checkbox">
260 <label><input type='checkbox' name='form_show_available'
261 <?php echo ($show_available_times) ? ' checked' : ''; ?>> <?php echo xlt('Show Available Times'); # check this to show available times on the report ?>
262 </label>
263 </div>
264 </td>
265 <td></td>
266 <td>
267 <div class="checkbox">
268 <label><input type="checkbox" name="incl_reminders" id="incl_reminders"
269 <?php echo ($incl_reminders ? ' checked':''); # This will include the reminder for the patients on the report ?>>
270 <?php echo xlt('Show Reminders'); ?>
271 </label>
272 </div>
273 </td>
275 <tr>
276 <td></td>
277 <?php # these two selects will show entries that do not have a facility or a provider ?>
278 <td>
279 <div class="checkbox">
280 <label><input type="checkbox" name="with_out_provider" id="with_out_provider" <?php echo ($chk_with_out_provider) ? "checked" : ""; ?>><?php echo xlt('Without Provider'); ?>
281 </label>
282 </div>
283 </td>
284 <td></td>
285 <td>
286 <div class="checkbox">
287 <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'); ?>
288 </label>
289 </div>
290 </td>
291 </tr>
293 </table>
295 </div>
297 </td>
298 <td align='left' valign='middle' height="100%">
299 <table style='border-left: 1px solid; width: 100%; height: 100%'>
300 <tr>
301 <td>
302 <div class="text-center">
303 <div class="btn-group" role="group">
304 <a href='#' class='btn btn-default btn-save' onclick='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
305 <?php echo xlt('Submit'); ?>
306 </a>
307 <?php if ($_POST['form_refresh'] || $_POST['form_orderby']) { ?>
308 <a href='#' class='btn btn-default btn-print' id='printbutton'>
309 <?php echo xlt('Print'); ?>
310 </a>
311 <a href='#' class='btn btn-default btn-transmit' onclick='window.open("../patient_file/printed_fee_sheet.php?fill=2","_blank")' onsubmit='return top.restoreSession()'>
312 <?php echo xlt('Superbills'); ?>
313 </a>
314 <a href='#' class='btn btn-default btn-transmit' onclick='window.open("../patient_file/addr_appt_label.php","_blank")' onsubmit='return top.restoreSession()'>
315 <?php echo xlt('Address Labels'); ?>
316 </a>
317 <?php } ?>
318 </div>
319 </div>
320 </td>
321 </tr>
322 <tr>&nbsp;&nbsp;<?php echo xlt('Most column headers can be clicked to change sort order') ?></tr>
323 </table>
324 </td>
325 </tr>
326 </table>
328 </div>
329 <!-- end of search parameters --> <?php
330 if ($_POST['form_refresh'] || $_POST['form_orderby']) {
331 $showDate = ($from_date != $to_date) || (!$to_date);
333 <div id="report_results">
334 <table>
336 <thead>
337 <th><a href="nojs.php" onclick="return dosort('doctor')"
338 <?php echo ($form_orderby == "doctor") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('Provider'); ?>
339 </a></th>
341 <th <?php echo $showDate ? '' : 'style="display:none;"' ?>><a href="nojs.php" onclick="return dosort('date')"
342 <?php echo ($form_orderby == "date") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('Date'); ?></a>
343 </th>
345 <th><a href="nojs.php" onclick="return dosort('time')"
346 <?php echo ($form_orderby == "time") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('Time'); ?></a>
347 </th>
349 <th><a href="nojs.php" onclick="return dosort('patient')"
350 <?php echo ($form_orderby == "patient") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('Patient'); ?></a>
351 </th>
353 <th><a href="nojs.php" onclick="return dosort('pubpid')"
354 <?php echo ($form_orderby == "pubpid") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('ID'); ?></a>
355 </th>
357 <th><?php echo xlt('Home'); //Sorting by phone# not really useful ?></th>
359 <th><?php echo xlt('Cell'); //Sorting by phone# not really useful ?></th>
361 <th><a href="nojs.php" onclick="return dosort('type')"
362 <?php echo ($form_orderby == "type") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('Type'); ?></a>
363 </th>
365 <th><a href="nojs.php" onclick="return dosort('status')"
366 <?php echo ($form_orderby == "status") ? " style=\"color:#00cc00\"" : ""; ?>><?php echo xlt('Status'); ?></a>
367 </th>
368 </thead>
369 <tbody>
370 <!-- added for better print-ability -->
371 <?php
373 $lastdocname = "";
374 //Appointment Status Checking
375 $form_apptstatus = $_POST['form_apptstatus'];
376 $form_apptcat=null;
377 if (isset($_POST['form_apptcat'])) {
378 if ($form_apptcat!="ALL") {
379 $form_apptcat=intval($_POST['form_apptcat']);
383 //Without provider and facility data checking
384 $with_out_provider = null;
385 $with_out_facility = null;
387 if (isset($_POST['with_out_provider'])) {
388 $with_out_provider = $_POST['with_out_provider'];
391 if (isset($_POST['with_out_facility'])) {
392 $with_out_facility = $_POST['with_out_facility'];
395 $appointments = fetchAppointments($from_date, $to_date, $patient, $provider, $facility, $form_apptstatus, $with_out_provider, $with_out_facility, $form_apptcat);
397 if ($show_available_times) {
398 $availableSlots = getAvailableSlots($from_date, $to_date, $provider, $facility);
399 $appointments = array_merge($appointments, $availableSlots);
402 $appointments = sortAppointments($appointments, $form_orderby);
403 $pid_list = array(); // Initialize list of PIDs for Superbill option
404 $totalAppontments = count($appointments);
406 foreach ($appointments as $appointment) {
407 array_push($pid_list, $appointment['pid']);
408 $patient_id = $appointment['pid'];
409 $docname = $appointment['ulname'] . ', ' . $appointment['ufname'] . ' ' . $appointment['umname'];
411 $errmsg = "";
412 $pc_apptstatus = $appointment['pc_apptstatus'];
416 <tr valign='top' id='p1.<?php echo attr($patient_id) ?>' bgcolor='<?php echo $bgcolor ?>'>
417 <td class="detail">&nbsp;<?php echo ($docname == $lastdocname) ? "" : text($docname) ?>
418 </td>
420 <td class="detail" <?php echo $showDate ? '' : 'style="display:none;"' ?>><?php echo text(oeFormatShortDate($appointment['pc_eventDate'])) ?>
421 </td>
423 <td class="detail"><?php echo text(oeFormatTime($appointment['pc_startTime'])) ?>
424 </td>
426 <td class="detail">&nbsp;<?php echo text($appointment['fname'] . " " . $appointment['lname']) ?>
427 </td>
429 <td class="detail">&nbsp;<?php echo text($appointment['pubpid']) ?></td>
431 <td class="detail">&nbsp;<?php echo text($appointment['phone_home']) ?></td>
433 <td class="detail">&nbsp;<?php echo text($appointment['phone_cell']) ?></td>
435 <td class="detail">&nbsp;<?php echo text(xl_appt_category($appointment['pc_catname'])) ?></td>
437 <td class="detail">&nbsp;
438 <?php
439 //Appointment Status
440 if ($pc_apptstatus != "") {
441 echo getListItemTitle('apptstat', $pc_apptstatus);
444 </td>
445 </tr>
447 <?php
448 if ($patient_id && $incl_reminders) {
449 // collect reminders first, so can skip it if empty
450 $rems = fetch_reminders($patient_id, $appointment['pc_eventDate']);
453 <?php
454 if ($patient_id && (!empty($rems) || !empty($appointment['pc_hometext']))) { // Not display of available slot or not showing reminders and comments empty ?>
455 <tr valign='top' id='p2.<?php echo attr($patient_id) ?>' >
456 <td colspan=<?php echo $showDate ? '"3"' : '"2"' ?> class="detail" />
457 <td colspan=<?php echo ($incl_reminders ? "3":"6") ?> class="detail" align='left'>
458 <?php
459 if (trim($appointment['pc_hometext'])) {
460 echo '<b>'.xlt('Comments') .'</b>: '.attr($appointment['pc_hometext']);
463 if ($incl_reminders) {
464 echo "<td class='detail' colspan='3' align='left'>";
465 $new_line = '';
466 foreach ($rems as $rem_due => $rem_items) {
467 echo "$new_line<b>$rem_due</b>: ".attr($rem_items);
468 $new_line = '<br>';
471 echo "</td>";
474 </td>
475 </tr>
476 <?php
477 } // End of row 2 display
479 $lastdocname = $docname;
482 // assign the session key with the $pid_list array - note array might be empty -- handle on the printed_fee_sheet.php page.
483 $_SESSION['pidList'] = $pid_list;
485 <tr>
486 <td colspan="10" align="left"><?php echo xlt('Total number of appointments'); ?>:&nbsp;<?php echo text($totalAppontments);?></td>
487 </tr>
488 </tbody>
489 </table>
490 </div>
491 <!-- end of search results -->
492 <?php } else { ?>
493 <div class='text'><?php echo xlt('Please input search criteria above, and click Submit to view results.'); ?>
494 </div>
495 <?php } ?> <input type="hidden" name="form_orderby"
496 value="<?php echo attr($form_orderby) ?>" /> <input type="hidden"
497 name="patient" value="<?php echo attr($patient) ?>" /> <input type='hidden'
498 name='form_refresh' id='form_refresh' value='' /></form>
500 <script type="text/javascript">
502 <?php
503 if ($alertmsg) {
504 echo " alert('$alertmsg');\n";
508 </script>
510 </body>
512 </html>