withoutMiddleware(EnsurePlatformSession::class); $this->owner = User::create([ 'public_id' => 'opd-census-owner', 'name' => 'Owner', 'email' => 'opd-census-owner@example.com', ]); $this->organization = Organization::create([ 'owner_ref' => $this->owner->public_id, 'name' => 'OPD Clinic', 'slug' => 'opd-clinic', 'settings' => [ 'onboarded' => true, 'facility_type' => 'hospital', 'plan' => 'pro', 'plan_expires_at' => now()->addMonth()->toIso8601String(), 'rollout' => [CareFeatures::ASSESSMENTS_ENGINE => 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' => 'Tema Harbour Clinic', 'is_active' => true, ]); $this->department = Department::create([ 'owner_ref' => $this->owner->public_id, 'branch_id' => $this->branch->id, 'name' => 'Outpatient', 'type' => 'outpatient', 'is_active' => true, ]); $this->opd = CareUnit::create([ 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'department_id' => $this->department->id, 'name' => 'OPD', 'kind' => 'outpatient', 'code' => 'OP', 'is_active' => true, ]); } public function test_outpatient_board_includes_checked_in_department_visits_without_manual_place(): void { $patient = Patient::create([ 'uuid' => (string) Str::uuid(), 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'branch_id' => $this->branch->id, 'patient_number' => 'P-OPD-1', 'first_name' => 'Yaw', 'last_name' => 'Adjei', ]); $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_IN_PROGRESS, 'checked_in_at' => now(), ]); Appointment::create([ 'uuid' => (string) Str::uuid(), 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'branch_id' => $this->branch->id, 'department_id' => $this->department->id, 'patient_id' => $patient->id, 'visit_id' => $visit->id, 'type' => Appointment::TYPE_WALK_IN, 'status' => Appointment::STATUS_WAITING, 'checked_in_at' => now(), ]); $otherDept = Department::create([ 'owner_ref' => $this->owner->public_id, 'branch_id' => $this->branch->id, 'name' => 'Dental', 'type' => 'dentistry', 'is_active' => true, ]); $otherPatient = Patient::create([ 'uuid' => (string) Str::uuid(), 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'branch_id' => $this->branch->id, 'patient_number' => 'P-OPD-2', 'first_name' => 'Ama', 'last_name' => 'Other', ]); $otherVisit = Visit::create([ 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'branch_id' => $this->branch->id, 'patient_id' => $otherPatient->id, 'status' => Visit::STATUS_OPEN, 'checked_in_at' => now(), ]); Appointment::create([ 'uuid' => (string) Str::uuid(), 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'branch_id' => $this->branch->id, 'department_id' => $otherDept->id, 'patient_id' => $otherPatient->id, 'visit_id' => $otherVisit->id, 'type' => Appointment::TYPE_WALK_IN, 'status' => Appointment::STATUS_WAITING, 'checked_in_at' => now(), ]); $census = app(CareUnitCensusService::class); $visits = $census->visitsForUnit($this->opd, $this->owner->public_id); $this->assertTrue($census->isClinicUnit($this->opd)); $this->assertCount(1, $visits); $this->assertTrue($visits->contains('id', $visit->id)); $this->assertFalse($visits->contains('id', $otherVisit->id)); $user = User::create([ 'public_id' => 'opd-nurse', 'name' => 'OPD Nurse', 'email' => 'opd-nurse@example.com', ]); $member = Member::create([ 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'user_ref' => $user->public_id, 'role' => 'nurse', 'branch_id' => $this->branch->id, ]); $roster = app(RosterService::class); $day = $roster->ensureDefaultShifts($this->organization, $this->owner->public_id)->firstWhere('code', 'day'); $roster->assign( $this->opd, $day, $member, now()->toDateString(), $this->owner->public_id, $this->owner->public_id, ); $this->actingAs($user) ->get(route('care.nursing.station', ['unit' => $this->opd->id])) ->assertOk() ->assertSee('Yaw Adjei') ->assertSee('In clinic') ->assertDontSee('Ama Other'); $this->actingAs($user) ->get(route('care.care-units.show', $this->opd)) ->assertOk() ->assertSee('Yaw Adjei') ->assertSee('in clinic') ->assertSee('Clinic'); } public function test_nursing_action_auto_places_clinic_visit_onto_opd(): void { $this->seed(AssessmentTemplateSeeder::class); $patient = Patient::create([ 'uuid' => (string) Str::uuid(), 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'branch_id' => $this->branch->id, 'patient_number' => 'P-OPD-3', 'first_name' => 'Kofi', 'last_name' => 'Mensah', ]); $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([ 'uuid' => (string) Str::uuid(), 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'branch_id' => $this->branch->id, 'department_id' => $this->department->id, 'patient_id' => $patient->id, 'visit_id' => $visit->id, 'type' => Appointment::TYPE_WALK_IN, 'status' => Appointment::STATUS_CHECKED_IN, 'checked_in_at' => now(), ]); $this->actingAs($this->owner) ->post(route('care.care-units.vitals.store', [$this->opd, $visit]), [ 'pulse' => 78, 'spo2' => 98, ]) ->assertRedirect(route('care.care-units.assessments', $this->opd)); $visit->refresh(); $this->assertSame($this->opd->id, (int) $visit->care_unit_id); $this->assertNotNull($visit->placed_at); } public function test_inpatient_unit_still_requires_placement(): void { $ward = CareUnit::create([ 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'department_id' => $this->department->id, 'name' => 'Medical Ward', 'kind' => 'inpatient', 'is_active' => true, ]); $patient = Patient::create([ 'uuid' => (string) Str::uuid(), 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'branch_id' => $this->branch->id, 'patient_number' => 'P-WARD-X', 'first_name' => 'Efua', 'last_name' => 'Boateng', ]); $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([ 'uuid' => (string) Str::uuid(), 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'branch_id' => $this->branch->id, 'department_id' => $this->department->id, 'patient_id' => $patient->id, 'visit_id' => $visit->id, 'type' => Appointment::TYPE_WALK_IN, 'status' => Appointment::STATUS_WAITING, 'checked_in_at' => now(), ]); $visits = app(CareUnitCensusService::class)->visitsForUnit($ward, $this->owner->public_id); $this->assertCount(0, $visits); } }