From d5a30a79eaa2f1b09a649cc7b07f5ff217e89441 Mon Sep 17 00:00:00 2001 From: Dr Masroor Ehsan Date: Tue, 7 Jan 2025 00:03:49 +0600 Subject: [PATCH] DDL --- app/DAL/{Radiologist.php => Radiologists.php} | 10 +++++----- .../Controllers/Staff/StudyAssignmentController.php | 4 ++-- database/factories/UserFactory.php | 1 - .../0001_01_01_000000_create_users_table.php | 1 - database/seeders/InstituteSeeder.php | 4 ++-- database/seeders/UserSeeder.php | 10 +++++----- 6 files changed, 14 insertions(+), 16 deletions(-) rename app/DAL/{Radiologist.php => Radiologists.php} (78%) diff --git a/app/DAL/Radiologist.php b/app/DAL/Radiologists.php similarity index 78% rename from app/DAL/Radiologist.php rename to app/DAL/Radiologists.php index 886b163..2950d56 100644 --- a/app/DAL/Radiologist.php +++ b/app/DAL/Radiologists.php @@ -5,9 +5,9 @@ use App\Services\UserService; use Illuminate\Support\Facades\DB; -final readonly class Radiologist +final readonly class Radiologists { - public static function assignables() + public static function worklist_stats(int $days, int $report_status) { $sql = <<<'SQL' SELECT @@ -26,8 +26,8 @@ public static function assignables() studies WHERE --received_at::DATE >= NOW() - INTERVAL '3 DAY' - assigned_at::DATE >= NOW() - INTERVAL '3 DAY' - AND report_status < 3 + assigned_at::DATE >= NOW() - INTERVAL '%d DAY' + AND report_status < %d AND reported_at IS NULL GROUP BY assigned_physician_id @@ -42,7 +42,7 @@ public static function assignables() users.display_name SQL; - $rows = DB::select($sql); + $rows = DB::select(sprintf($sql, $days, $report_status)); foreach ($rows as $row) { $row->last_seen = UserService::getLastSeen((int) $row->id); } diff --git a/app/Http/Controllers/Staff/StudyAssignmentController.php b/app/Http/Controllers/Staff/StudyAssignmentController.php index 6f815ca..5acaaeb 100644 --- a/app/Http/Controllers/Staff/StudyAssignmentController.php +++ b/app/Http/Controllers/Staff/StudyAssignmentController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\Staff; -use App\DAL\Radiologist; +use App\DAL\Radiologists; use App\Http\Controllers\HashidControllerBase; use App\Http\Requests\AssignPhysicianRequest; use App\Models\Enums\UserRole; @@ -18,7 +18,7 @@ public function show() $this->decodeKeys(); $study = Study::with('assignedPhysician')->findOrFail($this->key); $rads = User::active()->role(UserRole::Radiologist)->get(['id', 'display_name', 'profile_photo_path', 'first_name', 'last_name', 'created_at']); - $stats = Radiologist::assignables(); + $stats = Radiologists::worklist_stats(); foreach ($stats as $rad) { $found = $rads->where('id', $rad->id)->first(); if ($found) { diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 494bb5f..ed02dcd 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -35,7 +35,6 @@ public function definition(): array 'username' => fake()->unique()->userName(), 'email' => fake()->unique()->safeEmail(), 'email_verified_at' => fake()->dateTime(), - 'last_seen_at' => fake()->dateTime(), 'phone' => fake()->phoneNumber(), 'password' => static::$password ??= Hash::make('password'), 'two_factor_secret' => null, diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php index 572bc5e..445fffb 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/0001_01_01_000000_create_users_table.php @@ -27,7 +27,6 @@ public function up(): void $table->foreignIdFor(Institute::class)->nullable()->index(); $table->foreignIdFor(Facility::class)->nullable()->index(); $table->string('timezone')->default('Asia/Dhaka'); - $table->timestamp('last_seen_at')->nullable(); $table->rememberToken(); $table->timestamps(); }); diff --git a/database/seeders/InstituteSeeder.php b/database/seeders/InstituteSeeder.php index 322945e..4d5ee5a 100644 --- a/database/seeders/InstituteSeeder.php +++ b/database/seeders/InstituteSeeder.php @@ -19,8 +19,8 @@ public function run(): void 'name' => 'Chevron', 'is_active' => true, ]); - $srini = Institute::create([ - 'name' => 'Srinivasa', + $cmch = Institute::create([ + 'name' => 'CMCH', 'is_active' => true, ]); Institute::create([ diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 568de5d..63413fc 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -24,7 +24,7 @@ public function run(): void $usr = User::factory()->create([ 'first_name' => 'Administrator', - 'display_name' => 'Administrator', + 'display_name' => 'Admin', 'username' => 'admin', 'email' => 'admin@example.com', 'email_verified_at' => now(), @@ -33,7 +33,7 @@ public function run(): void $usr->assignRole(UserRole::Admin); $chevron = Institute::where('name', 'Chevron')->first(); - $srini = Institute::where('name', 'Srinivasa')->first(); + $cmch = Institute::where('name', 'CMCH')->first(); User::factory(2)->create([ 'institute_id' => $chevron->id, @@ -42,18 +42,18 @@ public function run(): void $u->assignRole(UserRole::Technician); }); User::factory(2)->create([ - 'institute_id' => $srini->id, + 'institute_id' => $cmch->id, ]) ->each(function ($u) { $u->assignRole(UserRole::Technician); }); - User::factory(4)->create() + User::factory(8)->create() ->each(function ($u) { $u->assignRole(UserRole::Radiologist); }); - User::factory(4)->create() + User::factory(3)->create() ->each(function ($u) { $u->assignRole(UserRole::Guest); });