first commit

This commit is contained in:
2026-06-16 10:45:41 +07:00
commit ccecc0bc6b
144 changed files with 124547 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Database\Seeders\LongitudinalSurveillanceSeeder;
use Database\Seeders\SurveillanceSeeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
$this->call(
[
SurveillanceSeeder::class,
LongitudinalSurveillanceSeeder::class,
]
);
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use App\Models\Surveillance;
class LongitudinalSurveillanceSeeder extends Seeder
{
public function run(): void
{
$start = Carbon::create(2020, 1, 1);
$end = Carbon::now();
$provinces = [
'Phnom Penh',
'Siem Reap',
'Battambang',
'Kampong Cham',
'Preah Sihanouk'
];
$surveillances = Surveillance::all();
$current = $start->copy();
while ($current <= $end) {
foreach ($surveillances as $surveillance) {
// seasonal influenza peak (NovFeb)
$month = $current->month;
$seasonFactor = in_array($month, [11, 12, 1, 2]) ? 1.5 : 1;
// covid surge 20202022
$covidFactor = ($current->year <= 2022) ? 1.8 : 1;
$baseCases = rand(5, 15);
$weeklyCases = (int) ($baseCases * $seasonFactor * $covidFactor);
for ($i = 0; $i < $weeklyCases; $i++) {
$labCode = strtoupper($surveillance->code) .
'-' . $current->format('Y') .
'-' . uniqid();
DB::table('analytic.surveillance_cases')->insert([
'lab_code' => $labCode,
'is_newcase' => 1,
'sentinel_site_name' => 'Sentinel A',
'site_province_name' => $provinces[array_rand($provinces)],
'surveillance_id' => $surveillance->id,
'year_data' => $current->year,
'week_data' => $current->week,
'case_date' => $current->copy(),
'patient_age_inday' => rand(100, 25000),
'patient_sex' => rand(0, 1) ? 'M' : 'F',
'is_alive' => rand(0, 10) > 1 ? 1 : 0,
'patient_privince' => $provinces[array_rand($provinces)]
]);
$pathogen = rand(0, 1)
? 'Influenza A'
: 'SARS-CoV-2';
$isPositive = rand(0, 100) < 35 ? 1 : 0;
DB::table('analytic.case_lab_results')->insert([
'lab_code' => $labCode,
'is_positive' => $isPositive,
'pathogen_name' => $pathogen,
'subtype' => null,
'indicator' => null
]);
}
}
$current->addWeek();
}
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Carbon\Carbon;
use App\Models\Surveillance;
use App\Models\SurveillanceCase;
use App\Models\CaseLabResult;
class SurveillanceDataSeeder extends Seeder
{
public function run(): void
{
$provinces = ['Phnom Penh', 'Siem Reap', 'Battambang', 'Kampong Cham'];
$pathogens = ['Influenza A', 'Influenza B', 'SARS-CoV-2'];
$programs = Surveillance::all();
foreach ($programs as $program) {
for ($i = 0; $i < 300; $i++) {
$date = Carbon::now()->subDays(rand(0, 90));
$case = SurveillanceCase::create([
'lab_code' => uniqid('LAB'),
'case_date' => $date->toDateString(),
'is_newcase' => 1,
'sentinel_site_name' => 'Sentinel Site ' . rand(1, 5),
'site_province_name' => $provinces[array_rand($provinces)],
'surveillance_id' => $program->id,
'year_data' => $date->year,
'week_data' => $date->weekOfYear,
'patient_age_inday' => rand(100, 25000),
'patient_sex' => rand(0, 1) ? 'M' : 'F',
'is_alive' => 1,
'patient_privince' => $provinces[array_rand($provinces)]
]);
foreach ($pathogens as $pathogen) {
$positiveRate = $pathogen === 'Influenza A' ? 0.2 :
($pathogen === 'Influenza B' ? 0.15 : 0.1);
CaseLabResult::create([
'lab_code' => $case->lab_code,
'is_positive' => rand(0, 100) < ($positiveRate * 100) ? 1 : 0,
'pathogen_name' => $pathogen,
'subtype' => null,
'indicator' => null
]);
}
}
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\Surveillance;
class SurveillanceSeeder extends Seeder
{
public function run(): void
{
Surveillance::insert([
[
'code' => 'SARI',
'name_en' => 'Severe Acute Respiratory Infection',
'name_kh' => 'SARI',
'start_date' => '2026-01-01',
'end_date' => null
],
[
'code' => 'ILI',
'name_en' => 'Influenza Like Illness',
'name_kh' => 'ILI',
'start_date' => '2026-01-01',
'end_date' => null
],
[
'code' => 'AFI',
'name_en' => 'Acute Febrile Illness',
'name_kh' => 'AFI',
'start_date' => '2026-01-01',
'end_date' => null
],
]);
}
}