Align specialty queue board with hero waiting counts.
Deploy Ladill Care / deploy (push) Successful in 35s

Board lists used type-only departments while KPIs used provisioned department IDs, so Waiting could show N with an empty WAITING column.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-20 18:52:03 +00:00
co-authored by Cursor
parent 9443465c5c
commit 4dd683161a
3 changed files with 87 additions and 5 deletions
@@ -1458,8 +1458,6 @@ class SpecialtyModuleController extends Controller
->orderBy('name')
->get();
$departmentIds = $departments->pluck('id')->all();
$branchId = (int) ($branchScope ?: $departments->first()?->branch_id);
if ($practitionerScope !== null && $practitionerScope !== []) {
$pracBranch = (int) \App\Models\Practitioner::owned($owner)
@@ -1475,6 +1473,23 @@ class SpecialtyModuleController extends Controller
// while Call next is local.
$kpiBranch = $branchScope ?? ($branchId > 0 ? $branchId : null);
// Same department set as SpecialtyShellService::kpis() (provisioned IDs, not
// type-only). Otherwise hero "Waiting: N" can disagree with an empty board.
$departmentIds = $shell->departmentIds($organization, $module, $owner, $kpiBranch);
if ($departmentIds !== [] && $departments->isEmpty()) {
$departments = Department::owned($owner)
->whereIn('id', $departmentIds)
->where('is_active', true)
->with('branch')
->orderBy('name')
->get();
if (! $branchId && $departments->isNotEmpty()) {
$branchId = (int) $departments->first()->branch_id;
$kpiBranch = $branchScope ?? ($branchId > 0 ? $branchId : null);
$departmentIds = $shell->departmentIds($organization, $module, $owner, $kpiBranch);
}
}
$waiting = Appointment::owned($owner)
->where('organization_id', $organization->id)
->whereIn('status', [Appointment::STATUS_WAITING, Appointment::STATUS_CHECKED_IN])
@@ -1571,6 +1586,11 @@ class SpecialtyModuleController extends Controller
->limit(20)
->get();
// Keep hero tiles aligned with the board columns (same collections).
$kpis['waiting'] = $waiting->count();
$kpis['in_progress'] = $inConsultation->count();
$kpis['completed_today'] = $done->count();
$workspaceVisit = null;
$patientHeader = null;
$timeline = [];
@@ -230,9 +230,9 @@
:title="$specialtyLabel.' queue'"
description="Move patients from waiting through called, in care, and done."
:stats="[
['value' => number_format($kpis['waiting'] ?? $queue->count()), 'label' => 'Waiting'],
['value' => number_format($kpis['in_progress'] ?? $inConsultation->count()), 'label' => 'In care'],
['value' => number_format($kpis['completed_today'] ?? 0), 'label' => 'Today'],
['value' => number_format($queue->count()), 'label' => 'Waiting'],
['value' => number_format($inConsultation->count()), 'label' => 'In care'],
['value' => number_format(($done ?? collect())->count()), 'label' => 'Today'],
]">
@if ($canManageQueue ?? false)
<x-slot name="actions">
@@ -237,4 +237,66 @@ class CareWomensHealthSuiteTest extends TestCase
->assertOk()
->assertDontSee('Health overview');
}
public function test_queue_board_lists_waiting_on_provisioned_non_type_departments(): void
{
// KPIs use specialty_module_provisioning.department_ids; the board used to
// only load departments by type=womens_health, so hero said "Waiting: N"
// while WAITING stayed empty.
$legacyDesk = Department::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'name' => 'ANC desk',
'type' => 'maternity',
'is_active' => true,
]);
$settings = $this->organization->settings ?? [];
$provisioning = $settings['specialty_module_provisioning']['womens_health'] ?? [];
$provisioning['department_ids'] = [$legacyDesk->id];
$settings['specialty_module_provisioning']['womens_health'] = $provisioning;
$this->organization->update(['settings' => $settings]);
$this->organization->refresh();
$patient = Patient::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'patient_number' => 'P-WH-QUEUE',
'first_name' => 'Efua',
'last_name' => 'Asante',
'gender' => 'female',
'date_of_birth' => '1990-03-12',
]);
$visit = Visit::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'patient_id' => $patient->id,
'status' => Visit::STATUS_OPEN,
'checked_in_at' => now(),
]);
Appointment::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'patient_id' => $patient->id,
'department_id' => $legacyDesk->id,
'visit_id' => $visit->id,
'type' => Appointment::TYPE_WALK_IN,
'status' => Appointment::STATUS_WAITING,
'scheduled_at' => now(),
'waiting_at' => now(),
'checked_in_at' => now(),
]);
$this->actingAs($this->owner)
->get(route('care.specialty.show', 'womens_health'))
->assertOk()
->assertSee('Efua Asante')
->assertDontSee('No patients waiting.');
}
}