Eye module improvements with other minor improvements
[openemr.git] / portal / add_edit_event_user.php
blob4b9fddda1d0836b2bf4a055cdd055787ca81f904
1 <?php
2 /**
4 * Modified from interface/main/calendar/add_edit_event.php for
5 * the patient portal.
7 * @package OpenEMR
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 * @copyright Copyright (C) 2005-2006 Rod Roark <rod@sunsetsystems.com>
13 * @copyright Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
14 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
15 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
18 // continue session
19 session_start();
21 //landing page definition -- where to go if something goes wrong
22 $landingpage = "index.php?site=".$_SESSION['site_id'];
25 // kick out if patient not authenticated
26 if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) {
27 $pid = $_SESSION['pid'];
28 } else {
29 session_destroy();
30 header('Location: '.$landingpage.'&w');
31 exit;
36 $ignoreAuth = 1;
37 global $ignoreAuth;
39 require_once("../interface/globals.php");
40 require_once("$srcdir/patient.inc");
41 require_once("$srcdir/forms.inc");
43 // Exit if the modify calendar for portal flag is not set-pulled for v5
44 /* if (!($GLOBALS['portal_onsite_appt_modify'])) {
45 echo add_escape_custom( xl('You are not authorized to schedule appointments.'),ENT_NOQUOTES);
46 exit;
47 } */
49 // Things that might be passed by our opener.
51 $eid = $_GET['eid']; // only for existing events
52 $date = $_GET['date']; // this and below only for new events
53 $userid = $_GET['userid'];
54 $default_catid = $_GET['catid'] ? $_GET['catid'] : '5';
55 $patientid = $_GET['patid'];
58 if ($date) {
59 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
60 } else {
61 $date = date("Y-m-d");
65 $starttimem = '00';
66 if (isset($_GET['starttimem'])) {
67 $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) {
75 $starttimeh += 12;
78 } else {
79 $starttimeh = date("G");
82 $startampm = '';
84 $info_msg = "";
86 // ===========================
87 // EVENTS TO FACILITIES (lemonsoftware)
88 // edit event case - if there is no association made, then insert one with the first facility
89 /*if ( $eid ) {
90 $selfacil = '';
91 $facility = sqlQuery("SELECT pc_facility, pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
92 if ( !$facility['pc_facility'] ) {
93 $qmin = sqlQuery("SELECT MIN(id) as minId FROM facility");
94 $min = $qmin['minId'];
96 // multiple providers case
97 if ( $GLOBALS['select_multi_providers'] ) {
98 $mul = $facility['pc_multiple'];
99 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
101 // EOS multiple
103 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
104 $e2f = $minId;
105 } else {
106 $e2f = $facility['pc_facility'];
109 // EOS E2F
110 // ===========================
111 // ===========================
113 // EVENTS TO FACILITIES (lemonsoftware)
114 //(CHEMED) get facility name
115 // edit event case - if there is no association made, then insert one with the first facility
116 if ($eid) {
117 $selfacil = '';
118 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
119 FROM openemr_postcalendar_events
120 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
121 WHERE pc_eid = $eid");
122 if (!$facility['pc_facility']) {
123 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ".$facility['pc_aid']);
124 $min = $qmin['minId'];
125 $min_name = $qmin['facility'];
127 // multiple providers case
128 if ($GLOBALS['select_multi_providers']) {
129 $mul = $facility['pc_multiple'];
130 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_multiple = $mul");
133 // EOS multiple
135 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = $min WHERE pc_eid = $eid");
136 $e2f = $min;
137 $e2f_name = $min_name;
138 } else {
139 $e2f = $facility['pc_facility'];
140 $e2f_name = $facility['name'];
144 // EOS E2F
145 // ===========================
148 // If we are saving, then save and close the window.
150 if ($_POST['form_action'] == "save") {
151 //print_r($_POST);
152 //exit();
153 $event_date = fixDate($_POST['form_date']);
155 // Compute start and end time strings to be saved.
156 if ($_POST['form_allday']) {
157 $tmph = 0;
158 $tmpm = 0;
159 $duration = 24 * 60;
160 } else {
161 $tmph = $_POST['form_hour'] + 0;
162 $tmpm = $_POST['form_minute'] + 0;
163 if ($_POST['form_ampm'] == '2' && $tmph < 12) {
164 $tmph += 12;
167 $duration = $_POST['form_duration'];
170 $starttime = "$tmph:$tmpm:00";
172 $tmpm += $duration;
173 while ($tmpm >= 60) {
174 $tmpm -= 60;
175 ++$tmph;
178 $endtime = "$tmph:$tmpm:00";
180 // Useless garbage that we must save.
181 $locationspec = 'a:6:{s:14:"event_location";N;s:13:"event_street1";N;' .
182 's:13:"event_street2";N;s:10:"event_city";N;s:11:"event_state";N;s:12:"event_postal";N;}';
184 // More garbage, but this time 1 character of it is used to save the
185 // repeat type.
186 if ($_POST['form_repeat']) {
187 $recurrspec = 'a:5:{' .
188 's:17:"event_repeat_freq";s:1:"' . $_POST['form_repeat_freq'] . '";' .
189 's:22:"event_repeat_freq_type";s:1:"' . $_POST['form_repeat_type'] . '";' .
190 's:19:"event_repeat_on_num";s:1:"1";' .
191 's:19:"event_repeat_on_day";s:1:"0";' .
192 's:20:"event_repeat_on_freq";s:1:"0";}';
193 } else {
194 $recurrspec = 'a:5:{' .
195 's:17:"event_repeat_freq";N;' .
196 's:22:"event_repeat_freq_type";s:1:"0";' .
197 's:19:"event_repeat_on_num";s:1:"1";' .
198 's:19:"event_repeat_on_day";s:1:"0";' .
199 's:20:"event_repeat_on_freq";s:1:"1";}';
202 //The modification of the start date for events that take place on one day of the week
203 //for example monday, or thursday. We set the start date on the first day of the week
204 //that the event is scheduled. For example if you set the event to repeat on each monday
205 //the start date of the event will be set on the first monday after the day the event is scheduled
206 if ($_POST['form_repeat_type'] == 5) {
207 $exploded_date= explode("-", $event_date);
208 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
209 if ($edate=="Tue") {
210 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+6, $exploded_date[0]));
211 } elseif ($edate=="Wed") {
212 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+5, $exploded_date[0]));
213 } elseif ($edate=="Thu") {
214 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+4, $exploded_date[0]));
215 } elseif ($edate=="Fri") {
216 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+3, $exploded_date[0]));
217 } elseif ($edate=="Sat") {
218 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+2, $exploded_date[0]));
219 } elseif ($edate=="Sun") {
220 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+1, $exploded_date[0]));
222 } elseif ($_POST['form_repeat_type'] == 6) {
223 $exploded_date= explode("-", $event_date);
224 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
225 if ($edate=="Wed") {
226 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+6, $exploded_date[0]));
227 } elseif ($edate=="Thu") {
228 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+5, $exploded_date[0]));
229 } elseif ($edate=="Fri") {
230 $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]));
233 } elseif ($edate=="Sun") {
234 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+2, $exploded_date[0]));
235 } elseif ($edate=="Mon") {
236 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+1, $exploded_date[0]));
238 } elseif ($_POST['form_repeat_type'] == 7) {
239 $exploded_date= explode("-", $event_date);
240 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
241 if ($edate=="Thu") {
242 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+6, $exploded_date[0]));
243 } elseif ($edate=="Fri") {
244 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+5, $exploded_date[0]));
245 } elseif ($edate=="Sat") {
246 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+4, $exploded_date[0]));
247 } elseif ($edate=="Sun") {
248 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+3, $exploded_date[0]));
249 } elseif ($edate=="Mon") {
250 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+2, $exploded_date[0]));
251 } elseif ($edate=="Tue") {
252 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+1, $exploded_date[0]));
254 } elseif ($_POST['form_repeat_type'] == 8) {
255 $exploded_date= explode("-", $event_date);
256 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
257 if ($edate=="Fri") {
258 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+6, $exploded_date[0]));
259 } elseif ($edate=="Sat") {
260 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+5, $exploded_date[0]));
261 } elseif ($edate=="Sun") {
262 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+4, $exploded_date[0]));
263 } elseif ($edate=="Mon") {
264 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+3, $exploded_date[0]));
265 } elseif ($edate=="Tue") {
266 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+2, $exploded_date[0]));
267 } elseif ($edate=="Wed") {
268 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+1, $exploded_date[0]));
270 } elseif ($_POST['form_repeat_type'] == 9) {
271 $exploded_date= explode("-", $event_date);
272 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
273 if ($edate=="Sat") {
274 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+6, $exploded_date[0]));
275 } elseif ($edate=="Sun") {
276 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+5, $exploded_date[0]));
277 } elseif ($edate=="Mon") {
278 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+4, $exploded_date[0]));
279 } elseif ($edate=="Tue") {
280 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+3, $exploded_date[0]));
281 } elseif ($edate=="Wed") {
282 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+2, $exploded_date[0]));
283 } elseif ($edate=="Thu") {
284 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+1, $exploded_date[0]));
286 }//if end
287 /* =======================================================
288 // UPDATE EVENTS
289 ========================================================*/
290 if ($eid) {
291 // what is multiple key around this $eid?
292 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
294 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
295 /* ==========================================
296 // multi providers BOS
297 ==========================================*/
299 // obtain current list of providers regarding the multiple key
300 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple={$row['pc_multiple']}");
301 while ($current = sqlFetchArray($up)) {
302 $providers_current[] = $current['pc_aid'];
305 $providers_new = $_POST['form_provider_ae'];
307 // this difference means that some providers from current was UNCHECKED
308 // so we must delete this event for them
309 $r1 = array_diff($providers_current, $providers_new);
310 if (count($r1)) {
311 foreach ($r1 as $to_be_removed) {
312 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid='$to_be_removed' AND pc_multiple={$row['pc_multiple']}");
316 // this difference means that some providers was added
317 // so we must insert this event for them
318 $r2 = array_diff($providers_new, $providers_current);
319 if (count($r2)) {
320 foreach ($r2 as $to_be_inserted) {
321 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)
322 VALUES ( " .
323 "'" . $_POST['form_category'] . "', " .
324 "'" . $row['pc_multiple'] . "', " .
325 "'" . $to_be_inserted . "', " .
326 "'" . $_POST['form_pid'] . "', " .
327 "'" . add_escape_custom($_POST['form_title']) . "', " .
328 "NOW(), " .
329 "'" . add_escape_custom($_POST['form_comments']) . "', " .
330 "'" . $_SESSION['providerId'] . "', " .
331 "'" . $event_date . "', " .
332 "'" . fixDate($_POST['form_enddate']) . "', " .
333 "'" . ($duration * 60) . "', " .
334 "'" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
335 "'$recurrspec', " .
336 "'$starttime', " .
337 "'$endtime', " .
338 "'" . $_POST['form_allday'] . "', " .
339 "'" . $_POST['form_apptstatus'] . "', " .
340 "'" . $_POST['form_prefcat'] . "', " .
341 "'$locationspec', " .
342 "1, " .
343 "1, " .(int)$_POST['facility']. " )"); // FF stuff
344 } // foreach
345 } //if count
348 // after the two diffs above, we must update for remaining providers
349 // those who are intersected in $providers_current and $providers_new
350 foreach ($_POST['form_provider_ae'] as $provider) {
351 sqlStatement("UPDATE openemr_postcalendar_events SET " .
352 "pc_catid = '" . $_POST['form_category'] . "', " .
353 "pc_pid = '" . $_POST['form_pid'] . "', " .
354 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
355 "pc_time = NOW(), " .
356 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
357 "pc_informant = '" . $_SESSION['providerId'] . "', " .
358 "pc_eventDate = '" . $event_date . "', " .
359 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
360 "pc_duration = '" . ($duration * 60) . "', " .
361 "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
362 "pc_recurrspec = '$recurrspec', " .
363 "pc_startTime = '$starttime', " .
364 "pc_endTime = '$endtime', " .
365 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
366 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
367 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
368 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
369 "WHERE pc_aid = '$provider' AND pc_multiple={$row['pc_multiple']}");
370 } // foreach
372 /* ==========================================
373 // multi providers EOS
374 ==========================================*/
375 } elseif (!$row['pc_multiple']) {
376 if ($GLOBALS['select_multi_providers']) {
377 $prov = $_POST['form_provider_ae'][0];
378 } else {
379 $prov = $_POST['form_provider_ae'];
382 // simple provider case
383 sqlStatement("UPDATE openemr_postcalendar_events SET " .
384 "pc_catid = '" . $_POST['form_category'] . "', " .
385 "pc_aid = '" . $prov . "', " .
386 "pc_pid = '" . $_POST['form_pid'] . "', " .
387 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
388 "pc_time = NOW(), " .
389 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
390 "pc_informant = '" . $_SESSION['providerId'] . "', " .
391 "pc_eventDate = '" . $event_date . "', " .
392 "pc_endDate = '" . fixDate($_POST['form_enddate']) . "', " .
393 "pc_duration = '" . ($duration * 60) . "', " .
394 "pc_recurrtype = '" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
395 "pc_recurrspec = '$recurrspec', " .
396 "pc_startTime = '$starttime', " .
397 "pc_endTime = '$endtime', " .
398 "pc_alldayevent = '" . $_POST['form_allday'] . "', " .
399 "pc_apptstatus = '" . $_POST['form_apptstatus'] . "', " .
400 "pc_prefcatid = '" . $_POST['form_prefcat'] . "' ," .
401 "pc_facility = '" .(int)$_POST['facility'] ."' " . // FF stuff
402 "WHERE pc_eid = '$eid'");
405 // =======================================
406 // EOS multi providers case
407 // =======================================
409 // EVENTS TO FACILITIES
411 $e2f = (int)$eid;
413 /* =======================================================
414 // INSERT EVENTS
415 ========================================================*/
416 } else {
417 // =======================================
418 // multi providers case
419 // =======================================
421 if (is_array($_POST['form_provider_ae'])) {
422 // obtain the next available unique key to group multiple providers around some event
423 $q = sqlStatement("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
424 $max = sqlFetchArray($q);
425 $new_multiple_value = $max['max'] + 1;
427 foreach ($_POST['form_provider_ae'] as $provider) {
428 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
429 "pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
430 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
431 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
432 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
433 ") VALUES ( " .
434 "'" . $_POST['form_category'] . "', " .
435 "'" . $new_multiple_value . "', " .
436 "'" . $provider . "', " .
437 "'" . $_POST['form_pid'] . "', " .
438 "'" . add_escape_custom($_POST['form_title']) . "', " .
439 "NOW(), " .
440 "'" . add_escape_custom($_POST['form_comments']) . "', " .
441 "'" . $_SESSION['providerId'] . "', " .
442 "'" . $event_date . "', " .
443 "'" . fixDate($_POST['form_enddate']) . "', " .
444 "'" . ($duration * 60) . "', " .
445 "'" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
446 "'$recurrspec', " .
447 "'$starttime', " .
448 "'$endtime', " .
449 "'" . $_POST['form_allday'] . "', " .
450 "'" . $_POST['form_apptstatus'] . "', " .
451 "'" . $_POST['form_prefcat'] . "', " .
452 "'$locationspec', " .
453 "1, " .
454 "1, " .(int)$_POST['facility']. " )"); // FF stuff
455 } // foreach
456 } else {
457 $_POST['form_apptstatus'] = '^';
458 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
459 "pc_catid, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
460 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
461 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
462 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
463 ") VALUES ( " .
464 "'" . $_POST['form_category'] . "', " .
465 "'" . $_POST['form_provider_ae'] . "', " .
466 "'" . $_POST['form_pid'] . "', " .
467 "'" . add_escape_custom($_POST['form_title']) . "', " .
468 "NOW(), " .
469 "'" . add_escape_custom($_POST['form_comments']) . "', " .
470 "'" . $_SESSION['providerId'] . "', " .
471 "'" . $event_date . "', " .
472 "'" . fixDate($_POST['form_enddate']) . "', " .
473 "'" . ($duration * 60) . "', " .
474 "'" . ($_POST['form_repeat'] ? '1' : '0') . "', " .
475 "'$recurrspec', " .
476 "'$starttime', " .
477 "'$endtime', " .
478 "'" . $_POST['form_allday'] . "', " .
479 "'" . $_POST['form_apptstatus'] . "', " .
480 "'" . $_POST['form_prefcat'] . "', " .
481 "'$locationspec', " .
482 "1, " .
483 "1," .(int)$_POST['facility']. ")"); // FF stuff
484 } // INSERT single
485 } // else - insert
487 // Save new DOB if it's there.
488 $patient_dob = trim($_POST['form_dob']);
489 if ($patient_dob && $_POST['form_pid']) {
490 sqlStatement("UPDATE patient_data SET DOB = '$patient_dob' WHERE " .
491 "pid = '" . $_POST['form_pid'] . "'");
494 // Auto-create a new encounter if appropriate.
497 /* if ($GLOBALS['auto_create_new_encounters'] &&
498 $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
501 // We decided not to auto-create blank enconter when user arrives. Todd's decision 18 Jun 2010
502 // Applied by Cassian Lup (cassian.lup@clinicdr.com)
504 if (0) {
505 $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
506 "pid = '" . $_POST['form_pid'] . "' AND date = '$event_date 00:00:00'");
507 if ($tmprow['count'] == 0) {
508 $tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = '" .
509 $_POST['form_provider_ae'] . "'");
510 $username = $tmprow['username'];
511 $facility = $tmprow['facility'];
512 $facility_id = $tmprow['facility_id'];
513 $conn = $GLOBALS['adodb']['db'];
514 $encounter = $conn->GenID("sequences");
515 addForm(
516 $encounter,
517 "New Patient Encounter",
518 sqlInsert("INSERT INTO form_encounter SET " .
519 "date = '$event_date', " .
520 "onset_date = '$event_date', " .
521 "reason = '" . add_escape_custom($_POST['form_comments']) . "', " .
522 "facility = '$facility', " .
523 "facility_id = '$facility_id', " .
524 "pid = '" . $_POST['form_pid'] . "', " .
525 "encounter = '$encounter'"),
526 "newpatient",
527 $_POST['form_pid'],
528 "1",
529 "NOW()",
530 $username
532 $info_msg .= "New encounter $encounter was created. ";
535 } else if ($_POST['form_action'] == "delete") {
536 // =======================================
537 // multi providers case
538 // =======================================
539 if ($GLOBALS['select_multi_providers']) {
540 // what is multiple key around this $eid?
541 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = $eid");
542 if ($row['pc_multiple']) {
543 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_multiple = {$row['pc_multiple']}");
544 } else {
545 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = $eid");
548 // =======================================
549 // EOS multi providers case
550 // =======================================
551 } else {
552 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = '$eid'");
556 if ($_POST['form_action'] != "") {
557 // Leave
558 $_SESSION['whereto'] = 'appointmentpanel';
559 header('Location:./home.php#appointmentpanel');
560 exit();
563 // If we get this far then we are displaying the form.
565 $statuses = array(
566 '-' => '',
567 '*' => xl('* Reminder done'),
568 '+' => xl('+ Chart pulled'),
569 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
570 '?' => xl('? No show'),
571 '@' => xl('@ Arrived'),
572 '~' => xl('~ Arrived late'),
573 '!' => xl('! Left w/o visit'),
574 '#' => xl('# Ins/fin issue'),
575 '<' => xl('< In exam room'),
576 '>' => xl('> Checked out'),
577 '$' => xl('$ Coding done'),
578 '^' => xl('^ Pending'),
581 $repeats = 0; // if the event repeats
582 $repeattype = '0';
583 $repeatfreq = '0';
584 $patienttitle = "";
585 $hometext = "";
586 $row = array();
588 // If we are editing an existing event, then get its data.
589 if ($eid) {
590 $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = $eid");
591 $date = $row['pc_eventDate'];
592 $userid = $row['pc_aid'];
593 $patientid = $row['pc_pid'];
594 $starttimeh = substr($row['pc_startTime'], 0, 2) + 0;
595 $starttimem = substr($row['pc_startTime'], 3, 2);
596 $repeats = $row['pc_recurrtype'];
597 $multiple_value = $row['pc_multiple'];
599 if (preg_match('/"event_repeat_freq_type";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
600 $repeattype = $matches[1];
603 if (preg_match('/"event_repeat_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
604 $repeatfreq = $matches[1];
607 $hometext = $row['pc_hometext'];
608 if (substr($hometext, 0, 6) == ':text:') {
609 $hometext = substr($hometext, 6);
611 } else {
612 $patientid=$_GET['pid'];
615 // If we have a patient ID, get the name and phone numbers to display.
616 if ($patientid) {
617 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
618 "FROM patient_data WHERE pid = '" . $patientid . "'");
619 $patientname = $prow['lname'] . ", " . $prow['fname'];
620 if ($prow['phone_home']) {
621 $patienttitle .= " H=" . $prow['phone_home'];
624 if ($prow['phone_biz']) {
625 $patienttitle .= " W=" . $prow['phone_biz'];
629 // Get the providers list.
630 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
631 "authorized != 0 AND active = 1 ORDER BY lname, fname");
633 //-------------------------------------
634 //(CHEMED)
635 //Set default facility for a new event based on the given 'userid'
636 if ($userid) {
637 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = $userid"));
638 $e2f = $pref_facility['facility_id'];
639 $e2f_name = $pref_facility['facility'];
642 //END of CHEMED -----------------------
644 // Get event categories.
645 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
646 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
648 // Fix up the time format for AM/PM.
649 $startampm = '1';
650 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
651 $startampm = '2';
652 if ($starttimeh > 12) {
653 $starttimeh -= 12;
658 <html>
659 <head>
661 <title><?php echo $eid ? "Edit" : "Add New" ?> <?php xl('Event', 'e');?></title>
663 <link href="assets/css/style.css?v=<?php echo $v_js_includes; ?>" rel="stylesheet" type="text/css" />
664 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
665 </head>
667 <body class="skin-blue" >
668 <div class="well">
669 <form class="form-inline" method='post' name='theaddform' id='theaddform' action='add_edit_event_user.php?eid=<?php echo $eid ?>'>
670 <input type="hidden" name="form_action" id="form_action" value="">
671 <input type='hidden' name='form_category' id='form_category' value='<?php echo $row['pc_catid'] ? $row['pc_catid'] : '5'; ?>' />
672 <input type='hidden' name='form_apptstatus' id='form_apptstatus' value='<?php echo $row['pc_apptstatus'] ? $row['pc_apptstatus'] : "^" ?>' />
673 <table border='0' width='100%'>
674 <tr>
675 <td width='1%' nowrap>
676 <b><?php xl('Visit', 'e'); ?>: </b>
677 </td>
678 <td nowrap style='padding:0px 5px 5px 0'>
679 <input class="form-control" type="text" id='form_title' name='form_title' value='<?php echo htmlspecialchars($row['pc_title'], ENT_QUOTES) ? htmlspecialchars(['pc_title'], ENT_QUOTES) : 'Office Visit'; ?>' readonly='readonly'/>
680 </td>
681 <td></td>
682 <td width='1%' nowrap>
683 <b><?php xl('Date', 'e'); ?>:</b>
684 </td>
685 <td colspan='2' nowrap id='tdallday1'>
686 <input class="form-control" type='text' size='10' name='form_date' readonly id='form_date'
687 value='<?php echo (isset($eid) && $eid) ? $row['pc_eventDate'] : $date; ?>' />
688 </td>
689 </tr>
690 <tr>
691 <td nowrap>
692 <b><?php //xl('Title','e'); ?></b>
693 </td>
694 <td style='padding:0px 5px 5px 0' nowrap>
695 <!-- <input class="form-control input-sm" type='text' size='10' name='form_title' readonly value='<?php //echo htmlspecialchars($row['pc_title'],ENT_QUOTES) ?>' title='<?php //xl('Event title','e'); ?>' /> -->
696 </td>
697 <td nowrap>
698 </td>
699 <td width='1%' nowrap id='tdallday2'>
700 <b><?php xl('Time', 'e');?>:</b>
701 </td>
702 <td width='1%' nowrap id='tdallday3'>
703 <input class="form-control inline" type='text' size='2' name='form_hour' value='<?php echo (isset($eid)) ? $starttimeh : ''; ?>'
704 title='<?php xl('Event start time', 'e'); ?>' readonly/> :
705 <input class="form-control inline" type='text' size='2' name='form_minute' value='<?php echo (isset($eid)) ? $starttimem : ''; ?>'
706 title='<?php xl('Event start time', 'e'); ?>' readonly/>&nbsp; <!-- -->
707 <select class="form-control" name='form_ampm' title='Note: 12:00 noon is PM, not AM' readonly >
708 <option value='1'><?php xl('AM', 'e'); ?></option>
709 <option value='2'<?php echo ($startampm == '2') ? " selected" : ""; ?>><?php xl('PM', 'e'); ?></option>
710 </select>
711 </td>
712 </tr>
713 <tr>
714 <td nowrap>
715 <b><?php xl('Patient', 'e'); ?>:</b>
716 </td>
717 <td style='padding:0px 5px 5px 0' nowrap>
718 <input class="form-control" type='text' id='form_patient' name='form_patient' value='<?php echo $patientname ?>' title='Patient' readonly />
719 <input type='hidden' name='form_pid' value='<?php echo $patientid ?>' />
720 </td>
721 <td nowrap>
722 &nbsp;
723 </td>
724 <td nowrap id='tdallday4'><?php xl('Duration', 'e'); ?></td>
725 <td nowrap id='tdallday5'>
726 <input class="form-control input-sm" type='text' size='1' name='form_duration' value='<?php echo $row['pc_duration'] ? ($row['pc_duration']*1/60) : "0" ?>' readonly /><?php echo xl('minutes'); ?>
727 </td>
728 </tr>
729 <tr>
730 </tr>
731 <tr>
732 <td nowrap>
733 <b><?php xl('Provider', 'e'); ?>:</b>
734 </td>
735 <td style='padding:0px 5px 5px 0' nowrap>
736 <select class="form-control" name='form_provider_ae' id='form_provider_ae' onchange='change_provider();'>
737 <?php
738 // present a list of providers to choose from
739 // default to the currently logged-in user
740 while ($urow = sqlFetchArray($ures)) {
741 echo " <option value='" . $urow['id'] . "'";
742 if (($urow['id'] == $_GET['userid'])||($urow['id']== $userid)) {
743 echo " selected";
746 echo ">" . $urow['lname'];
747 if ($urow['fname']) {
748 echo ", " . $urow['fname'];
751 echo "</option>\n";
754 </select>
755 </td>
756 <td nowrap style='font-size:8pt'>
757 </td>
758 <td><input type='button' class='btn btn-danger btn-sm' value='<?php xl('Openings', 'e');?>' onclick='find_available()' /></td>
759 <td></td>
760 </tr>
761 <tr>
762 <td nowrap>
763 <b><?php xl('Reason', 'e'); ?>:</b>
764 </td>
765 <td style='padding:0px 5px 5px 0' colspan='4' nowrap>
766 <input class="form-control" type='text' size='40' name='form_comments' style='width:100%' value='<?php echo htmlspecialchars($hometext, ENT_QUOTES) ?>' title='<?php xl('Optional information about this event', 'e');?>' />
767 </td>
768 </tr>
769 </table>
771 <input type='button' name='form_save' class='btn btn-success btn-md' onsubmit='return false' value='<?php xl('Save', 'e');?>' onclick="validate()" />
772 &nbsp;
773 </p>
774 </form>
775 <script>
777 var durations = new Array();
778 // var rectypes = new Array();
779 <?php
780 // Read the event categories, generate their options list, and get
781 // the default event duration from them if this is a new event.
782 $catoptions = "";
783 $prefcat_options = " <option value='0'>-- None --</option>\n";
784 $thisduration = 0;
785 if ($eid) {
786 $thisduration = $row['pc_alldayevent'] ? 1440 : round($row['pc_duration'] / 60);
789 while ($crow = sqlFetchArray($cres)) {
790 $duration = round($crow['pc_duration'] / 60);
791 if ($crow['pc_end_all_day']) {
792 $duration = 1440;
795 echo " durations[" . $crow['pc_catid'] . "] = $duration\n";
796 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
797 $catoptions .= " <option value='" . $crow['pc_catid'] . "'";
798 if ($eid) {
799 if ($crow['pc_catid'] == $row['pc_catid']) {
800 $catoptions .= " selected";
802 } else {
803 if ($crow['pc_catid'] == $default_catid) {
804 $catoptions .= " selected";
805 $thisduration = $duration;
809 $catoptions .= ">" . $crow['pc_catname'] . "</option>\n";
811 // This section is to build the list of preferred categories:
812 if ($duration) {
813 $prefcat_options .= " <option value='" . $crow['pc_catid'] . "'";
814 if ($eid) {
815 if ($crow['pc_catid'] == $row['pc_prefcatid']) {
816 $prefcat_options .= " selected";
820 $prefcat_options .= ">" . $crow['pc_catname'] . "</option>\n";
825 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
827 // This is for callback by the find-patient popup.
828 function setpatient(pid, lname, fname, dob) {
829 var f = document.forms.namedItem("theaddform");
830 f.form_patient.value = lname + ', ' + fname;
831 f.form_pid.value = pid;
832 dobstyle = (dob == '' || dob.substr(5, 10) == '00-00') ? '' : 'none';
833 document.getElementById('dob_row').style.display = dobstyle;
835 function change_provider(){
836 var f = document.forms.namedItem("theaddform");
837 f.form_date.value='';
838 f.form_hour.value='';
839 f.form_minute.value='';
841 // This is for callback by the find-patient popup.
842 function unsetpatient() {
843 var f = document.forms.namedItem("theaddform");
844 f.form_patient.value = '';
845 f.form_pid.value = '';
848 // This invokes the find-patient popup.
849 function sel_patient() {
850 dlgopen('find_patient_popup.php', '_blank', 500, 400);
853 // Do whatever is needed when a new event category is selected.
854 // For now this means changing the event title and duration.
855 function set_display() {
856 var f = document.forms.namedItem("theaddform");
857 var si = document.getElementById('form_category');
858 if (si.selectedIndex >= 0) {
859 var catid = si.options[si.selectedIndex].value;
860 var style_apptstatus = document.getElementById('title_apptstatus').style;
861 var style_prefcat = document.getElementById('title_prefcat').style;
862 if (catid == '2') { // In Office
863 style_apptstatus.display = 'none';
864 style_prefcat.display = '';
865 f.form_apptstatus.style.display = 'none';
866 f.form_prefcat.style.display = '';
867 } else {
868 style_prefcat.display = 'none';
869 style_apptstatus.display = '';
870 f.form_prefcat.style.display = 'none';
871 f.form_apptstatus.style.display = '';
876 // Gray out certain fields according to selection of Category DDL
877 function categoryChanged() {
878 var value = '5';
880 document.getElementById("form_patient").disabled=false;
881 //document.getElementById("form_apptstatus").disabled=false;
882 //document.getElementById("form_prefcat").disabled=false;
886 // Do whatever is needed when a new event category is selected.
887 // For now this means changing the event title and duration.
888 function set_category() {
889 var f = document.forms.namedItem("theaddform");
890 var s = f.form_category;
891 if (s.selectedIndex >= 0) {
892 var catid = s.options[s.selectedIndex].value;
893 f.form_title.value = s.options[s.selectedIndex].text;
894 f.form_duration.value = durations[catid];
895 set_display();
899 // Modify some visual attributes when the all-day or timed-event
900 // radio buttons are clicked.
901 function set_allday() {
902 var f = document.forms.namedItem("theaddform");
903 var color1 = '#777777';
904 var color2 = '#777777';
905 var disabled2 = true;
906 /*if (document.getElementById('rballday1').checked) {
907 color1 = '#000000';
909 if (document.getElementById('rballday2').checked) {
910 color2 = '#000000';
911 disabled2 = false;
913 document.getElementById('tdallday1').style.color = color1;
914 document.getElementById('tdallday2').style.color = color2;
915 document.getElementById('tdallday3').style.color = color2;
916 document.getElementById('tdallday4').style.color = color2;
917 document.getElementById('tdallday5').style.color = color2;
918 f.form_hour.disabled = disabled2;
919 f.form_minute.disabled = disabled2;
920 f.form_ampm.disabled = disabled2;
921 f.form_duration.disabled = disabled2;
924 // Modify some visual attributes when the Repeat checkbox is clicked.
925 function set_repeat() {
926 var f = document.forms.namedItem("theaddform");
927 var isdisabled = true;
928 var mycolor = '#777777';
929 var myvisibility = 'hidden';
930 /*if (f.form_repeat.checked) {
931 isdisabled = false;
932 mycolor = '#000000';
933 myvisibility = 'visible';
935 //f.form_repeat_type.disabled = isdisabled;
936 //f.form_repeat_freq.disabled = isdisabled;
937 //f.form_enddate.disabled = isdisabled;
938 document.getElementById('tdrepeat1').style.color = mycolor;
939 document.getElementById('tdrepeat2').style.color = mycolor;
940 document.getElementById('img_enddate').style.visibility = myvisibility;
943 // This is for callback by the find-available popup.
944 function setappt(year,mon,mday,hours,minutes) {
945 var f = document.forms.namedItem("theaddform");
946 f.form_date.value = '' + year + '-' +
947 ('' + (mon + 100)).substring(1) + '-' +
948 ('' + (mday + 100)).substring(1);
949 f.form_ampm.selectedIndex = (hours >= 12) ? 1 : 0;
950 f.form_hour.value = (hours > 12) ? hours - 12 : hours;
951 f.form_minute.value = ('' + (minutes + 100)).substring(1);
954 // Invoke the find-available popup.
955 function find_available() {
956 // when making an appointment for a specific provider
957 var se = document.getElementById('form_provider_ae');
958 <?php if ($userid != 0) { ?>
959 s = se.value;
960 <?php } else {?>
961 s = se.options[se.selectedIndex].value;
962 <?php }?>
963 var formDate = document.getElementById('form_date');
964 var url = 'find_appt_popup_user.php?bypatient&providerid=' + s + '&catid=5' + '&startdate=' + formDate.value;
965 var params = {
966 buttons: [
967 {text: '<?php echo xla('Cancel'); ?>', close: true, style: 'danger btn-sm'}
970 allowResize: true,
971 dialogId: 'apptDialog',
972 type: 'iframe'
974 dlgopen(url, 'apptFind', 'modal-md', 300, '', 'Find Date', params);
977 // Check for errors when the form is submitted.
978 function validate() {
979 var f = document.getElementById('theaddform');
980 if (!f.form_date.value || !f.form_hour.value || !f.form_minute.value) {
981 alert('Please click on "Openings" to select a time.');
982 return false;
985 // in lunch outofoffice reserved vacation
986 // f.form_category.value='2';
987 if (f.form_patient.value=='Click to select' && (!(
988 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'
989 || f.form_category.value=='10'))) {
990 alert('Please select a patient.');
991 return false;
992 } else if (f.form_category.value=='10') {
993 unsetpatient();
995 var form_action = document.getElementById('form_action');
996 form_action.value="save";
997 f.submit();
998 return false;
1001 function deleteEvent() {
1002 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?")) {
1003 var f = document.getElementById('theaddform');
1004 var form_action = document.getElementById('form_action');
1005 form_action.value="delete";
1006 f.submit();
1007 return true;
1009 return false;
1012 <?php if ($eid) { ?>
1013 set_display();
1014 <?php } ?>
1016 $(document).ready(function() {
1017 $('.datepicker').datetimepicker({
1018 <?php $datetimepicker_timepicker = false; ?>
1019 <?php $datetimepicker_showseconds = false; ?>
1020 <?php $datetimepicker_formatInput = false; ?>
1021 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
1022 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
1025 </script>
1026 </div>
1027 </body>
1028 </html>