How do appointment reminders work?

Go look at my fax module: oe-module-faxsms/rc_sms_notification.php at master · openemr/oe-module-faxsms · GitHub
It’s setup for cron jobs and will prob give a clue how to do.

Thank you very much for your answer Jerry. please where can i see the class “OpenEMR\Modules\FaxSMS\Controllers\AppDispatch”

That class is part of the fax module using Twilio SMS and Ring Central fax/sms. It won’t help with your project.
This is important part:

_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
$_SERVER['SERVER_NAME'] = 'localhost';
$backpic = "";

// for cron
if ($argc > 1 && empty($_SESSION['site_id']) && empty($_GET['site'])) {
    $c = stripos($argv[1], 'site=');
    if ($c === false) {
        echo xlt("Missing Site Id using default") . "\n";
        $argv[1] = "site=default";
    }
    $args = explode('=', $argv[1]);
    $_GET['site'] = isset($args[1]) ? $args[1] : 'default';
}
if (php_sapi_name() === 'cli') {
    $_SERVER[‘HTTP_HOST’] = ‘localhost’;
    $ignoreAuth = true;
}
require_once(__DIR__ . "/../../../globals.php");
require_once("$srcdir/appointments.inc.php");

It shows how to call from command line for cron. Note
To decrypt password look here around L-47: library/classes/postmaster.php

Well, it’s finished. The script works for both cron and windows (task scheduler). I have tested it on Rocky Linux 8.5 and Windows 11 (xampp), both with php 8.1. The logs are recorded in openemr/modules/sms_email_reminder/logs (I think you have to create the logs folder). Thank you very much @sjpadgett.
It only works for sending emails. It’s just 2 scripts that need to replace and read the readme.txt file. I hope it serves you.
Regards.
Luis.

cron_email_notification.php (4.2 KB)
cron_functions.php (14.1 KB)
readme.txt (429 Bytes)

2 Likes

@luisuriarte Thanks for posting this. I’m going to look over to see if I can’t get it into core then bring back for next 6.1 patch so you don’t have to worry with keeping up with a custom script.

Tanks Jerry.
In cron_functions.php (line 119) change $mail->From = $strFrom;
to
$mail->From = $SenderEmail;
And… line 80:
$SenderMail = $GLOBALS[‘patient_reminder_sender_email’];
to
$SenderEmail = $GLOBALS[‘patient_reminder_sender_email’];
Edit: Sorry
Regards
Luis.

1 Like

Well.
I made some changes. Now update, also the patient_tracker_element table (it already appears in the flow board) and on the other hand, there is the option that in addition to the patient’s email, you can also send to the trusted email. Since the message body can be html, in the message template (Series Communication Tool / Email Notification) you can use HTML tags (HTML Reference)
Here the changes.

In cron_email_notification.php I modified

            $prow['email'],
			$prow['email_direct'], //<-----
            $db_email_msg['email_subject'],
....			
cron_updateentry($TYPE, $prow['pid'], $prow['pc_eid'], $prow['pt_tracker_id']);

In cron_functions.php I Deleted

        //$cc = "";
        //$bcc = "";
		        //if (strlen($cc) > 5) {
        //    $headers .= "Cc: $cc\r\n";
        //}

        //if (strlen($bcc) > 5) {
        //    $headers .= "Bcc: $bcc\r\n";
        //}

I Modified

function cron_SendMail($to, $cc, $subject, $vBody, $from)
...
        $cnt .= "\nTo : " . $to;
		$cnt .= "\nCc : " . $cc;
        $cnt .= "\nSubject : " . $subject;
....
       $mstatus = @mail($to, $cc, $subject, $vBody, $headers);
....
        $strTo = $to;
		$recipient_line = __LINE__;
		$strCc = $cc;
        $recipient_line = __LINE__;
....
		$mail->AddAddress($strTo);
		//$mail->addCC($strCc); //Remove comment to send, also to trusted mail
		$mail->WordWrap = 50;
		$mail->IsHTML(true);
