Add settings-gated appointment notifications and fix Bird key validation.
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:
isaacclad
2026-07-13 13:31:28 +00:00
co-authored by Cursor
parent 7c33432dc9
commit d13d460e32
10 changed files with 625 additions and 15 deletions
@@ -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.';
}
}
@@ -5,8 +5,10 @@ namespace App\Http\Controllers\Care;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
use App\Models\Branch;
use App\Services\Care\AppointmentPatientNotifier;
use App\Services\Care\AuditLogger;
use App\Services\Care\CarePermissions;
use App\Services\Messaging\MessagingCredentialsService;
use App\Services\Queue\QueueClient;
use App\Support\OrganizationBranding;
use Illuminate\Http\RedirectResponse;
@@ -17,11 +19,12 @@ class SettingsController extends Controller
{
use ScopesToAccount;
public function edit(Request $request): View
public function edit(Request $request, MessagingCredentialsService $credentials): View
{
$this->authorizeAbility($request, 'settings.view');
$organization = $this->organization($request);
$canManage = app(CarePermissions::class)->can($this->member($request), 'settings.manage');
$credential = $credentials->forOrganization($organization);
$branchCount = Branch::owned($this->ownerRef($request))
->where('organization_id', $organization->id)
@@ -31,6 +34,8 @@ class SettingsController extends Controller
'organization' => $organization,
'canManage' => $canManage,
'branchCount' => $branchCount,
'messagingSmsReady' => $credential->hasValidSms(),
'messagingEmailReady' => $credential->hasValidBird(),
'facilityTypes' => [
'clinic' => 'Clinic',
'hospital' => 'Hospital',
@@ -53,6 +58,10 @@ class SettingsController extends Controller
'logo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp,svg', 'max:2048'],
'remove_logo' => ['nullable', 'boolean'],
'queue_integration_enabled' => ['nullable', 'boolean'],
'notify_appointment_booked_sms' => ['nullable', 'boolean'],
'notify_appointment_booked_email' => ['nullable', 'boolean'],
'notify_video_scheduled_sms' => ['nullable', 'boolean'],
'notify_video_scheduled_email' => ['nullable', 'boolean'],
]);
$settings = $organization->settings ?? [];
@@ -60,9 +69,13 @@ class SettingsController extends Controller
$settings['facility_type'] = $validated['facility_type'];
$wantsQueue = $request->boolean('queue_integration_enabled');
$hadQueue = (bool) data_get($settings, 'queue_integration_enabled', false);
$settings['queue_integration_enabled'] = $wantsQueue;
$settings[AppointmentPatientNotifier::SETTING_BOOKED_SMS] = $request->boolean('notify_appointment_booked_sms');
$settings[AppointmentPatientNotifier::SETTING_BOOKED_EMAIL] = $request->boolean('notify_appointment_booked_email');
$settings[AppointmentPatientNotifier::SETTING_VIDEO_SMS] = $request->boolean('notify_video_scheduled_sms');
$settings[AppointmentPatientNotifier::SETTING_VIDEO_EMAIL] = $request->boolean('notify_video_scheduled_email');
if ($wantsQueue && $queue->configured()) {
$branch = Branch::owned($owner)->where('organization_id', $organization->id)->orderBy('name')->first();
try {