Speed up Queue board loads by dropping sync and gate side effects.
Deploy Ladill Care / deploy (push) Successful in 1m22s
Deploy Ladill Care / deploy (push) Successful in 1m22s
Stop issuing missing tickets and refreshing financial gates on every GET; eager-load advances, cap board rows, and cache specialty department maps. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -61,37 +61,32 @@ class QueueController extends Controller
|
||||
}
|
||||
|
||||
if ($this->queueBridge->isEnabled($organization)) {
|
||||
$syncBranches = $lockToPractitioner
|
||||
? Practitioner::owned($owner)
|
||||
->whereIn('id', $practitionerScope ?: [0])
|
||||
->pluck('branch_id')
|
||||
->map(fn ($id) => (int) $id)
|
||||
->unique()
|
||||
->filter()
|
||||
->values()
|
||||
->all()
|
||||
: array_filter([$branchId]);
|
||||
|
||||
foreach ($syncBranches as $syncBranchId) {
|
||||
$this->queueBridge->syncMissingAppointmentTickets($organization, $syncBranchId, 100);
|
||||
}
|
||||
|
||||
// Ticket backfill belongs on check-in / Call next / care:queue-sync-tickets —
|
||||
// not on every board GET (can issue up to 100 tickets with provisioner work).
|
||||
if ($branchId > 0) {
|
||||
$queueIntegration = $this->queueBridge->listMeta($organization, $queueContext, $branchId);
|
||||
} elseif ($syncBranches !== []) {
|
||||
$queueIntegration = $this->queueBridge->listMeta(
|
||||
$organization,
|
||||
$queueContext,
|
||||
(int) $syncBranches[0],
|
||||
);
|
||||
} elseif ($lockToPractitioner && $practitionerScope) {
|
||||
$firstBranch = (int) Practitioner::owned($owner)
|
||||
->whereIn('id', $practitionerScope)
|
||||
->value('branch_id');
|
||||
if ($firstBranch > 0) {
|
||||
$queueIntegration = $this->queueBridge->listMeta(
|
||||
$organization,
|
||||
$queueContext,
|
||||
$firstBranch,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$boardLimit = AppointmentService::QUEUE_BOARD_LIMIT;
|
||||
|
||||
if ($lockToPractitioner) {
|
||||
$queue = $this->appointments->queueForPractitioners(
|
||||
$owner,
|
||||
$practitionerScope ?? [],
|
||||
$branchId > 0 ? $branchId : null,
|
||||
$boardLimit,
|
||||
);
|
||||
$inConsultation = Appointment::owned($owner)
|
||||
->where('organization_id', $organization->id)
|
||||
@@ -99,10 +94,11 @@ class QueueController extends Controller
|
||||
->whereIn('practitioner_id', $practitionerScope ?: [0])
|
||||
->with(['patient', 'practitioner', 'consultation', 'visit', 'organization'])
|
||||
->orderBy('started_at')
|
||||
->limit($boardLimit)
|
||||
->get();
|
||||
} else {
|
||||
$queue = $branchId
|
||||
? $this->appointments->queue($owner, $branchId, $practitionerId)
|
||||
? $this->appointments->queue($owner, $branchId, $practitionerId, true, null, $boardLimit)
|
||||
: collect();
|
||||
$inConsultation = Appointment::owned($owner)
|
||||
->where('organization_id', $organization->id)
|
||||
@@ -111,6 +107,7 @@ class QueueController extends Controller
|
||||
->when($practitionerId, fn ($q) => $q->where('practitioner_id', $practitionerId))
|
||||
->with(['patient', 'practitioner', 'consultation', 'visit', 'organization'])
|
||||
->orderBy('started_at')
|
||||
->limit($boardLimit)
|
||||
->get();
|
||||
}
|
||||
|
||||
@@ -126,6 +123,36 @@ class QueueController extends Controller
|
||||
$todayQuery->where('branch_id', $branchId);
|
||||
}
|
||||
|
||||
$waitingCountQuery = Appointment::owned($owner)
|
||||
->where('organization_id', $organization->id)
|
||||
->whereIn('status', [Appointment::STATUS_WAITING, Appointment::STATUS_CHECKED_IN]);
|
||||
if ($lockToPractitioner) {
|
||||
$waitingCountQuery->whereIn('practitioner_id', $practitionerScope ?: [0]);
|
||||
if ($branchId > 0) {
|
||||
$waitingCountQuery->where('branch_id', $branchId);
|
||||
}
|
||||
} elseif ($branchId) {
|
||||
$waitingCountQuery->where('branch_id', $branchId);
|
||||
if ($practitionerId) {
|
||||
$waitingCountQuery->where(function ($q) use ($practitionerId) {
|
||||
$q->where('practitioner_id', $practitionerId)->orWhereNull('practitioner_id');
|
||||
});
|
||||
}
|
||||
} else {
|
||||
$waitingCountQuery->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
$inCareCountQuery = Appointment::owned($owner)
|
||||
->where('organization_id', $organization->id)
|
||||
->where('status', Appointment::STATUS_IN_CONSULTATION);
|
||||
if ($lockToPractitioner) {
|
||||
$inCareCountQuery->whereIn('practitioner_id', $practitionerScope ?: [0]);
|
||||
} else {
|
||||
$inCareCountQuery
|
||||
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))
|
||||
->when($practitionerId, fn ($q) => $q->where('practitioner_id', $practitionerId));
|
||||
}
|
||||
|
||||
$doneQuery = Appointment::owned($owner)
|
||||
->where('organization_id', $organization->id)
|
||||
->where('status', Appointment::STATUS_COMPLETED)
|
||||
@@ -145,11 +172,13 @@ class QueueController extends Controller
|
||||
->get();
|
||||
|
||||
$heroStats = [
|
||||
'waiting' => $queue->count(),
|
||||
'in_consultation' => $inConsultation->count(),
|
||||
'waiting' => $waitingCountQuery->count(),
|
||||
'in_consultation' => $inCareCountQuery->count(),
|
||||
'today' => $todayQuery->count(),
|
||||
];
|
||||
|
||||
$specialtyDepartmentMap = $this->queueBridge->specialtyDepartmentMap($organization);
|
||||
|
||||
return view('care.queue.index', [
|
||||
'organization' => $organization,
|
||||
'branches' => $branches,
|
||||
@@ -174,6 +203,7 @@ class QueueController extends Controller
|
||||
'queueIntegration' => $queueIntegration,
|
||||
'queueContext' => $queueContext,
|
||||
'specialtyLabel' => $specialtyLabel,
|
||||
'specialtyDepartmentMap' => $specialtyDepartmentMap,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -623,7 +623,7 @@ class SpecialtyModuleController extends Controller
|
||||
$practitionerScope !== null,
|
||||
fn ($q) => $q->whereIn('practitioner_id', $practitionerScope ?: [0]),
|
||||
)
|
||||
->with(['patient', 'practitioner', 'department', 'visit'])
|
||||
->with(['patient', 'practitioner', 'department', 'visit.currentStageAdvance.stage'])
|
||||
->orderBy('queue_position')
|
||||
->orderBy('checked_in_at')
|
||||
->limit(50)
|
||||
|
||||
Reference in New Issue
Block a user