5 * Modified from main codebase for the patient portal.
8 * @link http://www.open-emr.org
9 * @author Rod Roark <rod@sunsetsystems.com>
10 * @author Jerry Padgett <sjpadgett@gmail.com>
11 * @author Brady Miller <brady.g.miller@gmail.com>
12 * @author Ian Jardine ( github.com/epsdky )
13 * @copyright Copyright (C) 2005-2013 Rod Roark <rod@sunsetsystems.com>
14 * @copyright Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
15 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
16 * @copyright Copyright (C) 2019 Ian Jardine ( github.com/epsdky )
17 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
20 // Note from Rod 2013-01-22:
21 // This module needs to be refactored to share the same code that is in
22 // interface/main/calendar/find_appt_popup.php. It contains an old version
23 // of that logic and does not support exception dates for repeating events.
25 // Rod mentioned in the previous comment that the code "does not support exception dates for repeating events".
26 // This issue no longer exists - epsdky 2019
29 // Will start the (patient) portal OpenEMR session/cookie.
30 require_once(dirname(__FILE__
) . "/../src/Common/Session/SessionUtil.php");
31 OpenEMR\Common\Session\SessionUtil
::portalSessionStart();
34 //landing page definition -- where to go if something goes wrong
35 $landingpage = "index.php?site=" . urlencode($_SESSION['site_id']);
38 // kick out if patient not authenticated
39 if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) {
40 $pid = $_SESSION['pid'];
42 OpenEMR\Common\Session\SessionUtil
::portalSessionCookieDestroy();
43 header('Location: ' . $landingpage . '&w');
49 $ignoreAuth_onsite_portal = true;
51 require_once("../interface/globals.php");
52 require_once("$srcdir/patient.inc.php");
53 require_once(dirname(__FILE__
) . "/../library/appointments.inc.php");
55 use OpenEMR\Core\Header
;
56 use OpenEMR\Services\Utils\DateFormatterUtils
;
58 $input_catid = $_REQUEST['catid'];
60 // Record an event into the slots array for a specified day.
61 function doOneDay($catid, $udate, $starttime, $duration, $prefcatid)
63 global $slots, $slotsecs, $slotstime, $slotbase, $slotcount, $input_catid;
64 $udate = strtotime($starttime, $udate);
65 if ($udate < $slotstime) {
69 $i = (int)($udate / $slotsecs) - $slotbase;
70 $iend = (int)(($duration +
$slotsecs - 1) / $slotsecs) +
$i;
71 if ($iend > $slotcount) {
79 for (; $i < $iend; ++
$i) {
80 if ($catid == 2) { // in office
81 // If a category ID was specified when this popup was invoked, then select
82 // only IN events with a matching preferred category or with no preferred
83 // category; other IN events are to be treated as OUT events.
85 if (!empty($slots[$i])) {
86 if ($prefcatid == $input_catid ||
!$prefcatid) {
98 break; // ignore any positive duration for IN
99 } elseif ($catid == 3) { // out of office
101 break; // ignore any positive duration for OUT
102 } else { // all other events reserve time
108 // seconds per time slot
109 $slotsecs = $GLOBALS['calendar_interval'] * 60;
113 $srow = sqlQuery("SELECT pc_duration FROM openemr_postcalendar_categories WHERE pc_catid = ?", array($input_catid));
114 if ($srow['pc_duration']) {
115 $catslots = ceil($srow['pc_duration'] / $slotsecs);
121 $searchdays = 7; // default to a 1-week lookahead
122 if ($_REQUEST['searchdays'] ??
null) {
123 $searchdays = $_REQUEST['searchdays'];
127 if (!empty($_REQUEST['startdate'])) {
128 $sdate = DateFormatterUtils
::DateToYYYYMMDD($_REQUEST['startdate']);
130 $sdate = date("Y-m-d");
133 // Get an end date - actually the date after the end date.
134 preg_match("/(\d\d\d\d)\D*(\d\d)\D*(\d\d)/", $sdate, $matches);
137 mktime(0, 0, 0, $matches[2], $matches[3] +
$searchdays, $matches[1])
140 // compute starting time slot number and number of slots.
141 $slotstime = strtotime("$sdate 00:00:00");
142 $slotetime = strtotime("$edate 00:00:00");
143 $slotbase = (int)($slotstime / $slotsecs);
144 $slotcount = (int)($slotetime / $slotsecs) - $slotbase;
146 if ($slotcount <= 0 ||
$slotcount > 100000) {
147 die("Invalid date range.");
150 $slotsperday = (int)(60 * 60 * 24 / $slotsecs);
152 // If we have a provider, search.
154 if ($_REQUEST['providerid']) {
155 $providerid = $_REQUEST['providerid'];
157 // Create and initialize the slot array. Values are bit-mapped:
158 // bit 0 = in-office occurs here
159 // bit 1 = out-of-office occurs here
161 // So, values may range from 0 to 7.
163 $slots = array_pad(array(), $slotcount, 0);
165 // Note there is no need to sort the query results.
166 // echo $sdate." -- ".$edate;
167 $query = "SELECT pc_eventDate, pc_endDate, pc_startTime, pc_duration, " .
168 "pc_recurrtype, pc_recurrspec, pc_alldayevent, pc_catid, pc_prefcatid, pc_title " .
169 "FROM openemr_postcalendar_events " .
170 "WHERE pc_aid = ? AND " .
171 "((pc_endDate >= ? AND pc_eventDate < ?) OR " .
172 "(pc_endDate = '0000-00-00' AND pc_eventDate >= ? AND pc_eventDate < ?))";
174 $sqlBindArray = array();
175 array_push($sqlBindArray, $providerid, $sdate, $edate, $sdate, $edate);
177 $events2 = fetchEvents($sdate, $edate, null, null, false, 0, $sqlBindArray, $query);
178 foreach ($events2 as $row) {
179 $thistime = strtotime($row['pc_eventDate'] . " 00:00:00");
183 $row['pc_startTime'],
190 // Mark all slots reserved where the provider is not in-office.
191 // Actually we could do this in the display loop instead.
193 for ($i = 0; $i < $slotcount; ++
$i) {
194 if (($i %
$slotsperday) == 0) {
198 if ($slots[$i] & 1) {
202 if ($slots[$i] & 2) {
215 <title
><?php
echo xlt('Find Available Appointments'); ?
></title
>
216 <?php Header
::setupHeader(['no_main-theme', 'portal-theme', 'datetime-picker', 'opener']); ?
>
219 function setappt(year
, mon
, mday
, hours
, minutes
) {
220 opener
.setappt(year
, mon
, mday
, hours
, minutes
);
229 /* this eliminates the padding normally around a FORM tag */
247 #searchResults table {
249 border
-collapse
: collapse
;
250 background
-color
: var(--white
);
254 border
-bottom
: 1px solid
var(--gray600
);
259 background
-color
: #BBCCDD;
265 text
-decoration
: none
;
269 color
: var(--danger
);
271 text
-decoration
: none
;
277 <body
class="body_top">
279 <div
class="table-primary" id
="searchCriteria">
280 <form method
='post' name
='theform' action
='./find_appt_popup_user.php?providerid=<?php echo attr_url($providerid); ?>&catid=<?php echo attr_url($input_catid); ?>'>
281 <input type
="hidden" name
='bypatient' />
282 <div
class="form-row mx-0 align-items-center">
283 <label
for="startdate" class="col-1 mx-2 col-form-label"><?php
echo xlt('Start date:'); ?
></label
>
284 <div
class="col-auto">
285 <input type
='text' class='datepicker form-control' name
='startdate' id
='startdate' size
='10' value
='<?php echo attr(DateFormatterUtils::oeFormatShortDate($sdate)); ?>' title
='starting date for search' />
287 <label
for="searchdays" class="col-auto col-form-label"><?php
echo xlt('for'); ?
></label
>
288 <div
class="col-auto">
289 <input type
='text' class="form-control" name
='searchdays' id
='searchdays' size
='3' value
='<?php echo attr($searchdays); ?>' title
='Number of days to search from the start date' />
291 <label
for="searchdays" class="col-auto col-form-label"><?php
echo xlt('days'); ?
></label
>
292 <div
class="col-auto">
293 <input type
='submit' class="btn btn-primary btn-sm btn-block" value
='<?php echo xla('Search
'); ?>' />
298 <?php
if (!empty($slots)) : ?
>
299 <div id
="searchResultsHeader">
300 <table
class='table table-bordered'>
305 <div id
="searchResults" class="container-fluid">
306 <div
class="table-responsive">
307 <table
class='table table-sm table-striped table-bordered'>
308 <thead id
="searchResultsHeader">
310 <th
class="table-dark text-light"><?php
echo xlt('Day'); ?
></th
>
311 <th
class="srTimes"><?php
echo xlt('Available Times'); ?
></th
>
316 $ampmFlag = "am"; // establish an AM-PM line break flag
317 for ($i = 0; $i < $slotcount; ++
$i) {
319 for ($j = $i; $j < $i +
$catslots; ++
$j) {
320 if ($slots[$j] >= 4) {
326 continue; // skip reserved slots
329 $utime = ($slotbase +
$i) * $slotsecs;
330 $thisdate = date("Y-m-d", $utime);
331 if ($thisdate != $lastdate) {
332 // if a new day, start a new row
339 $lastdate = $thisdate;
340 echo " <tr class='oneresult'>\n";
341 echo " <td class='table-dark text-light'>" . date("l", $utime) . "<br />" . date("Y-m-d", $utime) . "</td>\n";
342 echo " <td class='srTimes'>";
343 echo "<div id='am'>AM<hr class='m-0 p-0 mb-n3'/><br/>";
344 $ampmFlag = "am"; // reset the AMPM flag
347 $ampm = date('a', $utime);
348 if ($ampmFlag != $ampm) {
349 echo "</div><div id='pm'><hr class='m-0 p-0' />PM<hr class='m-0 p-0 mb-n3' /><br/>";
354 $atitle = "Choose " . date("h:i a", $utime);
355 $adate = getdate($utime);
357 $anchor = "<a href='' onclick='return setappt(" .
358 attr_js(date("Y", $utime)) . "," .
359 attr_js($adate['mon']) . "," .
360 attr_js($adate['mday']) . "," .
361 attr_js(date("G", $utime)) . "," .
362 attr_js(date("i", $utime)) . "," .
363 attr_js(date('a', $utime)) . ")'" .
364 " title='" . attr($atitle) . "' alt='" . attr($atitle) . "'" .
366 echo (strlen(date('g', $utime)) < 2 ?
"<span style='visibility:hidden'>0</span>" : "") .
367 $anchor . date("g:i", $utime) . "</a> ";
369 // If category duration is more than 1 slot, increment $i appropriately.
370 // This is to avoid reporting available times on undesirable boundaries.
378 echo " <tr><td colspan='2'> " . xlt('No openings were found for this period.') . "</td></tr>\n";
391 // jQuery stuff to make the page a little easier to use
393 $
(".oneresult").hover(function () {
394 $
(this
).toggleClass("highlight");
396 $
(this
).toggleClass("highlight");
398 $
(".oneresult a").hover(function () {
399 $
(this
).toggleClass("blue_highlight");
400 $
(this
).children().toggleClass("blue_highlight");
402 $
(this
).toggleClass("blue_highlight");
403 $
(this
).children().toggleClass("blue_highlight");
406 $
('.datepicker').datetimepicker({
407 <?php
$datetimepicker_timepicker = false; ?
>
408 <?php
$datetimepicker_formatInput = true; ?
>
409 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
410 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>