getManageConfig('booking_refresh') == '0') { $refresh_disable = true; } else { $refresh_disable = false; } //----- Check for current patient if ($travel) { // Kludge travel, patient = 0 $patient = 0; $type = "pat"; $room = 0; } elseif ($patient>0) { $this_patient = CreateObject('FreeMED.Patient', $patient, ($type=="temp")); if (!isset($_REQUEST['type'])) { $_REQUEST['type'] = $type = 'pat'; } } elseif ($_COOKIE["current_patient"]>0) { if ($type != 'temp') { $this_patient = CreateObject('FreeMED.Patient', $_COOKIE["current_patient"]); $type = "pat"; // kludge to keep real patient for this $_REQUEST['patient'] = $patient = $_COOKIE['current_patient']; } } //----- Create scheduler object $scheduler = CreateObject('FreeMED.Scheduler'); //----- Ledger and checking for collections, only if patient if ($_REQUEST['type'] != 'temp') { $ledger = CreateObject('FreeMED.Ledger'); $collections = $ledger->collection_warning($_REQUEST['patient']); } else { $collections = false; } //----- Check ACLs if (!freemed::acl('schedule', 'book')) { trigger_error(__("You do not have permission to book an appointment."), E_USER_ERROR); } //------HIPAA Logging $user_to_log=$_SESSION['authdata']['user']; if((LOGLEVEL<1)||LOG_HIPAA){syslog(LOG_INFO,"book_appointment.php|user $user_to_log accesses patient $patient");} // Check for current physician, if not, use default if (!isset($physician) and $this_user->isPhysician()) { $_REQUEST['physician'] = $physician = $this_user->getPhysician(); } // If we have an ID present and we haven't been here, pull from database if ($_REQUEST['id'] and !$_REQUEST['been_here']) { $appt = freemed::get_link_rec ($_REQUEST['id'], "scheduler"); $selected_date = $appt['caldateof']; $type = $appt['caltype']; $duration = $appt['calduration']; $_REQUEST['facility'] = $facility = $appt['calfacility']; $room = $appt['calroom']; $_REQUEST['physician'] = $physician = $appt['calphysician']; $patient = $appt['calpatient']; $status = $appt['calstatus']; $_REQUEST['note'] = $note = stripslashes($appt['calprenote']); } elseif (!$been_here and !isset($room)) { // Fudge room, if we have a current facility if ($_COOKIE['default_facility']) { if (!isset($_REQUEST['facility'])) { $_REQUEST['facility'] = $facility = $_COOKIE['default_facility']; } // Get first room from there $result = $sql->query("SELECT * FROM room ". "WHERE roompos='".addslashes( $_REQUEST['facility'])."'"); if ($sql->results($result)) { $r = $sql->fetch_array($result); $room = $r['id']; } } if ($this_user->getManageConfig('default_room')) { $room = $this_user->getManageConfig('default_room'); $_REQUEST['facility'] = $facility = freemed::get_link_rec($room, 'room', 'roompos'); } } // Set duration to :15 by default if (!isset($duration)) { $_REQUEST['duration'] = $duration = 15; } if (strlen($selected_date) != 10) { $selected_date = date('Y-m-d'); } // fix date if not correct //----- Set previous and next date variables... $next = freemed_get_date_next ($selected_date); $next_wk = $selected_date; for ($i=1;$i<=7;$i++) $next_wk = freemed_get_date_next ($next_wk); $prev = freemed_get_date_prev ($selected_date); $prev_wk = $selected_date; for ($i=1;$i<=7;$i++) $prev_wk = freemed_get_date_prev ($prev_wk); //--------------- Start actual scheduler ---------------------- //----- Display patient management bar if not travel if (!$travel) { $display_buffer .= freemed::patient_box($this_patient); } else { // Display travel bar $display_buffer .= "
".__("Travel")."
"; } //----- Create form if ($scheduler->date_in_the_past($selected_date)) { $calendar_form .= "
".__("this date occurs in the past")."
"; } // Deal with "next available" stuff passed if ($_REQUEST['na']) { $na_criteria = $_REQUEST['na']; unset($_REQUEST['na']); unset($na); $_REQUEST['stage'] = $stage = 'nextavailable'; } switch ($_REQUEST['stage']) { default: // If there is a template, set duration and find which rooms // work under these circumstances if ($_REQUEST['appttemplate'] > 0) { $_REQUEST['duration'] = $duration = module_function ( 'AppointmentTemplates', 'get_duration', array ( $_REQUEST['appttemplate'] ) ); $rooms = module_function ( 'AppointmentTemplates', 'get_rooms', array ( $_REQUEST['appttemplate'] ) ); } $calendar_form .= "
"; //----- Add calendar to the top $calendar_form .= ""; //----- Room/Physician/etc selection $calendar_form .= "
".generate_calendar_mini($scheduler, $selected_date)." ".html_form::form_table(array( "".__("Patient")."" => ( $_REQUEST['type'] == 'temp' ? $this_patient->fullName(). "" : freemed::patient_widget("patient"). scheduler_collection_warning($collections) ), "".__("Template")."" => module_function( "AppointmentTemplates", "widget", array ( "appttemplate", '', 'id', array('refresh' => ( $refresh_disable ? false : true ))) ), "".__("Provider")."" => html_form::select_widget( "physician", array_merge( freemed::query_to_array( "SELECT phylname,phyfname, ". "CONCAT(phylname,', ',phyfname) AS k,". "id AS v FROM physician ". "WHERE phylname != '' AND phyref != 'yes' ". "ORDER BY phylname,phyfname" ), array(__("Other") => "0") ), array('refresh' => ( $refresh_disable ? false : true )) ), "".__("Duration")."" => html_form::select_widget( "duration", array ( "0:05" => 5, "0:10" => 10, "0:15" => 15, "0:20" => 20, "0:25" => 25, "0:30" => 30, "0:35" => 35, "0:40" => 40, "0:45" => 45, "0:50" => 50, "0:55" => 55, "1:00" => 60, "1:15" => 75, "1:30" => 90, "1:45" => 105, "2:00" => 120, "2:15" => 135, "2:30" => 150, "2:45" => 165, "3:00" => 180, "3:15" => 195, "3:20" => 200, "3:30" => 210, "3:45" => 225, "4:00" => 240, "4:15" => 255, "4:30" => 270, "4:45" => 285, "5:00" => 300, "5:15" => 315, "5:30" => 330, "5:45" => 345, "6:00" => 360, "6:15" => 375, "6:30" => 390, "6:45" => 405, "7:00" => 420, "7:30" => 450, "8:00" => 480 ) //,array('refresh' => ( $refresh_disable ? false : true )) ), "".__("Facility")."" => module_function( 'FacilityModule', 'widget', array ( 'facility' ) ), "".__("Next Available")."" => na_widget() ), "", "", "")."
"; $calendar_form .= display_booking_calendar($selected_date); //----- End of page $calendar_form .= "
\n"; $display_buffer .= $calendar_form; template_display(); break; // end default page case '2': // stage 2 if ($a = unserialize(stripslashes($_REQUEST['na_choice']))) { $_REQUEST['selected_date'] = $a[0]; $_REQUEST['hour'] = $a[1]; $_REQUEST['minute'] = $a[2]; } if ($_REQUEST['appttemplate']) { global $note; $_REQUEST['note'] = $note = module_function( 'AppointmentTemplates', 'get_description', array ( $_REQUEST['appttemplate'] ) ); } $display_buffer .= pre_screen(); //ob_start(); //print "
";
	//print_r($_REQUEST);
	//print "
