Обновлен стартовый экран

Переписаны запросы для статистики, отчетов
Добавлена интеграция отчета сестры
This commit is contained in:
brusnitsyn
2026-05-28 22:10:00 +09:00
parent 90e0d04dfd
commit 739168d427
96 changed files with 6663 additions and 1465 deletions

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('report_duty_migration_patients', function (Blueprint $table) {
$table->bigInteger('original_id')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('report_duty_migration_patients', function (Blueprint $table) {
$table->dropColumn('original_id');
});
}
};

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('duty_report_metric_results', function (Blueprint $table) {
$table->id('metrika_result_id')
->comment('Идентификатор результата метрики');
$table->foreignIdFor(\App\Models\MetrikaItem::class, 'rf_metrika_item_id')
->comment('Идентификатор метрики')
->constrained();
$table->foreignIdFor(\App\Models\ReportDuty::class, 'rf_report_id')
->comment('Идентификатор отчета')
->constrained();
$table->text('value');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('duty_report_metric_results');
}
};

View File

@@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('report_duty_reanimations', function (Blueprint $table) {
$table->id();
$table->bigInteger('original_id')->unique();
$table->bigInteger('migration_patient_id');
$table->bigInteger('medical_history_id');
$table->dateTime('in_date')->unique();
$table->dateTime('out_date')->nullable();
$table->text('description')->nullable();
$table->text('comment')->nullable();
$table->bigInteger('stationar_branch_id');
$table->bigInteger('migration_stationar_branch_id');
$table->bigInteger('migration_department_id');
$table->bigInteger('doctor_id');
$table->bigInteger('user_id')->nullable();
$table->bigInteger('mis_user_id')->nullable();
$table->timestamps();
$table->unique(['migration_patient_id', 'in_date'], 'uniq_rdr_migration_patient_id_and_in_date');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('report_duty_reanimations');
}
};

View File

@@ -0,0 +1,48 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('observable_medical_histories', function (Blueprint $table) {
$table->id();
$table->string('source_type');
$table->bigInteger('original_id');
$table->dateTime('observable_in');
$table->dateTime('observable_out')->nullable();
$table->text('observable_reason')->nullable();
$table->text('out_reason')->nullable();
$table->string('medical_card_number')->nullable();
$table->string('full_name');
$table->date('birth_date')->nullable();
$table->dateTime('recipient_date');
$table->dateTime('extract_date')->nullable();
$table->dateTime('death_date')->nullable();
$table->boolean('male')->default(true);
$table->integer('urgency_id')->nullable();
$table->integer('hospital_result_id')->nullable();
$table->integer('visit_result_id')->nullable();
$table->text('comment')->nullable();
$table->foreignIdFor(\App\Models\User::class, 'user_id');
$table->unique(['source_type', 'original_id']); // защита от дублей
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('observable_medical_histories');
}
};

View File

@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('duty_unwanted_events', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(\App\Models\ReportDuty::class, 'report_duty_id');
$table->string('title');
$table->text('comment');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('duty_unwanted_events');
}
};

View File

@@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
// Обновляем слаги существующих ролей под единую схему
DB::table('roles')->where('slug', 'head_of_department')->update([
'slug' => 'zav',
'name' => 'Заведующий отделением',
]);
DB::table('roles')->where('slug', 'doctor')->update([
'slug' => 'dej',
'name' => 'Врач-дежурный',
]);
// Добавляем новые роли (если ещё не существуют)
$existing = DB::table('roles')->pluck('slug')->toArray();
$newRoles = [
['name' => 'Главный врач', 'slug' => 'gv', 'is_active' => true],
['name' => 'Зам. главного врача', 'slug' => 'zam', 'is_active' => true],
['name' => 'Старшая мед. сестра', 'slug' => 'nurse', 'is_active' => true],
];
foreach ($newRoles as $role) {
if (! in_array($role['slug'], $existing)) {
DB::table('roles')->insert($role);
}
}
}
public function down(): void
{
DB::table('roles')->where('slug', 'zav')->update(['slug' => 'head_of_department', 'name' => 'Заведующий отделением']);
DB::table('roles')->where('slug', 'dej')->update(['slug' => 'doctor', 'name' => 'Врач']);
DB::table('roles')->whereIn('slug', ['gv', 'zam', 'nurse'])->delete();
}
};

View File