....
 $mail->Send(
                $strFrom,
                array( $strTo ),
                array(
                "From: $strFrom",
                "To: $strTo",
				"Cc: $strCc",
				"Subject: $subject",
                "Date Time :" . date("d M, Y  h:i:s")
....
function cron_updateentry($type, $pid, $pc_eid, $tracker_id)
{
  
    //$query="update openemr_postcalendar_events set $set ";
    $query = "update openemr_postcalendar_events , patient_tracker_element set ";

    // larry :: and here again same story - this time for sms pc_sendalertsms - no such field in the table
    if ($type == 'SMS') {
        $query .= " openemr_postcalendar_events.pc_sendalertsms='YES' ,  openemr_postcalendar_events.pc_apptstatus='SMS' , patient_tracker_element.status='SMS' ";
    } else {
        //$query .= " pc_sendalertemail='YES' ";
		$query .= " openemr_postcalendar_events.pc_sendalertemail='YES' ,  openemr_postcalendar_events.pc_apptstatus='EMAIL' , patient_tracker_element.status='EMAIL' ";
    }

    $query .= " where openemr_postcalendar_events.pc_pid=? and openemr_postcalendar_events.pc_eid=? and patient_tracker_element.pt_tracker_id= ? ";
    //echo "<br />".$query;
    $db_sql = (sqlStatement($query, [$pid, $pc_eid, $tracker_id]));
}
....
    $patient_field = "pd.pid,pd.title,pd.fname,pd.lname,pd.mname,pd.phone_cell,pd.email,pd.email_direct,pd.hipaa_allowsms,pd.hipaa_allowemail,";
....
    $query = "select $patient_field pd.pid,ope.pc_eid,ope.pc_pid,ope.pc_title,
			ope.pc_hometext,ope.pc_eventDate,ope.pc_endDate,
			ope.pc_duration,ope.pc_alldayevent,ope.pc_startTime,ope.pc_endTime,
			CONCAT(u.fname, ' ', u.mname, ' ', u.lname) user_name, pte.pt_tracker_id
		from 
			patient_tracker_element pte
			INNER JOIN patient_tracker pt ON pte.pt_tracker_id = pt.id
			INNER JOIN openemr_postcalendar_events ope ON ope.pc_eid = pt.eid
			INNER JOIN patient_data pd ON ope.pc_pid = pd.id
			INNER JOIN users u ON u.id = ope.pc_aid
		where 
			ope.pc_pid=pd.pid $ssql 
		order by 
			ope.pc_eventDate,ope.pc_endDate,pd.pid";
		

cron_email_notification.php (4.1 KB)
cron_functions.php (14.7 KB)
Regards.
Luis.

Code cleaning
cron_functions.php (12.1 KB)
cron_email_notification.php (4.1 KB)

1 Like

great job @luisuriarte , you can check out the contributing guide and see how it’s pretty straightforward to create an environment for creating and submitting a pull request to bring your enhancements into the community codebase and happy to help you out if needed.

1 Like

Thank you very much, @stephenwaite , @sjpadgett
I already created my first pull request

1 Like

I have been following this thread. I’m interested in writing a new tutorial or updating current tutorials.

This week I’ll start working on it. I will have to implement it myself first.

1 Like

Has anyone been able to use this for sending email?

Hi @harmone75
This works, but is still under PR review. First you need to replace the two attachments in openemr/modules/sms_email_reminder/. In that folder create another one with name logs. Then you must run the following command every hour with cron(linux) or Scheduled Tasks (windows): php /path_to_openemr/modules/sms_email_reminder/cron_email_notification.php.
In Globals/Notification, you must configure the data of the mail server and senders. In Miscellaneous/Batch Communication Tools/Email Notification, you must configure the subject.
cron_functions.php (10.7 KB)
cron_email_notification.php (4.2 KB)

Regards.
Luis.

2 Likes

Thank you Luis, I am kind of a novice when it comes to the cron jobs; however, when you state create another one with name logs, can you provide an example of that, if you have one?

It means to create a new directory named “logs” within the following directory:

/path to openemr/modules/sms_email_reminder/

Such that you will have the following:

/path to openemr/modules/sms_email_reminder/logs

Do you have access to your openemr installation?

1 Like

Thank you,

Yes, I have access to my emr installation

I received this error when I run my cron jobs, could anyone provide any insight

Status: 404 Not Found
Content-type: text/html; charset=UTF-8

No input file specified.

This is my cron command

php /home/creat616/technologyreconstruction.com/openemr/modules/sms_email_reminder/

The command should be:
php /home/creat616/technologyreconstruction.com/openemr/modules/sms_email_reminder/cron_email_notification.php

Thank you for that information, I am not receiving this error, is that a coding issue within the php file? or information in the clients database?

To verify if it works, you must see the files in the logs directory:
ls /path_to_openemr/modules/sms_email_reminder/logs
And in appointment change the status to EMAIL Confimed.
image