4 * Modified from interface/main/calendar/add_edit_event.php for
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
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'];
30 header('Location: '.$landingpage.'&w');
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);
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'];
59 $date = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6);
61 $date = date("Y-m-d");
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) {
79 $starttimeh = date("G");
86 // EVENTS TO FACILITIES (lemonsoftware)
87 //(CHEMED) get facility name
88 // edit event case - if there is no association made, then insert one with the first facility
91 $facility = sqlQuery("SELECT pc_facility, pc_multiple, pc_aid, facility.name
92 FROM openemr_postcalendar_events
93 LEFT JOIN facility ON (openemr_postcalendar_events.pc_facility = facility.id)
94 WHERE pc_eid = ?", array($eid));
95 if (!$facility['pc_facility']) {
96 $qmin = sqlQuery("SELECT facility_id as minId, facility FROM users WHERE id = ?", array($facility['pc_aid']));
97 $min = $qmin['minId'];
98 $min_name = $qmin['facility'];
100 // multiple providers case
101 if ($GLOBALS['select_multi_providers']) {
102 $mul = $facility['pc_multiple'];
103 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_multiple = ?", array($min, $mul));
108 sqlStatement("UPDATE openemr_postcalendar_events SET pc_facility = ? WHERE pc_eid = ?", array($min, $eid));
110 $e2f_name = $min_name;
112 $e2f = $facility['pc_facility'];
113 $e2f_name = $facility['name'];
118 // ===========================
121 // If we are saving, then save and close the window.
123 if ($_POST['form_action'] == "save") {
126 $event_date = fixDate($_POST['form_date']);
128 // Compute start and end time strings to be saved.
129 if ($_POST['form_allday']) {
134 $tmph = $_POST['form_hour'] +
0;
135 $tmpm = $_POST['form_minute'] +
0;
136 if ($_POST['form_ampm'] == '2' && $tmph < 12) {
140 $duration = $_POST['form_duration'];
143 $starttime = "$tmph:$tmpm:00";
146 while ($tmpm >= 60) {
151 $endtime = "$tmph:$tmpm:00";
153 // Useless garbage that we must save.
154 $locationspec = 'a:6:{s:14:"event_location";N;s:13:"event_street1";N;' .
155 's:13:"event_street2";N;s:10:"event_city";N;s:11:"event_state";N;s:12:"event_postal";N;}';
157 // More garbage, but this time 1 character of it is used to save the
159 if ($_POST['form_repeat']) {
160 $recurrspec = 'a:5:{' .
161 's:17:"event_repeat_freq";s:1:"' . $_POST['form_repeat_freq'] . '";' .
162 's:22:"event_repeat_freq_type";s:1:"' . $_POST['form_repeat_type'] . '";' .
163 's:19:"event_repeat_on_num";s:1:"1";' .
164 's:19:"event_repeat_on_day";s:1:"0";' .
165 's:20:"event_repeat_on_freq";s:1:"0";}';
167 $recurrspec = 'a:5:{' .
168 's:17:"event_repeat_freq";N;' .
169 's:22:"event_repeat_freq_type";s:1:"0";' .
170 's:19:"event_repeat_on_num";s:1:"1";' .
171 's:19:"event_repeat_on_day";s:1:"0";' .
172 's:20:"event_repeat_on_freq";s:1:"1";}';
175 //The modification of the start date for events that take place on one day of the week
176 //for example monday, or thursday. We set the start date on the first day of the week
177 //that the event is scheduled. For example if you set the event to repeat on each monday
178 //the start date of the event will be set on the first monday after the day the event is scheduled
179 if ($_POST['form_repeat_type'] == 5) {
180 $exploded_date= explode("-", $event_date);
181 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
183 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
6, $exploded_date[0]));
184 } elseif ($edate=="Wed") {
185 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
186 } elseif ($edate=="Thu") {
187 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
188 } elseif ($edate=="Fri") {
189 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
190 } elseif ($edate=="Sat") {
191 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
192 } elseif ($edate=="Sun") {
193 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
195 } elseif ($_POST['form_repeat_type'] == 6) {
196 $exploded_date= explode("-", $event_date);
197 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
199 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
6, $exploded_date[0]));
200 } elseif ($edate=="Thu") {
201 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
202 } elseif ($edate=="Fri") {
203 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
204 } elseif ($edate=="Sat") {
205 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
206 } elseif ($edate=="Sun") {
207 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
208 } elseif ($edate=="Mon") {
209 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
211 } elseif ($_POST['form_repeat_type'] == 7) {
212 $exploded_date= explode("-", $event_date);
213 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
215 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
6, $exploded_date[0]));
216 } elseif ($edate=="Fri") {
217 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
218 } elseif ($edate=="Sat") {
219 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
220 } elseif ($edate=="Sun") {
221 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
222 } elseif ($edate=="Mon") {
223 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
224 } elseif ($edate=="Tue") {
225 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
227 } elseif ($_POST['form_repeat_type'] == 8) {
228 $exploded_date= explode("-", $event_date);
229 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
231 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
6, $exploded_date[0]));
232 } elseif ($edate=="Sat") {
233 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
234 } elseif ($edate=="Sun") {
235 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
236 } elseif ($edate=="Mon") {
237 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
238 } elseif ($edate=="Tue") {
239 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
240 } elseif ($edate=="Wed") {
241 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
243 } elseif ($_POST['form_repeat_type'] == 9) {
244 $exploded_date= explode("-", $event_date);
245 $edate = date("D", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2], $exploded_date[0]));
247 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
6, $exploded_date[0]));
248 } elseif ($edate=="Sun") {
249 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
5, $exploded_date[0]));
250 } elseif ($edate=="Mon") {
251 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
4, $exploded_date[0]));
252 } elseif ($edate=="Tue") {
253 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
3, $exploded_date[0]));
254 } elseif ($edate=="Wed") {
255 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
2, $exploded_date[0]));
256 } elseif ($edate=="Thu") {
257 $event_date=date("Y-m-d", mktime(0, 0, 0, $exploded_date[1], $exploded_date[2]+
1, $exploded_date[0]));
260 /* =======================================================
262 ========================================================*/
264 // what is multiple key around this $eid?
265 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
267 if ($GLOBALS['select_multi_providers'] && $row['pc_multiple']) {
268 /* ==========================================
269 // multi providers BOS
270 ==========================================*/
272 // obtain current list of providers regarding the multiple key
273 $up = sqlStatement("SELECT pc_aid FROM openemr_postcalendar_events WHERE pc_multiple = ?", array($row['pc_multiple']));
274 while ($current = sqlFetchArray($up)) {
275 $providers_current[] = $current['pc_aid'];
278 $providers_new = $_POST['form_provider_ae'];
280 // this difference means that some providers from current was UNCHECKED
281 // so we must delete this event for them
282 $r1 = array_diff($providers_current, $providers_new);
284 foreach ($r1 as $to_be_removed) {
285 sqlQuery("DELETE FROM openemr_postcalendar_events WHERE pc_aid = ? AND pc_multiple = ?", array($to_be_removed, $row['pc_multiple']));
289 // this difference means that some providers was added
290 // so we must insert this event for them
291 $r2 = array_diff($providers_new, $providers_current);
293 foreach ($r2 as $to_be_inserted) {
294 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)
296 "'" . add_escape_custom($_POST['form_category']) . "', " .
297 "'" . add_escape_custom($row['pc_multiple']) . "', " .
298 "'" . add_escape_custom($to_be_inserted) . "', " .
299 "'" . add_escape_custom($_POST['form_pid']) . "', " .
300 "'" . add_escape_custom($_POST['form_title']) . "', " .
302 "'" . add_escape_custom($_POST['form_comments']) . "', " .
303 "'" . add_escape_custom($_SESSION['providerId']) . "', " .
304 "'" . add_escape_custom($event_date) . "', " .
305 "'" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
306 "'" . add_escape_custom(($duration * 60)) . "', " .
307 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
308 "'" . add_escape_custom($recurrspec) . "', " .
309 "'" . add_escape_custom($starttime) . "', " .
310 "'" . add_escape_custom($endtime) . "', " .
311 "'" . add_escape_custom($_POST['form_allday']) . "', " .
312 "'" . add_escape_custom($_POST['form_apptstatus']) . "', " .
313 "'" . add_escape_custom($_POST['form_prefcat']) . "', " .
314 "'" . add_escape_custom($locationspec) . "', " .
316 "1, " .(int)$_POST['facility']. " )"); // FF stuff
321 // after the two diffs above, we must update for remaining providers
322 // those who are intersected in $providers_current and $providers_new
323 foreach ($_POST['form_provider_ae'] as $provider) {
324 sqlStatement("UPDATE openemr_postcalendar_events SET " .
325 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
326 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
327 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
328 "pc_time = NOW(), " .
329 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
330 "pc_informant = '" . add_escape_custom($_SESSION['providerId']) . "', " .
331 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
332 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
333 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
334 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
335 "pc_recurrspec = '" . add_escape_custom($recurrspec) . "', " .
336 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
337 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
338 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
339 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
340 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "', " .
341 "pc_facility = '" . (int)$_POST['facility'] . "' " . // FF stuff
342 "WHERE pc_aid = '" . add_escape_custom($provider) . "' AND pc_multiple='" . add_escape_custom($row['pc_multiple']) . "'");
345 /* ==========================================
346 // multi providers EOS
347 ==========================================*/
348 } elseif (!$row['pc_multiple']) {
349 if ($GLOBALS['select_multi_providers']) {
350 $prov = $_POST['form_provider_ae'][0];
352 $prov = $_POST['form_provider_ae'];
355 // simple provider case
356 sqlStatement("UPDATE openemr_postcalendar_events SET " .
357 "pc_catid = '" . add_escape_custom($_POST['form_category']) . "', " .
358 "pc_aid = '" . add_escape_custom($prov) . "', " .
359 "pc_pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
360 "pc_title = '" . add_escape_custom($_POST['form_title']) . "', " .
361 "pc_time = NOW(), " .
362 "pc_hometext = '" . add_escape_custom($_POST['form_comments']) . "', " .
363 "pc_informant = '" . add_escape_custom($_SESSION['providerId']) . "', " .
364 "pc_eventDate = '" . add_escape_custom($event_date) . "', " .
365 "pc_endDate = '" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
366 "pc_duration = '" . add_escape_custom(($duration * 60)) . "', " .
367 "pc_recurrtype = '" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
368 "pc_recurrspec = '" . add_escape_custom($recurrspec) . "', " .
369 "pc_startTime = '" . add_escape_custom($starttime) . "', " .
370 "pc_endTime = '" . add_escape_custom($endtime) . "', " .
371 "pc_alldayevent = '" . add_escape_custom($_POST['form_allday']) . "', " .
372 "pc_apptstatus = '" . add_escape_custom($_POST['form_apptstatus']) . "', " .
373 "pc_prefcatid = '" . add_escape_custom($_POST['form_prefcat']) . "', " .
374 "pc_facility = '" . (int)$_POST['facility'] ."' " . // FF stuff
375 "WHERE pc_eid = '" . add_escape_custom($eid) . "'");
378 // =======================================
379 // EOS multi providers case
380 // =======================================
382 // EVENTS TO FACILITIES
386 /* =======================================================
388 ========================================================*/
390 // =======================================
391 // multi providers case
392 // =======================================
394 if (is_array($_POST['form_provider_ae'])) {
395 // obtain the next available unique key to group multiple providers around some event
396 $q = sqlStatement("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events");
397 $max = sqlFetchArray($q);
398 $new_multiple_value = $max['max'] +
1;
400 foreach ($_POST['form_provider_ae'] as $provider) {
401 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
402 "pc_catid, pc_multiple, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
403 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
404 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
405 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
407 "'" . add_escape_custom($_POST['form_category']) . "', " .
408 "'" . add_escape_custom($new_multiple_value) . "', " .
409 "'" . add_escape_custom($provider) . "', " .
410 "'" . add_escape_custom($_POST['form_pid']) . "', " .
411 "'" . add_escape_custom($_POST['form_title']) . "', " .
413 "'" . add_escape_custom($_POST['form_comments']) . "', " .
414 "'" . add_escape_custom($_SESSION['providerId']) . "', " .
415 "'" . add_escape_custom($event_date) . "', " .
416 "'" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
417 "'" . add_escape_custom(($duration * 60)) . "', " .
418 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
419 "'" . add_escape_custom($recurrspec) . "', " .
420 "'" . add_escape_custom($starttime) . "', " .
421 "'" . add_escape_custom($endtime) . "', " .
422 "'" . add_escape_custom($_POST['form_allday']) . "', " .
423 "'" . add_escape_custom($_POST['form_apptstatus']) . "', " .
424 "'" . add_escape_custom($_POST['form_prefcat']) . "', " .
425 "'" . add_escape_custom($locationspec) . "', " .
427 "1, " .(int)$_POST['facility']. " )"); // FF stuff
430 $_POST['form_apptstatus'] = '^';
431 sqlInsert("INSERT INTO openemr_postcalendar_events ( " .
432 "pc_catid, pc_aid, pc_pid, pc_title, pc_time, pc_hometext, " .
433 "pc_informant, pc_eventDate, pc_endDate, pc_duration, pc_recurrtype, " .
434 "pc_recurrspec, pc_startTime, pc_endTime, pc_alldayevent, " .
435 "pc_apptstatus, pc_prefcatid, pc_location, pc_eventstatus, pc_sharing, pc_facility " .
437 "'" . add_escape_custom($_POST['form_category']) . "', " .
438 "'" . add_escape_custom($_POST['form_provider_ae']) . "', " .
439 "'" . add_escape_custom($_POST['form_pid']) . "', " .
440 "'" . add_escape_custom($_POST['form_title']) . "', " .
442 "'" . add_escape_custom($_POST['form_comments']) . "', " .
443 "'" . add_escape_custom($_SESSION['providerId']) . "', " .
444 "'" . add_escape_custom($event_date) . "', " .
445 "'" . add_escape_custom(fixDate($_POST['form_enddate'])) . "', " .
446 "'" . add_escape_custom(($duration * 60)) . "', " .
447 "'" . ($_POST['form_repeat'] ?
'1' : '0') . "', " .
448 "'" . add_escape_custom($recurrspec) . "', " .
449 "'" . add_escape_custom($starttime) . "', " .
450 "'" . add_escape_custom($endtime) . "', " .
451 "'" . add_escape_custom($_POST['form_allday']) . "', " .
452 "'" . add_escape_custom($_POST['form_apptstatus']) . "', " .
453 "'" . add_escape_custom($_POST['form_prefcat']) . "', " .
454 "'" . add_escape_custom($locationspec) . "', " .
456 "1, " . (int)$_POST['facility'] . ")"); // FF stuff
460 // Save new DOB if it's there.
461 $patient_dob = trim($_POST['form_dob']);
462 if ($patient_dob && $_POST['form_pid']) {
463 sqlStatement("UPDATE patient_data SET DOB = ? WHERE " .
464 "pid = ?", array($patient_dob, $_POST['form_pid']));
467 // Auto-create a new encounter if appropriate.
470 /* if ($GLOBALS['auto_create_new_encounters'] &&
471 $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d'))
474 // We decided not to auto-create blank enconter when user arrives. Todd's decision 18 Jun 2010
475 // Applied by Cassian Lup (cassian.lup@clinicdr.com)
478 $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " .
479 "pid = ? AND date = ?", array($_POST['form_pid'], $event_date." 00:00:00"));
480 if ($tmprow['count'] == 0) {
481 $tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = ?", array($_POST['form_provider_ae']));
482 $username = $tmprow['username'];
483 $facility = $tmprow['facility'];
484 $facility_id = $tmprow['facility_id'];
485 $conn = $GLOBALS['adodb']['db'];
486 $encounter = $conn->GenID("sequences");
489 "New Patient Encounter",
490 sqlInsert("INSERT INTO form_encounter SET " .
491 "date = '" . add_escape_custom($event_date) . "', " .
492 "onset_date = '" . add_escape_custom($event_date) . "', " .
493 "reason = '" . add_escape_custom($_POST['form_comments']) . "', " .
494 "facility = '" . add_escape_custom($facility) . "', " .
495 "facility_id = '" . add_escape_custom($facility_id) . "', " .
496 "pid = '" . add_escape_custom($_POST['form_pid']) . "', " .
497 "encounter = '" . add_escape_custom($encounter) . "'"),
504 $info_msg .= "New encounter $encounter was created. ";
507 } else if ($_POST['form_action'] == "delete") {
508 // =======================================
509 // multi providers case
510 // =======================================
511 if ($GLOBALS['select_multi_providers']) {
512 // what is multiple key around this $eid?
513 $row = sqlQuery("SELECT pc_multiple FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
514 if ($row['pc_multiple']) {
515 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_multiple = ?", array($row['pc_multiple']));
517 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
520 // =======================================
521 // EOS multi providers case
522 // =======================================
524 sqlStatement("DELETE FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
528 if ($_POST['form_action'] != "") {
530 $_SESSION['whereto'] = 'appointmentpanel';
531 header('Location:./home.php#appointmentpanel');
535 // If we get this far then we are displaying the form.
539 '*' => xl('* Reminder done'),
540 '+' => xl('+ Chart pulled'),
541 'x' => xl('x Cancelled'), // added Apr 2008 by JRM
542 '?' => xl('? No show'),
543 '@' => xl('@ Arrived'),
544 '~' => xl('~ Arrived late'),
545 '!' => xl('! Left w/o visit'),
546 '#' => xl('# Ins/fin issue'),
547 '<' => xl('< In exam room'),
548 '>' => xl('> Checked out'),
549 '$' => xl('$ Coding done'),
550 '^' => xl('^ Pending'),
553 $repeats = 0; // if the event repeats
560 // If we are editing an existing event, then get its data.
562 $row = sqlQuery("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid));
563 $date = $row['pc_eventDate'];
564 $userid = $row['pc_aid'];
565 $patientid = $row['pc_pid'];
566 $starttimeh = substr($row['pc_startTime'], 0, 2) +
0;
567 $starttimem = substr($row['pc_startTime'], 3, 2);
568 $repeats = $row['pc_recurrtype'];
569 $multiple_value = $row['pc_multiple'];
571 if (preg_match('/"event_repeat_freq_type";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
572 $repeattype = $matches[1];
575 if (preg_match('/"event_repeat_freq";s:1:"(\d)"/', $row['pc_recurrspec'], $matches)) {
576 $repeatfreq = $matches[1];
579 $hometext = $row['pc_hometext'];
580 if (substr($hometext, 0, 6) == ':text:') {
581 $hometext = substr($hometext, 6);
584 $patientid=$_GET['pid'];
587 // If we have a patient ID, get the name and phone numbers to display.
589 $prow = sqlQuery("SELECT lname, fname, phone_home, phone_biz, DOB " .
590 "FROM patient_data WHERE pid = ?", array($patientid));
591 $patientname = $prow['lname'] . ", " . $prow['fname'];
592 if ($prow['phone_home']) {
593 $patienttitle .= " H=" . $prow['phone_home'];
596 if ($prow['phone_biz']) {
597 $patienttitle .= " W=" . $prow['phone_biz'];
601 // Get the providers list.
602 $ures = sqlStatement("SELECT id, username, fname, lname FROM users WHERE " .
603 "authorized != 0 AND active = 1 ORDER BY lname, fname");
605 //-------------------------------------
607 //Set default facility for a new event based on the given 'userid'
609 $pref_facility = sqlFetchArray(sqlStatement("SELECT facility_id, facility FROM users WHERE id = ?", array($userid)));
610 $e2f = $pref_facility['facility_id'];
611 $e2f_name = $pref_facility['facility'];
614 //END of CHEMED -----------------------
616 // Get event categories.
617 $cres = sqlStatement("SELECT pc_catid, pc_catname, pc_recurrtype, pc_duration, pc_end_all_day " .
618 "FROM openemr_postcalendar_categories ORDER BY pc_catname");
620 // Fix up the time format for AM/PM.
622 if ($starttimeh >= 12) { // p.m. starts at noon and not 12:01
624 if ($starttimeh > 12) {
633 <title
><?php
echo $eid ?
xlt("Edit Event") : xlt("Add New Event"); ?
></title
>
635 <link href
="assets/css/style.css?v=<?php echo $v_js_includes; ?>" rel
="stylesheet" type
="text/css" />
636 <script type
="text/javascript" src
="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script
>
639 <body
class="skin-blue" >
641 <form
class="form-inline" method
='post' name
='theaddform' id
='theaddform' action
='add_edit_event_user.php?eid=<?php echo attr($eid); ?>'>
642 <input type
="hidden" name
="form_action" id
="form_action" value
="">
643 <input type
='hidden' name
='form_category' id
='form_category' value
='<?php echo $row['pc_catid
'] ? attr($row['pc_catid
']) : '5'; ?>' />
644 <input type
='hidden' name
='form_apptstatus' id
='form_apptstatus' value
='<?php echo $row['pc_apptstatus
'] ? attr($row['pc_apptstatus
']) : "^" ?>' />
645 <table border
='0' width
='100%'>
647 <td width
='1%' nowrap
>
648 <b
><?php
echo xlt('Visit'); ?
>: </b
>
650 <td nowrap style
='padding:0px 5px 5px 0'>
651 <input
class="form-control" type
="text" id
='form_title' name
='form_title' value
='<?php echo ($row['pc_title
'] > "") ? attr($row['pc_title
']) : xla('Office Visit
'); ?>' readonly
='readonly'/>
654 <td width
='1%' nowrap
>
655 <b
><?php
echo xlt('Date'); ?
>:</b
>
657 <td colspan
='2' nowrap id
='tdallday1'>
658 <input
class="form-control" type
='text' size
='10' name
='form_date' readonly id
='form_date'
659 value
='<?php echo (isset($eid) && $eid) ? attr($row['pc_eventDate
']) : attr($date); ?>' />
664 <b
><?php
//xl('Title','e'); ?></b>
666 <td style
='padding:0px 5px 5px 0' nowrap
>
667 <!-- <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
'); ?>' /> -->
671 <td width
='1%' nowrap id
='tdallday2'>
672 <b
><?php
echo xlt('Time');?
>:</b
>
674 <td width
='1%' nowrap id
='tdallday3'>
675 <input
class="form-control inline" type
='text' size
='2' name
='form_hour' value
='<?php echo (isset($eid)) ? $starttimeh : ''; ?>'
676 title
='<?php echo xla('Event start time
'); ?>' readonly
/> :
677 <input
class="form-control inline" type
='text' size
='2' name
='form_minute' value
='<?php echo (isset($eid)) ? $starttimem : ''; ?>'
678 title
='<?php echo xla('Event start time
'); ?>' readonly
/> 
; <!-- -->
679 <select
class="form-control" name
='form_ampm' title
='Note: 12:00 noon is PM, not AM' readonly
>
680 <option value
='1'><?php
echo xlt('AM'); ?
></option
>
681 <option value
='2'<?php
echo ($startampm == '2') ?
" selected" : ""; ?
>><?php
echo xlt('PM'); ?
></option
>
687 <b
><?php
echo xlt('Patient'); ?
>:</b
>
689 <td style
='padding:0px 5px 5px 0' nowrap
>
690 <input
class="form-control" type
='text' id
='form_patient' name
='form_patient' value
='<?php echo attr($patientname); ?>' title
='Patient' readonly
/>
691 <input type
='hidden' name
='form_pid' value
='<?php echo attr($patientid); ?>' />
696 <td nowrap id
='tdallday4'><?php
echo xlt('Duration'); ?
></td
>
697 <td nowrap id
='tdallday5'>
698 <input
class="form-control input-sm" type
='text' size
='1' name
='form_duration' value
='<?php echo $row['pc_duration
'] ? ($row['pc_duration
']*1/60) : "15" ?>' readonly
/><?php
echo " " . xlt('minutes'); ?
>
705 <b
><?php
echo xlt('Provider'); ?
>:</b
>
707 <td style
='padding:0px 5px 5px 0' nowrap
>
708 <select
class="form-control" name
='form_provider_ae' id
='form_provider_ae' onchange
='change_provider();'>
710 // present a list of providers to choose from
711 // default to the currently logged-in user
712 while ($urow = sqlFetchArray($ures)) {
713 echo " <option value='" . attr($urow['id']) . "'";
714 if (($urow['id'] == $_GET['userid'])||
($urow['id']== $userid)) {
718 echo ">" . text($urow['lname']);
719 if ($urow['fname']) {
720 echo ", " . text($urow['fname']);
728 <td nowrap style
='font-size:8pt'>
730 <td
><input type
='button' class='btn btn-danger btn-sm' value
='<?php echo xla('Openings
');?>' onclick
='find_available()' /></td
>
735 <b
><?php
echo xlt('Reason'); ?
>:</b
>
737 <td style
='padding:0px 5px 5px 0' colspan
='4' nowrap
>
738 <input
class="form-control" type
='text' size
='40' name
='form_comments' style
='width:100%' value
='<?php echo attr($hometext); ?>' title
='<?php echo xla('Optional information about this event
'); ?>' />
743 <input type
='button' name
='form_save' class='btn btn-success btn-md' onsubmit
='return false' value
='<?php echo xla('Save
'); ?>' onclick
="validate()" />
749 var durations
= new Array();
751 // Read the event categories, generate their options list, and get
752 // the default event duration from them if this is a new event.
754 $prefcat_options = " <option value='0'>-- None --</option>\n";
757 $thisduration = $row['pc_alldayevent'] ?
1440 : round($row['pc_duration'] / 60);
760 while ($crow = sqlFetchArray($cres)) {
761 $duration = round($crow['pc_duration'] / 60);
762 if ($crow['pc_end_all_day']) {
766 echo " durations[" . attr($crow['pc_catid']) . "] = " . text($duration) . "\n";
767 // echo " rectypes[" . $crow['pc_catid'] . "] = " . $crow['pc_recurrtype'] . "\n";
768 $catoptions .= " <option value='" . attr($crow['pc_catid']) . "'";
770 if ($crow['pc_catid'] == $row['pc_catid']) {
771 $catoptions .= " selected";
774 if ($crow['pc_catid'] == $default_catid) {
775 $catoptions .= " selected";
776 $thisduration = $duration;
780 $catoptions .= ">" . text($crow['pc_catname']) . "</option>\n";
782 // This section is to build the list of preferred categories:
784 $prefcat_options .= " <option value='" . attr($crow['pc_catid']) . "'";
786 if ($crow['pc_catid'] == $row['pc_prefcatid']) {
787 $prefcat_options .= " selected";
791 $prefcat_options .= ">" . text($crow['pc_catname']) . "</option>\n";
796 <?php
require($GLOBALS['srcdir'] . "/restoreSession.php"); ?
>
798 // This is for callback by the find-patient popup.
799 function setpatient(pid
, lname
, fname
, dob
) {
800 var f
= document
.forms
.namedItem("theaddform");
801 f
.form_patient
.value
= lname +
', ' + fname
;
802 f
.form_pid
.value
= pid
;
803 dobstyle
= (dob
== '' || dob
.substr(5, 10) == '00-00') ?
'' : 'none';
804 document
.getElementById('dob_row').style
.display
= dobstyle
;
806 function change_provider(){
807 var f
= document
.forms
.namedItem("theaddform");
808 f
.form_date
.value
='';
809 f
.form_hour
.value
='';
810 f
.form_minute
.value
='';
812 // This is for callback by the find-patient popup.
813 function unsetpatient() {
814 var f
= document
.forms
.namedItem("theaddform");
815 f
.form_patient
.value
= '';
816 f
.form_pid
.value
= '';
819 // This invokes the find-patient popup.
820 function sel_patient() {
821 dlgopen('find_patient_popup.php', '_blank', 500, 400);
824 // Do whatever is needed when a new event category is selected.
825 // For now this means changing the event title and duration.
826 function set_display() {
827 var f
= document
.forms
.namedItem("theaddform");
828 var si
= document
.getElementById('form_category');
829 if (si
.selectedIndex
>= 0) {
830 var catid
= si
.options
[si
.selectedIndex
].value
;
831 var style_apptstatus
= document
.getElementById('title_apptstatus').style
;
832 var style_prefcat
= document
.getElementById('title_prefcat').style
;
833 if (catid
== '2') { // In Office
834 style_apptstatus
.display
= 'none';
835 style_prefcat
.display
= '';
836 f
.form_apptstatus
.style
.display
= 'none';
837 f
.form_prefcat
.style
.display
= '';
839 style_prefcat
.display
= 'none';
840 style_apptstatus
.display
= '';
841 f
.form_prefcat
.style
.display
= 'none';
842 f
.form_apptstatus
.style
.display
= '';
847 // Gray out certain fields according to selection of Category DDL
848 function categoryChanged() {
851 document
.getElementById("form_patient").disabled
=false;
852 //document.getElementById("form_apptstatus").disabled=false;
853 //document.getElementById("form_prefcat").disabled=false;
857 // Do whatever is needed when a new event category is selected.
858 // For now this means changing the event title and duration.
859 function set_category() {
860 var f
= document
.forms
.namedItem("theaddform");
861 var s
= f
.form_category
;
862 if (s
.selectedIndex
>= 0) {
863 var catid
= s
.options
[s
.selectedIndex
].value
;
864 f
.form_title
.value
= s
.options
[s
.selectedIndex
].text
;
865 f
.form_duration
.value
= durations
[catid
];
870 // Modify some visual attributes when the all-day or timed-event
871 // radio buttons are clicked.
872 function set_allday() {
873 var f
= document
.forms
.namedItem("theaddform");
874 var color1
= '#777777';
875 var color2
= '#777777';
876 var disabled2
= true;
877 /*if (document.getElementById('rballday1').checked) {
880 if (document.getElementById('rballday2').checked) {
884 document
.getElementById('tdallday1').style
.color
= color1
;
885 document
.getElementById('tdallday2').style
.color
= color2
;
886 document
.getElementById('tdallday3').style
.color
= color2
;
887 document
.getElementById('tdallday4').style
.color
= color2
;
888 document
.getElementById('tdallday5').style
.color
= color2
;
889 f
.form_hour
.disabled
= disabled2
;
890 f
.form_minute
.disabled
= disabled2
;
891 f
.form_ampm
.disabled
= disabled2
;
892 f
.form_duration
.disabled
= disabled2
;
895 // Modify some visual attributes when the Repeat checkbox is clicked.
896 function set_repeat() {
897 var f
= document
.forms
.namedItem("theaddform");
898 var isdisabled
= true;
899 var mycolor
= '#777777';
900 var myvisibility
= 'hidden';
901 /*if (f.form_repeat.checked) {
904 myvisibility = 'visible';
906 //f.form_repeat_type.disabled = isdisabled;
907 //f.form_repeat_freq.disabled = isdisabled;
908 //f.form_enddate.disabled = isdisabled;
909 document
.getElementById('tdrepeat1').style
.color
= mycolor
;
910 document
.getElementById('tdrepeat2').style
.color
= mycolor
;
911 document
.getElementById('img_enddate').style
.visibility
= myvisibility
;
914 // This is for callback by the find-available popup.
915 function setappt(year
,mon
,mday
,hours
,minutes
) {
916 var f
= document
.forms
.namedItem("theaddform");
917 f
.form_date
.value
= '' + year +
'-' +
918 ('' +
(mon +
100)).substring(1) +
'-' +
919 ('' +
(mday +
100)).substring(1);
920 f
.form_ampm
.selectedIndex
= (hours
>= 12) ?
1 : 0;
921 f
.form_hour
.value
= (hours
> 12) ? hours
- 12 : hours
;
922 f
.form_minute
.value
= ('' +
(minutes +
100)).substring(1);
925 // Invoke the find-available popup.
926 function find_available() {
927 // when making an appointment for a specific provider
928 var se
= document
.getElementById('form_provider_ae');
929 <?php
if ($userid != 0) { ?
>
932 s
= se
.options
[se
.selectedIndex
].value
;
934 var formDate
= document
.getElementById('form_date');
935 var url
= 'find_appt_popup_user.php?bypatient&providerid=' + s +
'&catid=5' +
'&startdate=' + formDate
.value
;
938 {text
: '<?php echo xla('Cancel
'); ?>', close
: true, style
: 'danger btn-sm'}
942 dialogId
: 'apptDialog',
945 dlgopen(url
, 'apptFind', 'modal-md', 300, '', 'Find Date', params
);
948 // Check for errors when the form is submitted.
949 function validate() {
950 var f
= document
.getElementById('theaddform');
951 if (!f
.form_date
.value ||
!f
.form_hour
.value ||
!f
.form_minute
.value
) {
952 alert('Please click on "Openings" to select a time.');
956 // in lunch outofoffice reserved vacation
957 // f.form_category.value='2';
958 if (f
.form_patient
.value
=='Click to select' && (!(
959 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'
960 || f
.form_category
.value
=='10'))) {
961 alert('Please select a patient.');
963 } else if (f
.form_category
.value
=='10') {
966 var form_action
= document
.getElementById('form_action');
967 form_action
.value
="save";
972 function deleteEvent() {
973 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?")) {
974 var f
= document
.getElementById('theaddform');
975 var form_action
= document
.getElementById('form_action');
976 form_action
.value
="delete";
987 $
(document
).ready(function() {
988 $
('.datepicker').datetimepicker({
989 <?php
$datetimepicker_timepicker = false; ?
>
990 <?php
$datetimepicker_showseconds = false; ?
>
991 <?php
$datetimepicker_formatInput = false; ?
>
992 <?php
require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?
>
993 <?php
// can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>