2 // Copyright (C) 2005-2010 Rod Roark <rod@sunsetsystems.com>
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 $alertmsg = ''; // not used yet but maybe later
26 $patient = $_REQUEST['patient'];
28 if ($patient && ! $_POST['form_from_date']) {
29 // If a specific patient, default to 2 years ago.
31 $from_date = date("$tmp-m-d");
33 $from_date = fixDate($_POST['form_from_date'], date('Y-m-d'));
34 $to_date = fixDate($_POST['form_to_date'], date('Y-m-d'));
37 $show_available_times = false;
38 if ( $_POST['form_show_available'] ) {
39 $show_available_times = true;
42 $chk_with_out_provider = false;
43 if ( $_POST['with_out_provider'] ) {
44 $chk_with_out_provider = true;
47 $chk_with_out_facility = false;
48 if ( $_POST['with_out_facility'] ) {
49 $chk_with_out_facility = true;
52 //$to_date = fixDate($_POST['form_to_date'], '');
53 $provider = $_POST['form_provider'];
54 $facility = $_POST['form_facility']; //(CHEMED) facility filter
55 $form_orderby = getComparisonOrder( $_REQUEST['form_orderby'] ) ?
$_REQUEST['form_orderby'] : 'date';
57 // Reminders related stuff
58 $incl_reminders = isset($_POST['incl_reminders']) ?
1 : 0;
59 function fetch_rule_txt ($list_id, $option_id) {
60 $rs = sqlQuery('SELECT title, seq from list_options WHERE list_id=? AND option_id=?',
61 array($list_id, $option_id));
62 $rs['title'] = xl_list_label($rs['title']);
65 function fetch_reminders($pid, $appt_date) {
66 $rems = test_rules_clinic('','passive_alert',$appt_date,'reminders-due',$pid);
70 foreach ($rems as $ix => $rem) {
72 $rule_txt = fetch_rule_txt ('rule_reminder_due_opt', $rem['due_status']);
73 $seq_due[$ix] = $rule_txt['seq'];
74 $rem_out['due_txt'] = $rule_txt['title'];
75 $rule_txt = fetch_rule_txt ('rule_action_category', $rem['category']);
76 $seq_cat[$ix] = $rule_txt['seq'];
77 $rem_out['cat_txt'] = $rule_txt['title'];
78 $rule_txt = fetch_rule_txt ('rule_action', $rem['item']);
79 $seq_act[$ix] = $rule_txt['seq'];
80 $rem_out['act_txt'] = $rule_txt['title'];
81 $rems_out[$ix] = $rem_out;
83 array_multisort($seq_due, SORT_DESC
, $seq_cat, SORT_ASC
, $seq_act, SORT_ASC
, $rems_out);
85 foreach ($rems_out as $ix => $rem) {
86 $rems[$rem['due_txt']] .= (isset($rems[$rem['due_txt']]) ?
', ':'').
87 $rem['act_txt'].' '.$rem['cat_txt'];
96 <?php
html_header_show();?
>
98 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
100 <title
><?php
echo xlt('Appointments Report'); ?
></title
>
102 <script type
="text/javascript" src
="../../library/overlib_mini.js"></script
>
103 <script type
="text/javascript" src
="../../library/textformat.js"></script
>
104 <script type
="text/javascript" src
="../../library/dialog.js"></script
>
105 <script type
="text/javascript" src
="../../library/js/jquery.1.3.2.js"></script
>
107 <script type
="text/javascript">
109 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
111 $
(document
).ready(function() {
112 var win
= top
.printLogSetup ? top
: opener
.top
;
113 win
.printLogSetup(document
.getElementById('printbutton'));
116 function dosort(orderby
) {
117 var f
= document
.forms
[0];
118 f
.form_orderby
.value
= orderby
;
123 function oldEvt(eventid
) {
124 dlgopen('../main/calendar/add_edit_event.php?eid=' + eventid
, 'blank', 550, 270);
127 function refreshme() {
128 // location.reload();
129 document
.forms
[0].submit();
134 <style type
="text/css">
135 /* specifically include & exclude from printing */
141 #report_parameters_daterange {
145 #report_results table {
150 /* specifically exclude some from the screen */
152 #report_parameters_daterange {
160 <body
class="body_top">
162 <!-- Required
for the popup date selectors
-->
164 style
="position: absolute; visibility: hidden; z-index: 1000;"></div
>
166 <span
class='title'><?php
echo xlt('Report'); ?
> - <?php
echo xlt('Appointments'); ?
></span
>
168 <div id
="report_parameters_daterange"><?php
echo date("d F Y", strtotime($from_date)) ." to ". date("d F Y", strtotime($to_date)); #sets date range for calendars ?>
171 <form method
='post' name
='theform' id
='theform' action
='appointments_report.php' onsubmit
='return top.restoreSession()'>
173 <div id
="report_parameters">
178 <div style
='float: left'>
182 <td
class='label'><?php
echo xlt('Facility'); ?
>:</td
>
183 <td
><?php
dropdown_facility($facility , 'form_facility'); ?
>
185 <td
class='label'><?php
echo xlt('Provider'); ?
>:</td
>
188 // Build a drop-down list of providers.
191 $query = "SELECT id, lname, fname FROM users WHERE ".
192 "authorized = 1 $provider_facility_filter ORDER BY lname, fname"; //(CHEMED) facility filter
194 $ures = sqlStatement($query);
196 echo " <select name='form_provider'>\n";
197 echo " <option value=''>-- " . xlt('All') . " --\n";
199 while ($urow = sqlFetchArray($ures)) {
200 $provid = $urow['id'];
201 echo " <option value='" . attr($provid) . "'";
202 if ($provid == $_POST['form_provider']) echo " selected";
203 echo ">" . text($urow['lname']) . ", " . text($urow['fname']) . "\n";
211 <td
class='label'><?php
echo xlt('From'); ?
>:</td
>
212 <td
><input type
='text' name
='form_from_date' id
="form_from_date"
213 size
='10' value
='<?php echo attr($from_date) ?>'
214 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
215 title
='yyyy-mm-dd'> <img src
='../pic/show_calendar.gif'
216 align
='absbottom' width
='24' height
='22' id
='img_from_date'
217 border
='0' alt
='[?]' style
='cursor: pointer'
218 title
='<?php echo xlt('Click here to choose a date
'); ?>'></td
>
219 <td
class='label'><?php
echo xlt('To'); ?
>:</td
>
220 <td
><input type
='text' name
='form_to_date' id
="form_to_date"
221 size
='10' value
='<?php echo attr($to_date) ?>'
222 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
223 title
='yyyy-mm-dd'> <img src
='../pic/show_calendar.gif'
224 align
='absbottom' width
='24' height
='22' id
='img_to_date'
225 border
='0' alt
='[?]' style
='cursor: pointer'
226 title
='<?php echo xlt('Click here to choose a date
'); ?>'></td
>
230 <td
class='label'><?php
echo xlt('Status'); # status code drop down creation ?>:</td>
231 <td
><?php
generate_form_field(array('data_type'=>1,'field_id'=>'apptstatus','list_id'=>'apptstat','empty_title'=>'All'),$_POST['form_apptstatus']);?
></td
>
232 <td
><?php
echo xlt('Category') #category drop down creation ?>:</td>
234 <select id
="form_apptcat" name
="form_apptcat">
236 $categories=fetchAppointmentCategories();
237 echo "<option value='ALL'>".xlt("All")."</option>";
238 while($cat=sqlFetchArray($categories))
240 echo "<option value='".attr($cat['id'])."'";
241 if($cat['id']==$_POST['form_apptcat'])
243 echo " selected='true' ";
245 echo ">".text(xl_appt_category($cat['category']))."</option>";
253 <td
><label
><input type
='checkbox' name
='form_show_available'
254 <?php
if ( $show_available_times ) echo ' checked'; ?
>> <?php
echo xlt('Show Available Times'); # check this to show available times on the report ?>
257 <td
><label
><input type
="checkbox" name
="incl_reminders" id
="incl_reminders"
258 <?php
echo ($incl_reminders ?
' checked':''); # This will include the reminder for the patients on the report ?>>
259 <?php
echo xlt('Show Reminders'); ?
></label
></td
>
263 <?php
# these two selects will show entries that do not have a facility or a provider ?>
264 <td
><label
><input type
="checkbox" name
="with_out_provider" id
="with_out_provider" <?php
if($chk_with_out_provider) echo "checked";?
>> 
;<?php
echo xlt('Without Provider'); ?
></label
></td
>
266 <td
><label
><input type
="checkbox" name
="with_out_facility" id
="with_out_facility" <?php
if($chk_with_out_facility) echo "checked";?
>> 
;<?php
echo xlt('Without Facility'); ?
></label
></td
>
274 <td align
='left' valign
='middle' height
="100%">
275 <table style
='border-left: 1px solid; width: 100%; height: 100%'>
278 <div style
='margin-left: 15px'>
279 <a href
='#' class='css_button' onclick
='$("#form_refresh").attr("value","true"); $("#theform").submit();'>
280 <span
> <?php
echo xlt('Submit'); ?
> </span
> </a
>
281 <?php
if ($_POST['form_refresh'] ||
$_POST['form_orderby'] ) { ?
>
282 <a href
='#' class='css_button' id
='printbutton'>
283 <span
> <?php
echo xlt('Print'); ?
> </span
> </a
>
284 <a href
='#' class='css_button' onclick
='window.open("../patient_file/printed_fee_sheet.php?fill=2","_blank")' onsubmit
='return top.restoreSession()'>
285 <span
> <?php
echo xlt('Superbills'); ?
> </span
> </a
>
289 <tr
> 
; 
;<?php
echo xlt('Most column headers can be clicked to change sort order') ?
></tr
>
296 <!-- end of search parameters
--> <?php
297 if ($_POST['form_refresh'] ||
$_POST['form_orderby']) {
298 $showDate = ($from_date != $to_date) ||
(!$to_date);
300 <div id
="report_results">
304 <th
><a href
="nojs.php" onclick
="return dosort('doctor')"
305 <?php
if ($form_orderby == "doctor") echo " style=\"color:#00cc00\"" ?
>><?php
echo xlt('Provider'); ?
>
308 <th
<?php
echo $showDate ?
'' : 'style="display:none;"' ?
>><a href
="nojs.php" onclick
="return dosort('date')"
309 <?php
if ($form_orderby == "date") echo " style=\"color:#00cc00\"" ?
>><?php
echo xlt('Date'); ?
></a
>
312 <th
><a href
="nojs.php" onclick
="return dosort('time')"
313 <?php
if ($form_orderby == "time") echo " style=\"color:#00cc00\"" ?
>><?php
echo xlt('Time'); ?
></a
>
316 <th
><a href
="nojs.php" onclick
="return dosort('patient')"
317 <?php
if ($form_orderby == "patient") echo " style=\"color:#00cc00\"" ?
>><?php
echo xlt('Patient'); ?
></a
>
320 <th
><a href
="nojs.php" onclick
="return dosort('pubpid')"
321 <?php
if ($form_orderby == "pubpid") echo " style=\"color:#00cc00\"" ?
>><?php
echo xlt('ID'); ?
></a
>
324 <th
><?php
echo xlt('Home'); //Sorting by phone# not really useful ?></th>
326 <th
><?php
echo xlt('Cell'); //Sorting by phone# not really useful ?></th>
328 <th
><a href
="nojs.php" onclick
="return dosort('type')"
329 <?php
if ($form_orderby == "type") echo " style=\"color:#00cc00\"" ?
>><?php
echo xlt('Type'); ?
></a
>
332 <th
><a href
="nojs.php" onclick
="return dosort('status')"
333 <?php
if ($form_orderby == "status") echo " style=\"color:#00cc00\"" ?
>><?php
echo xlt('Status'); ?
></a
>
337 <!-- added
for better
print-ability
-->
341 //Appointment Status Checking
342 $form_apptstatus = $_POST['form_apptstatus'];
344 if(isset($_POST['form_apptcat']))
346 if($form_apptcat!="ALL")
348 $form_apptcat=intval($_POST['form_apptcat']);
352 //Without provider and facility data checking
353 $with_out_provider = null;
354 $with_out_facility = null;
356 if( isset($_POST['with_out_provider']) ){
357 $with_out_provider = $_POST['with_out_provider'];
360 if( isset($_POST['with_out_facility']) ){
361 $with_out_facility = $_POST['with_out_facility'];
363 $appointments = fetchAppointments( $from_date, $to_date, $patient, $provider, $facility, $form_apptstatus, $with_out_provider, $with_out_facility,$form_apptcat );
365 if ( $show_available_times ) {
366 $availableSlots = getAvailableSlots( $from_date, $to_date, $provider, $facility );
367 $appointments = array_merge( $appointments, $availableSlots );
370 $appointments = sortAppointments( $appointments, $form_orderby );
371 $pid_list = array(); // Initialize list of PIDs for Superbill option
372 $totalAppontments = count($appointments);
374 foreach ( $appointments as $appointment ) {
375 array_push($pid_list,$appointment['pid']);
376 $patient_id = $appointment['pid'];
377 $docname = $appointment['ulname'] . ', ' . $appointment['ufname'] . ' ' . $appointment['umname'];
380 $pc_apptstatus = $appointment['pc_apptstatus'];
384 <tr valign
='top' id
='p1.<?php echo attr($patient_id) ?>' bgcolor
='<?php echo $bgcolor ?>'>
385 <td
class="detail"> 
;<?php
echo ($docname == $lastdocname) ?
"" : text($docname) ?
>
388 <td
class="detail" <?php
echo $showDate ?
'' : 'style="display:none;"' ?
>><?php
echo text(oeFormatShortDate($appointment['pc_eventDate'])) ?
>
391 <td
class="detail"><?php
echo text(oeFormatTime($appointment['pc_startTime'])) ?
>
394 <td
class="detail"> 
;<?php
echo text($appointment['fname'] . " " . $appointment['lname']) ?
>
397 <td
class="detail"> 
;<?php
echo text($appointment['pubpid']) ?
></td
>
399 <td
class="detail"> 
;<?php
echo text($appointment['phone_home']) ?
></td
>
401 <td
class="detail"> 
;<?php
echo text($appointment['phone_cell']) ?
></td
>
403 <td
class="detail"> 
;<?php
echo text(xl_appt_category($appointment['pc_catname'])) ?
></td
>
405 <td
class="detail"> 
;
408 if($pc_apptstatus != ""){
409 $frow['data_type']=1;
410 $frow['list_id']='apptstat';
411 generate_print_field($frow, $pc_apptstatus);
417 <?php
if ($patient_id && $incl_reminders) {
418 // collect reminders first, so can skip it if empty
419 $rems = fetch_reminders ($patient_id, $appointment['pc_eventDate']);
421 <?php
if ($patient_id && (!empty($rems) ||
!empty($appointment['pc_hometext']))) { // Not display of available slot or not showing reminders and comments empty ?>
422 <tr valign
='top' id
='p2.<?php echo attr($patient_id) ?>' >
423 <td colspan
=<?php
echo $showDate ?
'"3"' : '"2"' ?
> class="detail" />
424 <td colspan
=<?php
echo ($incl_reminders ?
"3":"6") ?
> class="detail" align
='left'>
426 if (trim($appointment['pc_hometext'])) {
427 echo '<b>'.xlt('Comments') .'</b>: '.attr($appointment['pc_hometext']);
429 if ($incl_reminders) {
430 echo "<td class='detail' colspan='3' align='left'>";
432 foreach ($rems as $rem_due => $rem_items) {
433 echo "$new_line<b>$rem_due</b>: ".attr($rem_items);
442 } // End of row 2 display
444 $lastdocname = $docname;
446 // assign the session key with the $pid_list array - note array might be empty -- handle on the printed_fee_sheet.php page.
447 $_SESSION['pidList'] = $pid_list;
450 <td colspan
="10" align
="left"><?php
echo xlt('Total number of appointments'); ?
>: 
;<?php
echo text($totalAppontments);?
></td
>
455 <!-- end of search results
--> <?php
} else { ?
>
456 <div
class='text'><?php
echo xlt('Please input search criteria above, and click Submit to view results.'); ?
>
458 <?php
} ?
> <input type
="hidden" name
="form_orderby"
459 value
="<?php echo attr($form_orderby) ?>" /> <input type
="hidden"
460 name
="patient" value
="<?php echo attr($patient) ?>" /> <input type
='hidden'
461 name
='form_refresh' id
='form_refresh' value
='' /></form
>
463 <script type
="text/javascript">
466 if ($alertmsg) { echo " alert('$alertmsg');\n"; }
473 <!-- stuff
for the popup calendar
-->
474 <style type
="text/css">
475 @import
url(../../library
/dynarch_calendar
.css
);
477 <script type
="text/javascript" src
="../../library/dynarch_calendar.js"></script
>
478 <?php
include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?
>
479 <script type
="text/javascript"
480 src
="../../library/dynarch_calendar_setup.js"></script
>
481 <script type
="text/javascript">
482 Calendar
.setup({inputField
:"form_from_date", ifFormat
:"%Y-%m-%d", button
:"img_from_date"});
483 Calendar
.setup({inputField
:"form_to_date", ifFormat
:"%Y-%m-%d", button
:"img_to_date"});