Роли, переделывание отчета, изменение на главной странице
This commit is contained in:
151
app/Http/Controllers/Api/ReportController.php
Normal file
151
app/Http/Controllers/Api/ReportController.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Mis\FormattedPatientResource;
|
||||
use App\Models\MetrikaGroup;
|
||||
use App\Models\MetrikaResult;
|
||||
use App\Models\MisMedicalHistory;
|
||||
use App\Models\ObservationPatient;
|
||||
use App\Models\Report;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
$department = $user->department;
|
||||
|
||||
$beds = (int)$department->metrikaDefault()->where('rf_metrika_item_id', 1)->first()->value;
|
||||
$occupiedBeds = optional(Report::where('rf_department_id', $user->rf_department_id)
|
||||
->join('metrika_results', 'reports.report_id', '=', 'metrika_results.rf_report_id')
|
||||
->where('metrika_results.rf_metrika_item_id', 8)
|
||||
->orderBy('sent_at', 'desc')->first())->value ?? 0;
|
||||
|
||||
$percentLoadedBeds = intval($occupiedBeds) * 100 / $beds;
|
||||
|
||||
$metrikaGroup = MetrikaGroup::whereMetrikaGroupId(2)->first();
|
||||
$metrikaItems = $metrikaGroup->metrikaItems;
|
||||
|
||||
return response()->json([
|
||||
'department' => [
|
||||
'beds' => $beds,
|
||||
'percentLoadedBeds' => $percentLoadedBeds,
|
||||
],
|
||||
'metrikaItems' => $metrikaItems
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'metrics' => 'required',
|
||||
'observationPatients' => 'nullable',
|
||||
'departmentId' => 'required|integer',
|
||||
]);
|
||||
|
||||
$metrics = $data['metrics'];
|
||||
$observationPatients = $data['observationPatients'];
|
||||
|
||||
$metriks = [];
|
||||
foreach ($metrics as $key => $value) {
|
||||
$metrika = new MetrikaResult;
|
||||
$metrikaId = (int)Str::replace('metrika_item_', '', $key);
|
||||
$metrika->rf_metrika_item_id = $metrikaId;
|
||||
$metrika->value = $value;
|
||||
|
||||
$metriks[] = $metrika;
|
||||
}
|
||||
|
||||
\DB::beginTransaction();
|
||||
|
||||
$report = Report::create([
|
||||
'rf_department_id' => $data['departmentId'],
|
||||
'rf_user_id' => Auth::user()->id,
|
||||
'created_at' => now(),
|
||||
'sent_at' => now()
|
||||
]);
|
||||
|
||||
foreach ($metriks as $metrika) {
|
||||
$metrika->rf_report_id = $report->report_id;
|
||||
$metrika->save();
|
||||
}
|
||||
|
||||
foreach ($observationPatients as $observationPatient) {
|
||||
ObservationPatient::create([
|
||||
'rf_department_id' => $data['departmentId'],
|
||||
'rf_report_id' => $report->report_id,
|
||||
'rf_medicalhistory_id' => $observationPatient['id'],
|
||||
'rf_mkab_id' => null
|
||||
]);
|
||||
}
|
||||
|
||||
\DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'success'
|
||||
]);
|
||||
}
|
||||
|
||||
public function getPatients(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'status' => 'required|string', // plan emergency
|
||||
]);
|
||||
|
||||
$status = $data['status'];
|
||||
|
||||
$model = new MisMedicalHistory();
|
||||
if ($status === 'plan') {
|
||||
$patients = MisMedicalHistory::select(
|
||||
[
|
||||
...$model->getFillable(),
|
||||
DB::raw('ROW_NUMBER() OVER (ORDER BY "DateRecipient" DESC) as num')
|
||||
])
|
||||
->where('rf_EmerSignID', 1)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->get();
|
||||
} else if ($status === 'emergency') {
|
||||
$patients = MisMedicalHistory::select(
|
||||
[
|
||||
...$model->getFillable(),
|
||||
DB::raw('ROW_NUMBER() OVER (ORDER BY "DateRecipient" DESC) as num')
|
||||
])
|
||||
->where('rf_EmerSignID', 2)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->get();
|
||||
}
|
||||
|
||||
return response()->json(FormattedPatientResource::collection($patients));
|
||||
}
|
||||
|
||||
public function getPatientsCount(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'status' => 'required|string', // plan emergency
|
||||
]);
|
||||
|
||||
$status = $data['status'];
|
||||
|
||||
$model = new MisMedicalHistory();
|
||||
if ($status === 'plan') {
|
||||
$count = MisMedicalHistory::select($model->getFillable())
|
||||
->where('rf_EmerSignID', 1)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
} else if ($status === 'emergency') {
|
||||
$count = MisMedicalHistory::select($model->getFillable())
|
||||
->where('rf_EmerSignID', 2)
|
||||
->orderBy('DateRecipient', 'DESC')
|
||||
->count();
|
||||
}
|
||||
|
||||
return response()->json($count);
|
||||
}
|
||||
}
|
||||
33
app/Http/Controllers/Api/RoleController.php
Normal file
33
app/Http/Controllers/Api/RoleController.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Role;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RoleController extends Controller
|
||||
{
|
||||
public function getUserRoles(Request $request)
|
||||
{
|
||||
$roles = $request->user()->roles;
|
||||
|
||||
return response()->json(
|
||||
$roles
|
||||
);
|
||||
}
|
||||
|
||||
public function setUserRole(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'role_id' => 'required|integer|exists:roles,id'
|
||||
]);
|
||||
}
|
||||
|
||||
public function getRoles()
|
||||
{
|
||||
$roles = Role::all();
|
||||
|
||||
return response()->json($roles);
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,7 @@ class IndexController extends Controller
|
||||
|
||||
$fillableModel =
|
||||
|
||||
$departments = Department::with(['lpu'])->whereHas('lpu', function ($query) {
|
||||
$query->where('mainlpuid', 1);
|
||||
})->get();
|
||||
$departments = Department::all();
|
||||
|
||||
return Inertia::render('Report/Index', [
|
||||
'depatments' => $departments,
|
||||
|
||||
24
app/Http/Controllers/Web/ReportController.php
Normal file
24
app/Http/Controllers/Web/ReportController.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
$department = $user->department;
|
||||
|
||||
$beds = $department->metrikaDefault()->where('rf_metrika_item_id', 1)->first()->value;
|
||||
|
||||
return Inertia::render('Report/Index', [
|
||||
'department' => [
|
||||
'beds' => $beds
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,13 @@
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Department;
|
||||
use App\Models\MetrikaForm;
|
||||
use App\Models\MetrikaGroup;
|
||||
use App\Models\MetrikaItem;
|
||||
use App\Models\MetrikaResult;
|
||||
use App\Models\Report;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -15,6 +19,64 @@ use Inertia\Inertia;
|
||||
class StatisticController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$userDepartment = $user->department;
|
||||
|
||||
$data = [];
|
||||
|
||||
$departments = Department::select('department_id', 'name_short')->get();
|
||||
|
||||
foreach ($departments as $department) {
|
||||
$allCount = MetrikaResult::whereHas('report', function ($query) use ($userDepartment, $department) {
|
||||
$query->where('rf_department_id', $department->department_id);
|
||||
})->where('rf_metrika_item_id', 3)
|
||||
->sum(DB::raw('value::integer'));
|
||||
|
||||
$leaveCount = MetrikaResult::whereHas('report', function ($query) use ($userDepartment, $department) {
|
||||
$query->where('rf_department_id', $department->department_id);
|
||||
})->where('rf_metrika_item_id', 7)
|
||||
->sum(DB::raw('value::integer'));
|
||||
|
||||
$consistCount = optional(MetrikaResult::where('rf_metrika_item_id', 8)
|
||||
->whereHas('report', function (Builder $query) use ($department) {
|
||||
$query->where('rf_department_id', $department->department_id);
|
||||
})->join('reports', 'metrika_results.rf_report_id', '=', 'reports.report_id')
|
||||
->select('metrika_results.value')
|
||||
->orderBy('reports.sent_at', 'desc')
|
||||
)->value('value') ?? 0;
|
||||
|
||||
$beds = (int)optional($department->metrikaDefault()
|
||||
->where('rf_metrika_item_id', 1)
|
||||
->first())->value ?? 0;
|
||||
|
||||
$occupiedBeds = (int)optional(Report::where('rf_department_id', $department->department_id)
|
||||
->join('metrika_results', 'reports.report_id', '=', 'metrika_results.rf_report_id')
|
||||
->where('metrika_results.rf_metrika_item_id', 8)
|
||||
->orderBy('reports.sent_at', 'desc')
|
||||
->first())->value ?? 0;
|
||||
|
||||
$percentLoadedBeds = $beds > 0 ? $occupiedBeds * 100 / $beds : 0;
|
||||
|
||||
$data[] = [
|
||||
'department' => $department->name_short,
|
||||
'beds' => $beds,
|
||||
'all' => $allCount,
|
||||
'plan' => '0',
|
||||
'emergency' => '0',
|
||||
'leave' => $leaveCount,
|
||||
'consist' => $consistCount,
|
||||
'percentLoadedBeds' => $percentLoadedBeds,
|
||||
];
|
||||
}
|
||||
|
||||
return Inertia::render('Statistic/Index', [
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public function indexOld(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ class HandleInertiaRequests extends Middleware
|
||||
'name' => $user->name,
|
||||
'token' => Session::get('token'),
|
||||
'permissions' => $user->permissions(),
|
||||
'role' => $user->currentRole(),
|
||||
'available_departments' => $user->availableDepartments(),
|
||||
'current_department' => $user->department
|
||||
] : null,
|
||||
|
||||
27
app/Http/Resources/Mis/FormattedPatientResource.php
Normal file
27
app/Http/Resources/Mis/FormattedPatientResource.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Mis;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class FormattedPatientResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->MedicalHistoryID,
|
||||
'num' => $this->num,
|
||||
'fullname' => Str::ucwords(Str::lower("$this->FAMILY $this->Name $this->OT")),
|
||||
'age' => Carbon::parse($this->BD)->diff(Carbon::now())->format('%y'),
|
||||
'birth_date' => Carbon::parse($this->BD)->format('d.m.Y'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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