first commit
This commit is contained in:
1
dashboard/database/.gitignore
vendored
Normal file
1
dashboard/database/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
44
dashboard/database/factories/UserFactory.php
Normal file
44
dashboard/database/factories/UserFactory.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignId('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->longText('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->integer('expiration')->index();
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->integer('expiration')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cache');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('surveillances', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('code');
|
||||
$table->string('name_en');
|
||||
$table->string('name_kh');
|
||||
$table->date('start_date');
|
||||
$table->date('end_date')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('surveillances');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('surveillance_cases', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('lab_code');
|
||||
$table->integer('is_newcase');
|
||||
$table->string('sentinel_site_name');
|
||||
$table->string('site_province_name');
|
||||
$table->unsignedInteger('surveillance_id');
|
||||
$table->integer('year_data');
|
||||
$table->integer('week_data');
|
||||
$table->integer('patient_age_inday');
|
||||
$table->string('patient_sex');
|
||||
$table->tinyInteger('is_alive');
|
||||
$table->string('patient_privince');
|
||||
|
||||
$table->foreign('surveillance_id')
|
||||
->references('id')
|
||||
->on('surveillances')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->index('lab_code');
|
||||
$table->index('year_data');
|
||||
$table->index('week_data');
|
||||
$table->index('site_province_name');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('surveillance_cases');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('case_lab_results', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('lab_code');
|
||||
$table->integer('is_positive');
|
||||
$table->string('pathogen_name');
|
||||
$table->string('subtype')->nullable();
|
||||
$table->string('indicator')->nullable();
|
||||
|
||||
$table->index('lab_code');
|
||||
$table->index('pathogen_name');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('case_lab_results');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('last_synced_logs', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->unsignedInteger('surveillance_id');
|
||||
$table->dateTime('last_synced_date');
|
||||
|
||||
$table->foreign('surveillance_id')
|
||||
->references('id')
|
||||
->on('surveillances')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('last_synced_logs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('surveillance_cases', function (Blueprint $table) {
|
||||
$table->date('case_date')->after('lab_code');
|
||||
$table->index('case_date');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('surveillance_cases', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('surveillance_cases', function (Blueprint $table) {
|
||||
$table->index(['surveillance_id', 'case_date'], 'idx_surveillance_date');
|
||||
$table->index('lab_code', 'idx_lab_code');
|
||||
$table->index(['site_province_name', 'case_date'], 'idx_province_date');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('surveillance_cases', function (Blueprint $table) {
|
||||
$table->dropIndex('idx_surveillance_date');
|
||||
$table->dropIndex('idx_lab_code');
|
||||
$table->dropIndex('idx_province_date');
|
||||
});
|
||||
}
|
||||
};
|
||||
23
dashboard/database/seeders/DatabaseSeeder.php
Normal file
23
dashboard/database/seeders/DatabaseSeeder.php
Normal 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,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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 (Nov–Feb)
|
||||
$month = $current->month;
|
||||
$seasonFactor = in_array($month, [11, 12, 1, 2]) ? 1.5 : 1;
|
||||
|
||||
// covid surge 2020–2022
|
||||
$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();
|
||||
}
|
||||
}
|
||||
}
|
||||
57
dashboard/database/seeders/SurveillanceDataSeeder.php
Normal file
57
dashboard/database/seeders/SurveillanceDataSeeder.php
Normal 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
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
dashboard/database/seeders/SurveillanceSeeder.php
Normal file
36
dashboard/database/seeders/SurveillanceSeeder.php
Normal 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
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user