instalasi-sim-rs/app/Models/Registration.php

124 lines
2.9 KiB
PHP

<?php
namespace App\Models;
use App\Traits\InteractsWithUuid;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Registration extends Model
{
use HasFactory, InteractsWithUuid;
protected $table = 't_registration';
protected $primaryKey = 'id';
protected $keyType = 'string';
public $incrementing = false;
protected $fillable = [
'registration_number',
'patient_id',
'employee_id',
'service_room_id',
'insurance_id',
'created_by',
'registration_type',
'patient_type',
'registration_datetime',
'discharge_datetime',
'estimated_discharge',
'diagnoses',
'prescriptions',
'medical_notes',
'complaint',
'status',
'payment_status',
'need_icu',
'is_referral',
'referral_from',
'is_active'
];
protected $casts = [
'registration_datetime' => 'datetime',
'discharge_datetime' => 'datetime',
'estimated_discharge' => 'datetime',
'diagnoses' => 'array',
'prescriptions' => 'array',
'need_icu' => 'boolean',
'is_referral' => 'boolean',
'is_active' => 'boolean',
];
protected $attributes = [
'registration_type' => 'Rawat Jalan',
'patient_type' => 'Umum',
'status' => 'registered',
'payment_status' => 'unpaid',
'need_icu' => false,
'is_referral' => false,
'is_active' => true,
];
public function patient()
{
return $this->belongsTo(Patient::class, 'patient_id');
}
public function employee()
{
return $this->belongsTo(Employee::class, 'employee_id');
}
public function serviceRoom()
{
return $this->belongsTo(ServiceRoom::class, 'service_room_id');
}
public function insurance()
{
return $this->belongsTo(Insurance::class, 'insurance_id');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function scopeActive($query)
{
return $query->where('is_active', true);
}
public function scopeInpatient($query)
{
return $query->where('registration_type', 'Rawat Inap');
}
public function scopeOutpatient($query)
{
return $query->where('registration_type', 'Rawat Jalan');
}
public function scopeEmergency($query)
{
return $query->where('registration_type', 'UGD');
}
// Helpers
public function isCompleted(): bool
{
return $this->status === 'completed';
}
public function isPaid(): bool
{
return $this->payment_status === 'paid' || $this->payment_status === 'insurance_cover';
}
public function getFormattedRegistrationNumber(): string
{
return $this->registration_number;
}
}