* @author Jerry Padgett * @author Brady Miller * @author Ian Jardine ( github.com/epsdky ) * @copyright Copyright (C) 2005-2013 Rod Roark * @copyright Copyright (C) 2016-2017 Jerry Padgett * @copyright Copyright (c) 2019 Brady Miller * @copyright Copyright (C) 2019 Ian Jardine ( github.com/epsdky ) * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 */ // Note from Rod 2013-01-22: // This module needs to be refactored to share the same code that is in // interface/main/calendar/find_appt_popup.php. It contains an old version // of that logic and does not support exception dates for repeating events. // Rod mentioned in the previous comment that the code "does not support exception dates for repeating events". // This issue no longer exists - epsdky 2019 //continue session // Will start the (patient) portal OpenEMR session/cookie. require_once(dirname(__FILE__) . "/../src/Common/Session/SessionUtil.php"); OpenEMR\Common\Session\SessionUtil::portalSessionStart(); // //landing page definition -- where to go if something goes wrong $landingpage = "index.php?site=" . urlencode($_SESSION['site_id']); // // kick out if patient not authenticated if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) { $pid = $_SESSION['pid']; } else { OpenEMR\Common\Session\SessionUtil::portalSessionCookieDestroy(); header('Location: ' . $landingpage . '&w'); exit(); } // $ignoreAuth_onsite_portal = true; require_once("../interface/globals.php"); require_once("$srcdir/patient.inc"); require_once(dirname(__FILE__) . "/../library/appointments.inc.php"); use OpenEMR\Core\Header; $input_catid = $_REQUEST['catid']; // Record an event into the slots array for a specified day. function doOneDay($catid, $udate, $starttime, $duration, $prefcatid) { global $slots, $slotsecs, $slotstime, $slotbase, $slotcount, $input_catid; $udate = strtotime($starttime, $udate); if ($udate < $slotstime) { return; } $i = (int)($udate / $slotsecs) - $slotbase; $iend = (int)(($duration + $slotsecs - 1) / $slotsecs) + $i; if ($iend > $slotcount) { $iend = $slotcount; } if ($iend <= $i) { $iend = $i + 1; } for (; $i < $iend; ++$i) { if ($catid == 2) { // in office // If a category ID was specified when this popup was invoked, then select // only IN events with a matching preferred category or with no preferred // category; other IN events are to be treated as OUT events. if ($input_catid) { if ($prefcatid == $input_catid || !$prefcatid) { $slots[$i] |= 1; } else { $slots[$i] |= 2; } } else { $slots[$i] |= 1; } break; // ignore any positive duration for IN } elseif ($catid == 3) { // out of office $slots[$i] |= 2; break; // ignore any positive duration for OUT } else { // all other events reserve time $slots[$i] |= 4; } } } // seconds per time slot $slotsecs = $GLOBALS['calendar_interval'] * 60; $catslots = 1; if ($input_catid) { $srow = sqlQuery("SELECT pc_duration FROM openemr_postcalendar_categories WHERE pc_catid = ?", array($input_catid)); if ($srow['pc_duration']) { $catslots = ceil($srow['pc_duration'] / $slotsecs); } } $info_msg = ""; $searchdays = 7; // default to a 1-week lookahead if ($_REQUEST['searchdays']) { $searchdays = $_REQUEST['searchdays']; } // Get a start date. if ( $_REQUEST['startdate'] && preg_match( "/(\d\d\d\d)\D*(\d\d)\D*(\d\d)/", $_REQUEST['startdate'], $matches ) ) { $sdate = $matches[1] . '-' . $matches[2] . '-' . $matches[3]; } else { $sdate = date("Y-m-d"); } // Get an end date - actually the date after the end date. preg_match("/(\d\d\d\d)\D*(\d\d)\D*(\d\d)/", $sdate, $matches); $edate = date( "Y-m-d", mktime(0, 0, 0, $matches[2], $matches[3] + $searchdays, $matches[1]) ); // compute starting time slot number and number of slots. $slotstime = strtotime("$sdate 00:00:00"); $slotetime = strtotime("$edate 00:00:00"); $slotbase = (int)($slotstime / $slotsecs); $slotcount = (int)($slotetime / $slotsecs) - $slotbase; if ($slotcount <= 0 || $slotcount > 100000) { die("Invalid date range."); } $slotsperday = (int)(60 * 60 * 24 / $slotsecs); // If we have a provider, search. // if ($_REQUEST['providerid']) { $providerid = $_REQUEST['providerid']; // Create and initialize the slot array. Values are bit-mapped: // bit 0 = in-office occurs here // bit 1 = out-of-office occurs here // bit 2 = reserved // So, values may range from 0 to 7. // $slots = array_pad(array(), $slotcount, 0); // Note there is no need to sort the query results. // echo $sdate." -- ".$edate; $query = "SELECT pc_eventDate, pc_endDate, pc_startTime, pc_duration, " . "pc_recurrtype, pc_recurrspec, pc_alldayevent, pc_catid, pc_prefcatid, pc_title " . "FROM openemr_postcalendar_events " . "WHERE pc_aid = ? AND " . "((pc_endDate >= ? AND pc_eventDate < ?) OR " . "(pc_endDate = '0000-00-00' AND pc_eventDate >= ? AND pc_eventDate < ?))"; $sqlBindArray = array(); array_push($sqlBindArray, $providerid, $sdate, $edate, $sdate, $edate); ////// $events2 = fetchEvents($sdate, $edate, null, null, false, 0, $sqlBindArray, $query); foreach ($events2 as $row) { $thistime = strtotime($row['pc_eventDate'] . " 00:00:00"); doOneDay( $row['pc_catid'], $thistime, $row['pc_startTime'], $row['pc_duration'], $row['pc_prefcatid'] ); } ////// // Mark all slots reserved where the provider is not in-office. // Actually we could do this in the display loop instead. $inoffice = false; for ($i = 0; $i < $slotcount; ++$i) { if (($i % $slotsperday) == 0) { $inoffice = false; } if ($slots[$i] & 1) { $inoffice = true; } if ($slots[$i] & 2) { $inoffice = false; } if (!$inoffice) { $slots[$i] |= 4; } } } ?> <?php echo xlt('Find Available Appointments'); ?>
' />
= 4) { $available = false; } } if (!$available) { continue; // skip reserved slots } $utime = ($slotbase + $i) * $slotsecs; $thisdate = date("Y-m-d", $utime); if ($thisdate != $lastdate) { // if a new day, start a new row if ($lastdate) { echo ""; echo "\n"; echo " \n"; } $lastdate = $thisdate; echo " \n"; echo " \n"; echo " \n"; echo " \n"; } else { echo " \n"; } ?>
" . date("l", $utime) . "
" . date("Y-m-d", $utime) . "
"; echo "
AM

"; $ampmFlag = "am"; // reset the AMPM flag } $ampm = date('a', $utime); if ($ampmFlag != $ampm) { echo "

PM

"; } $ampmFlag = $ampm; $atitle = "Choose " . date("h:i a", $utime); $adate = getdate($utime); $anchor = ""; echo (strlen(date('g', $utime)) < 2 ? "0" : "") . $anchor . date("g:i", $utime) . " "; // If category duration is more than 1 slot, increment $i appropriately. // This is to avoid reporting available times on undesirable boundaries. $i += $catslots - 1; } if ($lastdate) { echo "
" . xlt('No openings were found for this period.') . "