"; //$display_buffer .= ob_get_contents(); //ob_end_clean(); template_display(); break; // end stage 2 case __("Confirm Booking"): case '3': $display_buffer .= process(); template_display(); break; // end stage 3 case 'nextavailable': // display criteria, allow choice $_nextday = $scheduler->date_add($_REQUEST['selected_date']); switch ($na_criteria) { case 'inaweek': $display_buffer .= display_available_appointments(array( 'date' => $scheduler->date_add($_REQUEST['selected_date'], 7), 'days' => 7, 'provider' => $_REQUEST['physician'], 'duration' => $_REQUEST['duration'] )); break; case 'in2weeks': $display_buffer .= display_available_appointments(array( 'date' => $scheduler->date_add($_REQUEST['selected_date'], 14), 'days' => 7, 'provider' => $_REQUEST['physician'], 'duration' => $_REQUEST['duration'] )); break; // end in2weeks case 'inamonth': $display_buffer .= display_available_appointments(array( 'date' => $scheduler->date_add($_REQUEST['selected_date'], 28), 'days' => 7, 'provider' => $_REQUEST['physician'], 'duration' => $_REQUEST['duration'] )); break; // end inamonth case 'weekday': $display_buffer .= display_available_appointments(array( 'date' => $scheduler->date_add($_REQUEST['selected_date'], 7), 'weekday' => true, 'provider' => $_REQUEST['physician'], 'duration' => $_REQUEST['duration'] )); break; // end weekday case 'mon': $display_buffer .= display_available_appointments(array( 'date' => $_next_day, 'days' => 28, 'forceday' => 1, // monday 'provider' => $_REQUEST['physician'], 'duration' => $_REQUEST['duration'] )); break; // end mon case 'tue': $display_buffer .= display_available_appointments(array( 'date' => $_next_day, 'days' => 28, 'forceday' => 2, // tuesday 'provider' => $_REQUEST['physician'], 'duration' => $_REQUEST['duration'] )); break; // end tue case 'wed': $display_buffer .= display_available_appointments(array( 'date' => $_next_day, 'days' => 28, 'forceday' => 3, // wednesday 'provider' => $_REQUEST['physician'], 'duration' => $_REQUEST['duration'] )); break; // end wed case 'thu': $display_buffer .= display_available_appointments(array( 'date' => $_next_day, 'days' => 28, 'forceday' => 4, // thursday 'provider' => $_REQUEST['physician'], 'duration' => $_REQUEST['duration'] )); break; // end thu case 'fri': $display_buffer .= display_available_appointments(array( 'date' => $_next_day, 'days' => 28, 'forceday' => 5, // friday 'provider' => $_REQUEST['physician'], 'duration' => $_REQUEST['duration'] )); break; // end fri case 'sat': $display_buffer .= display_available_appointments(array( 'date' => $_next_day, 'days' => 28, 'forceday' => 6, // saturday 'provider' => $_REQUEST['physician'], 'duration' => $_REQUEST['duration'] )); break; // end sat break; default: trigger_error(__("That is not a valid selection!"), E_USER_ERROR); break; // end default } template_display(); break; // end next available } trigger_error(__("You should never be here!"), E_USER_ERROR); //------------------------------------------------- FUNCTIONS ---------------- function process () { global $id, $sql, $page_title, $scheduler; global $room, $facility, $patient, $appttemplate, $selected_date, $hour, $minute, $duration, $physician, $type; // Process form here if (!$id) { $page_title = __("Book Appointment"); } else { $page_title = __("Move Appointment"); } $buffer .= "
". ( $id ? __("Moving") : __("Booking") )." ... "; // Travel kludge modifications if ($travel) { $facility = 0; $room = 0; $patient = 0; $note = stripslashes(__("Travel")); } else { // Get facility for current room $facility = freemed::get_link_field($room, "room", "roompos"); $note = stripslashes($_REQUEST['note']); } if (!$_REQUEST['id']) { $result = $scheduler->set_appointment( array ( "caldateof" => $selected_date, "caltype" => $type, "calhour" => $hour, "calminute" => $minute, "calduration" => $duration, "calfacility" => $_REQUEST['facility'], "calroom" => $room, "calphysician" => $physician, "calpatient" => $patient, "calstatus" => 'scheduled', "calprenote" => $note, "calappttemplate" => $_REQUEST['appttemplate']+0 ) ); $move = false; } else { // Perform move $result = $scheduler->move_appointment( $id, array ( "caldateof" => $_REQUEST['selected_date'], "calhour" => $_REQUEST['hour'], "calminute" => $_REQUEST['minute'], "calduration" => $_REQUEST['duration'], "calfacility" => $facility, "calroom" => $room, "calprenote" => $note, "calphysician" => $_REQUEST['physician'] ) ); $move = true; } if ($result) { $buffer .= __("done")."."; } else { $buffer .= __("ERROR"); } $display_buffer .= "

