2 // Copyright (C) 2005-2006 Rod Roark <rod@sunsetsystems.com>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // The event editor looks something like this:
11 //------------------------------------------------------------//
12 // Category __________________V O All day event //
13 // Date _____________ [?] O Time ___:___ __V //
14 // Title ___________________ duration ____ minutes //
15 // Patient _(Click_to_select)_ //
16 // Provider __________________V X Repeats ______V ______V //
17 // Status __________________V until __________ [?] //
18 // Comments ________________________________________________ //
20 // [Save] [Find Available] [Delete] [Cancel] //
21 //------------------------------------------------------------//
26 //landing page definition -- where to go if something goes wrong
27 $landingpage = "index.php?site=".$_SESSION['site_id'];
30 // kick out if patient not authenticated
31 if ( isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite']) ) {
32 $pid = $_SESSION['pid'];
36 header('Location: '.$landingpage.'&w');
44 include_once("../interface/globals.php");
45 include_once("$srcdir/patient.inc");
46 include_once("$srcdir/forms.inc");
48 // Exit if the modify calendar for portal flag is not set
49 if (!($GLOBALS['portal_onsite_appt_modify'])) {
50 echo htmlspecialchars( xl('You are not authorized to schedule appointments.'),ENT_NOQUOTES
);
54 // Things that might be passed by our opener.
56 $eid = $_GET['eid']; // only for existing events
57 $date = $_GET['date']; // this and below only for new events
58 $userid = $_GET['userid'];
59 $default_catid = $_GET['catid'] ?
$_GET['catid'] : '5';
60 $patientid = $_GET['patid'];
63 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
65 $date = date("Y-m-d");
68 if (isset($_GET['starttimem']))
69 $starttimem = substr('00' . $_GET['starttimem'], -2);
71 if (isset($_GET['starttimeh'])) {
72 $starttimeh = $_GET['starttimeh'];
73 if (isset($_GET['startampm'])) {
74 if ($_GET['startampm'] == '2' && $starttimeh < 12)
78 $starttimeh = date("G");
84 // ===========================
85 // EVENTS TO FACILITIES (lemonsoftware)
86 // edit event case - if there is no association made, then insert one with the first facility
89 $facility = sqlQuery("SELECT pc_facility, pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
90 if ( !$facility['pc_facility'] ) {
91 $qmin = sqlQuery("SELECT MIN(id) as minId FROM facility");
92 $min = $qmin['minId'];
94 // multiple providers case
95 if ( $GLOBALS['select_multi_providers'] ) {
96 $mul = $facility['pc_multiple'];
97 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
101 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
104 $e2f = $facility['pc_facility'];
108 // ===========================
109 // ===========================
111 // EVENTS TO FACILITIES (lemonsoftware)
112 //(CHEMED) get facility name
113 // edit event case - if there is no association made, then insert one with the first facility
116 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
117 FROM openemr_postcalendar_events
118 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
119 WHERE pc_eid = $eid");
120 if ( !$facility['pc_facility'] ) {
121 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ".$facility['pc_aid']);
122 $min = $qmin['minId'];
123 $min_name = $qmin['facility'];
125 // multiple providers case
126 if ( $GLOBALS['select_multi_providers'] ) {
127 $mul = $facility['pc_multiple'];
128 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
132 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
134 $e2f_name = $min_name;
136 $e2f = $facility['pc_facility'];
137 $e2f_name = $facility['name'];
141 // ===========================
144 // If we are saving, then save and close the window.
146 if ($_POST['form_action'] == "save") {
149 $event_date = fixDate($_POST['form_date']);
151 // Compute start and end time strings to be saved.
152 if ($_POST['form_allday']) {
157 $tmph = $_POST['form_hour'] +
0;
158 $tmpm = $_POST['form_minute'] +
0;
159 if ($_POST['form_ampm'] == '2' && $tmph < 12) $tmph +
= 12;
160 $duration = $_POST['form_duration'];
162 $starttime = "$tmph:$tmpm:00";
165 while ($tmpm >= 60) {
169 $endtime = "$tmph:$tmpm:00";
171 // Useless garbage that we must save.
172 $locationspec = 'a:6:{s:14:"event_location";N;s:13:"event_street1";N;' .
173 's:13:"event_street2";N;s:10:"event_city";N;s:11:"event_state";N;s:12:"event_postal";N;}';
175 // More garbage, but this time 1 character of it is used to save the
177 if ($_POST['form_repeat']) {
178 $recurrspec = 'a:5:{' .
179 's:17:"event_repeat_freq";s:1:"' . $_POST['form_repeat_freq'] . '";' .
180 's:22:"event_repeat_freq_type";s:1:"' . $_POST['form_repeat_type'] . '";' .
181 's:19:"event_repeat_on_num";s:1:"1";' .
182 's:19:"event_repeat_on_day";s:1:"0";' .
183 's:20:"event_repeat_on_freq";s:1:"0";}';
185 $recurrspec = 'a:5:{' .
186 's:17:"event_repeat_freq";N;' .
187 's:22:"event_repeat_freq_type";s:1:"0";' .
188 's:19:"event_repeat_on_num";s:1:"1";' .
189 's:19:"event_repeat_on_day";s:1:"0";' .
190 's:20:"event_repeat_on_freq";s:1:"1";}';
193 //The modification of the start date for events that take place on one day of the week
194 //for example monday, or thursday. We set the start date on the first day of the week
195 //that the event is scheduled. For example if you set the event to repeat on each monday
196 //the start date of the event will be set on the first monday after the day the event is scheduled
197 if($_POST['form_repeat_type'] == 5)
199 $exploded_date= explode("-",$event_date);
200 $edate = date("D",mktime(0,0,0,$exploded_date[1],$exploded_date[2],$exploded_date[0]));
202 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
6,$exploded_date[0]));
204 elseif($edate=="Wed") {
205 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
5,$exploded_date[0]));
207 elseif($edate=="Thu") {
208 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
4,$exploded_date[0]));
210 elseif($edate=="Fri") {
211 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
3,$exploded_date[0]));
213 elseif($edate=="Sat") {
214 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
2,$exploded_date[0]));
216 elseif($edate=="Sun") {
217 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
1,$exploded_date[0]));
219 } elseif($_POST['form_repeat_type'] == 6) {
220 $exploded_date= explode("-",$event_date);
221 $edate = date("D",mktime(0,0,0,$exploded_date[1],$exploded_date[2],$exploded_date[0]));
223 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
6,$exploded_date[0]));
225 elseif($edate=="Thu") {
226 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
5,$exploded_date[0]));
228 elseif($edate=="Fri") {
229 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
4,$exploded_date[0]));
231 elseif($edate=="Sat") {
232 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
3,$exploded_date[0]));
234 elseif($edate=="Sun") {
235 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
2,$exploded_date[0]));
237 elseif($edate=="Mon") {
238 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
1,$exploded_date[0]));
240 } elseif($_POST['form_repeat_type'] == 7) {
241 $exploded_date= explode("-",$event_date);
242 $edate = date("D",mktime(0,0,0,$exploded_date[1],$exploded_date[2],$exploded_date[0]));
244 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
6,$exploded_date[0]));
246 elseif($edate=="Fri") {
247 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
5,$exploded_date[0]));
249 elseif($edate=="Sat") {
250 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
4,$exploded_date[0]));
252 elseif($edate=="Sun") {
253 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
3,$exploded_date[0]));
255 elseif($edate=="Mon") {
256 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
2,$exploded_date[0]));
258 elseif($edate=="Tue") {
259 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
1,$exploded_date[0]));
261 } elseif($_POST['form_repeat_type'] == 8) {
262 $exploded_date= explode("-",$event_date);
263 $edate = date("D",mktime(0,0,0,$exploded_date[1],$exploded_date[2],$exploded_date[0]));
265 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
6,$exploded_date[0]));
267 elseif($edate=="Sat") {
268 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
5,$exploded_date[0]));
270 elseif($edate=="Sun") {
271 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
4,$exploded_date[0]));
273 elseif($edate=="Mon") {
274 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
3,$exploded_date[0]));
276 elseif($edate=="Tue") {
277 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
2,$exploded_date[0]));
279 elseif($edate=="Wed") {
280 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
1,$exploded_date[0]));
282 } elseif($_POST['form_repeat_type'] == 9) {
283 $exploded_date= explode("-",$event_date);
284 $edate = date("D",mktime(0,0,0,$exploded_date[1],$exploded_date[2],$exploded_date[0]));
286 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
6,$exploded_date[0]));
288 elseif($edate=="Sun") {
289 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
5,$exploded_date[0]));
291 elseif($edate=="Mon") {
292 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
4,$exploded_date[0]));
294 elseif($edate=="Tue") {
295 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
3,$exploded_date[0]));
297 elseif($edate=="Wed") {
298 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
2,$exploded_date[0]));
300 elseif($edate=="Thu") {
301 $event_date=date("Y-m-d",mktime(0,0,0,$exploded_date[1],$exploded_date[2]+
1,$exploded_date[0]));
304 /* =======================================================
306 ========================================================*/
309 // what is multiple key around this $eid?
310 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
312 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
313 /* ==========================================
314 // multi providers BOS
315 ==========================================*/
317 // obtain current list of providers regarding the multiple key
318 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
319 while ($current = sqlFetchArray($up)) {
320 $providers_current[] = $current['pc_aid'];
323 $providers_new = $_POST['form_provider'];
325 // this difference means that some providers from current was UNCHECKED
326 // so we must delete this event for them
327 $r1 = array_diff ($providers_current, $providers_new);
329 foreach ($r1 as $to_be_removed) {
330 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid='$to_be_removed' AND pc_multiple={$row['pc_multiple']}");
334 // this difference means that some providers was added
335 // so we must insert this event for them
336 $r2 = array_diff ($providers_new, $providers_current);
338 foreach ($r2 as $to_be_inserted) {
339 sqlInsert("INSERT INTO openemr_postcalendar_events ( pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility)
341 "'" . $_POST['form_category'] . "', " .
342 "'" . $row['pc_multiple'] . "', " .
343 "'" . $to_be_inserted . "', " .
344 "'" . $_POST['form_pid'] . "', " .
345 "'" . $_POST['form_title'] . "', " .
347 "'" . $_POST['form_comments'] . "', " .
348 "'" . $_SESSION['authUserID'] . "', " .
349 "'" . $event_date . "', " .
350 "'" . fixDate($_POST['form_enddate']) . "', " .
351 "'" . ($duration * 60) . "', " .
352 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
356 "'" . $_POST['form_allday'] . "', " .
357 "'" . $_POST['form_apptstatus'] . "', " .
358 "'" . $_POST['form_prefcat'] . "', " .
359 "'$locationspec', " .
361 "1, " .(int)$_POST['facility']. " )"); // FF stuff
366 // after the two diffs above, we must update for remaining providers
367 // those who are intersected in $providers_current and $providers_new
368 foreach ($_POST['form_provider'] as $provider) {
369 sqlStatement("UPDATE openemr_postcalendar_events SET " .
370 "pc_catid = '" . $_POST['form_category'] . "', " .
371 "pc_pid = '" . $_POST['form_pid'] . "', " .
372 "pc_title = '" . $_POST['form_title'] . "', " .
373 "pc_time = NOW(), " .
374 "pc_hometext = '" . $_POST['form_comments'] . "', " .
375 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
376 "pc_eventDate = '" . $event_date . "', " .
377 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
378 "pc_duration = '" . ($duration * 60) . "', " .
379 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
380 "pc_recurrspec = '$recurrspec', " .
381 "pc_startTime = '$starttime', " .
382 "pc_endTime = '$endtime', " .
383 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
384 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
385 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
386 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
387 "WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
390 /* ==========================================
391 // multi providers EOS
392 ==========================================*/
394 } elseif ( !$row['pc_multiple'] ) {
395 if ( $GLOBALS['select_multi_providers'] ) {
396 $prov = $_POST['form_provider'][0];
398 $prov = $_POST['form_provider'];
401 // simple provider case
402 sqlStatement("UPDATE openemr_postcalendar_events SET " .
403 "pc_catid = '" . $_POST['form_category'] . "', " .
404 "pc_aid = '" . $prov . "', " .
405 "pc_pid = '" . $_POST['form_pid'] . "', " .
406 "pc_title = '" . $_POST['form_title'] . "', " .
407 "pc_time = NOW(), " .
408 "pc_hometext = '" . $_POST['form_comments'] . "', " .
409 "pc_informant = '" . $_SESSION['authUserID'] . "', " .
410 "pc_eventDate = '" . $event_date . "', " .
411 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
412 "pc_duration = '" . ($duration * 60) . "', " .
413 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
414 "pc_recurrspec = '$recurrspec', " .
415 "pc_startTime = '$starttime', " .
416 "pc_endTime = '$endtime', " .
417 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
418 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
419 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
420 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
421 "WHERE pc_eid = '$eid'");
425 // =======================================
426 // EOS multi providers case
427 // =======================================
429 // EVENTS TO FACILITIES
433 /* =======================================================
435 ========================================================*/
438 // =======================================
439 // multi providers case
440 // =======================================
442 if (is_array($_POST['form_provider'])) {
444 // obtain the next available unique key to group multiple providers around some event
445 $q = sqlStatement ("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
446 $max = sqlFetchArray($q);
447 $new_multiple_value = $max['max'] +
1;
449 foreach ($_POST['form_provider'] as $provider) {
450 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
451 "pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
452 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
453 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
454 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
456 "'" . $_POST['form_category'] . "', " .
457 "'" . $new_multiple_value . "', " .
458 "'" . $provider . "', " .
459 "'" . $_POST['form_pid'] . "', " .
460 "'" . $_POST['form_title'] . "', " .
462 "'" . $_POST['form_comments'] . "', " .
463 "'" . $_SESSION['authUserID'] . "', " .
464 "'" . $event_date . "', " .
465 "'" . fixDate($_POST['form_enddate']) . "', " .
466 "'" . ($duration * 60) . "', " .
467 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
471 "'" . $_POST['form_allday'] . "', " .
472 "'" . $_POST['form_apptstatus'] . "', " .
473 "'" . $_POST['form_prefcat'] . "', " .
474 "'$locationspec', " .
476 "1, " .(int)$_POST['facility']. " )"); // FF stuff
481 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
482 "pc_catid, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
483 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
484 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
485 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
487 "'" . $_POST['form_category'] . "', " .
488 "'" . $_POST['form_provider'] . "', " .
489 "'" . $_POST['form_pid'] . "', " .
490 "'" . $_POST['form_title'] . "', " .
492 "'" . $_POST['form_comments'] . "', " .
493 "'" . $_SESSION['authUserID'] . "', " .
494 "'" . $event_date . "', " .
495 "'" . fixDate($_POST['form_enddate']) . "', " .
496 "'" . ($duration * 60) . "', " .
497 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
501 "'" . $_POST['form_allday'] . "', " .
502 "'" . $_POST['form_apptstatus'] . "', " .
503 "'" . $_POST['form_prefcat'] . "', " .
504 "'$locationspec', " .
506 "1," .(int)$_POST['facility']. ")"); // FF stuff
510 // Save new DOB if it's there.
511 $patient_dob = trim($_POST['form_dob']);
512 if ($patient_dob && $_POST['form_pid']) {
513 sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
514 "pid = '" . $_POST['form_pid'] . "'");
517 // Auto-create a new encounter if appropriate.
520 /* if ($GLOBALS['auto_create_new_encounters'] &&
521 $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
524 // We decided not to auto-create blank enconter when user arrives. Todd's decision 18 Jun 2010
525 // Applied by Cassian Lup (cassian.lup@clinicdr.com)
528 $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
529 "pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'");
530 if ($tmprow['count'] == 0) {
531 $tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = '" .
532 $_POST['form_provider'] . "'");
533 $username = $tmprow['username'];
534 $facility = $tmprow['facility'];
535 $facility_id = $tmprow['facility_id'];
536 $conn = $GLOBALS['adodb']['db'];
537 $encounter = $conn->GenID("sequences");
538 addForm($encounter, "New Patient Encounter",
539 sqlInsert("INSERT INTO form_encounter SET " .
540 "date = '$event_date', " .
541 "onset_date = '$event_date', " .
542 "reason = '" . $_POST['form_comments'] . "', " .
543 "facility = '$facility', " .
544 "facility_id = '$facility_id', " .
545 "pid = '" . $_POST['form_pid'] . "', " .
546 "encounter = '$encounter'"
548 "newpatient", $_POST['form_pid'], "1", "NOW()", $username
550 $info_msg .= "New encounter $encounter was created. ";
555 else if ($_POST['form_action'] == "delete") {
556 // =======================================
557 // multi providers case
558 // =======================================
559 if ($GLOBALS['select_multi_providers']) {
560 // what is multiple key around this $eid?
561 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
562 if ( $row['pc_multiple'] ) {
563 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_multiple = {$row['pc_multiple']}");
565 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = $eid");
567 // =======================================
568 // EOS multi providers case
569 // =======================================
571 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = '$eid'");
575 if ($_POST['form_action'] != "") {
576 // Close this window and refresh the calendar display.
577 echo "<html>\n<body>\n<script language='JavaScript'>\n";
578 if ($info_msg) echo " alert('$info_msg');\n";
579 // echo " if (!opener.closed && opener.refreshme) opener.refreshme();\n";
580 // echo " if (!opener.closed && opener.refreshme) window.opener.location.reload(true);\n";
581 // echo " opener.refreshme();";
582 // echo " window.location='https://ehr.clinicdr.com/".$GLOBALS['instance_name']."/clinicdr-ehr/interface/main/calendar/index.php?module=PostCalendar&func=view&tplview=default&pc_category=&pc_topic='";
583 echo " parent.jQuery.fn.fancybox.close();\n";
584 echo "</script>\n</body>\n</html>\n";
587 // If we get this far then we are displaying the form.
591 '*' => xl('* Reminder done'),
592 '+' => xl('+ Chart pulled'),
593 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
594 '?' => xl('? No show'),
595 '@' => xl('@ Arrived'),
596 '~' => xl('~ Arrived late'),
597 '!' => xl('! Left w/o visit'),
598 '#' => xl('# Ins/fin issue'),
599 '<' => xl('< In exam room'),
600 '>' => xl('> Checked out'),
601 '$' => xl('$ Coding done'),
604 $repeats = 0; // if the event repeats
611 // If we are editing an existing event, then get its data.
613 $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
614 $date = $row['pc_eventDate'];
615 $userid = $row['pc_aid'];
616 $patientid = $row['pc_pid'];
617 $starttimeh = substr($row['pc_startTime'], 0, 2) +
0;
618 $starttimem = substr($row['pc_startTime'], 3, 2);
619 $repeats = $row['pc_recurrtype'];
620 $multiple_value = $row['pc_multiple'];
622 if (preg_match('/"event_repeat_freq_type";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
623 $repeattype = $matches[1];
625 if (preg_match('/"event_repeat_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
626 $repeatfreq = $matches[1];
628 $hometext = $row['pc_hometext'];
629 if (substr($hometext, 0, 6) == ':text:') $hometext = substr($hometext, 6);
632 $patientid=$_GET['pid'];
635 // If we have a patient ID, get the name and phone numbers to display.
637 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
638 "FROM patient_data WHERE pid = '" . $patientid . "'");
639 $patientname = $prow['lname'] . ", " . $prow['fname'];
640 if ($prow['phone_home']) $patienttitle .= " H=" . $prow['phone_home'];
641 if ($prow['phone_biz']) $patienttitle .= " W=" . $prow['phone_biz'];
644 // Get the providers list.
645 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
646 "authorized != 0 AND active = 1 ORDER BY lname, fname");
648 //-------------------------------------
650 //Set default facility for a new event based on the given 'userid'
652 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
653 $e2f = $pref_facility['facility_id'];
654 $e2f_name = $pref_facility['facility'];
656 //END of CHEMED -----------------------
658 // Get event categories.
659 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
660 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
662 // Fix up the time format for AM/PM.
664 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
666 if ($starttimeh > 12) $starttimeh -= 12;
672 <?php
html_header_show(); ?
>
673 <title
><?php
echo $eid ?
"Edit" : "Add New" ?
> <?php
xl('Event','e');?
></title
>
674 <link rel
="stylesheet" href
='<?php echo $css_header ?>' type
='text/css'>
677 td
{ font
-size
:0.8em
; }
680 <style type
="text/css">@import
url(../library
/dynarch_calendar
.css
);</style
>
681 <script type
="text/javascript" src
="../library/topdialog.js"></script
>
682 <script type
="text/javascript" src
="../library/dialog.js"></script
>
683 <script type
="text/javascript" src
="../library/textformat.js"></script
>
684 <script type
="text/javascript" src
="../library/dynarch_calendar.js"></script
>
685 <script type
="text/javascript" src
="../library/dynarch_calendar_en.js"></script
>
686 <script type
="text/javascript" src
="../library/dynarch_calendar_setup.js"></script
>
688 <script language
="JavaScript">
690 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
692 var durations
= new Array();
693 // var rectypes = new Array();
695 // Read the event categories, generate their options list, and get
696 // the default event duration from them if this is a new event.
698 $prefcat_options = " <option value='0'>-- None --</option>\n";
701 $thisduration = $row['pc_alldayevent'] ?
1440 : round($row['pc_duration'] / 60);
703 while ($crow = sqlFetchArray($cres)) {
704 $duration = round($crow['pc_duration'] / 60);
705 if ($crow['pc_end_all_day']) $duration = 1440;
706 echo " durations[" . $crow['pc_catid'] . "] = $duration\n";
707 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
708 $catoptions .= " <option value='" . $crow['pc_catid'] . "'";
710 if ($crow['pc_catid'] == $row['pc_catid']) $catoptions .= " selected";
712 if ($crow['pc_catid'] == $default_catid) {
713 $catoptions .= " selected";
714 $thisduration = $duration;
717 $catoptions .= ">" . $crow['pc_catname'] . "</option>\n";
719 // This section is to build the list of preferred categories:
721 $prefcat_options .= " <option value='" . $crow['pc_catid'] . "'";
723 if ($crow['pc_catid'] == $row['pc_prefcatid']) $prefcat_options .= " selected";
725 $prefcat_options .= ">" . $crow['pc_catname'] . "</option>\n";
731 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
733 // This is for callback by the find-patient popup.
734 function setpatient(pid
, lname
, fname
, dob
) {
735 var f
= document
.forms
[0];
736 f
.form_patient
.value
= lname +
', ' + fname
;
737 f
.form_pid
.value
= pid
;
738 dobstyle
= (dob
== '' || dob
.substr(5, 10) == '00-00') ?
'' : 'none';
739 document
.getElementById('dob_row').style
.display
= dobstyle
;
741 function change_provider(){
742 var f
= document
.forms
[0];
743 f
.form_date
.value
='';
744 f
.form_hour
.value
='';
745 f
.form_minute
.value
='';
747 // This is for callback by the find-patient popup.
748 function unsetpatient() {
749 var f
= document
.forms
[0];
750 f
.form_patient
.value
= '';
751 f
.form_pid
.value
= '';
754 // This invokes the find-patient popup.
755 function sel_patient() {
756 dlgopen('find_patient_popup.php', '_blank', 500, 400);
759 // Do whatever is needed when a new event category is selected.
760 // For now this means changing the event title and duration.
761 function set_display() {
762 var f
= document
.forms
[0];
763 var s
= f
.form_category
;
764 if (s
.selectedIndex
>= 0) {
765 var catid
= s
.options
[s
.selectedIndex
].value
;
766 var style_apptstatus
= document
.getElementById('title_apptstatus').style
;
767 var style_prefcat
= document
.getElementById('title_prefcat').style
;
768 if (catid
== '2') { // In Office
769 style_apptstatus
.display
= 'none';
770 style_prefcat
.display
= '';
771 f
.form_apptstatus
.style
.display
= 'none';
772 f
.form_prefcat
.style
.display
= '';
774 style_prefcat
.display
= 'none';
775 style_apptstatus
.display
= '';
776 f
.form_prefcat
.style
.display
= 'none';
777 f
.form_apptstatus
.style
.display
= '';
782 // Gray out certain fields according to selection of Category DDL
783 function categoryChanged() {
786 document
.getElementById("form_patient").disabled
=false;
787 //document.getElementById("form_apptstatus").disabled=false;
788 //document.getElementById("form_prefcat").disabled=false;
792 // Do whatever is needed when a new event category is selected.
793 // For now this means changing the event title and duration.
794 function set_category() {
795 var f
= document
.forms
[0];
796 var s
= f
.form_category
;
797 if (s
.selectedIndex
>= 0) {
798 var catid
= s
.options
[s
.selectedIndex
].value
;
799 f
.form_title
.value
= s
.options
[s
.selectedIndex
].text
;
800 f
.form_duration
.value
= durations
[catid
];
805 // Modify some visual attributes when the all-day or timed-event
806 // radio buttons are clicked.
807 function set_allday() {
808 var f
= document
.forms
[0];
809 var color1
= '#777777';
810 var color2
= '#777777';
811 var disabled2
= true;
812 /*if (document.getElementById('rballday1').checked) {
815 if (document.getElementById('rballday2').checked) {
819 document
.getElementById('tdallday1').style
.color
= color1
;
820 document
.getElementById('tdallday2').style
.color
= color2
;
821 document
.getElementById('tdallday3').style
.color
= color2
;
822 document
.getElementById('tdallday4').style
.color
= color2
;
823 document
.getElementById('tdallday5').style
.color
= color2
;
824 f
.form_hour
.disabled
= disabled2
;
825 f
.form_minute
.disabled
= disabled2
;
826 f
.form_ampm
.disabled
= disabled2
;
827 f
.form_duration
.disabled
= disabled2
;
830 // Modify some visual attributes when the Repeat checkbox is clicked.
831 function set_repeat() {
832 var f
= document
.forms
[0];
833 var isdisabled
= true;
834 var mycolor
= '#777777';
835 var myvisibility
= 'hidden';
836 /*if (f.form_repeat.checked) {
839 myvisibility = 'visible';
841 //f.form_repeat_type.disabled = isdisabled;
842 //f.form_repeat_freq.disabled = isdisabled;
843 //f.form_enddate.disabled = isdisabled;
844 document
.getElementById('tdrepeat1').style
.color
= mycolor
;
845 document
.getElementById('tdrepeat2').style
.color
= mycolor
;
846 document
.getElementById('img_enddate').style
.visibility
= myvisibility
;
849 // This is for callback by the find-available popup.
850 function setappt(year
,mon
,mday
,hours
,minutes
) {
851 var f
= document
.forms
[0];
852 f
.form_date
.value
= '' + year +
'-' +
853 ('' +
(mon +
100)).substring(1) +
'-' +
854 ('' +
(mday +
100)).substring(1);
855 f
.form_ampm
.selectedIndex
= (hours
>= 12) ?
1 : 0;
856 f
.form_hour
.value
= (hours
> 12) ? hours
- 12 : hours
;
857 f
.form_minute
.value
= ('' +
(minutes +
100)).substring(1);
860 // Invoke the find-available popup.
861 function find_available() {
862 //top.restoreSession();
863 // (CHEMED) Conditional value selection, because there is no <select> element
864 // when making an appointment for a specific provider
865 var s
= document
.forms
[0].form_provider
;
866 <?php
if ($userid != 0) { ?
>
867 s
= document
.forms
[0].form_provider
.value
;
869 s
= document
.forms
[0].form_provider
.options
[s
.selectedIndex
].value
;
871 // var fd2=document.forms[0].form_date2.value;
872 // document.forms[0].form_date.value=fd2.substring(6)+'-'+fd2.substring(0,2)+'-'+fd2.substring(3,5);
874 var formDate
= document
.forms
[0].form_date
;
875 window
.open('find_appt_popup_user.php?bypatient&providerid=' + s +
877 '&startdate=' + formDate
.value
, '_blank', 500, 400);
878 //END (CHEMED) modifications
881 // Check for errors when the form is submitted.
882 function validate() {
883 var f
= document
.getElementById('theform');
884 if (!f
.form_date
.value ||
!f
.form_hour
.value ||
!f
.form_minute
.value
) {
885 alert('Please click on "Openings" to select a time.');
889 // in lunch outofoffice reserved vacation
890 f
.form_category
.value
='12';
891 if (f
.form_patient
.value
=='Click to select' && (!(
892 f
.form_category
.value
=='2' || f
.form_category
.value
=='8' || f
.form_category
.value
=='3' || f
.form_category
.value
=='4' || f
.form_category
.value
=='11'
893 || f
.form_category
.value
=='10'))) {
894 alert('Please select a patient.');
896 } else if (f
.form_category
.value
=='10') {
899 var form_action
= document
.getElementById('form_action');
900 form_action
.value
="save";
902 //top.restoreSession();
907 function deleteEvent() {
908 if (confirm("Deleting this event cannot be undone. It cannot be recovered once it is gone. Are you sure you wish to delete this event?")) {
909 var f
= document
.getElementById('theform');
910 var form_action
= document
.getElementById('form_action');
911 form_action
.value
="delete";
922 <body
class="body_top" onunload
='imclosing()' onload
='categoryChanged()'>
924 <form method
='post' name
='theform' id
='theform' action
='add_edit_event_user.php?eid=<?php echo $eid ?>' />
925 <input type
="hidden" name
="form_action" id
="form_action" value
="">
928 <table border
='0' width
='100%'>
931 <td width
='1%' nowrap
>
932 <b
><?php
xl('Category','e'); ?
>:</b
>
935 <input type
="text" id
='form_category' name
='form_category' value
='Office Visit' readonly
='readonly' style
='width:100%'/>
938 <td width
='1%' nowrap
>
939 <b
><?php
xl('Date','e'); ?
>:</b
>
941 <td colspan
='2' nowrap id
='tdallday1'>
942 <input type
='text' size
='10' name
='form_date' readonly id
='form_date' <?php
echo $disabled ?
>
943 value
='<?php if (isset($eid)) { echo $eid ? $row['pc_eventDate
'] : $date; } ?>'
944 onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)'
950 <b
><?php
xl('Title','e'); ?
>:</b
>
953 <input type
='text' size
='10' name
='form_title' value
='<?php echo addslashes($row['pc_title
']) ?>'
955 title
='<?php xl('Event title
','e
'); ?>' />
959 <td width
='1%' nowrap id
='tdallday2'>
960 <?php
xl('Time','e'); ?
>
962 <td width
='1%' nowrap id
='tdallday3'>
963 <input type
='text' size
='2' name
='form_hour' value
='<?php if(isset($eid)) { echo $starttimeh; } ?>'
964 title
='<?php xl('Event start time
','e
'); ?>' readonly
/> :
965 <input type
='text' size
='2' name
='form_minute' value
='<?php if(isset($eid)) { echo $starttimem; } ?>'
966 title
='<?php xl('Event start time
','e
'); ?>' readonly
/> 
;
967 <select name
='form_ampm' title
='Note: 12:00 noon is PM, not AM' disabled
="disabled">
968 <option value
='1'><?php
xl('AM','e'); ?
></option
>
969 <option value
='2'<?php
if ($startampm == '2') echo " selected" ?
>><?php
xl('PM','e'); ?
></option
>
975 <b
><?php
xl('Patient','e'); ?
>:</b
>
978 <input type
='text' size
='10' id
='form_patient' name
='form_patient' style
='width:100%;' value
='<?php echo $patientname ?>' title
='Patient' readonly
/>
979 <input type
='hidden' name
='form_pid' value
='<?php echo $patientid ?>' />
984 <td nowrap id
='tdallday4'><?php
xl('duration','e'); ?
>
986 <td nowrap id
='tdallday5'>
987 <input type
='text' size
='4' name
='form_duration' readonly value
='<?php echo $thisduration ?>' title
='<?php xl('Event duration in minutes
','e
'); ?>' />
988 <?php
xl('minutes','e'); ?
>
1000 <b
><?php
xl('Provider','e'); ?
>:</b
>
1005 // present a list of providers to choose from
1006 // default to the currently logged-in user
1007 echo "<select name='form_provider' onchange='change_provider();' style='width:100%' />";
1008 while ($urow = sqlFetchArray($ures)) {
1009 echo " <option value='" . $urow['id'] . "'";
1010 // if ($urow['id'] == $_SESSION['authUserID']) echo " selected";
1011 if (($urow['id'] == $_GET['userid'])||
($urow['id']== $userid)) echo " selected";
1012 echo ">" . $urow['lname'];
1013 if ($urow['fname']) echo ", " . $urow['fname'];
1018 // } //END (CHEMED) IF
1022 <td nowrap style
='font-size:8pt'>
1025 <td
><input type
='button' value
='<?php xl('Openings
','e
');?>' onclick
='find_available()' /></td
>
1031 <b
><?php
xl('Comments','e'); ?
>:</b
>
1033 <td colspan
='4' nowrap
>
1034 <input type
='text' size
='40' name
='form_comments' style
='width:100%' value
='<?php echo $hometext ?>' title
='<?php xl('Optional information about this event
','e
');?>' />
1039 // DOB is important for the clinic, so if it's missing give them a chance
1040 // to enter it right here. We must display or hide this row dynamically
1041 // in case the patient-select popup is used.
1042 $patient_dob = trim($prow['DOB']);
1043 $dobstyle = ($prow && (!$patient_dob ||
substr($patient_dob, 5) == '00-00')) ?
1046 <tr id
='dob_row' style
='display:none<?php //echo $dobstyle
1048 <td colspan
='4' nowrap style
='display:none'>
1049 <font color
='white'><?php
xl('DOB is missing, please enter if possible','e'); ?
>:</font
></b
>
1052 <input type
='text' size
='10' name
='form_dob' id
='form_dob' style
='display:none' title
='<?php xl('yyyy
-mm
-dd date of birth
','e
');?>' onkeyup
='datekeyup(this,mypcc)' onblur
='dateblur(this,mypcc)' />
1053 <img src
='../../pic/show_calendar.gif' align
='absbottom' width
='24' height
='22'
1054 id
='img_dob' border
='0' alt
='[?]' style
='cursor:pointer;cursor:hand;display:none'
1055 title
='<?php xl('Click here to choose a date
','e
');?>'>
1062 <input type
='button' name
='form_save' value
='<?php xl('Save
','e
');?>' onclick
="validate()" />
1064 <input type
='button' value
='<?php xl('Cancel
','e
');?>' onclick
='parent.$.fn.fancybox.close()' />
1069 <script language
='JavaScript'>
1070 <?php
if ($eid) { ?
>
1078 //Calendar.setup({inputField:"form_dob", ifFormat:"%Y-%m-%d", button:"img_dob"});