Files
ladill-care/app/Models/Bed.php
T
isaaccladandCursor 45a1a95142
Deploy Ladill Care / deploy (push) Successful in 38s
Add visit placement on care units and beds.
Patients can be admitted, transferred, and discharged from unit/bed stays with occupancy sync, so MAR and ward boards have inpatient context.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-20 10:10:37 +00:00

61 lines
1.4 KiB
PHP

<?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\Relations\HasOne;
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');
}
public function stays(): HasMany
{
return $this->hasMany(BedStay::class, 'bed_id');
}
public function activeStay(): HasOne
{
return $this->hasOne(BedStay::class, 'bed_id')
->ofMany(
['id' => 'max'],
fn ($query) => $query->where('status', BedStay::STATUS_ACTIVE),
);
}
}