@@ -2,61 +2,103 @@
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
class PermissionAndRoleSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
Permission::create(['name' => 'Создание отчета']);
Permission::create(['name' => 'Редактирование отчета']);
Permission::create(['name' => 'Просмотр статистики']);
// Сброс кэша перед изменениями
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
Permission::create(['name' => 'Создание и редактирование пользователей']);
Permission::create(['name' => 'Создание и редактирование прав и ролей']);
Permission::create(['name' => 'Создание и редактирование метрик']);
// --- Права ---
$permissions = [
// Сводный отчёт (дежурный)
'report.create' => 'Создание сводного отчёта',
'report.edit' => 'Редактирование сводного отчёта (текущий период)',
'report.edit.past' => 'Редактирование сводного отчёта за прошлые периоды (+ нежелательные события, пациенты на контроле)',
'report.view' => 'Просмотр отчётов',
$admin = Role::create(['name' => 'admin']);
$gv = Role::create(['name' => 'gv']);
$zam = Role::create(['name' => 'zam']);
$zav = Role::create(['name' => 'zav']);
$dej = Role::create(['name' => 'dej']);
$nurse = Role::create(['name' => 'nurse']);
// Журнал пациентов (мед. сестра)
'nurse.report.view' => 'Просмотр журнала пациентов',
'nurse.report.create' => 'Создание и редактирование журнала пациентов',
'nurse.report.edit.past' => 'Редактирование журнала пациентов за прошлые периоды',
$admin->givePermissionTo([
'Создание отчета',
'Редактирование отчета',
'Просмотр статистики',
'Создание и редактирование пользователей',
'Создание и редактирование прав и ролей',
'Создание и редактирование метрик',
// Общее
'stats.view' => 'Просмотр статистики',
'users.manage' => 'Управление пользователями',
'roles.manage' => 'Управление ролями и правами',
'metrics.manage' => 'Управление метриками',
];
foreach ($permissions as $name => $label) {
Permission::firstOrCreate(['name' => $name]);
}
// --- Роли (slug совпадает со slug в App\Models\Role) ---
$admin = Role::firstOrCreate(['name' => 'admin']); // Администратор
$gv = Role::firstOrCreate(['name' => 'gv']); // Главный врач
$zam = Role::firstOrCreate(['name' => 'zam']); // Зам. глав. врача
$zav = Role::firstOrCreate(['name' => 'zav']); // Заведующий отделением
$dej = Role::firstOrCreate(['name' => 'dej']); // Врач-дежурный
$nurse = Role::firstOrCreate(['name' => 'nurse']); // Старшая мед. сестра
// --- Назначение прав ---
$admin->syncPermissions(array_keys($permissions));
// Главный врач: полный доступ к отчётам, статистике, метрикам
$gv->syncPermissions([
'report.create',
'report.edit',
'report.edit.past',
'report.view',
'nurse.report.view',
'nurse.report.create',
'nurse.report.edit.past',
'stats.view',
'metrics.manage',
]);
$gv->givePermissionTo([
'Создание отчета',
'Редактирование отчета',
'Просмотр статистики',
// Зам. главного врача: то же что и главный врач
$zam->syncPermissions([
'report.create',
'report.edit',
'report.edit.past',
'report.view',
'nurse.report.view',
'nurse.report.create',
'nurse.report.edit.past',
'stats.view',
'metrics.manage',
]);
$zam->givePermissionTo([
'Создание отчета',
'Редактирование отчета',
'Просмотр статистики',
// Заведующий отделением: создание/редактирование отчётов своего отделения
$zav->syncPermissions([
'report.create',
'report.edit',
'report.edit.past',
'report.view',
'nurse.report.view',
'nurse.report.create',
'nurse.report.edit.past',
'stats.view',
]);
$zav->givePermissionTo([
'Создание отчета',
'Редактирование отчета',
'Просмотр статистики',
// Врач-дежурный: создание сводного + просмотр журнала (без редактирования)
$dej->syncPermissions([
'report.create',
'report.edit',
'report.view',
'nurse.report.view',
]);
$dej->givePermissionTo([
'Создание отчета',
]);
$nurse->givePermissionTo([
'Создание отчета',
// Старшая мед. сестра: журнал пациентов (создание и просмотр)
$nurse->syncPermissions([
'report.view',
'nurse.report.view',
'nurse.report.create',
]);
}
}