4 * Modified from main codebase for the patient portal.
6 * Copyright (C) 2005-2006, 2013 Rod Roark <rod@sunsetsystems.com>
7 * Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
9 * LICENSE: This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 3
12 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
21 * @author Rod Roark <rod@sunsetsystems.com>
22 * @author Jerry Padgett <sjpadgett@gmail.com>
23 * @link http://www.open-emr.org
26 // Note from Rod 2013-01-22:
27 // This module needs to be refactored to share the same code that is in
28 // interface/main/calendar/find_appt_popup.php. It contains an old version
29 // of that logic and does not support exception dates for repeating events.
35 //landing page definition -- where to go if something goes wrong
36 $landingpage = "index.php?site=".$_SESSION['site_id'];
39 // kick out if patient not authenticated
40 if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) {
41 $pid = $_SESSION['pid'];
44 header('Location: '.$landingpage.'&w');
52 include_once("../interface/globals.php");
53 include_once("$srcdir/patient.inc");
55 // Exit if the modify calendar for portal flag is not set patched out v5
56 /* if (!($GLOBALS['portal_onsite_appt_modify'])) {
57 echo htmlspecialchars( xl('You are not authorized to schedule appointments.'),ENT_NOQUOTES);
61 $input_catid = $_REQUEST['catid'];
63 // Record an event into the slots array for a specified day.
64 function doOneDay($catid, $udate, $starttime, $duration, $prefcatid)
66 global $slots, $slotsecs, $slotstime, $slotbase, $slotcount, $input_catid;
67 $udate = strtotime($starttime, $udate);
68 if ($udate < $slotstime) {
72 $i = (int) ($udate / $slotsecs) - $slotbase;
73 $iend = (int) (($duration +
$slotsecs - 1) / $slotsecs) +
$i;
74 if ($iend > $slotcount) {
82 for (; $i < $iend; ++
$i) {
83 if ($catid == 2) { // in office
84 // If a category ID was specified when this popup was invoked, then select
85 // only IN events with a matching preferred category or with no preferred
86 // category; other IN events are to be treated as OUT events.
88 if ($prefcatid == $input_catid ||
!$prefcatid) {
97 break; // ignore any positive duration for IN
98 } else if ($catid == 3) { // out of office
100 break; // ignore any positive duration for OUT
101 } else { // all other events reserve time
107 // seconds per time slot
108 $slotsecs = $GLOBALS['calendar_interval'] * 60;
112 $srow = sqlQuery("SELECT pc_duration FROM openemr_postcalendar_categories WHERE pc_catid = '$input_catid'");
113 if ($srow['pc_duration']) {
114 $catslots = ceil($srow['pc_duration'] / $slotsecs);
120 $searchdays = 7; // default to a 1-week lookahead
121 if ($_REQUEST['searchdays']) {
122 $searchdays = $_REQUEST['searchdays'];
126 if ($_REQUEST['startdate'] && preg_match(
127 "/(\d\d\d\d)\D*(\d\d)\D*(\d\d)/",
128 $_REQUEST['startdate'],
131 $sdate = $matches[1] . '-' . $matches[2] . '-' . $matches[3];
133 $sdate = date("Y-m-d");
136 // Get an end date - actually the date after the end date.
137 preg_match("/(\d\d\d\d)\D*(\d\d)\D*(\d\d)/", $sdate, $matches);
140 mktime(0, 0, 0, $matches[2], $matches[3] +
$searchdays, $matches[1])
143 // compute starting time slot number and number of slots.
144 $slotstime = strtotime("$sdate 00:00:00");
145 $slotetime = strtotime("$edate 00:00:00");
146 $slotbase = (int) ($slotstime / $slotsecs);
147 $slotcount = (int) ($slotetime / $slotsecs) - $slotbase;
149 if ($slotcount <= 0 ||
$slotcount > 100000) {
150 die("Invalid date range.");
153 $slotsperday = (int) (60 * 60 * 24 / $slotsecs);
155 // If we have a provider, search.
157 if ($_REQUEST['providerid']) {
158 $providerid = $_REQUEST['providerid'];
160 // Create and initialize the slot array. Values are bit-mapped:
161 // bit 0 = in-office occurs here
162 // bit 1 = out-of-office occurs here
164 // So, values may range from 0 to 7.
166 $slots = array_pad(array(), $slotcount, 0);
168 // Note there is no need to sort the query results.
169 // echo $sdate." -- ".$edate;
170 $query = "SELECT pc_eventDate, pc_endDate, pc_startTime, pc_duration, " .
171 "pc_recurrtype, pc_recurrspec, pc_alldayevent, pc_catid, pc_prefcatid, pc_title " .
172 "FROM openemr_postcalendar_events " .
173 "WHERE pc_aid = '$providerid' AND " .
174 "((pc_endDate >= '$sdate' AND pc_eventDate < '$edate') OR " .
175 "(pc_endDate = '0000-00-00' AND pc_eventDate >= '$sdate' AND pc_eventDate < '$edate'))";
176 $res = sqlStatement($query);
179 while ($row = sqlFetchArray($res)) {
180 $thistime = strtotime($row['pc_eventDate'] . " 00:00:00");
181 if ($row['pc_recurrtype']) {
182 preg_match('/"event_repeat_freq_type";s:1:"(\d)"/', $row['pc_recurrspec'], $matches);
183 $repeattype = $matches[1];
185 preg_match('/"event_repeat_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches);
186 $repeatfreq = $matches[1];
187 if ($row['pc_recurrtype'] == 2) {
188 // Repeat type is 2 so frequency comes from event_repeat_on_freq.
189 preg_match('/"event_repeat_on_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches);
190 $repeatfreq = $matches[1];
197 preg_match('/"event_repeat_on_num";s:1:"(\d)"/', $row['pc_recurrspec'], $matches);
198 $my_repeat_on_num = $matches[1];
200 preg_match('/"event_repeat_on_day";s:1:"(\d)"/', $row['pc_recurrspec'], $matches);
201 $my_repeat_on_day = $matches[1];
203 $endtime = strtotime($row['pc_endDate'] . " 00:00:00") +
(24 * 60 * 60);
204 if ($endtime > $slotetime) {
205 $endtime = $slotetime;
209 while ($thistime < $endtime) {
210 // Skip the event if a repeat frequency > 1 was specified and this is
211 // not the desired occurrence.
216 $row['pc_startTime'],
222 if (++
$repeatix >= $repeatfreq) {
226 $adate = getdate($thistime);
228 if ($row['pc_recurrtype'] == 2) {
229 // Need to skip to nth or last weekday of the next month.
231 if ($adate['mon'] > 12) {
236 if ($my_repeat_on_num < 5) { // not last
238 $dow = jddayofweek(cal_to_jd(CAL_GREGORIAN
, $adate['mon'], $adate['mday'], $adate['year']));
239 if ($dow > $my_repeat_on_day) {
243 $adate['mday'] +
= ($my_repeat_on_num - 1) * 7 +
$my_repeat_on_day - $dow;
244 } else { // last weekday of month
245 $adate['mday'] = cal_days_in_month(CAL_GREGORIAN
, $adate['mon'], $adate['year']);
246 $dow = jddayofweek(cal_to_jd(CAL_GREGORIAN
, $adate['mon'], $adate['mday'], $adate['year']));
247 if ($dow < $my_repeat_on_day) {
251 $adate['mday'] +
= $my_repeat_on_day - $dow;
253 } // end recurrtype 2
255 else { // recurrtype 1
257 if ($repeattype == 0) { // daily
259 } else if ($repeattype == 1) { // weekly
261 } else if ($repeattype == 2) { // monthly
263 } else if ($repeattype == 3) { // yearly
265 } else if ($repeattype == 4) { // work days
266 if ($adate['wday'] == 5) { // if friday, skip to monday
268 } else if ($adate['wday'] == 6) { // saturday should not happen
273 } else if ($repeattype == 5) { // monday
275 } else if ($repeattype == 6) { // tuesday
277 } else if ($repeattype == 7) { // wednesday
279 } else if ($repeattype == 8) { // thursday
281 } else if ($repeattype == 9) { // friday
284 die("Invalid repeat type '$repeattype'");
286 } // end recurrtype 1
288 $thistime = mktime(0, 0, 0, $adate['mon'], $adate['mday'], $adate['year']);
294 $row['pc_startTime'],
301 // Mark all slots reserved where the provider is not in-office.
302 // Actually we could do this in the display loop instead.
304 for ($i = 0; $i < $slotcount; ++
$i) {
305 if (($i %
$slotsperday) == 0) {
309 if ($slots[$i] & 1) {
313 if ($slots[$i] & 2) {
325 <?php
html_header_show(); ?
>
326 <title
><?php
xl('Find Available Appointments', 'e'); ?
></title
>
327 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
328 <link href
="<?php echo $GLOBALS['assets_static_relative']; ?>/bootstrap-3-3-4/dist/css/bootstrap.min.css" rel
="stylesheet" type
="text/css" />
329 <?php
if ($_SESSION['language_direction'] == 'rtl') { ?
>
330 <link href
="<?php echo $GLOBALS['assets_static_relative']; ?>/bootstrap-rtl-3-3-4/dist/css/bootstrap-rtl.min.css" rel
="stylesheet" type
="text/css" />
332 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
335 <!-- for the pop up calendar
-->
336 <script src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-11-3/index.js" type
="text/javascript"></script
>
337 <script src
="<?php echo $GLOBALS['assets_static_relative']; ?>/bootstrap-3-3-4/dist/js/bootstrap.min.js" type
="text/javascript"></script
>
338 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script
>
342 function setappt(year
,mon
,mday
,hours
,minutes
) {
343 if (opener
.closed ||
! opener
.setappt
)
344 alert('<?php xl('The destination form was closed
; I cannot act on your selection
.', 'e
'); ?>');
346 opener
.setappt(year
,mon
,mday
,hours
,minutes
);
356 /* this eliminates the padding normally around a FORM tag */
363 /* font-size: 0.8em; */
364 background
-color
: #bfe6ff;
368 #searchResultsHeader {
370 background
-color
: lightgrey
;
372 #searchResultsHeader table {
373 width
: 96%
; /* not 100% because the 'searchResults' table has a scrollbar */
374 border
-collapse
: collapse
;
376 #searchResultsHeader th {
377 /* font-size: 0.7em; */
385 .srDate
{ width
: 20%
; }
386 .srTimes
{ width
: 80%
; }
388 #searchResults table {
390 border
-collapse
: collapse
;
391 background
-color
: white
;
394 /* font-size: 0.7em; */
395 border
-bottom
: 1px solid gray
;
396 padding
: 1px
5px
1px
5px
;
398 .highlight
{ background
-color
: #ff9; }
399 .blue_highlight
{ background
-color
: #BBCCDD; color: white; }
401 border
-bottom
: 1px solid lightgrey
;
405 #pm a { color: #c00; }
410 <body
class="body_top">
412 <div id
="searchCriteria">
413 <form method
='post' name
='theform' action
='./find_appt_popup_user.php?providerid=<?php echo $providerid ?>&catid=<?php echo $input_catid ?>'>
414 <input type
="hidden" name
='bypatient' />
416 <?php
xl('Start date:', 'e'); ?
>
419 <input type
='text' class='datepicker' name
='startdate' id
='startdate' size
='10' value
='<?php echo $sdate ?>'
420 title
='yyyy-mm-dd starting date for search'/>
422 <?php
xl('for', 'e'); ?
>
423 <input type
='text' name
='searchdays' size
='3' value
='<?php echo $searchdays ?>'
424 title
='Number of days to search from the start date' />
425 <?php
xl('days', 'e'); ?
> 
;
426 <input type
='submit' value
='<?php xl('Search
', 'e
'); ?>'>
429 <?php
if (!empty($slots)) : ?
>
431 <div id
="searchResultsHeader">
432 <table
class='table table-bordered'>
434 <th
class="srDate"><?php
xl('Day', 'e'); ?
></th
>
435 <th
class="srTimes"><?php
xl('Available Times', 'e'); ?
></th
>
440 <div id
="searchResults">
441 <table
class='table table-condensed table-inversed table-bordered'>
444 $ampmFlag = "am"; // establish an AM-PM line break flag
445 for ($i = 0; $i < $slotcount; ++
$i) {
447 for ($j = $i; $j < $i +
$catslots; ++
$j) {
448 if ($slots[$j] >= 4) {
454 continue; // skip reserved slots
457 $utime = ($slotbase +
$i) * $slotsecs;
458 $thisdate = date("Y-m-d", $utime);
459 if ($thisdate != $lastdate) {
460 // if a new day, start a new row
467 $lastdate = $thisdate;
468 echo " <tr class='oneresult'>\n";
469 echo " <td class='srDate'>" . date("l", $utime)."<br>".date("Y-m-d", $utime) . "</td>\n";
470 echo " <td class='srTimes'>";
471 echo "<div id='am'>AM ";
472 $ampmFlag = "am"; // reset the AMPM flag
475 $ampm = date('a', $utime);
476 if ($ampmFlag != $ampm) {
477 echo "</div><div id='pm'>PM ";
482 $atitle = "Choose ".date("h:i a", $utime);
483 $adate = getdate($utime);
484 $anchor = "<a href='' onclick='return setappt(" .
485 $adate['year'] . "," .
486 $adate['mon'] . "," .
487 $adate['mday'] . "," .
488 $adate['hours'] . "," .
489 $adate['minutes'] . ")'".
490 " title='$atitle' alt='$atitle'".
492 echo (strlen(date('g', $utime)) < 2 ?
"<span style='visibility:hidden'>0</span>" : "") .
493 $anchor . date("g:i", $utime) . "</a> ";
495 // If category duration is more than 1 slot, increment $i appropriately.
496 // This is to avoid reporting available times on undesirable boundaries.
504 echo " <tr><td colspan='2'> " . xl('No openings were found for this period.', 'e') . "</td></tr>\n";
515 <script language
='JavaScript'>
517 // jQuery stuff to make the page a little easier to use
518 $
(document
).ready(function(){
519 $
(".oneresult").mouseover(function() { $
(this
).toggleClass("highlight"); });
520 $
(".oneresult").mouseout(function() { $
(this
).toggleClass("highlight"); });
521 $
(".oneresult a").mouseover(function () { $
(this
).toggleClass("blue_highlight"); $
(this
).children().toggleClass("blue_highlight"); });
522 $
(".oneresult a").mouseout(function() { $
(this
).toggleClass("blue_highlight"); $
(this
).children().toggleClass("blue_highlight"); });
524 $
('.datepicker').datetimepicker({
525 <?php
$datetimepicker_timepicker = false; ?
>
526 <?php
$datetimepicker_formatInput = false; ?
>
527 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
528 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>