diff --git a/app/Http/Controllers/Care/SpecialtyModuleController.php b/app/Http/Controllers/Care/SpecialtyModuleController.php index cf1f418..833a7fb 100644 --- a/app/Http/Controllers/Care/SpecialtyModuleController.php +++ b/app/Http/Controllers/Care/SpecialtyModuleController.php @@ -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 = []; diff --git a/resources/views/care/specialty/shell.blade.php b/resources/views/care/specialty/shell.blade.php index ee289d9..3490206 100644 --- a/resources/views/care/specialty/shell.blade.php +++ b/resources/views/care/specialty/shell.blade.php @@ -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) diff --git a/tests/Feature/CareWomensHealthSuiteTest.php b/tests/Feature/CareWomensHealthSuiteTest.php index 2b6e2ff..6eeeb7e 100644 --- a/tests/Feature/CareWomensHealthSuiteTest.php +++ b/tests/Feature/CareWomensHealthSuiteTest.php @@ -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.'); + } }