first commit
This commit is contained in:
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,
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user