seeding from CSV

This commit is contained in:
Dr Masroor Ehsan 2025-02-01 12:46:34 +06:00
parent 8565d35fe9
commit ef2dd84cfb
4 changed files with 100 additions and 199 deletions

View File

@ -15,6 +15,7 @@ public function run(): void
$this->call([
RoleSeeder::class,
OrganizationSeeder::class,
DicomServerSeeder::class,
UserSeeder::class,
ModalityProcedureSeeder::class,
]);

View File

@ -2,12 +2,42 @@
namespace Database\Seeders;
use App\Models\DicomServer;
use Illuminate\Database\Seeder;
class DicomServerSeeder extends Seeder
{
public function run(): void
{
$skip_first = true;
$csv_file = fopen(base_path('database/data/dicom-servers.csv'), 'r');
while (($data = fgetcsv($csv_file, 2000, ',')) !== false) {
if ($skip_first) {
$skip_first = false;
continue;
}
$data = array_trim_strings($data, true);
DicomServer::create([
'is_active' => (bool) $data['0'],
'server_name' => strtoupper($data['1']),
'geo_code' => $data['2'],
'host' => $data['3'],
'http_port' => $data['4'],
'dicom_port' => $data['5'],
'rest_api_endpoint' => $data['6'],
'ae_title' => strtoupper($data['7']),
'username' => strtolower($data['8'] ?? ''),
'password' => $data['9'],
'wado_path' => $data['10'],
'stone_viewer_path' => $data['11'],
'ohif_viewer_path' => $data['12'],
'meddream_viewer_path' => $data['13'],
// 'organization' => $data['14'],
// 'department' => $data['15'],
]);
}
fclose($csv_file);
}
}

View File

@ -4,7 +4,6 @@
use App\Models\Department;
use App\Models\DicomRoutingRule;
use App\Models\DicomServer;
use App\Models\Organization;
use Illuminate\Database\Seeder;
@ -12,45 +11,42 @@ class OrganizationSeeder extends Seeder
{
public function run(): void
{
Organization::create([
'name' => 'CATCH-ALL',
'is_active' => true,
]);
$chev = Organization::create([
'name' => 'Chevron',
'is_active' => true,
]);
$cmch = Organization::create([
'name' => 'CMCH',
'is_active' => true,
]);
$dummy = Organization::create([
'name' => 'Dummy Site',
'is_active' => false,
]);
$organizations = [];
$dept_chev_xr = Department::create(
[
'is_active' => true,
'name' => 'Chev-CR',
'organization_id' => $chev->id,
]
);
$chev_dep_ct_mr = Department::create(
[
'is_active' => true,
'name' => 'Chev-MR',
'organization_id' => $chev->id,
]
);
$dept_cmch_mr = Department::create(
[
'is_active' => false,
'name' => 'CMCH MR',
'organization_id' => $cmch->id,
]
);
$skip_first = true;
$org_csv = fopen(base_path('database/data/organizations.csv'), 'r');
while (($data = fgetcsv($org_csv, 2000, ',')) !== false) {
if (! $skip_first) {
$data = array_trim_strings($data);
$name = $data['0'];
$organizations[$name] = Organization::create([
'name' => $name,
'is_active' => (bool) $data['1'],
]);
}
$skip_first = false;
}
fclose($org_csv);
$dept_csv = fopen(base_path('database/data/departments.csv'), 'r');
$skip_first = true;
while (($data = fgetcsv($dept_csv, 2000, ',')) !== false) {
if (! $skip_first) {
$data = array_trim_strings($data, true);
$name = $data['2'];
$org_name = $data['1'];
$org = $organizations[$org_name];
Department::create([
'name' => $name,
'is_active' => (bool) $data['0'],
'organization_id' => $org->id,
]);
}
$skip_first = false;
}
fclose($dept_csv);
/*
$rul_chev_mr_ct = DicomRoutingRule::create(
[
'is_active' => true,
@ -71,98 +67,6 @@ public function run(): void
'priority' => 99,
]
);
DicomServer::create(
[
'is_active' => true,
'server_name' => 'CTG-1',
'geo_code' => 'BD',
'host' => 'pacs.mylabctg.com',
'http_port' => 8042,
'dicom_port' => 4242,
'rest_api_endpoint' => 'http://pacs.mylabctg.com:8042/',
'wado_path' => 'dicom-web',
'ae_title' => 'BLACKFISH',
'stone_viewer_path' => 'stone-webviewer/index.html',
'ohif_viewer_path' => 'ohif/viewer',
]
);
DicomServer::create(
[
'is_active' => true,
'server_name' => 'HEL-1',
'geo_code' => 'FI',
'host' => 'helsinki.mylabctg.com',
'http_port' => 8042,
'dicom_port' => 4242,
'rest_api_endpoint' => 'http://helsinki.mylabctg.com:8042/',
'wado_path' => 'dicom-web',
'ae_title' => 'BLACKFISH',
'stone_viewer_path' => 'stone-webviewer/index.html',
'ohif_viewer_path' => 'ohif/viewer',
]
);
DicomServer::create(
[
'is_active' => true,
'server_name' => 'SGP-1',
'geo_code' => 'SG',
'host' => 'singapore.mylabctg.com',
'http_port' => 8042,
'dicom_port' => 4242,
'rest_api_endpoint' => 'http://singapore.mylabctg.com:8042/',
'wado_path' => 'dicom-web',
'ae_title' => 'BLACKFISH',
'stone_viewer_path' => 'stone-webviewer/index.html',
'ohif_viewer_path' => 'ohif/viewer',
]
);
DicomServer::create(
[
'is_active' => true,
'server_name' => 'Texas',
'geo_code' => 'US',
'host' => 'texas.mylabctg.com',
'http_port' => 8042,
'dicom_port' => 4242,
'rest_api_endpoint' => 'http://texas.mylabctg.com:8042/',
'wado_path' => 'dicom-web',
'ae_title' => 'BLACKFISH',
'stone_viewer_path' => 'stone-webviewer/index.html',
'ohif_viewer_path' => 'ohif/viewer',
]
);
DicomServer::create(
[
'is_active' => false,
'server_name' => 'San Jose',
'geo_code' => 'US',
'host' => 'san-jose.mylabctg.com',
'http_port' => 8042,
'dicom_port' => 4242,
'rest_api_endpoint' => 'http://san-jose.mylabctg.com:8042/',
'wado_path' => 'dicom-web',
'ae_title' => 'BLACKFISH',
'stone_viewer_path' => 'stone-webviewer/index.html',
'ohif_viewer_path' => 'ohif/viewer',
]
);
DicomServer::create(
[
'is_active' => false,
'server_name' => 'MAA-1',
'host' => 'pacs.mylabctg.com',
'geo_code' => 'IN',
'http_port' => 8043,
'dicom_port' => 4242,
'rest_api_endpoint' => 'http://pacs.mylabctg.com:8042/',
'ae_title' => 'BLACKFISH',
'wado_path' => 'dicom-web',
'stone_viewer_path' => 'stone-webviewer/index.html',
'ohif_viewer_path' => 'ohif/viewer',
'organization_id' => $chev->id,
'department_id' => $dept_chev_xr->id,
]
);
*/
}
}

