Add settings-gated appointment notifications and fix Bird key validation.
Deploy Ladill Care / deploy (push) Successful in 58s
Deploy Ladill Care / deploy (push) Successful in 58s
Patients can be SMS/email notified on booking and video schedule when enabled in Settings. Bird validation now accepts only lsk_live_ keys, strips paste artifacts, and surfaces the platform error. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Care;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
|
||||
use App\Models\Appointment;
|
||||
use App\Services\Care\AppointmentPatientNotifier;
|
||||
use App\Services\Care\AuditLogger;
|
||||
use App\Services\Meet\MeetClient;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@@ -14,7 +15,7 @@ class AppointmentMeetController extends Controller
|
||||
{
|
||||
use ScopesToAccount;
|
||||
|
||||
public function schedule(Request $request, Appointment $appointment): RedirectResponse
|
||||
public function schedule(Request $request, Appointment $appointment, AppointmentPatientNotifier $notifier): RedirectResponse
|
||||
{
|
||||
$this->authorizeAbility($request, 'appointments.manage');
|
||||
$this->authorizeOwner($request, $appointment);
|
||||
@@ -27,8 +28,14 @@ class AppointmentMeetController extends Controller
|
||||
$appointment->loadMissing('patient');
|
||||
$patient = $appointment->patient;
|
||||
$owner = $this->ownerRef($request);
|
||||
$organization = $this->organization($request);
|
||||
$user = $request->user();
|
||||
|
||||
$inviteEmails = [];
|
||||
if ($notifier->shouldInvitePatientEmailViaMeet($organization)) {
|
||||
$inviteEmails = array_values(array_filter([(string) $patient->email]));
|
||||
}
|
||||
|
||||
$response = MeetClient::for($owner)->createRoom([
|
||||
'title' => 'Video visit — '.$patient->fullName(),
|
||||
'description' => $appointment->reason,
|
||||
@@ -42,7 +49,7 @@ class AppointmentMeetController extends Controller
|
||||
'entity_type' => 'appointment',
|
||||
'entity_id' => $appointment->uuid,
|
||||
],
|
||||
'invite_emails' => array_values(array_filter([$patient->email])),
|
||||
'invite_emails' => $inviteEmails,
|
||||
]);
|
||||
|
||||
$appointment->update([
|
||||
@@ -52,20 +59,29 @@ class AppointmentMeetController extends Controller
|
||||
|
||||
AuditLogger::record($owner, 'appointment.meet_scheduled', $appointment->organization_id, $owner, Appointment::class, $appointment->id);
|
||||
|
||||
$notifier->notifyVideoScheduled($organization, $appointment->fresh(['patient', 'branch']));
|
||||
|
||||
return redirect()->route('care.appointments.show', $appointment)
|
||||
->with('success', 'Video visit scheduled. The patient will receive a join link.');
|
||||
->with('success', 'Video visit scheduled.'.($this->notifyHint($organization, $notifier)));
|
||||
}
|
||||
|
||||
public function start(Request $request, Appointment $appointment): RedirectResponse
|
||||
public function start(Request $request, Appointment $appointment, AppointmentPatientNotifier $notifier): RedirectResponse
|
||||
{
|
||||
$this->authorizeAbility($request, 'consultations.manage');
|
||||
$this->authorizeOwner($request, $appointment);
|
||||
|
||||
$owner = $this->ownerRef($request);
|
||||
$organization = $this->organization($request);
|
||||
$appointment->loadMissing('patient');
|
||||
$user = $request->user();
|
||||
$createdRoom = false;
|
||||
|
||||
if (! $appointment->meet_room_uuid) {
|
||||
$inviteEmails = [];
|
||||
if ($notifier->shouldInvitePatientEmailViaMeet($organization)) {
|
||||
$inviteEmails = array_values(array_filter([(string) $appointment->patient->email]));
|
||||
}
|
||||
|
||||
$response = MeetClient::for($owner)->createRoom([
|
||||
'title' => 'Video visit — '.$appointment->patient->fullName(),
|
||||
'description' => $appointment->reason,
|
||||
@@ -76,17 +92,34 @@ class AppointmentMeetController extends Controller
|
||||
'entity_type' => 'appointment',
|
||||
'entity_id' => $appointment->uuid,
|
||||
],
|
||||
'invite_emails' => array_values(array_filter([$appointment->patient->email])),
|
||||
'invite_emails' => $inviteEmails,
|
||||
]);
|
||||
|
||||
$appointment->update([
|
||||
'meet_room_uuid' => data_get($response, 'room.uuid'),
|
||||
'meet_join_url' => data_get($response, 'join_url'),
|
||||
]);
|
||||
$createdRoom = true;
|
||||
}
|
||||
|
||||
if ($createdRoom) {
|
||||
$notifier->notifyVideoScheduled($organization, $appointment->fresh(['patient', 'branch']));
|
||||
}
|
||||
|
||||
$start = MeetClient::for($owner)->startRoom((string) $appointment->meet_room_uuid, $owner);
|
||||
|
||||
return redirect()->away((string) (data_get($start, 'join_url') ?: $appointment->meet_join_url));
|
||||
}
|
||||
|
||||
private function notifyHint($organization, AppointmentPatientNotifier $notifier): string
|
||||
{
|
||||
$sms = $notifier->organizationWants($organization, AppointmentPatientNotifier::SETTING_VIDEO_SMS);
|
||||
$email = $notifier->organizationWants($organization, AppointmentPatientNotifier::SETTING_VIDEO_EMAIL);
|
||||
|
||||
if ($sms || $email) {
|
||||
return ' Patient notification settings will be applied.';
|
||||
}
|
||||
|
||||
return ' Enable video notifications in Settings to alert the patient.';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user