Add facilities filter in calendar view.
[openemr.git] / interface / main / calendar / modules / PostCalendar / pntemplates / default / views / week / default.html
blob3bd9e81c547d256e18c4d01902857ff2a6e7717c
1 [-*Smarty*-]
2 [-*****************************************************************************-]
3 [-* This is the source code for both day/default.html and week/default.html. *-]
4 [-* They should always be identical. If you change one, copy to the other! *-]
5 [-*****************************************************************************-]
6 [-* Copyright (C) 2005-2006 Rod Roark <rod@sunsetsystems.com> and others *-]
7 [-* *-]
8 [-* This program is free software; you can redistribute it and/or *-]
9 [-* modify it under the terms of the GNU General Public License *-]
10 [-* as published by the Free Software Foundation; either version 2 *-]
11 [-* of the License, or (at your option) any later version. *-]
12 [-*****************************************************************************-]
13 [-config_load file="default.conf"-]
14 [-*Load the Language Definitions*-]
15 [-config_load file="lang.$USER_LANG"-]
16 [-include file="$TPL_NAME/views/header.html"-]
17 [-* we want to include out stylesheet for this view*-]
18 [-fetch file="$TPL_STYLE_PATH/day.css" assign="css"-]
19 [-eval var=$css-]
21 <style>
22 a {
23 text-decoration:none;
25 td {
26 font-family: Arial, Helvetica, sans-serif;
28 .tacell {
29 font-size:10pt;
30 background-color:#ddffdd;
31 text-align:right;
33 .tucell {
34 font-size:10pt;
35 background-color:#ffbbbb;
36 text-align:right;
38 .eacell {
39 font-size:10pt;
40 background-color:#ffffff;
42 .eucell {
43 font-size:10pt;
44 background-color:#ffbbbb;
46 .bordyy {
48 .bordyn {
49 border-top-width:0px;
50 padding-top:0px;
52 .bordny {
53 border-bottom-width:0px;
54 padding-bottom:0px;
56 .bordnn {
57 border-top-width:0px;
58 border-bottom-width:0px;
59 padding-top:0px;
60 padding-bottom:0px;
62 div.tiny { width:1px; height:1px; font-size:1px; }
63 </style>
65 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
66 <script type="text/javascript" src="../../../library/dialog.js"></script>
67 <script type="text/javascript" src="../../../library/textformat.js"></script>
68 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
69 <script type="text/javascript" src="../../../library/dynarch_calendar_en.js"></script>
70 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
72 <script language='JavaScript'>
74 var mypcc = '[-php-] echo $GLOBALS['phone_country_code'] [-/php-]';
76 // This is called from the event editor popup.
77 function refreshme() {
78 top.restoreSession();
79 document.forms[0].submit();
82 function newEvt(startampm, starttimeh, starttimem, eventdate, providerid, catid) {
83 dlgopen('add_edit_event.php?startampm=' + startampm +
84 '&starttimeh=' + starttimeh + '&starttimem=' + starttimem +
85 '&date=' + eventdate + '&userid=' + providerid + '&catid=' + catid,
86 '_blank', 550, 270);
89 function oldEvt(eventdate, eventid) {
90 dlgopen('add_edit_event.php?eid=' + eventid, '_blank', 550, 270);
93 function goPid(pid) {
94 top.restoreSession();
95 [-php-]
96 if ($GLOBALS['concurrent_layout']) {
97 echo " top.RTop.location = '../../patient_file/summary/demographics.php' " .
98 "+ '?set_pid=' + pid;\n";
99 } else {
100 echo " top.location = '../../patient_file/patient_file.php' " .
101 "+ '?set_pid=' + pid + '&pid=' + pid;\n";
103 [-/php-]
106 function GoToToday(theForm){
107 var todays_date = new Date();
108 var theMonth = todays_date.getMonth() + 1;
109 theMonth = theMonth < 10 ? "0" + theMonth : theMonth;
110 theForm.jumpdate.value = todays_date.getFullYear() + "-" + theMonth + "-" + todays_date.getDate();
111 top.restoreSession();
112 theForm.submit();
115 </script>
117 <!-- Required for the popup date selectors -->
118 <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
120 [-php-]
122 // A_CATEGORY is an ordered array of associative-array categories.
123 // Keys of interest are: id, name, color, desc, event_duration.
125 // echo "<!-- A_CATEGORY = "; print_r($this->_tpl_vars['A_CATEGORY']); echo " -->\n"; // debugging
126 // echo "<!-- A_EVENTS = "; print_r($this->_tpl_vars['A_EVENTS']); echo " -->\n"; // debugging
128 $A_CATEGORY =& $this->_tpl_vars['A_CATEGORY'];
130 // [-if $PRINT_VIEW != 1-]
131 // [-*Main Navigation*-]
132 // [-include file="$TPL_NAME/views/global/navigation.html"-]
133 // [-/if-]
135 $A_EVENTS =& $this->_tpl_vars['A_EVENTS'];
136 // $S_EVENTS =& $this->_tpl_vars['S_EVENTS']; // Deleted by Rod
137 $providers =& $this->_tpl_vars['providers'];
138 $times =& $this->_tpl_vars['times'];
139 $interval = $this->_tpl_vars['interval'];
140 $viewtype = $this->_tpl_vars['VIEW_TYPE'];
141 $PREV_WEEK_URL = $this->_tpl_vars['PREV_WEEK_URL'];
142 $NEXT_WEEK_URL = $this->_tpl_vars['NEXT_WEEK_URL'];
143 $PREV_DAY_URL = $this->_tpl_vars['PREV_DAY_URL'];
144 $NEXT_DAY_URL = $this->_tpl_vars['NEXT_DAY_URL'];
146 $Date = postcalendar_getDate();
147 if (!isset($y)) $y = substr($Date, 0, 4);
148 if (!isset($m)) $m = substr($Date, 4, 2);
149 if (!isset($d)) $d = substr($Date, 6, 2);
151 // echo "<!-- There are " . count($A_EVENTS) . " A_EVENTS days -->\n";
153 $MULTIDAY = count($A_EVENTS) > 1;
155 $provinfo = getProviderInfo();
157 echo "<form name='theform' action='index.php?module=PostCalendar&func=view" .
158 "&tplview=default&pc_category=&pc_topic=' " .
159 "method='post' onsubmit='return top.restoreSession()'>\n";
160 echo "<center>\n";
161 echo "<table border='0' cellpadding='0' cellspacing='0' width='99%'>\n";
162 echo " <tr><td colspan='3' height='5'></td></tr>\n";
163 echo " <tr>\n";
165 // Build the scrolling selection list of providers.
166 echo " <td rowspan='2' align='left' valign='top' width='33%' nowrap>\n";
167 echo " <select multiple size='3' name='pc_username[]'>\n";
168 echo " <option value='__PC_ALL__'>" .xl ("All Users"). "</option>\n";
169 foreach ($provinfo as $doc) {
170 $username = $doc['username'];
171 echo " <option value='$username'";
172 foreach ($providers as $provider)
173 if ($provider['username'] == $username) echo " selected";
174 echo ">" . $doc['fname'] . " " . $doc['lname'] . "</option>\n";
176 echo " </select>\n";
178 // ==============================
179 // FACILITY FILTERING (lemonsoftware)
180 $facilities = getFacilities();
181 echo " <select name='pc_facility'>\n";
182 if ( !$_SESSION['pc_facility'] ) $selected = "selected='selected'";
183 echo " <option value='0' $selected>" .xl('All Facilities'). "</option>\n";
184 foreach ($facilities as $fa) {
185 $selected = ( $_SESSION['pc_facility'] == $fa['id']) ? "selected='selected'" : "" ;
186 echo " <option value='" .$fa['id']. "' $selected>" .$fa['name']. "</option>\n";
188 echo " </select>\n";
189 // EOS FF
190 // ==============================
192 echo " </td>\n";
194 // Build the date and view type selectors and the Go button and the Today button.
195 echo " <td align='center' valign='top' width='34%' nowrap>\n";
197 echo " <input type='text' size='10' name='jumpdate' id='jumpdate'\n" .
198 " value='$y-$m-$d' title='yyyy-mm-dd date to go to'\n" .
199 " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' />\n" .
200 " <img src='../../pic/show_calendar.gif' id='img_jumpdate' align='absbottom'\n" .
201 " width='24' height='22' border='0' alt='[?]' style='cursor:pointer'\n" .
202 " title='" .xl ("Click here to choose a date"). "'>\n";
204 echo " &nbsp;<select name='viewtype'>\n";
205 foreach ( array ('day' => xl("Day View"), 'week' => xl("Week View"), 'month' => xl("Month View"), 'year' => xl("Year View"))
206 as $key => $value) {
207 echo " <option value='$key'";
208 if ($key == $viewtype) echo " selected";
209 echo ">$value</option>\n";
211 echo " </select>\n";
212 echo " &nbsp;<input type='submit' name='bnsubmit' value='" .xl ("Go"). "' />\n";
213 echo " &nbsp;<input type='submit' name='bnsubmit' value='" .xl ("Today"). "' onClick='GoToToday(theform);' />\n";
214 echo " </td>\n";
216 // Show the Add and Search buttons.
217 echo " <td align='right' valign='top' width='33%' nowrap>\n";
218 echo " <input type='button' value='" .xl ("Add"). "' onclick='newEvt(1, 9, 00, $Date, 0, 0)' />\n";
219 echo " <input type='button' value='" . xl ("Search") .
220 "' onclick='top.restoreSession();location=\"index.php?module=PostCalendar&func=search\"' />\n";
221 echo " </td>\n";
222 echo " </tr>\n";
224 // Show the date/range and its previous- and next-day/week selectors.
225 echo " <tr>\n";
226 echo " <td align='center' width='34%' nowrap>\n";
227 $atmp = array_keys($A_EVENTS);
229 if ($MULTIDAY) {
230 echo "<a href='$PREV_WEEK_URL' onclick='top.restoreSession()'>&lt;&lt;</a>&nbsp;\n";
231 echo dateformat(strtotime($atmp[0]));
232 echo " - ";
233 echo dateformat(strtotime($atmp[count($atmp)-1]));
234 echo "&nbsp;<a href='$NEXT_WEEK_URL' onclick='top.restoreSession()'>&gt;&gt;</a>\n";
235 } else {
236 echo "<a href='$PREV_DAY_URL' onclick='top.restoreSession()'>&lt;&lt;</a>&nbsp;\n";
237 echo dateformat(strtotime($atmp[0]), true);
238 echo "&nbsp;<a href='$NEXT_DAY_URL' onclick='top.restoreSession()'>&gt;&gt;</a>\n";
240 echo " </td>\n";
241 echo " <td align='right' width='33%' nowrap>\n";
242 echo " &nbsp;\n";
243 echo " </td>\n";
245 echo " </tr>\n";
246 echo "</table>\n";
247 echo "</center>\n";
248 echo "</form>\n";
250 [-/php-]
252 <script language='JavaScript'>
253 Calendar.setup({inputField:"jumpdate", ifFormat:"%Y-%m-%d", button:"img_jumpdate"});
254 </script>
256 [-assign var="dayname" value=$DATE|date_format:"%w"-]
257 [-assign var="day" value=$DATE|date_format:"%d"|string_format:"%1d"-]
258 [-assign var="month" value=$DATE|date_format:"%m"|string_format:"%1d"-]
259 [-assign var="year" value=$DATE|date_format:"%Y"|string_format:"%4d"-]
261 [-pc_sort_events var="S_EVENTS" sort="time" order="asc" value=$A_EVENTS-]
263 [-php-]
265 echo "<table width='100%' border='1' cellpadding='1' cellspacing='0' >\n";
266 $tdstylearr = array('bordyy', 'bordny', 'bordyn', 'bordnn');
268 // For each day...
269 foreach ($A_EVENTS as $date => $events) {
270 $need_headers = true;
271 $eventdate = substr($date, 0, 4) . substr($date, 5, 2) . substr($date, 8, 2);
273 // If multiple days then show a date header for each.
274 if ($MULTIDAY) {
275 echo " <tr>\n";
276 echo " <td colspan='" . (count($providers) * 2) . "' align='center'>" .
277 dateformat(strtotime($date), true) . "</td>";
278 echo " </tr>\n";
281 $arr_events = $S_EVENTS[$date];
282 list($slotkey, $slotevent) = each($arr_events);
284 // This is an array of provider status information for this day,
285 // used to properly assign table cell attributes.
286 $provstat = array();
288 $slotindex = 0;
289 $lastslotindex = count($times) - 1;
291 // For each time slot...
292 foreach ($times as $slottime) {
293 $startampm = ($slottime['mer']) == "pm" ? 2 : 1;
294 $starttimeh = $slottime['hour'];
295 $starttimem = $slottime['minute'];
296 $slotendmins = $starttimeh * 60 + $starttimem + $interval;
298 // Repeat doc names at 1PM. This is a kludge; omit it for released code.
299 // if ($starttimeh == 13 && $starttimem == 0) $need_headers = true;
301 // Get all events for all providers just for this time slot now, because we
302 // can pick up where we left off and because we don't want to re-scan all
303 // events for the day for each table cell.
305 $arr_slot = array();
306 for (; isset($slotkey); list($slotkey, $slotevent) = each($arr_events)) {
307 $starth = substr($slotevent['startTime'], 0, 2);
308 $startm = substr($slotevent['startTime'], 3, 2);
310 if (($starth * 60 + $startm) >= $slotendmins) break;
312 $arr_slot[$slotkey] = $slotevent;
314 $catid = $slotevent['catid'];
315 $providerid = $slotevent['aid'];
316 $durminutes = ceil($slotevent['duration'] / 60);
317 $durslots = ceil($durminutes / $interval);
319 // While we're here, collect information for cell cosmetics.
320 if ($catid == 2) { // in office
321 $provstat[$providerid]['in'] = true;
323 // Save preferred category info for this IN event.
324 $provstat[$providerid]['in_cat'] = -1;
325 $provstat[$providerid]['in_slot0'] = $slotindex;
326 $provstat[$providerid]['in_slots'] = 1;
327 if ($slotevent['prefcatid']) {
328 foreach ($A_CATEGORY as $catkey => $catval) {
329 if ($catval['id'] == $slotevent['prefcatid']) {
330 $provstat[$providerid]['in_cat'] = $catkey;
331 $provstat[$providerid]['in_slots'] =
332 ceil(ceil($catval['event_duration'] / 60) / $interval);
333 break;
336 // Debugging:
337 if ($provstat[$providerid]['in_cat'] < 0) {
338 echo "<!-- Unmatched prefcatid = " . $slotevent['prefcatid'] . " -->\n"; // debugging
343 else if ($catid == 3) { // out of office
344 $provstat[$providerid]['in'] = false;
346 else if ($catid == 4 || $catid == 8 || $catid == 11) { // unavailable types
347 // unavailable slots are marked 'res' for appropriate coloring.
348 $endindex = $slotindex + $durslots;
349 for ($i = $slotindex; $i < $endindex; ++$i) {
350 $provstat[$providerid][$i]['res'] = true;
353 // If duration > slot size then mark slots for border control. A slot
354 // marked 'ext' is not to have a border between itself and the slot below.
355 if ($durslots > 1) {
356 $endindex = $slotindex + $durslots - 1;
357 for ($i = $slotindex; $i < $endindex; ++$i) {
358 $provstat[$providerid][$i]['ext'] = true;
362 // Finished getting event information for this time slot.
364 // Write a header row with the provider names if appropriate.
365 if ($need_headers) {
366 $need_headers = false;
367 echo " <tr>\n";
368 foreach ($providers as $provider) {
369 echo " <td colspan='2' align='center'>";
370 echo $provider['fname'][0] . " " . $provider['lname'];
371 echo "</td>\n";
373 echo " </tr>\n";
376 echo " <tr>\n";
378 // We are now ready to write the table row for the current time slot.
379 // This loops once for each provider to be displayed.
381 foreach ($providers as $provider) {
382 $providerid = $provider['id'];
384 // Mark this as a no-bottom-border slot if the preferred category
385 // duration extends beyond it.
387 // echo "<!-- slotindex=$slotindex in=" . $provstat[$providerid]['in'] .
388 // " in_cat=" . $provstat[$providerid]['in_cat'] .
389 // " in_slot0=" . $provstat[$providerid]['in_slot0'] .
390 // " in_slots=" . $provstat[$providerid]['in_slots'] . " -->\n"; // debugging
392 if ($provstat[$providerid]['in']) {
393 if (($slotindex + 1 - $provstat[$providerid]['in_slot0']) % $provstat[$providerid]['in_slots'])
394 $provstat[$providerid][$slotindex]['ext'] = true;
397 $content = ""; // this will be the event cell content
399 $clsuffix = "acell";
400 if ($provstat[$providerid][$slotindex]['res'] || ! $provstat[$providerid]['in']) {
401 $clsuffix = "ucell";
404 // Remove top and/or bottom table cell borders using CSS when events span
405 // time slots or when the practitioner is not in-office. Using "rowspan"
406 // would be a difficult and inferior solution to this problem.
408 $tdstyleix = 0;
409 $timelabel = true;
410 if ($slotindex < $lastslotindex &&
411 ($provstat[$providerid][$slotindex]['ext'] || !$provstat[$providerid]['in'])) {
412 $tdstyleix += 1; // no bottom
414 if ($slotindex > 0 && ($provstat[$providerid][$slotindex-1]['ext'] ||
415 !($provstat[$providerid]['in'] || $provstat[$providerid]['wasin']))) {
416 $tdstyleix += 2; // no top
417 $timelabel = false;
419 $tdstyle = ' ' . $tdstylearr[$tdstyleix];
421 $disptimeh = ($starttimeh > 12) ? ($starttimeh - 12) : $starttimeh;
423 $in_cat_id = 0;
424 if ($provstat[$providerid]['in_cat'] >= 0) {
425 $category =& $A_CATEGORY[$provstat[$providerid]['in_cat']];
426 if ($category['id']) $in_cat_id = $category['id'];
429 // If a slot omits the top border, then we omit the TOD cell's top border
430 // and skip writing its time-of-day text. This way we can get some rows
431 // with no content at all, which should produce a more compact and readable
432 // calendar display.
434 echo " <td class='t$clsuffix$tdstyle'";
435 if ($slotindex == 0) echo " width='1%'";
436 echo ">";
437 if ($timelabel) {
438 echo "<a href='javascript:newEvt($startampm,$starttimeh,$starttimem,$eventdate,$providerid,$in_cat_id)'>";
439 echo "$disptimeh:$starttimem</a>";
440 } else {
441 echo "<div class=tiny></div>"; // 1x1 px content so the browser does not suppress borders
443 echo "</td>\n";
445 echo " <td class='e$clsuffix$tdstyle'";
446 if ($clsuffix == "acell" && $in_cat_id) {
447 echo " style='background-color:" . $category['color'] . "'";
448 echo " title='" . $category['name'] . "'";
450 echo ">";
452 // Scan all events for this time slot and generate the associated HTML for
453 // this doc. JavaScript is used in hrefs to reduce the volume of output.
455 reset($arr_slot);
456 while (list($eventkey, $event) = each($arr_slot)) {
457 if ($event['aid'] != $providerid) continue;
458 if ($content) $content .= " ";
459 $starth = substr($event['startTime'], 0, 2);
460 $startm = substr($event['startTime'], 3, 2);
461 $eventid = $event['eid'];
462 $patientid = $event['pid'];
463 $commapos = strpos($event['patient_name'], ",");
464 $lname = addslashes(ucfirst(strtolower(substr($event['patient_name'], 0, $commapos))));
465 $fname = addslashes(ucfirst(strtolower(substr($event['patient_name'], $commapos + 2))));
466 $patient_dob = $event['patient_dob'];
467 $patient_age = $event['patient_age'];
468 $catid = $event['catid'];
469 $comment = $event['hometext'];
470 $catname = $event['catname'];
471 $title = "Age $patient_age ($patient_dob)";
472 if ($event['hometext'] && $GLOBALS['calendar_appt_style'] < 4)
473 $title .= " " . addslashes($event['hometext']);
474 if ($catid == 2 || $catid == 3 || $catid == 4 || $catid == 8 || $catid == 11) {
475 if ($catid == 2) $catname = "IN";
476 else if ($catid == 3) $catname = "OUT";
477 else if ($catid == 4) $catname = "VACATION";
478 else if ($catid == 8) $catname = "LUNCH";
479 else if ($catid == 11) $catname = "RESERVED";
480 // Omit lunch, vacation, etc. if the doc is not in-office.
481 if ($provstat[$providerid]['in'] || $catid < 4) {
482 $content .= "<a href='javascript:oldEvt($eventdate,$eventid)'>";
483 $content .= $catname . " - $comment</a>";
486 else { // some sort of patient appointment
487 $content .= "<a href='javascript:oldEvt($eventdate,$eventid)' title='$catname'>";
488 $content .= $starth . ':' . $startm . htmlspecialchars($event['apptstatus']) . "</a>";
489 $content .= "<a href='javascript:goPid($patientid)' title='$title'>";
490 if ($catid == 1) $content .= "<strike>";
491 $content .= $lname;
492 if ($GLOBALS['calendar_appt_style'] != 1) {
493 $content .= "," . $fname;
494 if ($event['title'] && $GLOBALS['calendar_appt_style'] >= 3) {
495 $content .= "(" . $event['title'];
496 if ($event['hometext'] && $GLOBALS['calendar_appt_style'] >= 4)
497 $content .= ": <font color='green'>" . htmlspecialchars(trim($event['hometext'])) . "</font>";
498 $content .= ")";
501 if ($catid == 1) $content .= "</strike>";
502 $content .= "</a>";
504 } // end while
506 if (! $content) $content = "<div class=tiny></div>"; // so the browser does not suppress borders
507 echo $content . "</td>\n";
509 // Keep track of whether the doc was in during the previous time slot.
510 $provstat[$providerid]['wasin'] = $provstat[$providerid]['in'];
512 } // end provider
514 echo " </tr>\n";
516 ++$slotindex;
517 } // end time slot
518 } // end day
520 echo "</table>\n";
522 // [-*footer*-]
523 // [-include file="$TPL_NAME/views/global/footer.html"-]
524 // [-include file="$TPL_NAME/views/footer.html"-]
526 [-/php-]
528 </body>
529 </html>