first commit
This commit is contained in:
28
database/seeders/DatabaseSeeder.php
Normal file
28
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// User::factory(10)->create();
|
||||
|
||||
User::factory()->create([
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
]);
|
||||
|
||||
$this->call(ProfileSeeder::class);
|
||||
$this->call(HospitalUnitSeeder::class);
|
||||
$this->call(DepartmentSeeder::class);
|
||||
$this->call(MedicalReportSeeder::class);
|
||||
}
|
||||
}
|
||||
42
database/seeders/DepartmentSeeder.php
Normal file
42
database/seeders/DepartmentSeeder.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\HospitalUnit;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DepartmentSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$departmentUnitMap = collect(config('medical-report.hospital_department_unit_map', []))
|
||||
->filter(fn (mixed $value, mixed $key): bool => is_string($key) && $key !== '' && is_string($value) && $value !== '');
|
||||
|
||||
collect(config('medical-report.hospital_departments', []))
|
||||
->filter(fn (mixed $name): bool => is_string($name) && trim($name) !== '')
|
||||
->each(function (string $name) use ($departmentUnitMap): void {
|
||||
$hospitalUnitId = null;
|
||||
$mappedUnitName = $departmentUnitMap->get($name);
|
||||
|
||||
if (is_string($mappedUnitName) && $mappedUnitName !== '') {
|
||||
$hospitalUnitId = HospitalUnit::query()
|
||||
->where('name', $mappedUnitName)
|
||||
->value('id');
|
||||
}
|
||||
|
||||
Department::query()->updateOrCreate(
|
||||
['code' => Str::slug(Str::ascii($name))],
|
||||
[
|
||||
'name' => $name,
|
||||
'hospital_unit_id' => $hospitalUnitId,
|
||||
'is_active' => true,
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
43
database/seeders/HospitalUnitSeeder.php
Normal file
43
database/seeders/HospitalUnitSeeder.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\HospitalUnit;
|
||||
use App\Models\Profile;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class HospitalUnitSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$reportingUnits = collect(config('medical-report.reporting_units', []))
|
||||
->filter(fn (mixed $value): bool => is_string($value) && trim($value) !== '')
|
||||
->values();
|
||||
$reportInputTypes = config('medical-report.reporting_unit_input_types', []);
|
||||
|
||||
collect(config('medical-report.finance_profiles', []))
|
||||
->each(function (array $profile) use ($reportingUnits, $reportInputTypes): void {
|
||||
$profileModel = Profile::query()->where('name', $profile['name'])->firstOrFail();
|
||||
|
||||
collect($profile['units'] ?? [])
|
||||
->filter(fn (mixed $value): bool => is_string($value) && trim($value) !== '')
|
||||
->values()
|
||||
->each(function (string $unitName) use ($profileModel, $reportingUnits, $reportInputTypes): void {
|
||||
HospitalUnit::query()->updateOrCreate(
|
||||
['slug' => Str::slug(Str::ascii($unitName))],
|
||||
[
|
||||
'profile_id' => $profileModel->id,
|
||||
'name' => $unitName,
|
||||
'is_reporting_unit' => $reportingUnits->contains($unitName),
|
||||
'report_input_type' => $reportInputTypes[$unitName] ?? null,
|
||||
'is_active' => true,
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
23
database/seeders/MedicalReportSeeder.php
Normal file
23
database/seeders/MedicalReportSeeder.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\MedicalReport;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class MedicalReportSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
MedicalReport::query()->firstOrCreate(
|
||||
['year' => 2026],
|
||||
[
|
||||
'name' => 'МЕД 2026',
|
||||
'input_overrides' => [],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
24
database/seeders/ProfileSeeder.php
Normal file
24
database/seeders/ProfileSeeder.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Profile;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ProfileSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
collect(config('medical-report.finance_profiles', []))
|
||||
->values()
|
||||
->each(function (array $profile, int $index): void {
|
||||
Profile::query()->updateOrCreate(
|
||||
['name' => $profile['name']],
|
||||
['sort_order' => $index + 1],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user