function InsertEventFull() { global $new_multiple_value, $provider, $event_date, $duration, $recurrspec, $starttime, $endtime, $locationspec; // ======================================= // multi providers case // ======================================= if (is_array($_POST['form_provider'])) { // obtain the next available unique key to group multiple providers around some event $q = sqlStatement("SELECT MAX(pc_multiple) as max FROM openemr_postcalendar_events"); $max = sqlFetchArray($q); $new_multiple_value = $max['max'] + 1; foreach ($_POST['form_provider'] as $provider) { $args = $_POST; // specify some special variables needed for the INSERT $args['new_multiple_value'] = $new_multiple_value; $args['form_provider'] = $provider; $args['event_date'] = $event_date; $args['duration'] = $duration * 60; $args['recurrspec'] = $recurrspec; $args['starttime'] = $starttime; $args['endtime'] = $endtime; $args['locationspec'] = $locationspec; InsertEvent($args); } // ==================================== // single provider // ==================================== } else { $args = $_POST; // specify some special variables needed for the INSERT $args['new_multiple_value'] = ""; $args['event_date'] = $event_date; $args['duration'] = $duration * 60; $args['recurrspec'] = $recurrspec; $args['starttime'] = $starttime; $args['endtime'] = $endtime; $args['locationspec'] = $locationspec; InsertEvent($args); } }
function update_event($eid) { $origEventRes = sqlStatement("SELECT * FROM openemr_postcalendar_events WHERE pc_eid = ?", array($eid)); $origEvent = sqlFetchArray($origEventRes); $oldRecurrspec = unserialize($origEvent['pc_recurrspec']); $duration = $origEvent['pc_duration']; $starttime = $origEvent['pc_startTime']; $endtime = $origEvent['pc_endTime']; $selected_date = date("Ymd"); if ($oldRecurrspec['exdate'] != "") { $oldRecurrspec['exdate'] .= "," . $selected_date; } else { $oldRecurrspec['exdate'] .= $selected_date; } // mod original event recur specs to exclude this date sqlStatement("UPDATE openemr_postcalendar_events SET pc_recurrspec = ? WHERE pc_eid = ?", array(serialize($oldRecurrspec), $eid)); // specify some special variables needed for the INSERT // no recurr specs, this is used for adding a new non-recurring event $noRecurrspec = array("event_repeat_freq" => "", "event_repeat_freq_type" => "", "event_repeat_on_num" => "1", "event_repeat_on_day" => "0", "event_repeat_on_freq" => "0", "exdate" => ""); // Useless garbage that we must save. $locationspecs = array("event_location" => "", "event_street1" => "", "event_street2" => "", "event_city" => "", "event_state" => "", "event_postal" => ""); $locationspec = serialize($locationspecs); $args['event_date'] = date('Y-m-d'); $args['duration'] = $duration; // this event is forced to NOT REPEAT $args['form_repeat'] = "0"; $args['recurrspec'] = $noRecurrspec; $args['form_enddate'] = "0000-00-00"; $args['starttime'] = $starttime; $args['endtime'] = $endtime; $args['locationspec'] = $locationspec; $args['form_category'] = $origEvent['pc_catid']; $args['new_multiple_value'] = $origEvent['pc_multiple']; $args['form_provider'] = $origEvent['pc_aid']; $args['form_pid'] = $origEvent['pc_pid']; $args['form_title'] = $origEvent['pc_title']; $args['form_allday'] = $origEvent['pc_alldayevent']; $args['form_apptstatus'] = '@'; $args['form_prefcat'] = $origEvent['pc_prefcatid']; $args['facility'] = $origEvent['pc_facility']; $args['billing_facility'] = $origEvent['pc_billing_location']; InsertEvent($args, 'payment'); }
InsertEvent($args); } // ==================================== // single provider // ==================================== } else { $args = $_POST; // specify some special variables needed for the INSERT $args['new_multiple_value'] = ""; $args['event_date'] = $event_date; $args['duration'] = $duration * 60; $args['recurrspec'] = $recurrspec; $args['starttime'] = $starttime; $args['endtime'] = $endtime; $args['locationspec'] = $locationspec; InsertEvent($args); } } // done with EVENT insert/update statements // Save new DOB if it's there. $patient_dob = trim($_POST['form_dob']); if ($patient_dob && $_POST['form_pid']) { sqlStatement("UPDATE patient_data SET DOB = '{$patient_dob}' WHERE " . "pid = '" . $_POST['form_pid'] . "'"); } // Auto-create a new encounter if appropriate. // if ($GLOBALS['auto_create_new_encounters'] && $_POST['form_apptstatus'] == '@' && $event_date == date('Y-m-d')) { $tmprow = sqlQuery("SELECT count(*) AS count FROM form_encounter WHERE " . "pid = '" . $_POST['form_pid'] . "' AND date = '{$event_date} 00:00:00'"); if ($tmprow['count'] == 0) { $tmprow = sqlQuery("SELECT username, facility, facility_id FROM users WHERE id = '" . $_POST['form_provider'] . "'"); $username = $tmprow['username'];
$facility = $_POST['pc_facility']; $pc_billing_location = $_POST['pc_billing_location']; $comments = $_POST['pc_hometext']; $pc_duration = $_POST['pc_duration']; $endTime = date('H:i:s', strtotime($_POST['appointmentTime']) + $pc_duration); $recurrspecs = array("event_repeat_freq" => "", "event_repeat_freq_type" => "", "event_repeat_on_num" => "1", "event_repeat_on_day" => "0", "event_repeat_on_freq" => "0", "exdate" => ""); $recurrspec = serialize($recurrspecs); $locationspecs = array("event_location" => "", "event_street1" => "", "event_street2" => "", "event_city" => "", "event_state" => "", "event_postal" => ""); $locationspec = serialize($locationspecs); if ($userId = validateToken($token)) { $user = getUsername($userId); $provider_username = getProviderUsername($admin_id); $acl_allow = acl_check('patients', 'appt', $user); if ($acl_allow) { $args = array('form_category' => $pc_catid, 'form_provider' => $admin_id, 'form_pid' => $patientId, 'form_title' => $pc_title, 'form_comments' => $comments, 'event_date' => $appointmentDate, 'form_enddate' => '', 'duration' => $pc_duration, 'recurrspec' => $recurrspecs, 'starttime' => $appointmentTime, 'endtime' => $endTime, 'form_allday' => 0, 'form_apptstatus' => $app_status, 'form_prefcat' => 0, 'locationspec' => $locationspec, 'facility' => $facility, 'billing_facility' => $pc_billing_location); $result = InsertEvent($args); $device_token_badge = getDeviceTokenBadge($provider_username, 'appointment'); $badge = $device_token_badge['badge']; $deviceToken = $device_token_badge['device_token']; if ($deviceToken) { $notification_res = notification($deviceToken, $badge, $msg_count = 0, $apt_count = 0, $message = 'New Appointment Notification!'); } if ($result) { $xml_array['status'] = 0; $xml_array['reason'] = 'The Appointment has been added.'; if ($notification_res) { $xml_array['notification'] = 'Add Appointment Notification(' . $notification_res . ')'; } else { $xml_array['notification'] = 'Notificaiotn Failed.'; } } else {