Files
streamline-emr/docker/_streamline-src/app/Console/Commands/SendAppointmentRemaindersCommand.php
T

58 lines
1.6 KiB
PHP
Executable File

<?php
namespace Streamline\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Streamline\Http\Controllers\SMSController;
class SendAppointmentRemaindersCommand extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'appointment:remainders';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send sms alerts to remind patients of appointments a day before';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct() {
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle() {
$tomorrow_start = Carbon::now()->startOfDay()->addDay();
$tomorrow_end = Carbon::now()->endOfDay()->addDay();
$appointments = DB::table('patient_appointments')
->whereBetween('appointment_date', [$tomorrow_start, $tomorrow_end])
->get();
foreach ($appointments as $appointment) {
if (is_sms_enabled()) {
// send sms alert to the patient
$sms = "This is a reminder that your appointment at " . get_name(1, 'id', 'name', 'hospital_information') .
" is scheduled for tomorrow the " . streamline_date($appointment->appointment_date) . " at " . $appointment->appointment_time;
(new SMSController)->send_appointments_alert($appointment->patient_id, $sms);
}
}
}
}