Add Care Units, beds, and dated staff assignments.
Deploy Ladill Care / deploy (push) Successful in 1m8s
Deploy Ladill Care / deploy (push) Successful in 1m8s
Models employment as department/unit/shift placements with primary and temporary kinds so nurses are not permanently bound to a ward. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToOwner;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Bed extends Model
|
||||
{
|
||||
use BelongsToOwner, SoftDeletes;
|
||||
|
||||
protected $table = 'care_beds';
|
||||
|
||||
protected $fillable = [
|
||||
'owner_ref',
|
||||
'organization_id',
|
||||
'care_unit_id',
|
||||
'label',
|
||||
'room',
|
||||
'status',
|
||||
'is_active',
|
||||
'sort_order',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function organization(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Organization::class, 'organization_id');
|
||||
}
|
||||
|
||||
public function careUnit(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CareUnit::class, 'care_unit_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToOwner;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class CareUnit extends Model
|
||||
{
|
||||
use BelongsToOwner, SoftDeletes;
|
||||
|
||||
protected $table = 'care_care_units';
|
||||
|
||||
protected $fillable = [
|
||||
'owner_ref',
|
||||
'organization_id',
|
||||
'department_id',
|
||||
'name',
|
||||
'code',
|
||||
'kind',
|
||||
'is_active',
|
||||
'sort_order',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function organization(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Organization::class, 'organization_id');
|
||||
}
|
||||
|
||||
public function department(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'department_id');
|
||||
}
|
||||
|
||||
public function beds(): HasMany
|
||||
{
|
||||
return $this->hasMany(Bed::class, 'care_unit_id')->orderBy('sort_order')->orderBy('label');
|
||||
}
|
||||
|
||||
public function assignments(): HasMany
|
||||
{
|
||||
return $this->hasMany(StaffAssignment::class, 'care_unit_id');
|
||||
}
|
||||
|
||||
public function supportsBeds(): bool
|
||||
{
|
||||
return $this->kind === 'inpatient';
|
||||
}
|
||||
|
||||
public function labelForSelect(): string
|
||||
{
|
||||
$dept = $this->relationLoaded('department')
|
||||
? $this->department
|
||||
: $this->department()->first();
|
||||
|
||||
$kindLabel = config('care.care_unit_kinds.'.$this->kind, $this->kind);
|
||||
$base = $this->name.($kindLabel ? ' ('.$kindLabel.')' : '');
|
||||
|
||||
if ($dept?->name) {
|
||||
return $dept->name.' — '.$base;
|
||||
}
|
||||
|
||||
return $base;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use App\Models\Concerns\BelongsToOwner;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Department extends Model
|
||||
@@ -27,6 +28,13 @@ class Department extends Model
|
||||
return $this->belongsTo(Branch::class, 'branch_id');
|
||||
}
|
||||
|
||||
public function careUnits(): HasMany
|
||||
{
|
||||
return $this->hasMany(CareUnit::class, 'department_id')
|
||||
->orderBy('sort_order')
|
||||
->orderBy('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Select option label — includes branch when set so multi-branch duplicates are distinguishable.
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use App\Models\Concerns\BelongsToOwner;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Member extends Model
|
||||
{
|
||||
@@ -24,6 +25,11 @@ class Member extends Model
|
||||
return $this->belongsTo(Branch::class, 'branch_id');
|
||||
}
|
||||
|
||||
public function staffAssignments(): HasMany
|
||||
{
|
||||
return $this->hasMany(StaffAssignment::class, 'member_id');
|
||||
}
|
||||
|
||||
public function hasRole(string ...$roles): bool
|
||||
{
|
||||
return in_array($this->role, $roles, true);
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToOwner;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class StaffAssignment extends Model
|
||||
{
|
||||
use BelongsToOwner, SoftDeletes;
|
||||
|
||||
protected $table = 'care_staff_assignments';
|
||||
|
||||
protected $fillable = [
|
||||
'owner_ref',
|
||||
'organization_id',
|
||||
'member_id',
|
||||
'department_id',
|
||||
'care_unit_id',
|
||||
'kind',
|
||||
'assignment_role',
|
||||
'shift_code',
|
||||
'starts_on',
|
||||
'ends_on',
|
||||
'status',
|
||||
'notes',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'starts_on' => 'date',
|
||||
'ends_on' => 'date',
|
||||
];
|
||||
}
|
||||
|
||||
public function organization(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Organization::class, 'organization_id');
|
||||
}
|
||||
|
||||
public function member(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id');
|
||||
}
|
||||
|
||||
public function department(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'department_id');
|
||||
}
|
||||
|
||||
public function careUnit(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CareUnit::class, 'care_unit_id');
|
||||
}
|
||||
|
||||
public function scopeEffectiveOn(Builder $query, CarbonInterface|string|null $date = null): Builder
|
||||
{
|
||||
$day = $date
|
||||
? (\Illuminate\Support\Carbon::parse($date)->toDateString())
|
||||
: now()->toDateString();
|
||||
|
||||
return $query
|
||||
->whereDate('starts_on', '<=', $day)
|
||||
->where(function (Builder $q) use ($day) {
|
||||
$q->whereNull('ends_on')->orWhereDate('ends_on', '>=', $day);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeActiveStatus(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'active');
|
||||
}
|
||||
|
||||
public function isEffectiveOn(CarbonInterface|string|null $date = null): bool
|
||||
{
|
||||
$day = $date
|
||||
? \Illuminate\Support\Carbon::parse($date)->startOfDay()
|
||||
: now()->startOfDay();
|
||||
|
||||
if ($this->starts_on->gt($day)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->ends_on !== null && $this->ends_on->lt($day)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->status === 'active';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user