131 lines
3.1 KiB
PHP
131 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
|
use HasFactory, Notifiable, HasApiTokens;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'rf_lpudoctor_id',
|
|
'rf_department_id',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
];
|
|
}
|
|
|
|
public function department(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Department::class, 'rf_department_id');
|
|
}
|
|
|
|
// Методы для проверки ролей
|
|
public function isAdmin()
|
|
{
|
|
return $this->role === 'admin';
|
|
}
|
|
|
|
public function isDoctor()
|
|
{
|
|
return $this->role === 'doctor';
|
|
}
|
|
|
|
public function isNurse()
|
|
{
|
|
return $this->role === 'nurse';
|
|
}
|
|
|
|
public function isHeadOfDepartment()
|
|
{
|
|
return $this->role === 'head_of_department';
|
|
}
|
|
|
|
public function isStatistician()
|
|
{
|
|
return $this->role === 'statistician';
|
|
}
|
|
|
|
// Получение доступных отделений
|
|
public function availableDepartments()
|
|
{
|
|
$departments = [
|
|
'Гематология',
|
|
'Хирургия',
|
|
'Терапия',
|
|
'Реанимация',
|
|
'Онкология',
|
|
'Кардиология',
|
|
'Неврология',
|
|
'Урология',
|
|
'Гинекология',
|
|
'Лаборатория'
|
|
];
|
|
|
|
if ($this->isAdmin() || $this->isHeadOfDepartment()) {
|
|
return $departments;
|
|
}
|
|
|
|
return $this->department ? [$this->department] : [];
|
|
}
|
|
|
|
// Получение доступных действий
|
|
public function permissions()
|
|
{
|
|
$permissions = [
|
|
'view_dashboard' => true,
|
|
'view_metrics' => true,
|
|
'view_reports' => true,
|
|
];
|
|
|
|
if ($this->isAdmin() || $this->isDoctor() || $this->isHeadOfDepartment()) {
|
|
$permissions['create_metrics'] = true;
|
|
$permissions['edit_metrics'] = true;
|
|
$permissions['delete_metrics'] = true;
|
|
$permissions['manage_users'] = $this->isAdmin();
|
|
}
|
|
|
|
if ($this->isStatistician()) {
|
|
$permissions['view_statistics'] = true;
|
|
$permissions['export_data'] = true;
|
|
}
|
|
|
|
return $permissions;
|
|
}
|
|
}
|