\n"; global $refresh; switch ($_REQUEST['return']) { case 'dayview': $refresh = "physician_day_view.php?selected_date=".urlencode($_REQUEST['selected_date'])."&physician=".urlencode($_REQUEST['physician']); return true; break; } if (!$travel) { if ($type != "temp") { $refresh = "manage.php?id=".urlencode($patient); $buffer .= " ".__("Manage Patient")."
"; } else { $refresh = "call-in.php?action=display&id=". urlencode($patient); $buffer .= " ".__("Manage Patient")." "; } // end checking type } else { // Travel "link" $refresh = "main.php"; } if ($move) { // Override refresh back to group calendar //$refresh = "module_loader.php?module=groupcalendar&selected_date=". // urlencode($_REQUEST['selected_date']); } return $buffer; } // end function process // We split this into a subroutine so we can call it more than once function display_booking_calendar ($date) { foreach ($GLOBALS AS $k => $v) { global ${$k}; } //----- Generate a multiple mapping index (multimap) $maps = $scheduler->multimap( "SELECT * FROM scheduler WHERE ". "calphysician='".addslashes($_REQUEST['physician'])."' AND ". "caldateof='".addslashes($date)."'", ( $_REQUEST['id']>0 ? $_REQUEST['id'] : -1 ) ); //----- Create blank map for time references $blank_map = $scheduler->map_init(); //----- Set how many columns we need $columns = count($maps); if ($columns < 2) { $columns = 2; while (count($maps) < 2) { $maps[] = $blank_map; } } $form .= "
"; // Loop through the hours for ($c_hour=freemed::config_value("calshr"); $c_hour". $scheduler->display_hour($c_hour)."\n"; // Loop through the minutes for ($c_min="00"; $c_min<60; $c_min+=5) { if ($c_min+0 != 0) { $form .= ""; } // Make sure to zero the current event counter $event = false; // Change cell_class $cell_class = alternate_colors ( array("calcell", "calcell_alt") ); // Get index $idx = sprintf('%02s:%02s', $c_hour, $c_min); // Generate minute cell $form .= "\n"; // Set fit to true, by default $fit = true; // Loop through all maps for($cur_map=0; $cur_map<$columns; $cur_map++) { // Check for fitting if (!$scheduler->map_fit($maps[$cur_map], $idx, $duration, $id) and isset($maps[$cur_map])) { //$display_buffer .= "$idx not fit on $cur_map
\n"; $fit = false; } if ($maps[$cur_map][$idx]['span'] == 0) { // Skip $event = true; } elseif ($maps[$cur_map][$idx]['link'] != 0) { // Display booking $booking = freemed::get_link_rec( $maps[$cur_map][$idx]['link'], 'scheduler' ); $bpatient = CreateObject('_FreeMED.Patient', $booking['calpatient'], ($booking['caltype'] == 'temp')); // Show the event $event = true; $form .= " \n"; } else { // If not, null block if (!$scheduler->map_fit($blank_map, $idx, $duration)) { $fit = false; } if ($fit) { $form .= "\n"; } else { $form .= "\n"; } } } // end looping // If overbooking, true fit by default if (freemed::config_value('cal_ob') == 'enable') { $fit = true; } elseif ($event) { $fit = false; } // Quick check to see if this will fit on a blank map if (!$scheduler->map_fit($blank_map, $idx, $duration)) { $fit = false; } // Add booking row if ($fit) { $form .= "\n"; } else { $form .= "\n"; } // End of row $form .= "\n"; $row = false; } // end minute looping // Display end of this row if ($row) { $form .= "\n"; } } // end hour looping //----- End of calendar $form .= "
   
