This commit is contained in:
Dr Masroor Ehsan 2025-01-11 00:53:19 +06:00
parent 34638604c1
commit 60ba494319
4 changed files with 46 additions and 12 deletions

View File

@ -12,6 +12,7 @@
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Concerns\HasTimestamps; use Illuminate\Database\Eloquent\Concerns\HasTimestamps;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Str; use Illuminate\Support\Str;
@ -116,12 +117,12 @@ public function numInstances(): string
public function readingPhysician(): BelongsTo public function readingPhysician(): BelongsTo
{ {
return $this->belongsTo(User::class, 'reporting_physician_id'); return $this->belongsTo(User::class, 'reading_physician_id');
} }
public function assignedPhysician(): BelongsTo public function assignedPhysicians(): BelongsToMany
{ {
return $this->belongsTo(User::class, 'assigned_physician_id'); return $this->belongsToMany(User::class, 'study_assignments');
} }
public function dicomServer(): BelongsTo public function dicomServer(): BelongsTo
@ -395,14 +396,14 @@ public function setReportStatus(ReportStatus $status, User|int|null $user = null
switch ($status) { switch ($status) {
case ReportStatus::Finalized: case ReportStatus::Finalized:
$params['reporting_physician_id'] = $user_id; $params['reading_physician_id'] = $user_id;
$params['reported_at'] = now(); $params['read_at'] = now();
break; break;
case ReportStatus::Approved: case ReportStatus::Approved:
if ($this->reporting_physician_id === null) { if ($this->reading_physician_id === null) {
$params['reporting_physician_id'] = $user_id; $params['reading_physician_id'] = $user_id;
$params['reported_at'] = now(); $params['read_at'] = now();
} }
$params['approving_physician_id'] = $user_id; $params['approving_physician_id'] = $user_id;
$params['approved_at'] = now(); $params['approved_at'] = now();
@ -425,7 +426,7 @@ protected function casts(): array
'report_status' => ReportStatus::class, 'report_status' => ReportStatus::class,
'priority' => Priority::class, 'priority' => Priority::class,
'received_at' => 'immutable_datetime', 'received_at' => 'immutable_datetime',
'reported_at' => 'immutable_datetime', 'read_at' => 'immutable_datetime',
'assigned_at' => 'immutable_datetime', 'assigned_at' => 'immutable_datetime',
'study_date' => 'immutable_datetime', 'study_date' => 'immutable_datetime',
'patient_birthdate' => 'immutable_date', 'patient_birthdate' => 'immutable_date',

View File

@ -10,6 +10,7 @@
use Carbon\Carbon; use Carbon\Carbon;
use Database\Factories\UserFactory; use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
@ -142,6 +143,11 @@ public function avatar(bool $gravatar = false): string
return (new Avatar)->create($this->name)->toBase64(); return (new Avatar)->create($this->name)->toBase64();
} }
public function assignedStudies(): BelongsToMany
{
return $this->belongsToMany(Study::class, 'study_assignments');
}
/** /**
* Get the attributes that should be cast. * Get the attributes that should be cast.
* *

View File

@ -37,7 +37,7 @@ public function up(): void
$table->timestamp('received_at'); $table->timestamp('received_at');
$table->timestamp('assigned_at')->nullable(); $table->timestamp('assigned_at')->nullable();
$table->timestamp('locked_at')->nullable(); $table->timestamp('locked_at')->nullable();
$table->timestamp('reported_at')->nullable(); $table->timestamp('read_at')->nullable();
$table->timestamp('approved_at')->nullable(); $table->timestamp('approved_at')->nullable();
$table->timestamp('archived_at')->nullable(); $table->timestamp('archived_at')->nullable();
@ -48,9 +48,9 @@ public function up(): void
$table->unsignedSmallInteger('series_count')->nullable(); $table->unsignedSmallInteger('series_count')->nullable();
$table->unsignedInteger('disk_size')->nullable(); $table->unsignedInteger('disk_size')->nullable();
$table->unsignedBigInteger('assigned_physician_id')->nullable(); // $table->unsignedBigInteger('assigned_physician_id')->nullable();
$table->unsignedBigInteger('locking_physician_id')->nullable(); $table->unsignedBigInteger('locking_physician_id')->nullable();
$table->unsignedBigInteger('reporting_physician_id')->nullable(); $table->unsignedBigInteger('reading_physician_id')->nullable();
$table->unsignedBigInteger('approving_physician_id')->nullable(); $table->unsignedBigInteger('approving_physician_id')->nullable();
$table->unsignedBigInteger('clinician_id')->nullable(); $table->unsignedBigInteger('clinician_id')->nullable();

View File

@ -0,0 +1,27 @@
<?php
use App\Models\Study;
use App\Models\User;
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::create('study_assignments', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(Study::class)->constrained()->cascadeOnDelete();
$table->foreignIdFor(User::class)->nullable()->constrained()->nullOnDelete();
$table->timestamps();
$table->unique(['study_id', 'user_id']);
});
}
public function down(): void
{
Schema::dropIfExists('study_assignments');
}
};