diff --git a/app/DAL/Studies/TechnicianWorklist.php b/app/DAL/Studies/TechnicianWorklist.php index a4d9416..39aa898 100644 --- a/app/DAL/Studies/TechnicianWorklist.php +++ b/app/DAL/Studies/TechnicianWorklist.php @@ -9,12 +9,12 @@ final class TechnicianWorklist extends WorklistBase protected function buildQuery(?int $user_id = null): Builder { $query = $this->getStudiesQuery(); - $facility_id = auth()->user()->facility_id; - if ($facility_id) { - $query = $query->where('facility_id', $facility_id); + $department_id = auth()->user()->department_id; + if ($department_id) { + $query = $query->where('department_id', $department_id); } else { - $institute_id = auth()->user()->institute_id; - $query = $query->where('institute_id', $institute_id); + $organization_id = auth()->user()->organization_id; + $query = $query->where('organization_id', $organization_id); } return $query; diff --git a/app/Filament/Resources/FacilityResource.php b/app/Filament/Resources/FacilityResource.php index 2b50e8c..41f89d6 100644 --- a/app/Filament/Resources/FacilityResource.php +++ b/app/Filament/Resources/FacilityResource.php @@ -3,7 +3,7 @@ namespace App\Filament\Resources; use App\Filament\Resources\FacilityResource\Pages; -use App\Models\Facility; +use App\Models\Department; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; @@ -11,7 +11,7 @@ class FacilityResource extends Resource { - protected static ?string $model = Facility::class; + protected static ?string $model = Department::class; protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; diff --git a/app/Filament/Resources/InstituteResource.php b/app/Filament/Resources/InstituteResource.php index 6770a8e..c7be48a 100644 --- a/app/Filament/Resources/InstituteResource.php +++ b/app/Filament/Resources/InstituteResource.php @@ -3,7 +3,7 @@ namespace App\Filament\Resources; use App\Filament\Resources\InstituteResource\Pages; -use App\Models\Institute; +use App\Models\Organization; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; @@ -11,7 +11,7 @@ class InstituteResource extends Resource { - protected static ?string $model = Institute::class; + protected static ?string $model = Organization::class; protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; diff --git a/app/Http/Resources/InstituteResource.php b/app/Http/Resources/InstituteResource.php index a7c0e3f..b0f863a 100644 --- a/app/Http/Resources/InstituteResource.php +++ b/app/Http/Resources/InstituteResource.php @@ -2,11 +2,11 @@ namespace App\Http\Resources; -use App\Models\Institute; +use App\Models\Organization; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -/** @mixin Institute */ +/** @mixin Organization */ class InstituteResource extends JsonResource { public function toArray(Request $request): array diff --git a/app/Models/Facility.php b/app/Models/Department.php similarity index 69% rename from app/Models/Facility.php rename to app/Models/Department.php index 4744b03..398f524 100644 --- a/app/Models/Facility.php +++ b/app/Models/Department.php @@ -6,13 +6,13 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; -class Facility extends Model +class Department extends Model { use Active; - public function institute(): BelongsTo + public function organization(): BelongsTo { - return $this->belongsTo(Institute::class); + return $this->belongsTo(Organization::class); } protected function casts(): array diff --git a/app/Models/DicomRoutingRule.php b/app/Models/DicomRoutingRule.php index 45bfbf3..1fa845d 100644 --- a/app/Models/DicomRoutingRule.php +++ b/app/Models/DicomRoutingRule.php @@ -17,14 +17,14 @@ public function conditions(): HasMany return $this->hasMany(DicomRuleCondition::class); } - public function institute(): BelongsTo + public function organization(): BelongsTo { - return $this->belongsTo(Institute::class); + return $this->belongsTo(Organization::class); } - public function facility(): BelongsTo + public function department(): BelongsTo { - return $this->belongsTo(Facility::class); + return $this->belongsTo(Department::class); } public function panel(): HasOne @@ -34,7 +34,7 @@ public function panel(): HasOne public function radiologist(): HasOne { - return $this->hasOne(User::class, 'radiologist_id'); + return $this->hasOne(User::class); } protected function casts(): array diff --git a/app/Models/DicomServer.php b/app/Models/DicomServer.php index d770633..1e0e792 100644 --- a/app/Models/DicomServer.php +++ b/app/Models/DicomServer.php @@ -12,12 +12,12 @@ class DicomServer extends BaseModel public function institute(): BelongsTo { - return $this->belongsTo(Institute::class); + return $this->belongsTo(Organization::class); } public function facility(): BelongsTo { - return $this->belongsTo(Facility::class); + return $this->belongsTo(Department::class); } public function stoneViewerUrl(): Uri diff --git a/app/Models/Modality.php b/app/Models/Modality.php index e2eaa7a..565f178 100644 --- a/app/Models/Modality.php +++ b/app/Models/Modality.php @@ -2,9 +2,4 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; - -class Modality extends BaseModel -{ - use HasFactory; -} +class Modality extends BaseModel {} diff --git a/app/Models/Institute.php b/app/Models/Organization.php similarity index 72% rename from app/Models/Institute.php rename to app/Models/Organization.php index da99505..cfe2964 100644 --- a/app/Models/Institute.php +++ b/app/Models/Organization.php @@ -6,14 +6,14 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\HasMany; -class Institute extends BaseModel +class Organization extends BaseModel { use Active; use HasFactory; - public function facilities(): HasMany + public function departments(): HasMany { - return $this->hasMany(Facility::class); + return $this->hasMany(Department::class); } protected function casts(): array diff --git a/app/Models/Procedure.php b/app/Models/Procedure.php index 753bff6..7620d70 100644 --- a/app/Models/Procedure.php +++ b/app/Models/Procedure.php @@ -2,10 +2,4 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; - -class Procedure extends BaseModel -{ - use HasFactory; - -} +class Procedure extends BaseModel {} diff --git a/app/Models/User.php b/app/Models/User.php index 982418a..b53ac84 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -161,12 +161,12 @@ public function radiologistProfile(): HasOne public function institute(): BelongsTo { - return $this->belongsTo(Institute::class); + return $this->belongsTo(Organization::class); } public function facility(): BelongsTo { - return $this->belongsTo(Facility::class); + return $this->belongsTo(Department::class); } public function canAccessPanel(Panel $panel): bool diff --git a/app/Services/StudyRouter/DicomStudyRouter.php b/app/Services/StudyRouter/DicomStudyRouter.php index 735d1d0..01c6104 100644 --- a/app/Services/StudyRouter/DicomStudyRouter.php +++ b/app/Services/StudyRouter/DicomStudyRouter.php @@ -8,7 +8,7 @@ use App\Models\AssignmentPanel; use App\Models\DicomRoutingRule; use App\Models\DicomRuleCondition; -use App\Models\Institute; +use App\Models\Organization; use App\Models\User; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; @@ -80,7 +80,7 @@ private static function initialize(): void } if (self::$catchAll < 0) { - self::$catchAll = Institute::where('name', 'CATCH-ALL') + self::$catchAll = Organization::where('name', 'CATCH-ALL') ->first('id') ->id; } diff --git a/database/factories/InstituteFactory.php b/database/factories/InstituteFactory.php index b648595..617163d 100644 --- a/database/factories/InstituteFactory.php +++ b/database/factories/InstituteFactory.php @@ -2,13 +2,13 @@ namespace Database\Factories; -use App\Models\Institute; +use App\Models\Organization; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Carbon; class InstituteFactory extends Factory { - protected $model = Institute::class; + protected $model = Organization::class; public function definition(): array { diff --git a/database/migrations/0000_01_31_074312_create_dicom_servers_table.php b/database/migrations/0000_01_31_074312_create_dicom_servers_table.php index 83f695a..576bfaa 100644 --- a/database/migrations/0000_01_31_074312_create_dicom_servers_table.php +++ b/database/migrations/0000_01_31_074312_create_dicom_servers_table.php @@ -1,7 +1,7 @@ string('stone_viewer_path')->nullable(); $table->string('ohif_viewer_path')->nullable(); $table->string('meddream_viewer_path')->nullable(); - $table->foreignIdFor(Institute::class)->nullable()->index(); - $table->foreignIdFor(Facility::class)->nullable()->index(); + $table->foreignIdFor(Organization::class)->nullable()->index(); + $table->foreignIdFor(Department::class)->nullable()->index(); $table->timestamps(); }); } 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 9e3eda1..993c04a 100644 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ b/database/migrations/0001_01_01_000000_create_users_table.php @@ -1,7 +1,7 @@ id(); $table->string('guid', 40)->unique()->index()->default(DB::raw("concat('USR-', gen_random_uuid())")); - $table->boolean('is_active')->default(true); + $table->boolean('is_active')->default(true)->index(); $table->string('prefix')->nullable(); $table->string('first_name'); $table->string('last_name')->nullable(); $table->string('display_name'); $table->string('username')->unique(); + $table->string('password'); $table->string('phone')->nullable()->index(); $table->string('email')->nullable()->index(); $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); $table->foreignId('current_team_id')->nullable(); $table->string('profile_photo_path')->nullable(); - $table->foreignIdFor(Institute::class)->nullable()->index(); - $table->foreignIdFor(Facility::class)->nullable()->index(); + $table->string('signature_image_path')->nullable(); + $table->text('signature_text')->nullable(); + $table->foreignIdFor(Organization::class)->nullable()->index(); + $table->foreignIdFor(Department::class)->nullable()->index(); $table->string('timezone')->default('Asia/Dhaka'); $table->rememberToken(); $table->timestamps(); diff --git a/database/migrations/2024_12_27_060234_create_studies_table.php b/database/migrations/2024_12_27_060234_create_studies_table.php index 5e9575f..78d8e67 100644 --- a/database/migrations/2024_12_27_060234_create_studies_table.php +++ b/database/migrations/2024_12_27_060234_create_studies_table.php @@ -3,6 +3,9 @@ use App\Domain\Report\ReportStatus; use App\Domain\Study\Priority; use App\Domain\Study\StudyLevelStatus; +use App\Models\Department; +use App\Models\DicomServer; +use App\Models\Organization; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; @@ -13,11 +16,11 @@ public function up(): void { Schema::create('studies', function (Blueprint $table) { $table->id(); - $table->unsignedBigInteger('dicom_server_id')->index(); - $table->unsignedBigInteger('institute_id')->index(); - $table->unsignedBigInteger('facility_id')->nullable(); + $table->foreignIdFor(DicomServer::class)->index(); + $table->foreignIdFor(Organization::class)->index(); + $table->foreignIdFor(Department::class)->nullable()->index(); - $table->unsignedTinyInteger('priority')->default(Priority::Routine); + $table->unsignedTinyInteger('priority')->default(Priority::Routine->value); $table->unsignedTinyInteger('study_status')->default(StudyLevelStatus::Pending->value); $table->unsignedTinyInteger('report_status')->default(ReportStatus::Unread->value); @@ -59,6 +62,16 @@ public function up(): void $table->timestamps(); $table->unique(['dicom_server_id', 'orthanc_uuid']); + + $table->index(['organization_id', 'priority', 'study_date']); + $table->index(['organization_id', 'received_at']); + $table->index(['organization_id', 'assigned_at']); + $table->index(['organization_id', 'locked_at']); + + $table->index(['department_id', 'priority', 'study_date']); + $table->index(['department_id', 'received_at']); + $table->index(['department_id', 'assigned_at']); + $table->index(['department_id', 'locked_at']); }); } diff --git a/database/migrations/2024_12_28_051451_create_study_reports_table.php b/database/migrations/2024_12_28_051451_create_study_reports_table.php index dd4833d..ca13ac7 100644 --- a/database/migrations/2024_12_28_051451_create_study_reports_table.php +++ b/database/migrations/2024_12_28_051451_create_study_reports_table.php @@ -1,8 +1,8 @@ unsignedTinyInteger('report_status')->default(ReportStatus::Unread->value); $table->string('accession_number', 64)->unique()->index()->default(DB::raw("concat('REP-', gen_random_uuid())")); - $table->foreignIdFor(Institute::class)->index()->nullable()->constrained()->nullOnDelete(); - $table->foreignIdFor(Facility::class)->index()->nullable()->constrained()->nullOnDelete(); + $table->foreignIdFor(Organization::class)->index()->nullable()->constrained()->nullOnDelete(); + $table->foreignIdFor(Department::class)->index()->nullable()->constrained()->nullOnDelete(); $table->foreignIdFor(Study::class)->index()->constrained()->cascadeOnDelete(); $table->foreignIdFor(User::class, 'read_by_id')->index()->constrained()->cascadeOnDelete(); $table->foreignIdFor(User::class, 'dictated_by_id')->index()->nullable()->constrained()->nullOnDelete(); diff --git a/database/migrations/2024_12_28_175040_create_dicom_routing_rules_table.php b/database/migrations/2024_12_28_175040_create_dicom_routing_rules_table.php index 4ddb7a6..759c922 100644 --- a/database/migrations/2024_12_28_175040_create_dicom_routing_rules_table.php +++ b/database/migrations/2024_12_28_175040_create_dicom_routing_rules_table.php @@ -2,8 +2,8 @@ use App\Domain\Rule\MatchCondition; use App\Models\AssignmentPanel; -use App\Models\Facility; -use App\Models\Institute; +use App\Models\Department; +use App\Models\Organization; use App\Models\User; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; @@ -16,9 +16,9 @@ public function up(): void Schema::create('dicom_routing_rules', static function (Blueprint $table) { $table->id(); $table->boolean('is_active')->default(true); - $table->foreignIdFor(Institute::class)->constrained()->cascadeOnDelete(); - $table->foreignIdFor(Facility::class)->nullable()->constrained()->cascadeOnDelete(); - $table->foreignIdFor(User::class, 'radiologist_id')->nullable()->constrained()->nullOnDelete(); + $table->foreignIdFor(Organization::class)->constrained()->cascadeOnDelete(); + $table->foreignIdFor(Department::class)->nullable()->constrained()->cascadeOnDelete(); + $table->foreignIdFor(User::class)->nullable()->constrained()->nullOnDelete(); $table->foreignIdFor(AssignmentPanel::class)->nullable()->constrained()->nullOnDelete(); $table->string('description')->nullable(); $table->string('match_condition')->default(MatchCondition::ANY->value); diff --git a/database/migrations/2025_01_07_904595_create_radiologist_profiles.php b/database/migrations/2025_01_07_904595_create_radiologist_profiles.php deleted file mode 100644 index 2e76304..0000000 --- a/database/migrations/2025_01_07_904595_create_radiologist_profiles.php +++ /dev/null @@ -1,25 +0,0 @@ -id(); - $table->foreignIdFor(User::class)->unique()->constrained()->cascadeOnDelete(); - $table->string('signature_image_path')->nullable(); - $table->text('signature_text')->nullable(); - $table->timestamps(); - }); - } - - public function down(): void - { - Schema::dropIfExists('radiologist_profiles'); - } -}; diff --git a/database/migrations/2025_01_11_699508_study_assignment.php b/database/migrations/2025_01_11_699508_create_study_assignments_table.php similarity index 100% rename from database/migrations/2025_01_11_699508_study_assignment.php rename to database/migrations/2025_01_11_699508_create_study_assignments_table.php diff --git a/database/seeders/InstituteSeeder.php b/database/seeders/InstituteSeeder.php index eaa9c4e..2f314c3 100644 --- a/database/seeders/InstituteSeeder.php +++ b/database/seeders/InstituteSeeder.php @@ -3,9 +3,9 @@ namespace Database\Seeders; use App\Domain\Rule\MatchMode; +use App\Models\Department; use App\Models\DicomServer; -use App\Models\Facility; -use App\Models\Institute; +use App\Models\Organization; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; @@ -13,31 +13,31 @@ class InstituteSeeder extends Seeder { public function run(): void { - Institute::create([ + Organization::create([ 'name' => 'CATCH-ALL', 'is_active' => true, ]); - $chev = Institute::create([ + $chev = Organization::create([ 'name' => 'Chevron', 'is_active' => true, ]); - $cmch = Institute::create([ + $cmch = Organization::create([ 'name' => 'CMCH', 'is_active' => true, ]); - $dummy = Institute::create([ + $dummy = Organization::create([ 'name' => 'Dummy Site', 'is_active' => false, ]); - $chev_xr = Facility::create( + $chev_xr = Department::create( [ 'is_active' => true, 'name' => 'Chevron XR', 'institute_id' => $chev->id, ] ); - $cmch_mr = Facility::create( + $cmch_mr = Department::create( [ 'is_active' => false, 'name' => 'CMCH MR', diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index f438a9d..20bc2b6 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -3,7 +3,7 @@ namespace Database\Seeders; use App\Domain\ACL\Role; -use App\Models\Institute; +use App\Models\Organization; use App\Models\RadiologistProfile; use App\Models\User; use Illuminate\Database\Seeder; @@ -33,8 +33,8 @@ public function run(): void ]); $usr->assignRole(Role::Admin); - $chevron = Institute::where('name', 'Chevron')->first(); - $cmch = Institute::where('name', 'CMCH')->first(); + $chevron = Organization::where('name', 'Chevron')->first(); + $cmch = Organization::where('name', 'CMCH')->first(); User::factory(4) ->create([