Deploy Ladill Care / deploy (push) Failing after 13s
Healthcare management app: patients, appointments, consultations, lab, pharmacy inventory, billing, and reports at care.ladill.com. Co-authored-by: Cursor <cursoragent@cursor.com>
185 lines
5.7 KiB
PHP
185 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Http\Middleware\EnsurePlatformSession;
|
|
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 Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
class CarePatientTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected User $user;
|
|
|
|
protected Organization $organization;
|
|
|
|
protected Branch $branch;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->withoutMiddleware(EnsurePlatformSession::class);
|
|
|
|
$this->user = User::create([
|
|
'public_id' => 'test-user-001',
|
|
'name' => 'Test User',
|
|
'email' => 'test@example.com',
|
|
]);
|
|
|
|
$this->organization = Organization::create([
|
|
'owner_ref' => $this->user->public_id,
|
|
'name' => 'Test Clinic',
|
|
'slug' => 'test-clinic',
|
|
'timezone' => 'UTC',
|
|
'settings' => ['onboarded' => true],
|
|
]);
|
|
|
|
Member::create([
|
|
'owner_ref' => $this->user->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'user_ref' => $this->user->public_id,
|
|
'role' => 'receptionist',
|
|
]);
|
|
|
|
$this->branch = Branch::create([
|
|
'owner_ref' => $this->user->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'name' => 'Main Branch',
|
|
'is_active' => true,
|
|
]);
|
|
|
|
Department::create([
|
|
'owner_ref' => $this->user->public_id,
|
|
'branch_id' => $this->branch->id,
|
|
'name' => 'General Outpatient',
|
|
'type' => 'outpatient',
|
|
'is_active' => true,
|
|
]);
|
|
}
|
|
|
|
public function test_patients_index_loads(): void
|
|
{
|
|
$this->actingAs($this->user)
|
|
->get(route('care.patients.index'))
|
|
->assertOk()
|
|
->assertSee('Patients');
|
|
}
|
|
|
|
public function test_can_register_patient(): void
|
|
{
|
|
$this->actingAs($this->user)
|
|
->post(route('care.patients.store'), [
|
|
'first_name' => 'Ama',
|
|
'last_name' => 'Mensah',
|
|
'phone' => '+233201234567',
|
|
'national_id' => 'GHA-123456789-0',
|
|
'gender' => 'female',
|
|
'date_of_birth' => '1990-05-15',
|
|
'branch_id' => $this->branch->id,
|
|
'allergies' => [
|
|
['allergen' => 'Penicillin', 'severity' => 'severe'],
|
|
],
|
|
'emergency_contacts' => [
|
|
['name' => 'Kofi Mensah', 'phone' => '+233209876543', 'is_primary' => true],
|
|
],
|
|
])
|
|
->assertRedirect();
|
|
|
|
$patient = Patient::first();
|
|
$this->assertNotNull($patient);
|
|
$this->assertSame('Ama Mensah', $patient->fullName());
|
|
$this->assertStringStartsWith('LC-', $patient->patient_number);
|
|
$this->assertDatabaseHas('care_patient_allergies', ['allergen' => 'Penicillin']);
|
|
$this->assertDatabaseHas('care_emergency_contacts', ['name' => 'Kofi Mensah']);
|
|
$this->assertDatabaseHas('care_audit_logs', ['action' => 'patient.created']);
|
|
}
|
|
|
|
public function test_can_search_patients_by_phone(): void
|
|
{
|
|
Patient::create([
|
|
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
|
'owner_ref' => $this->user->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'branch_id' => $this->branch->id,
|
|
'patient_number' => 'LC-2026-00001',
|
|
'first_name' => 'Kwame',
|
|
'last_name' => 'Asante',
|
|
'phone' => '+233244111222',
|
|
]);
|
|
|
|
$this->actingAs($this->user)
|
|
->get(route('care.patients.index', ['q' => '244111222']))
|
|
->assertOk()
|
|
->assertSee('Kwame Asante');
|
|
}
|
|
|
|
public function test_patient_dashboard_loads(): void
|
|
{
|
|
$patient = Patient::create([
|
|
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
|
'owner_ref' => $this->user->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'branch_id' => $this->branch->id,
|
|
'patient_number' => 'LC-2026-00001',
|
|
'first_name' => 'Efua',
|
|
'last_name' => 'Boateng',
|
|
]);
|
|
|
|
$this->actingAs($this->user)
|
|
->get(route('care.patients.show', $patient))
|
|
->assertOk()
|
|
->assertSee('Efua Boateng')
|
|
->assertSee('LC-2026-00001');
|
|
}
|
|
|
|
public function test_api_can_list_patients(): void
|
|
{
|
|
Patient::create([
|
|
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
|
'owner_ref' => $this->user->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'patient_number' => 'LC-2026-00001',
|
|
'first_name' => 'Api',
|
|
'last_name' => 'Patient',
|
|
]);
|
|
|
|
Sanctum::actingAs($this->user);
|
|
|
|
$this->getJson('/api/v1/patients')
|
|
->assertOk()
|
|
->assertJsonPath('data.0.first_name', 'Api');
|
|
}
|
|
|
|
public function test_api_can_create_patient(): void
|
|
{
|
|
Sanctum::actingAs($this->user);
|
|
|
|
$this->postJson('/api/v1/patients', [
|
|
'first_name' => 'Yaa',
|
|
'last_name' => 'Owusu',
|
|
'phone' => '+233555000111',
|
|
])
|
|
->assertCreated()
|
|
->assertJsonPath('first_name', 'Yaa');
|
|
|
|
$this->assertSame(1, Patient::count());
|
|
}
|
|
|
|
public function test_doctor_cannot_register_patient(): void
|
|
{
|
|
Member::where('user_ref', $this->user->public_id)->update(['role' => 'doctor']);
|
|
|
|
$this->actingAs($this->user)
|
|
->get(route('care.patients.create'))
|
|
->assertForbidden();
|
|
}
|
|
}
|