Show patients in queue on the doctor dashboard.
Deploy Ladill Care / deploy (push) Successful in 25s
Deploy Ladill Care / deploy (push) Successful in 25s
Clinical staff without admin KPIs get waiting and in-consultation lists in the empty space. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,12 +4,16 @@ namespace App\Http\Controllers\Care;
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
|
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
|
||||||
|
use App\Models\Appointment;
|
||||||
use App\Models\Branch;
|
use App\Models\Branch;
|
||||||
use App\Models\Member;
|
use App\Models\Member;
|
||||||
|
use App\Models\Practitioner;
|
||||||
|
use App\Services\Care\AppointmentService;
|
||||||
use App\Services\Care\CarePermissions;
|
use App\Services\Care\CarePermissions;
|
||||||
use App\Services\Care\OrganizationResolver;
|
use App\Services\Care\OrganizationResolver;
|
||||||
use App\Services\Care\ReportService;
|
use App\Services\Care\ReportService;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
|
|
||||||
class DashboardController extends Controller
|
class DashboardController extends Controller
|
||||||
@@ -19,6 +23,7 @@ class DashboardController extends Controller
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
protected ReportService $reports,
|
protected ReportService $reports,
|
||||||
protected CarePermissions $permissions,
|
protected CarePermissions $permissions,
|
||||||
|
protected AppointmentService $appointments,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function index(Request $request): View
|
public function index(Request $request): View
|
||||||
@@ -33,6 +38,8 @@ class DashboardController extends Controller
|
|||||||
$canDepartments = $this->permissions->can($member, 'admin.departments.view');
|
$canDepartments = $this->permissions->can($member, 'admin.departments.view');
|
||||||
$canBills = $this->permissions->can($member, 'bills.view');
|
$canBills = $this->permissions->can($member, 'bills.view');
|
||||||
$canFinance = $this->permissions->can($member, 'reports.finance.view');
|
$canFinance = $this->permissions->can($member, 'reports.finance.view');
|
||||||
|
$canConsult = $this->permissions->can($member, 'consultations.manage');
|
||||||
|
$showPatientQueue = $this->permissions->can($member, 'appointments.view') && ! $canBranches;
|
||||||
|
|
||||||
$branchQuery = Branch::owned($owner)->where('organization_id', $organization->id);
|
$branchQuery = Branch::owned($owner)->where('organization_id', $organization->id);
|
||||||
$this->scopeToBranch($request, $branchQuery);
|
$this->scopeToBranch($request, $branchQuery);
|
||||||
@@ -65,6 +72,10 @@ class DashboardController extends Controller
|
|||||||
includeBilling: $canBills || $canFinance,
|
includeBilling: $canBills || $canFinance,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
[$queue, $inConsultation, $practitionerId] = $showPatientQueue
|
||||||
|
? $this->patientQueueForMember($request, $organization->id, $owner, $member, $branchScope)
|
||||||
|
: [collect(), collect(), null];
|
||||||
|
|
||||||
return view('care.dashboard', [
|
return view('care.dashboard', [
|
||||||
'organization' => $organization,
|
'organization' => $organization,
|
||||||
'member' => $member,
|
'member' => $member,
|
||||||
@@ -77,6 +88,61 @@ class DashboardController extends Controller
|
|||||||
'canDepartments' => $canDepartments,
|
'canDepartments' => $canDepartments,
|
||||||
'canBills' => $canBills,
|
'canBills' => $canBills,
|
||||||
'canFinance' => $canFinance,
|
'canFinance' => $canFinance,
|
||||||
|
'canConsult' => $canConsult,
|
||||||
|
'showPatientQueue' => $showPatientQueue,
|
||||||
|
'patientQueue' => $queue,
|
||||||
|
'inConsultation' => $inConsultation,
|
||||||
|
'practitionerId' => $practitionerId,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{0: Collection<int, Appointment>, 1: Collection<int, Appointment>, 2: ?int}
|
||||||
|
*/
|
||||||
|
protected function patientQueueForMember(
|
||||||
|
Request $request,
|
||||||
|
int $organizationId,
|
||||||
|
string $owner,
|
||||||
|
?Member $member,
|
||||||
|
?int $branchScope,
|
||||||
|
): array {
|
||||||
|
$practitioner = null;
|
||||||
|
if ($member) {
|
||||||
|
$practitioner = Practitioner::owned($owner)
|
||||||
|
->where('organization_id', $organizationId)
|
||||||
|
->where('is_active', true)
|
||||||
|
->where(function ($query) use ($member) {
|
||||||
|
$query->where('member_id', $member->id)
|
||||||
|
->orWhere('user_ref', $member->user_ref);
|
||||||
|
})
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
$practitionerId = $practitioner?->id;
|
||||||
|
$branchId = $branchScope
|
||||||
|
?? $practitioner?->branch_id
|
||||||
|
?? Branch::owned($owner)
|
||||||
|
->where('organization_id', $organizationId)
|
||||||
|
->where('is_active', true)
|
||||||
|
->orderBy('name')
|
||||||
|
->value('id');
|
||||||
|
|
||||||
|
if (! $branchId) {
|
||||||
|
return [collect(), collect(), $practitionerId];
|
||||||
|
}
|
||||||
|
|
||||||
|
$queue = $this->appointments->queue($owner, (int) $branchId, $practitionerId);
|
||||||
|
|
||||||
|
$inConsultation = Appointment::owned($owner)
|
||||||
|
->where('organization_id', $organizationId)
|
||||||
|
->where('status', Appointment::STATUS_IN_CONSULTATION)
|
||||||
|
->where('branch_id', $branchId)
|
||||||
|
->when($practitionerId, fn ($q) => $q->where('practitioner_id', $practitionerId))
|
||||||
|
->with(['patient', 'practitioner', 'consultation'])
|
||||||
|
->orderBy('started_at')
|
||||||
|
->limit(20)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return [$queue, $inConsultation, $practitionerId];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,69 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@if (! empty($showPatientQueue))
|
||||||
|
<section class="mt-6 rounded-2xl border border-slate-200 bg-white">
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-3 border-b border-slate-100 px-5 py-4">
|
||||||
|
<div>
|
||||||
|
<h2 class="text-sm font-semibold text-slate-900">Patients in queue</h2>
|
||||||
|
<p class="mt-0.5 text-xs text-slate-500">
|
||||||
|
{{ $patientQueue->count() }} waiting
|
||||||
|
· {{ $inConsultation->count() }} in consultation
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<a href="{{ route('care.queue.index', array_filter(['practitioner_id' => $practitionerId])) }}" class="text-sm font-medium text-indigo-600 hover:text-indigo-800">Open full queue</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-0 lg:grid-cols-2 lg:divide-x lg:divide-slate-100">
|
||||||
|
<div class="px-5 py-4">
|
||||||
|
<h3 class="text-xs font-semibold uppercase tracking-wide text-slate-500">Waiting</h3>
|
||||||
|
<div class="mt-3 space-y-2">
|
||||||
|
@forelse ($patientQueue->take(8) as $appointment)
|
||||||
|
<div class="flex items-center justify-between gap-3 rounded-xl border border-slate-100 bg-slate-50 px-3 py-3">
|
||||||
|
<div class="min-w-0">
|
||||||
|
<p class="truncate font-medium text-slate-900">
|
||||||
|
@if ($appointment->queue_position)
|
||||||
|
<span class="mr-1.5 inline-flex h-5 w-5 items-center justify-center rounded-full bg-sky-100 text-[10px] font-bold text-sky-700">{{ $appointment->queue_position }}</span>
|
||||||
|
@endif
|
||||||
|
{{ $appointment->patient?->fullName() ?? 'Patient' }}
|
||||||
|
</p>
|
||||||
|
<p class="truncate text-xs text-slate-500">{{ $appointment->patient?->patient_number }} · {{ $appointment->reason ?? 'No reason noted' }}</p>
|
||||||
|
</div>
|
||||||
|
@if (! empty($canConsult))
|
||||||
|
<form method="POST" action="{{ route('care.queue.start', $appointment) }}" class="shrink-0">
|
||||||
|
@csrf
|
||||||
|
<button type="submit" class="rounded-lg bg-sky-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-sky-700">Start</button>
|
||||||
|
</form>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@empty
|
||||||
|
<p class="rounded-xl border border-dashed border-slate-200 px-4 py-8 text-center text-sm text-slate-500">No patients waiting right now.</p>
|
||||||
|
@endforelse
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="border-t border-slate-100 px-5 py-4 lg:border-t-0">
|
||||||
|
<h3 class="text-xs font-semibold uppercase tracking-wide text-slate-500">In consultation</h3>
|
||||||
|
<div class="mt-3 space-y-2">
|
||||||
|
@forelse ($inConsultation->take(8) as $appointment)
|
||||||
|
<div class="flex items-center justify-between gap-3 rounded-xl border border-emerald-100 bg-emerald-50 px-3 py-3">
|
||||||
|
<div class="min-w-0">
|
||||||
|
<p class="truncate font-medium text-slate-900">{{ $appointment->patient?->fullName() ?? 'Patient' }}</p>
|
||||||
|
<p class="truncate text-xs text-slate-500">{{ $appointment->practitioner?->name ?? 'Unassigned' }}</p>
|
||||||
|
</div>
|
||||||
|
@if ($appointment->consultation)
|
||||||
|
<a href="{{ route('care.consultations.show', $appointment->consultation) }}" class="shrink-0 text-sm font-medium text-sky-600 hover:text-sky-700">Open</a>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@empty
|
||||||
|
<p class="rounded-xl border border-dashed border-slate-200 px-4 py-8 text-center text-sm text-slate-500">No active consultations.</p>
|
||||||
|
@endforelse
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
@endif
|
||||||
|
|
||||||
@if (count($organizationCards) > 0)
|
@if (count($organizationCards) > 0)
|
||||||
@php
|
@php
|
||||||
$orgCols = match (count($organizationCards)) {
|
$orgCols = match (count($organizationCards)) {
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ class CareWebTest extends TestCase
|
|||||||
->assertOk()
|
->assertOk()
|
||||||
->assertSee('Patients today')
|
->assertSee('Patients today')
|
||||||
->assertSee('Appointments today')
|
->assertSee('Appointments today')
|
||||||
|
->assertSee('Patients in queue')
|
||||||
|
->assertSee('No patients waiting right now.')
|
||||||
->assertDontSee('Revenue today')
|
->assertDontSee('Revenue today')
|
||||||
->assertDontSee('Open bills')
|
->assertDontSee('Open bills')
|
||||||
->assertDontSee('Team members')
|
->assertDontSee('Team members')
|
||||||
|
|||||||
Reference in New Issue
Block a user