:".sprintf('%02s', $c_min)."event_calendar_print($maps[$cur_map][$idx]['link']))). "');\" onMouseOut=\"hidetooltip();\" >". "".$bpatient->fullName()."". "    
\n"; return $form; } // end function display_booking_calendar // Function: generate_calendar_mini // // Generate a miniature calendar, linking to the given page // // Parameters: // // $given_date - Date to be selected // // Returns: // // HTML code for miniature calendar // function generate_calendar_mini ($scheduler, $given_date) { // mostly hacked code from TWIG's calendar - ancient $cur_date = date('Y-m-d'); $lang_days = array ( "", __("Sun"), __("Mon"), __("Tue"), __("Wed"), __("Thu"), __("Fri"), __("Sat") ); $lang_months = array ( '', __("Jan"), __("Feb"), __("Mar"), __("Apr"), __("May"), __("Jun"), __("Jul"), __("Aug"), __("Sep"), __("Oct"), __("Nov"), __("Dec") ); // break current day into pieces list ($cur_year, $cur_month, $cur_day) = explode ("-", $cur_date); if ($cur_month < 10) $cur_month = "0".$cur_month; if ($cur_day < 10) $cur_day = "0".$cur_day ; // validate day if ((empty ($given_date)) or (!strpos($given_date, "-"))) { $this_date = $cur_date; } else { $this_date = $given_date; } // break day into pieces list ($this_year, $this_month, $this_day) = explode ("-", $this_date); // Figure out the last day of the month $lastday [4] = $lastday [6] = $lastday [9] = $lastday [11] = 30; // check for leap years in february) if (checkdate( $this_month, 29, $this_year )) { $lastday [2] = 29; } else { $lastday [2] = 28; } $lastday [1] = $lastday [3] = $lastday [5] = $lastday [7] = $lastday [8] = $lastday [10] = $lastday [12] = 31; // generate top of table $buffer .= "
"; // print days across top for( $i = 1; $i <= 7; $i++) { $buffer .= " "; } // end of day display $buffer .= " "; // calculate first day $first_day = date( 'w', mktime( 0, 0, 0, $this_month, 1, $this_year ) ); $day_row = 0; if( $first_day > 0 ) { while( $day_row < $first_day ) { $buffer .= "\t\n"; $day_row += 1; } } // end while day row < first day while( $day < $lastday[($this_month + 0)] ) { if( ( $day_row % 7 ) == 0) { $buffer .= "\t\n". "\n\n". "\n"; } $dayp = $day + 1; $thisclass = ( ( $dayp == $cur_day AND $this_month == $cur_month AND $this_year == $cur_year ) ? "calendar_mini_selected" : ( $dayp == $this_day ? "calendar_mini_current" : "calendar_mini_cell" ) ); $buffer .= " "; $day++; $day_row++; } while( $day_row % 7 ) { $buffer .= "\n"; $day_row += 1; } // end of day row $buffer .= "\n". "\n". "\n". "
"; // previous month link $buffer .= " scroll_prev_month( $scheduler->scroll_prev_month( $scheduler->scroll_prev_month($this_date) ) ). "'); document.myform.submit();\" class=\"button_text\" >3 scroll_prev_month($this_date). "'); document.myform.submit();\" class=\"button_text\" >".__("prev")." ".prepare($lang_months[0+$this_month])." ".$this_year." scroll_next_month($this_date). "'); document.myform.submit();\" class=\"button_text\" >".__("next")." scroll_next_month( $scheduler->scroll_next_month( $scheduler->scroll_next_month($this_date) ) ). "'); document.myform.submit();\" class=\"button_text\" >3
  ".htmlentities($lang_days[$i])."  
   
 \n"; $buffer .= "$dayp\n"; $buffer .= "   
