Роли, переделывание отчета, изменение на главной странице
This commit is contained in:
@@ -6,17 +6,29 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Department extends Model
|
||||
{
|
||||
protected $table = 'oms_department';
|
||||
protected $primaryKey = 'departmentid';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $primaryKey = 'department_id';
|
||||
|
||||
protected $fillable = [
|
||||
'departmentname',
|
||||
'rf_lpuid'
|
||||
'name_full',
|
||||
'name_short',
|
||||
'rf_mis_department_id',
|
||||
'rf_department_type'
|
||||
];
|
||||
|
||||
public function lpu(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
public function metrikaDefault()
|
||||
{
|
||||
return $this->hasOne(Lpu::class, 'lpuid', 'rf_lpuid');
|
||||
return $this->hasMany(DepartmentMetrikaDefault::class, 'rf_department_id', 'department_id');
|
||||
}
|
||||
|
||||
public function observationPatients(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(ObservationPatient::class, 'rf_department_id', 'department_id');
|
||||
}
|
||||
|
||||
public function reports(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Report::class, 'rf_department_id', 'department_id');
|
||||
}
|
||||
}
|
||||
|
||||
22
app/Models/DepartmentMetrikaDefault.php
Normal file
22
app/Models/DepartmentMetrikaDefault.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DepartmentMetrikaDefault extends Model
|
||||
{
|
||||
protected $primaryKey = 'department_metrika_default_id';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'rf_department_id',
|
||||
'rf_metrika_item_id',
|
||||
'value'
|
||||
];
|
||||
|
||||
public function departments()
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'rf_department_id');
|
||||
}
|
||||
}
|
||||
16
app/Models/DepartmentType.php
Normal file
16
app/Models/DepartmentType.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DepartmentType extends Model
|
||||
{
|
||||
protected $primaryKey = 'department_type_id';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'name_full',
|
||||
'name_short'
|
||||
];
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Lpu extends Model
|
||||
{
|
||||
protected $table = 'oms_lpu';
|
||||
protected $primaryKey = 'lpuid';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'mname_s',
|
||||
'mainlpuid'
|
||||
];
|
||||
|
||||
public function department(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Department::class, 'lpuid', 'rf_lpuid');
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,24 @@ class MetrikaGroup extends Model
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'metrika_group_id',
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
|
||||
public function groupItems()
|
||||
{
|
||||
return $this->hasMany(MetrikaGroupItem::class, 'rf_metrika_group_id', 'metrika_group_id');
|
||||
}
|
||||
|
||||
public function metrikaItems()
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
MetrikaItem::class,
|
||||
MetrikaGroupItem::class,
|
||||
'rf_metrika_group_id',
|
||||
'metrika_item_id',
|
||||
'metrika_group_id',
|
||||
'rf_metrika_item_id',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,9 @@ class MetrikaResult extends Model
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'rf_metrika_item_id',
|
||||
'rf_report_id',
|
||||
'rf_metrika_group_id',
|
||||
'value'
|
||||
];
|
||||
|
||||
public function report(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
@@ -20,13 +21,13 @@ class MetrikaResult extends Model
|
||||
return $this->belongsTo(Report::class, 'rf_report_id', 'report_id');
|
||||
}
|
||||
|
||||
public function group(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MetrikaGroup::class, 'rf_metrika_group_id', 'metrika_group_id');
|
||||
}
|
||||
// public function group(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
// {
|
||||
// return $this->belongsTo(MetrikaGroup::class, 'rf_metrika_group_id', 'metrika_group_id');
|
||||
// }
|
||||
|
||||
public function values(): HasMany
|
||||
{
|
||||
return $this->hasMany(MetrikaResultValue::class, 'rf_metrika_result_id', 'metrika_result_id');
|
||||
}
|
||||
// public function values(): HasMany
|
||||
// {
|
||||
// return $this->hasMany(MetrikaResultValue::class, 'rf_metrika_result_id', 'metrika_result_id');
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ class MetrikaResultValue extends Model
|
||||
protected $fillable = [
|
||||
'rf_metrika_result_id',
|
||||
'rf_metrika_item_id',
|
||||
'rf_report_id',
|
||||
'value',
|
||||
];
|
||||
|
||||
|
||||
21
app/Models/MisMedicalHistory.php
Normal file
21
app/Models/MisMedicalHistory.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MisMedicalHistory extends Model
|
||||
{
|
||||
protected $table = 'stt_medicalhistory';
|
||||
|
||||
protected $primaryKey = 'MedicalHistoryID';
|
||||
|
||||
protected $fillable = [
|
||||
'MedicalHistoryID',
|
||||
'FAMILY',
|
||||
'Name',
|
||||
'OT',
|
||||
'BD',
|
||||
'Address'
|
||||
];
|
||||
}
|
||||
18
app/Models/ObservationPatient.php
Normal file
18
app/Models/ObservationPatient.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ObservationPatient extends Model
|
||||
{
|
||||
protected $primaryKey = 'observation_patient_id';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'rf_medicalhistory_id',
|
||||
'rf_mkab_id',
|
||||
'rf_department_id',
|
||||
'rf_report_id',
|
||||
];
|
||||
}
|
||||
@@ -20,4 +20,9 @@ class Report extends Model
|
||||
{
|
||||
return $this->hasMany(MetrikaResult::class, 'rf_report_id', 'report_id');
|
||||
}
|
||||
|
||||
public function observationPatients(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(ObservationPatient::class, 'rf_report_id', 'report_id');
|
||||
}
|
||||
}
|
||||
|
||||
37
app/Models/Role.php
Normal file
37
app/Models/Role.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
|
||||
class Role extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
protected $primaryKey = 'role_id';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
public function userRoles(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserRole::class, 'rf_role_id', 'role_id');
|
||||
}
|
||||
|
||||
public function users(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
User::class,
|
||||
UserRole::class,
|
||||
'rf_role_id',
|
||||
'id',
|
||||
'role_id',
|
||||
'rf_user_id'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ namespace App\Models;
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
@@ -55,49 +58,60 @@ class User extends Authenticatable
|
||||
return $this->belongsTo(Department::class, 'rf_department_id');
|
||||
}
|
||||
|
||||
public function userRoles(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserRole::class, 'rf_user_id', 'id');
|
||||
}
|
||||
|
||||
public function roles(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
Role::class,
|
||||
UserRole::class,
|
||||
'rf_user_id',
|
||||
'role_id',
|
||||
'id',
|
||||
'rf_role_id'
|
||||
);
|
||||
}
|
||||
|
||||
public function currentRole()
|
||||
{
|
||||
$defaultRoleId = $this->roles()->where('is_default', true)->first()->role_id;
|
||||
$roleId = session('currentRoleId', $defaultRoleId);
|
||||
|
||||
$role = Role::where('role_id', $roleId)->first();
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
// Методы для проверки ролей
|
||||
public function isAdmin()
|
||||
{
|
||||
return $this->role === 'admin';
|
||||
return $this->currentRole()->slug === 'admin';
|
||||
}
|
||||
|
||||
public function isDoctor()
|
||||
{
|
||||
return $this->role === 'doctor';
|
||||
}
|
||||
|
||||
public function isNurse()
|
||||
{
|
||||
return $this->role === 'nurse';
|
||||
return $this->currentRole()->slug === 'doctor';
|
||||
}
|
||||
|
||||
public function isHeadOfDepartment()
|
||||
{
|
||||
return $this->role === 'head_of_department';
|
||||
return $this->currentRole()->slug === 'head_of_department';
|
||||
}
|
||||
|
||||
public function isStatistician()
|
||||
{
|
||||
return $this->role === 'statistician';
|
||||
return $this->currentRole()->slug === 'statistician';
|
||||
}
|
||||
|
||||
// Получение доступных отделений
|
||||
public function availableDepartments()
|
||||
{
|
||||
$departments = [
|
||||
'Гематология',
|
||||
'Хирургия',
|
||||
'Терапия',
|
||||
'Реанимация',
|
||||
'Онкология',
|
||||
'Кардиология',
|
||||
'Неврология',
|
||||
'Урология',
|
||||
'Гинекология',
|
||||
'Лаборатория'
|
||||
];
|
||||
$departments = Department::all();
|
||||
|
||||
if ($this->isAdmin() || $this->isHeadOfDepartment()) {
|
||||
if ($this->isAdmin()) {
|
||||
return $departments;
|
||||
}
|
||||
|
||||
|
||||
30
app/Models/UserRole.php
Normal file
30
app/Models/UserRole.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserRole extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
protected $primaryKey = 'user_role_id';
|
||||
|
||||
protected $fillable = [
|
||||
'rf_user_id',
|
||||
'rf_role_id',
|
||||
'is_active',
|
||||
'is_default',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'rf_user_id', 'id');
|
||||
}
|
||||
|
||||
public function role(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Role::class, 'rf_role_id', 'role_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user