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)); } }