View File

@ -8,6 +8,7 @@
use App\Models\User;
use App\Services\Pacs\Sync\StudiesSync;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role as SpatieRole;
class UserSeeder extends Seeder
{
@ -24,75 +25,40 @@ public function run(): void
]);
$usr->assignRole(Role::SystemAgent);
$usr = User::factory()->create([
'first_name' => 'Administrator',
'display_name' => 'Admin',
'username' => 'admin',
'email' => 'admin@example.com',
'email_verified_at' => now(),
'phone' => '+8801733938582',
$orgs = Organization::pluck('id', 'name');
$depts = Department::pluck('id', 'name');
$roles = SpatieRole::pluck('id', 'name');
$skip_first = true;
$csv_file = fopen(base_path('database/data/users.csv'), 'r');
while (($data = fgetcsv($csv_file, 2000, ',')) !== false) {
if ($skip_first) {
$skip_first = false;
continue;
}
$data = array_trim_strings($data, true);
$org_id = $data[9] ? $orgs[$data[9]] : null;
$dept_id = $data[10] ? $depts[$data[10]] : null;
$role = Role::from(strtolower($data[8]));
$user = User::create([
'is_active' => true,
'display_name' => $data[0],
'prefix' => $data[1],
'first_name' => $data[2],
'last_name' => $data[3],
'signature_text' => $data[4],
'username' => $data[5],
'password' => bcrypt('password'),
'email' => strtolower($data[6]),
'phone' => (string) $data[7],
'email_verified_at' => $data[6] ? now() : null,
'organization_id' => $org_id,
'department_id' => $dept_id,
]);
$usr->assignRole(Role::Admin);
$chevron = Organization::where('name', 'Chevron')->first();
$cmch = Organization::where('name', 'CMCH')->first();
$chev_xr = Department::where('organization_id', $chevron->id)->first();
User::factory(4)
->create([
'organization_id' => $chevron->id,
])
->each(function ($u, $key) {
$u->assignRole(Role::Technician);
$u->update([
'username' => sprintf('tech%d', $key + 1),
]);
});
User::factory(4)
->create([
'organization_id' => $chevron->id,
'department_id' => $chev_xr->id,
])
->each(function ($u, $key) {
$u->assignRole(Role::Technician);
$u->update([
'username' => sprintf('xrt%d', $key + 1),
]);
});
User::factory(4)
->create([
'organization_id' => $cmch->id,
])
->each(function ($u, $key) {
$u->assignRole(Role::Technician);
$u->update([
'username' => sprintf('cmctech%d', $key + 1),
]);
});
$images = [
'hossain-saad.png', 'nasir-uddin.png', 'sadrul-amin.png',
'khairul-islam.png', 'rabeya-khatoon.png', 'subash.png',
];
User::factory(9)
->create()
->each(function (User $u, $key) use ($images) {
$u->assignRole(Role::Radiologist);
$u->update([
'display_name' => sprintf('Dr. %s.%d', $u->first_name, $key + 1),
'username' => sprintf('rad%d', $key + 1),
'signature_image_path' => 'signatures/' . fake()->randomElement($images),
]);
});
User::factory(3)
->create()
->each(function ($u) {
$u->assignRole(Role::Guest);
});
$user->assignRole($role->value);
}
fclose($csv_file);
}
}