62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\Gender;
|
|
use EloquentFilter\Filterable;
|
|
use App\Traits\HasDateTimeFormatter;
|
|
use Slowlyo\OwlAdmin\Models\AdminUser;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
|
|
/**
|
|
* 病人
|
|
*/
|
|
class Patient extends Model
|
|
{
|
|
use HasDateTimeFormatter, Filterable;
|
|
|
|
protected $fillable = ['name', 'sex', 'phone', 'address', 'birthday', 'treat_at', 'illness', 'doctor_id', 'remarks'];
|
|
|
|
protected $appends = ['age', 'sex_text', 'treat_format', 'birthday_format'];
|
|
|
|
protected $casts = [
|
|
'sex' => Gender::class,
|
|
'treat_at' => 'date',
|
|
'birthday' => 'date',
|
|
];
|
|
|
|
protected function age(): Attribute
|
|
{
|
|
return new Attribute(
|
|
get: fn () => $this->birthday ? $this->birthday->diffInYears() : '',
|
|
);
|
|
}
|
|
|
|
protected function sexText(): Attribute
|
|
{
|
|
return new Attribute(
|
|
get: fn () => $this->sex ? $this->sex->text() : '',
|
|
);
|
|
}
|
|
|
|
protected function treatFormat(): Attribute
|
|
{
|
|
return new Attribute(
|
|
get: fn () => $this->treat_at ? $this->treat_at->format('Y-m-d') : '',
|
|
);
|
|
}
|
|
|
|
protected function birthdayFormat(): Attribute
|
|
{
|
|
return new Attribute(
|
|
get: fn () => $this->birthday ? $this->birthday->format('Y-m-d') : '',
|
|
);
|
|
}
|
|
|
|
public function doctor()
|
|
{
|
|
return $this->belongsTo(AdminUser::class, 'doctor_id');
|
|
}
|
|
}
|