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));
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,8 @@ class Appointment extends Model
|
||||
'uuid', 'owner_ref', 'organization_id', 'branch_id', 'patient_id',
|
||||
'practitioner_id', 'department_id', 'visit_id', 'type', 'status',
|
||||
'scheduled_at', 'checked_in_at', 'waiting_at', 'started_at',
|
||||
'completed_at', 'cancelled_at', 'queue_position', 'reason', 'notes', 'created_by',
|
||||
'completed_at', 'cancelled_at', 'queue_position', 'reason', 'notes',
|
||||
'meet_room_uuid', 'meet_join_url', 'created_by',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Meet;
|
||||
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
/**
|
||||
* Client for the Ladill Meet service API — schedule rooms linked to Care records.
|
||||
*/
|
||||
class MeetClient
|
||||
{
|
||||
public function __construct(private readonly string $ownerRef) {}
|
||||
|
||||
public static function for(string $ownerRef): self
|
||||
{
|
||||
return new self($ownerRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function createRoom(array $data): array
|
||||
{
|
||||
return $this->post('rooms', array_merge($data, [
|
||||
'owner_ref' => $this->ownerRef,
|
||||
'host_user_ref' => $data['host_user_ref'] ?? $this->ownerRef,
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function startRoom(string $roomUuid, ?string $hostUserRef = null): array
|
||||
{
|
||||
return $this->post("rooms/{$roomUuid}/start", [
|
||||
'host_user_ref' => $hostUserRef ?? $this->ownerRef,
|
||||
]);
|
||||
}
|
||||
|
||||
private function client(): PendingRequest
|
||||
{
|
||||
return Http::baseUrl((string) config('meet.url'))
|
||||
->withToken((string) config('meet.key'))
|
||||
->acceptJson()
|
||||
->asJson()
|
||||
->connectTimeout(10)
|
||||
->timeout(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function post(string $path, array $data): array
|
||||
{
|
||||
try {
|
||||
$response = $this->client()->post($path, $data);
|
||||
} catch (ConnectionException) {
|
||||
throw ValidationException::withMessages([
|
||||
'meet' => ['Could not reach the Meet service. Please try again in a moment.'],
|
||||
]);
|
||||
}
|
||||
|
||||
if ($response->status() === 422) {
|
||||
throw ValidationException::withMessages(
|
||||
$response->json('errors') ?: ['meet' => [$response->json('message') ?: 'Request failed.']]
|
||||
);
|
||||
}
|
||||
|
||||
if ($response->failed()) {
|
||||
abort($response->status() === 404 ? 404 : 502, 'Meet service error.');
|
||||
}
|
||||
|
||||
return (array) $response->json();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user