withoutMiddleware(EnsurePlatformSession::class); $this->owner = User::create([ 'public_id' => 'shell-owner', 'name' => 'Owner', 'email' => 'shell@example.com', ]); $this->organization = Organization::create([ 'owner_ref' => $this->owner->public_id, 'name' => 'Shell Clinic', 'slug' => 'shell-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, ]); } public function test_activating_emergency_seeds_service_catalog_and_stage_map(): void { app(SpecialtyModuleService::class)->activate( $this->organization, $this->owner->public_id, 'emergency', ); $this->organization->refresh(); $services = data_get($this->organization->settings, 'specialty_module_provisioning.emergency.services'); $this->assertIsArray($services); $this->assertNotEmpty($services); $this->assertTrue(collect($services)->contains(fn ($s) => ($s['code'] ?? '') === 'er.consultation')); $shell = app(SpecialtyShellService::class); $stages = $shell->stages('emergency'); $this->assertSame('arrival', $stages[0]['code'] ?? null); $this->assertGreaterThanOrEqual(4, count($stages)); } public function test_specialty_shell_overview_and_sections_render(): void { app(SpecialtyModuleService::class)->activate( $this->organization, $this->owner->public_id, 'emergency', ); $this->actingAs($this->owner) ->get(route('care.specialty.show', 'emergency')) ->assertOk() ->assertSee('Emergency') ->assertSee('Overview') ->assertSee('Waiting') ->assertSee('Stage map'); $this->actingAs($this->owner) ->get(route('care.specialty.visits', 'emergency')) ->assertOk() ->assertSee('Open visits'); $this->actingAs($this->owner) ->get(route('care.specialty.history', 'emergency')) ->assertOk() ->assertSee('Visit history'); $this->actingAs($this->owner) ->get(route('care.specialty.billing', 'emergency')) ->assertOk() ->assertSee('Service catalog') ->assertSee('er.consultation'); $this->actingAs($this->owner) ->get(route('care.specialty.workspace', 'emergency')) ->assertOk(); } public function test_dentistry_shell_has_chair_stage_and_catalog(): void { app(SpecialtyModuleService::class)->activate( $this->organization, $this->owner->public_id, 'dentistry', ); $shell = app(SpecialtyShellService::class); $codes = collect($shell->stages('dentistry'))->pluck('code')->all(); $this->assertContains('chair', $codes); $this->assertContains('procedure', $codes); $this->actingAs($this->owner) ->get(route('care.specialty.billing', 'dentistry')) ->assertOk() ->assertSee('den.fill'); } public function test_workspace_can_add_catalog_service_to_visit_bill(): void { app(SpecialtyModuleService::class)->activate( $this->organization, $this->owner->public_id, 'emergency', ); $department = Department::query() ->where('branch_id', $this->branch->id) ->where('type', 'emergency') ->firstOrFail(); $patient = Patient::create([ 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'branch_id' => $this->branch->id, 'patient_number' => 'P-ER-1', 'first_name' => 'Ama', 'last_name' => 'Mensah', 'gender' => 'female', 'date_of_birth' => '1992-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(), ]); $this->actingAs($this->owner) ->post(route('care.specialty.services.add', ['module' => 'emergency', 'visit' => $visit]), [ 'service_code' => 'er.consultation', ]) ->assertRedirect(); $this->assertDatabaseHas('care_bills', [ 'visit_id' => $visit->id, 'patient_id' => $patient->id, ]); $bill = Bill::query()->where('visit_id', $visit->id)->first(); $this->assertNotNull($bill); $this->assertTrue( $bill->lineItems()->where('description', 'Emergency consultation')->exists() ); } }