feat(dashboard): add sidebar, navbar, dynamic routes, summary & trend API, NIPH theme

This commit is contained in:
2026-03-03 16:40:56 +07:00
commit eb26018853
74 changed files with 12244 additions and 0 deletions

1
dashboard/database/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.sqlite*

View 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,
]);
}
}

View File

@@ -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');
}
};

View File

@@ -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');
}
};

View File

@@ -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');
}
};

View File

@@ -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');
}
};

View File

@@ -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');
}
};

View File

@@ -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');
}
};

View File

@@ -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');
}
};

View File

@@ -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) {
//
});
}
};

View File

@@ -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');
});
}
};

View File

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

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
],
]);
}
}