Deploy Ladill Care / deploy (push) Successful in 34s
Hide the patient-flow Queue board from nurses, reception, and other non-doctors; specialty home routes now render the queue board list instead of auto-opening the first open visit. Co-authored-by: Cursor <cursoragent@cursor.com>
245 lines
8.4 KiB
PHP
245 lines
8.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Http\Middleware\EnsurePlatformSession;
|
|
use App\Models\Appointment;
|
|
use App\Models\Branch;
|
|
use App\Models\Department;
|
|
use App\Models\Member;
|
|
use App\Models\Organization;
|
|
use App\Models\Patient;
|
|
use App\Models\User;
|
|
use App\Models\Visit;
|
|
use App\Services\Care\CarePermissions;
|
|
use App\Services\Care\SpecialtyModuleService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class CarePatientQueueAccessTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected User $owner;
|
|
|
|
protected Organization $organization;
|
|
|
|
protected Branch $branch;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->withoutMiddleware(EnsurePlatformSession::class);
|
|
|
|
$this->owner = User::create([
|
|
'public_id' => 'pq-access-owner',
|
|
'name' => 'Owner',
|
|
'email' => 'pq-access-owner@example.com',
|
|
]);
|
|
|
|
$this->organization = Organization::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'name' => 'PQ Clinic',
|
|
'slug' => 'pq-clinic',
|
|
'settings' => [
|
|
'onboarded' => true,
|
|
'facility_type' => 'clinic',
|
|
'plan' => 'pro',
|
|
'plan_expires_at' => now()->addMonth()->toIso8601String(),
|
|
'queue_integration_enabled' => true,
|
|
],
|
|
]);
|
|
|
|
Member::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'user_ref' => $this->owner->public_id,
|
|
'role' => 'hospital_admin',
|
|
]);
|
|
|
|
$this->branch = Branch::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'name' => 'Main',
|
|
'is_active' => true,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @return array{0: User, 1: Member}
|
|
*/
|
|
protected function makeStaff(string $role, string $suffix): array
|
|
{
|
|
$user = User::create([
|
|
'public_id' => 'pq-'.$suffix,
|
|
'name' => ucfirst($role).' '.$suffix,
|
|
'email' => $suffix.'@pq.example.com',
|
|
]);
|
|
$member = Member::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'user_ref' => $user->public_id,
|
|
'role' => $role,
|
|
'branch_id' => $this->branch->id,
|
|
]);
|
|
|
|
return [$user, $member];
|
|
}
|
|
|
|
public function test_nurse_loses_queue_manage_and_cannot_open_patient_queue(): void
|
|
{
|
|
[$nurseUser, $nurseMember] = $this->makeStaff('nurse', 'nurse1');
|
|
$permissions = app(CarePermissions::class);
|
|
|
|
$this->assertFalse($permissions->can($nurseMember, 'queue.manage'));
|
|
$this->assertFalse($permissions->canAccessPatientQueue($nurseMember));
|
|
$this->assertTrue($permissions->handlesFloorCare($nurseMember));
|
|
|
|
$this->actingAs($nurseUser)
|
|
->get(route('care.queue.index'))
|
|
->assertForbidden();
|
|
|
|
$this->actingAs($nurseUser)
|
|
->get(route('care.dashboard'))
|
|
->assertOk()
|
|
->assertDontSee('href="'.e(route('care.queue.index')).'"', false);
|
|
}
|
|
|
|
public function test_receptionist_and_other_non_doctors_cannot_open_patient_queue(): void
|
|
{
|
|
[$receptionistUser, $receptionistMember] = $this->makeStaff('receptionist', 'rec1');
|
|
[$pharmacistUser, $pharmacistMember] = $this->makeStaff('pharmacist', 'rx1');
|
|
$permissions = app(CarePermissions::class);
|
|
|
|
$this->assertFalse($permissions->canAccessPatientQueue($receptionistMember));
|
|
$this->assertFalse($permissions->canAccessPatientQueue($pharmacistMember));
|
|
$this->assertTrue($permissions->can($receptionistMember, 'queue.manage'));
|
|
|
|
$this->actingAs($receptionistUser)
|
|
->get(route('care.queue.index'))
|
|
->assertForbidden();
|
|
|
|
$this->actingAs($receptionistUser)
|
|
->get(route('care.dashboard'))
|
|
->assertOk()
|
|
->assertDontSee('href="'.e(route('care.queue.index')).'"', false);
|
|
|
|
$this->actingAs($pharmacistUser)
|
|
->get(route('care.queue.index'))
|
|
->assertForbidden();
|
|
}
|
|
|
|
public function test_doctor_can_open_redesigned_queue_board(): void
|
|
{
|
|
[$doctorUser, $doctorMember] = $this->makeStaff('doctor', 'doc1');
|
|
$permissions = app(CarePermissions::class);
|
|
|
|
$this->assertTrue($permissions->canAccessPatientQueue($doctorMember));
|
|
|
|
$this->actingAs($doctorUser)
|
|
->get(route('care.queue.index'))
|
|
->assertOk()
|
|
->assertSee('Patient flow')
|
|
->assertSee('Waiting')
|
|
->assertSee('Called')
|
|
->assertSee('Done');
|
|
|
|
$this->actingAs($doctorUser)
|
|
->get(route('care.dashboard'))
|
|
->assertOk()
|
|
->assertSee('Queue', false);
|
|
}
|
|
|
|
public function test_hospital_admin_does_not_get_patient_queue_board(): void
|
|
{
|
|
$adminMember = Member::query()
|
|
->where('user_ref', $this->owner->public_id)
|
|
->firstOrFail();
|
|
$permissions = app(CarePermissions::class);
|
|
|
|
$this->assertFalse($permissions->canAccessPatientQueue($adminMember));
|
|
$this->assertFalse($permissions->handlesFloorCare($adminMember));
|
|
|
|
$this->actingAs($this->owner)
|
|
->get(route('care.queue.index'))
|
|
->assertForbidden();
|
|
}
|
|
|
|
public function test_nurse_specialty_show_renders_list_not_auto_open_visit(): void
|
|
{
|
|
[$nurseUser] = $this->makeStaff('nurse', 'nurse-spec');
|
|
|
|
$modules = app(SpecialtyModuleService::class);
|
|
$modules->ensureDefaultModulesProvisioned($this->organization, $this->owner->public_id);
|
|
$modules->activate($this->organization->fresh(), $this->owner->public_id, 'blood_bank');
|
|
|
|
$department = Department::query()
|
|
->where('branch_id', $this->branch->id)
|
|
->where('type', 'blood_bank')
|
|
->firstOrFail();
|
|
|
|
$patient = Patient::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'branch_id' => $this->branch->id,
|
|
'patient_number' => 'P-BB-LIST',
|
|
'first_name' => 'Kwame',
|
|
'last_name' => 'Donor',
|
|
'gender' => 'male',
|
|
'date_of_birth' => '1988-01-01',
|
|
]);
|
|
|
|
$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' => $department->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($nurseUser)
|
|
->get(route('care.specialty.show', 'blood_bank'))
|
|
->assertOk()
|
|
->assertSee('Blood Bank')
|
|
->assertSee('Patient flow')
|
|
->assertSee('Waiting')
|
|
->assertSee('Kwame Donor')
|
|
->assertDontSee('No open visit selected');
|
|
|
|
$this->actingAs($nurseUser)
|
|
->get(route('care.specialty.workspace', 'blood_bank'))
|
|
->assertRedirect(route('care.specialty.show', 'blood_bank'));
|
|
}
|
|
|
|
public function test_nurse_specialty_show_redirects_to_workspace_not_queue(): void
|
|
{
|
|
[$nurseUser] = $this->makeStaff('nurse', 'nurse-spec-er');
|
|
|
|
app(SpecialtyModuleService::class)
|
|
->ensureDefaultModulesProvisioned($this->organization, $this->owner->public_id);
|
|
app(SpecialtyModuleService::class)
|
|
->activate($this->organization->fresh(), $this->owner->public_id, 'emergency');
|
|
|
|
$this->actingAs($nurseUser)
|
|
->get(route('care.specialty.show', 'emergency'))
|
|
->assertOk()
|
|
->assertSee('Patient flow')
|
|
->assertDontSee('href="'.e(route('care.queue.index')).'"', false);
|
|
}
|
|
}
|