\n". "<  \n". ">  \n". "".__("go to today")."\n". "
\n"; return $buffer; } // end function generate_calendar_mini function na_widget ( ) { $na_types = array ( "--" => '', __("One Week From Now") => 'inaweek', __("Two Weeks From Now") => 'in2weeks', __("One Month From Now") => 'inamonth', __("Weekdays Only") => 'weekdays', __("Mondays Only") => 'mon', __("Tuesdays Only") => 'tue', __("Wednesdays Only") => 'wed', __("Thursdays Only") => 'thu', __("Fridays Only") => 'fri', __("Saturdays Only") => 'sat' ); $buffer .= "\n"; return $buffer; } // end function na_widget function display_available_appointments ( $params ) { global $scheduler; // Set stage to be second stage once we choose something $_REQUEST['stage'] = '2'; $vars = array ( 'patient', 'physician', 'duration', 'appttemplate', 'type', 'id', 'facility', 'stage' ); $na = $scheduler->next_available($params); if (!$na) { return "
". __("There are no available appointments which match your criteria."). "
\n"; } $buffer .= "
\n"; $buffer .= "
\n"; $buffer .= "
\n"; $buffer .= __("Please select from the following available times and dates:")."
\n"; foreach ($vars AS $v) { $buffer .= "\n"; } $buffer .= "\n"; $buffer .= "
\n"; $buffer .= "
\n"; $buffer .= "\n"; $buffer .= "
\n"; $buffer .= "
\n"; return $buffer; } // end function display_available_appointments function pre_screen ( ) { global $scheduler; if ($_REQUEST['appttemplate']) { // Get list of available rooms $rooms = module_function ( 'AppointmentTemplates', 'get_rooms', array ( $_REQUEST['appttemplate'] ) ); // Make sure that we don't overbook anything ... if ($rooms) { foreach ($rooms AS $room_key => $this_room) { $map = $scheduler->map( "SELECT * FROM scheduler ". "WHERE calfacility='".addslashes($_REQUEST['facility'])."' ". "AND calphysician='".addslashes($_REQUEST['physician'])."' ". "AND caldateof='".addslashes($_REQUEST['selected_date'])."' " ); $idx = $_REQUEST['hour'].":".$_REQUEST['minute']; if (!$scheduler->map_fit($map, $idx, $_REQUEST['duration'])) { // Remove from list unset($rooms[$room_key]); } // end if doesn't fit } // end foreach rooms if (count($rooms) < 1) { // TODO: Should we ever be here? // TODO: Should this end differently? trigger_error(__("Unable to find open slot!"), E_USER_ERROR); } } // end checking for rooms } $provider = CreateObject('FreeMED.Physician', $_REQUEST['physician']); $patient = CreateObject('FreeMED.Patient', $_REQUEST['patient'], ($_REQUEST['type']=="temp")); $buffer .= "
\n"; $vars = array ( 'patient', 'selected_date', 'hour', 'minute', 'physician', 'duration', 'appttemplate', 'id', 'been_here', 'type' ); foreach ($vars AS $v) { $buffer .= "\n"; } $buffer .= html_form::form_table(array( __("Date") => fm_date_print($_REQUEST['selected_date']), __("Time") => $scheduler->display_time( $_REQUEST['hour'], $_REQUEST['minute'] ), __("Duration") => $_REQUEST['duration'].' min', __("Patient") => $patient->fullName(), __("Provider") => $provider->fullName(), __("Place of Service") => module_function ( 'FacilityModule', 'to_text', array ( $_REQUEST['facility'] ) ), __("Booking Location") => html_form::select_widget( "room", ( $travel ? array ( __("Travel") => "0" ) : freemed::query_to_array( "SELECT CONCAT(room.roomname,' (',". "facility.psrcity,', ',facility.psrstate,')') AS k,". "room.id AS v ". "FROM room,facility ". "WHERE room.roompos=facility.id AND ". "room.roombooking='y' ". ( $rooms ? " AND FIND_IN_SET(room.id, '".join(',', $rooms)."') " : "" ). "ORDER BY k" ) ) ), __("Note") => html_form::text_widget('note', 250) )); $buffer .= "
\n"; $buffer .= "\n"; $buffer .= "\n"; $buffer .= "
\n"; /* "caldateof" => $selected_date, "caltype" => $type, "calhour" => $hour, "calminute" => $minute, "calduration" => $duration, "calfacility" => $facility, "calroom" => $room, "calphysician" => $physician, "calpatient" => $patient, "calcptcode" => $cptcode, "calstatus" => 'scheduled' "calprenote" => stripslashes($note) */ return $buffer; } // end function pre_screen function scheduler_collection_warning ( $amt ) { if ($amt) { return "
\n". "". "[ \$$amt ".__("in collection")."]". ""; } else { return ""; } } // end method scheduler_collection_warning ?>