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