first commit
This commit is contained in:
22
app/Models/Department.php
Normal file
22
app/Models/Department.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Department extends Model
|
||||
{
|
||||
protected $table = 'oms_department';
|
||||
protected $primaryKey = 'departmentid';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'departmentname',
|
||||
'rf_lpuid'
|
||||
];
|
||||
|
||||
public function lpu(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
{
|
||||
return $this->hasOne(Lpu::class, 'lpuid', 'rf_lpuid');
|
||||
}
|
||||
}
|
||||
23
app/Models/Lpu.php
Normal file
23
app/Models/Lpu.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
122
app/Models/MetrikaForm.php
Normal file
122
app/Models/MetrikaForm.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MetrikaForm extends Model
|
||||
{
|
||||
protected $table = 'metrika_group_items';
|
||||
protected $primaryKey = 'metrika_group_item_id';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'rf_metrika_group_id',
|
||||
'rf_metrika_item_id'
|
||||
];
|
||||
|
||||
// Метод для получения данных формы
|
||||
public static function getFormData($groupId)
|
||||
{
|
||||
return self::with(['group', 'item'])
|
||||
->where('rf_metrika_group_id', $groupId)
|
||||
->get()
|
||||
->map(function ($formItem) {
|
||||
return [
|
||||
'metrika_group_item_id' => $formItem->metrika_group_item_id,
|
||||
'metrika_group_id' => $formItem->group->metrika_group_id,
|
||||
'metrika_group_name' => $formItem->group->name,
|
||||
'metrika_group_description' => $formItem->group->description,
|
||||
'metrika_item_id' => $formItem->item->metrika_item_id,
|
||||
'metrika_item_name' => $formItem->item->name,
|
||||
'metrika_item_description' => $formItem->item->description,
|
||||
'metrika_item_data_type' => $formItem->item->data_type,
|
||||
'validation_rules' => $formItem->item->validation_rules ?? [],
|
||||
'default_value' => $formItem->item->default_value,
|
||||
'is_required' => $formItem->item->is_required ?? false,
|
||||
'order' => $formItem->order ?? 0,
|
||||
'section' => $formItem->section ?? 'general'
|
||||
];
|
||||
})
|
||||
->sortBy('order')
|
||||
->values();
|
||||
}
|
||||
|
||||
// Связи
|
||||
public function group()
|
||||
{
|
||||
return $this->belongsTo(MetrikaGroup::class, 'rf_metrika_group_id', 'metrika_group_id');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo(MetrikaItem::class, 'rf_metrika_item_id', 'metrika_item_id');
|
||||
}
|
||||
|
||||
// Генерация схемы валидации для фронта
|
||||
public static function getValidationSchema($groupId)
|
||||
{
|
||||
$formItems = self::getFormData($groupId);
|
||||
|
||||
$schema = [];
|
||||
$defaults = [];
|
||||
|
||||
foreach ($formItems as $item) {
|
||||
$fieldName = "metrika_item_{$item['metrika_item_id']}";
|
||||
|
||||
// Правила валидации
|
||||
$rules = [];
|
||||
|
||||
if ($item['is_required']) {
|
||||
$rules[] = 'required';
|
||||
}
|
||||
|
||||
if ($item['validation_rules']) {
|
||||
foreach ($item['validation_rules'] as $rule => $value) {
|
||||
switch ($rule) {
|
||||
case 'min':
|
||||
$rules[] = "min:{$value}";
|
||||
break;
|
||||
case 'max':
|
||||
$rules[] = "max:{$value}";
|
||||
break;
|
||||
case 'numeric':
|
||||
$rules[] = 'numeric';
|
||||
break;
|
||||
case 'integer':
|
||||
$rules[] = 'integer';
|
||||
break;
|
||||
case 'string':
|
||||
$rules[] = 'string';
|
||||
break;
|
||||
case 'boolean':
|
||||
$rules[] = 'boolean';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$schema[$fieldName] = $rules;
|
||||
|
||||
// Значение по умолчанию
|
||||
$defaults[$fieldName] = $item['default_value'] ?? self::getDefaultByType($item['metrika_item_data_type']);
|
||||
}
|
||||
|
||||
return [
|
||||
'schema' => $schema,
|
||||
'defaults' => $defaults,
|
||||
'fields' => $formItems
|
||||
];
|
||||
}
|
||||
|
||||
private static function getDefaultByType($dataType)
|
||||
{
|
||||
return match($dataType) {
|
||||
'integer', 'float' => 0,
|
||||
'string', 'text' => '',
|
||||
'boolean' => false,
|
||||
'select' => null,
|
||||
default => ''
|
||||
};
|
||||
}
|
||||
}
|
||||
17
app/Models/MetrikaGroup.php
Normal file
17
app/Models/MetrikaGroup.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MetrikaGroup extends Model
|
||||
{
|
||||
protected $primaryKey = 'metrika_group_id';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'metrika_group_id',
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
}
|
||||
26
app/Models/MetrikaGroupItem.php
Normal file
26
app/Models/MetrikaGroupItem.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MetrikaGroupItem extends Model
|
||||
{
|
||||
protected $primaryKey = 'metrika_group_item_id';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'rf_metrika_group_id',
|
||||
'rf_metrika_item_id',
|
||||
];
|
||||
|
||||
public function group(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MetrikaGroup::class, 'rf_metrika_group_id', 'metrika_group_id');
|
||||
}
|
||||
|
||||
public function item(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MetrikaItem::class, 'rf_metrika_item_id', 'metrika_item_id');
|
||||
}
|
||||
}
|
||||
19
app/Models/MetrikaItem.php
Normal file
19
app/Models/MetrikaItem.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MetrikaItem extends Model
|
||||
{
|
||||
protected $primaryKey = 'metrika_item_id';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'metrika_item_id',
|
||||
'name',
|
||||
'description',
|
||||
'data_type',
|
||||
'is_active',
|
||||
];
|
||||
}
|
||||
32
app/Models/MetrikaResult.php
Normal file
32
app/Models/MetrikaResult.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class MetrikaResult extends Model
|
||||
{
|
||||
protected $primaryKey = 'metrika_result_id';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'rf_report_id',
|
||||
'rf_metrika_group_id',
|
||||
];
|
||||
|
||||
public function report(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
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 values(): HasMany
|
||||
{
|
||||
return $this->hasMany(MetrikaResultValue::class, 'rf_metrika_result_id', 'metrika_result_id');
|
||||
}
|
||||
}
|
||||
27
app/Models/MetrikaResultValue.php
Normal file
27
app/Models/MetrikaResultValue.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MetrikaResultValue extends Model
|
||||
{
|
||||
protected $primaryKey = 'metrika_result_value_id';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'rf_metrika_result_id',
|
||||
'rf_metrika_item_id',
|
||||
'value',
|
||||
];
|
||||
|
||||
public function result()
|
||||
{
|
||||
return $this->belongsTo(MetrikaResult::class, 'rf_metrika_result_id', 'metrika_result_id');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo(MetrikaItem::class, 'rf_metrika_item_id', 'metrika_item_id');
|
||||
}
|
||||
}
|
||||
23
app/Models/Report.php
Normal file
23
app/Models/Report.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Report extends Model
|
||||
{
|
||||
protected $primaryKey = 'report_id';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'created_at',
|
||||
'sent_at',
|
||||
'rf_department_id',
|
||||
'rf_user_id',
|
||||
];
|
||||
|
||||
public function metrikaResults(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MetrikaResult::class, 'rf_report_id', 'report_id');
|
||||
}
|
||||
}
|
||||
130
app/Models/User.php
Normal file
130
app/Models/User.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user