57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Log;
|
|
use App\Models\Organization;
|
|
use App\Models\OLDLMS\Healthcare;
|
|
use Exception;
|
|
|
|
class HealthcareSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
$datas = Organization::with('addresses')
|
|
->where('type', 'hospital')
|
|
->whereNotNull('corporate_id_partner')
|
|
->get();
|
|
|
|
foreach ($datas as $data) {
|
|
// Fetch related healthcare record
|
|
$healthCare = Healthcare::where('sHealthcare', 'like', '%' . $data->name . '%')->first();
|
|
$healthCareData = [
|
|
'sHealthCare' => $data->name,
|
|
'sAlamat' => $data->addresses->first()->text ?? null, // Assuming addresses is a collection
|
|
'nIDCountry' => 1,
|
|
'sStatus' => 1,
|
|
];
|
|
|
|
try {
|
|
if ($healthCare) {
|
|
// Update healthcare record
|
|
$healthCare->update($healthCareData);
|
|
} else {
|
|
// Insert healthcare record
|
|
$healthCareData = [
|
|
'sHealthCare' => $data->name,
|
|
'sAlamat' => $data->addresses->first()->text ?? null, // Assuming addresses is a collection
|
|
'nIDCountry' => 1,
|
|
'sStatus' => 1,
|
|
'nIDHealthCareCategory' => 1
|
|
];
|
|
Healthcare::create($healthCareData);
|
|
}
|
|
} catch (Exception $e) {
|
|
dd($e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|