Add Meet video visit scheduling for Care appointments.
Deploy Ladill Care / deploy (push) Successful in 38s
Deploy Ladill Care / deploy (push) Successful in 38s
Schedule and start video visits via the Meet service API, persist join links on appointments, and propagate the shared copy-button component. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
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\AuditLogger;
|
||||
use App\Services\Meet\MeetClient;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AppointmentMeetController extends Controller
|
||||
{
|
||||
use ScopesToAccount;
|
||||
|
||||
public function schedule(Request $request, Appointment $appointment): RedirectResponse
|
||||
{
|
||||
$this->authorizeAbility($request, 'appointments.manage');
|
||||
$this->authorizeOwner($request, $appointment);
|
||||
|
||||
if ($appointment->meet_join_url) {
|
||||
return redirect()->route('care.appointments.show', $appointment)
|
||||
->with('success', 'Video visit is already scheduled.');
|
||||
}
|
||||
|
||||
$appointment->loadMissing('patient');
|
||||
$patient = $appointment->patient;
|
||||
$owner = $this->ownerRef($request);
|
||||
|
||||
$response = MeetClient::for($owner)->createRoom([
|
||||
'title' => 'Video visit — '.$patient->fullName(),
|
||||
'description' => $appointment->reason,
|
||||
'scheduled_at' => ($appointment->scheduled_at ?? now()->addHour())->toIso8601String(),
|
||||
'duration_minutes' => 30,
|
||||
'branch_id' => $appointment->branch_id,
|
||||
'source' => [
|
||||
'app' => 'care',
|
||||
'entity_type' => 'appointment',
|
||||
'entity_id' => $appointment->uuid,
|
||||
],
|
||||
'invite_emails' => array_values(array_filter([$patient->email])),
|
||||
]);
|
||||
|
||||
$appointment->update([
|
||||
'meet_room_uuid' => data_get($response, 'room.uuid'),
|
||||
'meet_join_url' => data_get($response, 'join_url'),
|
||||
]);
|
||||
|
||||
AuditLogger::record($owner, 'appointment.meet_scheduled', $appointment->organization_id, $owner, Appointment::class, $appointment->id);
|
||||
|
||||
return redirect()->route('care.appointments.show', $appointment)
|
||||
->with('success', 'Video visit scheduled. The patient will receive a join link.');
|
||||
}
|
||||
|
||||
public function start(Request $request, Appointment $appointment): RedirectResponse
|
||||
{
|
||||
$this->authorizeAbility($request, 'consultations.manage');
|
||||
$this->authorizeOwner($request, $appointment);
|
||||
|
||||
$owner = $this->ownerRef($request);
|
||||
$appointment->loadMissing('patient');
|
||||
|
||||
if (! $appointment->meet_room_uuid) {
|
||||
$response = MeetClient::for($owner)->createRoom([
|
||||
'title' => 'Video visit — '.$appointment->patient->fullName(),
|
||||
'description' => $appointment->reason,
|
||||
'source' => [
|
||||
'app' => 'care',
|
||||
'entity_type' => 'appointment',
|
||||
'entity_id' => $appointment->uuid,
|
||||
],
|
||||
'invite_emails' => array_values(array_filter([$appointment->patient->email])),
|
||||
]);
|
||||
|
||||
$appointment->update([
|
||||
'meet_room_uuid' => data_get($response, 'room.uuid'),
|
||||
'meet_join_url' => data_get($response, 'join_url'),
|
||||
]);
|
||||
}
|
||||
|
||||
$start = MeetClient::for($owner)->startRoom((string) $appointment->meet_room_uuid, $owner);
|
||||
|
||||
return redirect()->away((string) (data_get($start, 'join_url') ?: $appointment->meet_join_url));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user