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\Care\Concerns\ScopesToAccount;
|
||||
use App\Models\Appointment;
|
||||
use App\Models\Branch;
|
||||
use App\Models\Member;
|
||||
use App\Models\Practitioner;
|
||||
use App\Services\Care\AppointmentService;
|
||||
use App\Services\Care\CarePermissions;
|
||||
use App\Services\Care\OrganizationResolver;
|
||||
use App\Services\Care\ReportService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class DashboardController extends Controller
|
||||
@@ -19,6 +23,7 @@ class DashboardController extends Controller
|
||||
public function __construct(
|
||||
protected ReportService $reports,
|
||||
protected CarePermissions $permissions,
|
||||
protected AppointmentService $appointments,
|
||||
) {}
|
||||
|
||||
public function index(Request $request): View
|
||||
@@ -33,6 +38,8 @@ class DashboardController extends Controller
|
||||
$canDepartments = $this->permissions->can($member, 'admin.departments.view');
|
||||
$canBills = $this->permissions->can($member, 'bills.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);
|
||||
$this->scopeToBranch($request, $branchQuery);
|
||||
@@ -65,6 +72,10 @@ class DashboardController extends Controller
|
||||
includeBilling: $canBills || $canFinance,
|
||||
);
|
||||
|
||||
[$queue, $inConsultation, $practitionerId] = $showPatientQueue
|
||||
? $this->patientQueueForMember($request, $organization->id, $owner, $member, $branchScope)
|
||||
: [collect(), collect(), null];
|
||||
|
||||
return view('care.dashboard', [
|
||||
'organization' => $organization,
|
||||
'member' => $member,
|
||||
@@ -77,6 +88,61 @@ class DashboardController extends Controller
|
||||
'canDepartments' => $canDepartments,
|
||||
'canBills' => $canBills,
|
||||
'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];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user