function send_reminders() { $logging = array(); // Collect active reminders that have not yet been sent. $active_unsent_reminders = fetch_reminders($patient_id, 'unsent'); $logging['total_pre_unsent_reminders'] = count($active_unsent_reminders); // Send the unsent reminders $logging['number_success_emails'] = 0; $logging['number_failed_emails'] = 0; $logging['number_success_calls'] = 0; $logging['number_failed_calls'] = 0; foreach ($active_unsent_reminders as $reminder) { // Collect patient information that reminder is going to. $sql = "SELECT `fname`, `lname`, `email`, `phone_home`, `hipaa_voice`, `hipaa_allowemail` from `patient_data` where `pid`=?"; $result = sqlQuery($sql, array($reminder['pid'])); $patientfname = $result['fname']; $patientlname = $result['lname']; $patientemail = $result['email']; $patientphone = $result['phone_home']; $hipaa_voice = $result['hipaa_voice']; $hipaa_allowemail = $result['hipaa_allowemail']; // Email to patient if Allow Email and set reminder sent flag. if ($hipaa_allowemail == "YES") { $mail = new MyMailer(); $sender_name = $GLOBALS['patient_reminder_sender_name']; $email_address = $GLOBALS['patient_reminder_sender_email']; $mail->FromName = $sender_name; // required $mail->Sender = $email_address; // required $mail->From = $email_address; // required $mail->AddAddress($patientemail, $patientfname . ", " . $patientlname); // required $mail->AddReplyTo($email_address, $sender_name); // required $category_title = generate_display_field(array('data_type' => '1', 'list_id' => 'rule_action_category'), $reminder['category']); $item_title = generate_display_field(array('data_type' => '1', 'list_id' => 'rule_action'), $reminder['item']); $mail->Body = "Dear " . $patientfname . ", This is a message from your clinic to remind you of your " . $category_title . ": " . $item_title; $mail->Subject = "Clinic Reminder"; if ($mail->Send()) { // deal with and keep track of this successful email sqlStatement("UPDATE `patient_reminders` SET `email_status`='1', `date_sent`=NOW() WHERE id=?", array($reminder['id'])); $logging['number_success_emails']++; } else { // deal with and keep track of this unsuccesful email $logging['number_failed_emails']++; } } // Call to patient if Allow Voice Message and set reminder sent flag. if ($hipaa_voice == "YES") { // Automated VOIP service provided by Maviq. Please visit http://signup.maviq.com for more information. $siteId = $GLOBALS['phone_gateway_username']; $token = $GLOBALS['phone_gateway_password']; $endpoint = $GLOBALS['phone_gateway_url']; $client = new MaviqClient($siteId, $token, $endpoint); //Set up params. $data = array("firstName" => $patientfname, "lastName" => $patientlname, "phone" => $patientphone, "timeRange" => "10-18", "type" => "reminder", "timeZone" => date('P'), "greeting" => str_replace("[[sender]]", $sender_name, str_replace("[[patient_name]]", $patientfname, $myrow['reminder_content']))); // Make the call. $response = $client->sendRequest("appointment", "POST", $data); if ($response->IsError) { // deal with and keep track of this unsuccessful call $logging['number_failed_calls']++; } else { // deal with and keep track of this succesful call sqlStatement("UPDATE `patient_reminders` SET `voice_status`='1', `date_sent`=NOW() WHERE id=?", array($reminder['id'])); $logging['number_success_calls']++; } } } // For logging purposes only: // Collect active reminders that have not yet been sent. $logging['total_post_unsent_reminders'] = count(fetch_reminders($patient_id, 'unsent')); return $logging; }
//Get the apptDate and apptTime $p_date = $prow['pc_eventDate']; //Need to format date to m/d/Y for Maviq API $pieces = explode("-", $p_date); $appt_date = date("m/d/Y", mktime(0, 0, 0, $pieces[1], $pieces[2], $pieces[0])); $appt_time = $prow['pc_startTime']; //get the greeting $greeting = $fac_msg_map[$prow['pc_facility']]; if ($greeting == null) { //Use the default when the message is not found $greeting = $GLOBALS['phone_appt_message']['Default']; } //Set up the parameters for the call $data = array("firstName" => $prow['fname'], "lastName" => $prow['lname'], "phone" => $prow['phone_home'], "apptDate" => $appt_date, "apptTime" => $appt_time, "doctor" => $prow['pc_aid'], "greeting" => $greeting, "timeRange" => $phone_time_range, "type" => "appointment", "timeZone" => date('P'), "callerId" => $fac_phone_map[$prow['pc_facility']]); //Make the call $response = $client->sendRequest("appointment", "POST", $data); // check response for success or error if ($response->IsError) { $strMsg = "Error starting phone call for {$prow['fname']} | {$prow['lname']} | {$prow['phone_home']} | {$appt_date} | {$appt_time} | {$response->ErrorMessage}\n"; } else { $strMsg = "\n========================" . $type . " || " . date("Y-m-d H:i:s") . "========================="; $strMsg .= "\nPhone reminder sent successfully: {$prow['fname']} | {$prow['lname']} | | {$prow['phone_home']} | {$appt_date} | {$appt_time} "; // insert entry in notification_log table cron_InsertNotificationLogEntry($prow, $greeting, $phone_url); //update entry >> pc_sendalertsms='Yes' cron_updateentry($type, $prow['pid'], $prow['pc_eid']); } //echo $strMsg; WriteLog($strMsg); } sqlClose();