Add shift templates, unit duty roster grid, and Nursing Services hub.
Deploy Ladill Care / deploy (push) Successful in 1m0s

Phase 3 staff management: real shift entities, week roster linked to temporary assignments, and a nursing ops module surface (registry, today’s allocation, unit shortcuts).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-20 10:40:25 +00:00
co-authored by Cursor
parent 9eb6c21828
commit b2cebe2908
20 changed files with 1439 additions and 8 deletions
@@ -0,0 +1,200 @@
<?php
namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Branch;
use App\Models\CareUnit;
use App\Models\Department;
use App\Models\Member;
use App\Models\Organization;
use App\Models\RosterEntry;
use App\Models\Shift;
use App\Models\StaffAssignment;
use App\Models\User;
use App\Services\Care\RosterService;
use App\Services\Care\SpecialtyModuleService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class CareRosterAndNursingServicesTest extends TestCase
{
use RefreshDatabase;
protected User $owner;
protected Organization $organization;
protected CareUnit $unit;
protected Member $nurseMember;
protected function setUp(): void
{
parent::setUp();
$this->withoutMiddleware(EnsurePlatformSession::class);
$this->owner = User::create([
'public_id' => 'roster-owner',
'name' => 'Owner',
'email' => 'roster-owner@example.com',
]);
$this->organization = Organization::create([
'owner_ref' => $this->owner->public_id,
'name' => 'Roster Hospital',
'slug' => 'roster-hospital',
'settings' => [
'onboarded' => true,
'facility_type' => 'hospital',
'plan' => 'pro',
'plan_expires_at' => now()->addMonth()->toIso8601String(),
],
]);
Member::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'user_ref' => $this->owner->public_id,
'role' => 'hospital_admin',
]);
$branch = Branch::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'name' => 'Main',
'is_active' => true,
]);
$department = Department::create([
'owner_ref' => $this->owner->public_id,
'branch_id' => $branch->id,
'name' => 'Medicine',
'type' => 'general',
'is_active' => true,
]);
$this->unit = CareUnit::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'department_id' => $department->id,
'name' => 'Medical Ward',
'kind' => 'inpatient',
'is_active' => true,
]);
$nurseUser = User::create([
'public_id' => 'roster-nurse',
'name' => 'Nurse Ama',
'email' => 'roster-nurse@example.com',
]);
$this->nurseMember = Member::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'user_ref' => $nurseUser->public_id,
'role' => 'nurse',
'branch_id' => $branch->id,
]);
}
public function test_default_shifts_are_seeded_on_index(): void
{
$this->actingAs($this->owner)
->get(route('care.shifts.index'))
->assertOk()
->assertSee('Day shift')
->assertSee('Evening shift')
->assertSee('Night shift');
$this->assertSame(3, Shift::query()->where('organization_id', $this->organization->id)->count());
}
public function test_roster_assign_links_temporary_staff_assignment(): void
{
$roster = app(RosterService::class);
$shifts = $roster->ensureDefaultShifts($this->organization, $this->owner->public_id);
$day = $shifts->firstWhere('code', 'day');
$this->actingAs($this->owner)
->post(route('care.care-units.roster.store', $this->unit), [
'shift_id' => $day->id,
'member_id' => $this->nurseMember->id,
'duty_date' => now()->toDateString(),
'notes' => 'Cover',
])
->assertRedirect();
$entry = RosterEntry::query()->first();
$this->assertNotNull($entry);
$this->assertSame(RosterEntry::STATUS_SCHEDULED, $entry->status);
$this->assertNotNull($entry->staff_assignment_id);
$assignment = StaffAssignment::query()->find($entry->staff_assignment_id);
$this->assertSame('temporary', $assignment->kind);
$this->assertSame('day', $assignment->shift_code);
$this->assertSame((int) $this->unit->id, (int) $assignment->care_unit_id);
}
public function test_roster_cancel_ends_assignment_and_allows_reassign(): void
{
$roster = app(RosterService::class);
$shifts = $roster->ensureDefaultShifts($this->organization, $this->owner->public_id);
$day = $shifts->firstWhere('code', 'day');
$date = now()->toDateString();
$entry = $roster->assign(
$this->unit,
$day,
$this->nurseMember,
$date,
$this->owner->public_id,
$this->owner->public_id,
);
$this->actingAs($this->owner)
->delete(route('care.care-units.roster.destroy', [$this->unit, $entry]))
->assertRedirect();
$this->assertSoftDeleted('care_roster_entries', ['id' => $entry->id]);
$this->assertDatabaseHas('care_staff_assignments', [
'id' => $entry->staff_assignment_id,
'status' => 'ended',
]);
$this->actingAs($this->owner)
->post(route('care.care-units.roster.store', $this->unit), [
'shift_id' => $day->id,
'member_id' => $this->nurseMember->id,
'duty_date' => $date,
])
->assertRedirect();
$this->assertSame(1, RosterEntry::query()->where('care_unit_id', $this->unit->id)->count());
}
public function test_nursing_services_hub_and_specialty_redirect(): void
{
$this->assertTrue(app(SpecialtyModuleService::class)->isEnabled($this->organization, 'nursing_services'));
$this->actingAs($this->owner)
->get(route('care.nursing.services'))
->assertOk()
->assertSee('Nursing Services')
->assertSee('Nurse Ama')
->assertSee('Medical Ward');
$this->actingAs($this->owner)
->get(route('care.specialty.show', 'nursing_services'))
->assertRedirect(route('care.nursing.services'));
}
public function test_unit_roster_grid_renders(): void
{
$this->actingAs($this->owner)
->get(route('care.care-units.roster', $this->unit))
->assertOk()
->assertSee('Week roster')
->assertSee('Day shift');
}
}