clinical report datetime support
[openemr.git] / modules / sms_email_reminder / cron_email_notification.php
blob31ce34c5f1b6b86cdf5494a5df2c9a37264e9b0c
1 <?php
3 ////////////////////////////////////////////////////////////////////
4 // Package: cron_email_notification
5 // Purpose: to be run by cron every hour, look for appointments
6 // in the pre-notification period and send an email reminder
7 //
8 // Created by:
9 // Updated by: Larry Lart on 10/03/2008
10 ////////////////////////////////////////////////////////////////////
12 // larry :: hack add for command line version
13 $_SERVER['REQUEST_URI']=$_SERVER['PHP_SELF'];
14 $_SERVER['SERVER_NAME']='localhost';
15 $backpic = "";
17 // email notification
18 $ignoreAuth=1;
19 include_once("../../interface/globals.php");
20 include_once("cron_functions.php");
22 $TYPE = "Email";
23 $CRON_TIME = 5;
25 // set cron time (time to event ?) - todo extra tests
26 $vectNotificationSettings = cron_GetNotificationSettings();
27 $CRON_TIME = $vectNotificationSettings['Send_Email_Before_Hours'];
29 $check_date = date("Y-m-d", mktime(date("h")+$EMAIL_NOTIFICATION_HOUR, 0, 0, date("m"), date("d"), date("Y")));
32 // get data from automatic_notification table
33 $db_email_msg = cron_getNotificationData($TYPE);
34 //my_print_r($db_email_msg);
36 // get patient data for send alert
37 $db_patient = cron_getAlertpatientData($TYPE);
38 echo "<br>Total ".count($db_patient)." Records Found\n";
39 for ($p=0; $p<count($db_patient); $p++) {
40 $prow =$db_patient[$p];
41 //my_print_r($prow);
43 if($prow['pc_eventDate'] < $check_date)
45 $app_date = date("Y-m-d")." ".$prow['pc_startTime'];
46 }else{
47 $app_date = $prow['pc_eventDate']." ".$prow['pc_startTime'];
50 $app_date = $prow['pc_eventDate']." ".$prow['pc_startTime'];
51 $app_time = strtotime($app_date);
53 $app_time_hour = round($app_time/3600);
54 $curr_total_hour = round(time()/3600);
56 $remaining_app_hour = round($app_time_hour - $curr_total_hour);
57 $remain_hour = round($remaining_app_hour - $EMAIL_NOTIFICATION_HOUR);
59 $strMsg = "\n========================".$TYPE." || ".date("Y-m-d H:i:s")."=========================";
60 $strMsg .= "\nSEND NOTIFICATION BEFORE:".$EMAIL_NOTIFICATION_HOUR." || CRONJOB RUN EVERY:".$CRON_TIME." || APPDATETIME:".$app_date." || REMAINING APP HOUR:".($remaining_app_hour)." || SEND ALERT AFTER:".($remain_hour);
62 if ($remain_hour >= -($CRON_TIME) && $remain_hour <= $CRON_TIME) {
63 // insert entry in notification_log table
64 cron_InsertNotificationLogEntry($TYPE, $prow, $db_email_msg);
66 //set message
67 $db_email_msg['message'] = cron_setmessage($prow, $db_email_msg);
69 // send mail to patinet
70 cron_SendMail(
71 $prow['email'],
72 $db_email_msg['email_subject'],
73 $db_email_msg['message'],
74 $db_email_msg['email_sender']
77 //update entry >> pc_sendalertemail='Yes'
78 cron_updateentry($TYPE, $prow['pid'], $prow['pc_eid']);
80 $strMsg .= " || ALERT SENT SUCCESSFULLY TO ".$prow['email'];
81 $strMsg .= "\n".$patient_info."\n".$smsgateway_info."\n".$data_info."\n".$db_email_msg['message'];
84 WriteLog($strMsg);
86 // larry :: get notification data again - since was updated by cron_updateentry
87 // todo :: instead fix not to modify the template aka $db_email_msg
88 $db_email_msg = cron_getNotificationData($TYPE);
91 sqlClose();
94 <html>
95 <head>
96 <title>Conrjob - Email Notification</title>
97 </head>
98 <body>
99 <center>
100 </center>
101 </body>
102 </html>