From 60ba4943191b96222c7e7e826fc2813bc1d65280 Mon Sep 17 00:00:00 2001 From: Dr Masroor Ehsan Date: Sat, 11 Jan 2025 00:53:19 +0600 Subject: [PATCH] DDL --- app/Models/Study.php | 19 ++++++------- app/Models/User.php | 6 +++++ ...2024_12_27_060234_create_studies_table.php | 6 ++--- .../2025_01_11_699508_study_assignment.php | 27 +++++++++++++++++++ 4 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 database/migrations/2025_01_11_699508_study_assignment.php diff --git a/app/Models/Study.php b/app/Models/Study.php index 59aac05..6bccc67 100644 --- a/app/Models/Study.php +++ b/app/Models/Study.php @@ -12,6 +12,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Concerns\HasTimestamps; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Support\Str; @@ -116,12 +117,12 @@ public function numInstances(): string 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 @@ -395,14 +396,14 @@ public function setReportStatus(ReportStatus $status, User|int|null $user = null switch ($status) { case ReportStatus::Finalized: - $params['reporting_physician_id'] = $user_id; - $params['reported_at'] = now(); + $params['reading_physician_id'] = $user_id; + $params['read_at'] = now(); break; case ReportStatus::Approved: - if ($this->reporting_physician_id === null) { - $params['reporting_physician_id'] = $user_id; - $params['reported_at'] = now(); + if ($this->reading_physician_id === null) { + $params['reading_physician_id'] = $user_id; + $params['read_at'] = now(); } $params['approving_physician_id'] = $user_id; $params['approved_at'] = now(); @@ -425,7 +426,7 @@ protected function casts(): array 'report_status' => ReportStatus::class, 'priority' => Priority::class, 'received_at' => 'immutable_datetime', - 'reported_at' => 'immutable_datetime', + 'read_at' => 'immutable_datetime', 'assigned_at' => 'immutable_datetime', 'study_date' => 'immutable_datetime', 'patient_birthdate' => 'immutable_date', diff --git a/app/Models/User.php b/app/Models/User.php index 5b5df38..275fa56 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -10,6 +10,7 @@ use Carbon\Carbon; use Database\Factories\UserFactory; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Facades\Storage; @@ -142,6 +143,11 @@ public function avatar(bool $gravatar = false): string 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. * 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 d38e488..80dec6b 100644 --- a/database/migrations/2024_12_27_060234_create_studies_table.php +++ b/database/migrations/2024_12_27_060234_create_studies_table.php @@ -37,7 +37,7 @@ public function up(): void $table->timestamp('received_at'); $table->timestamp('assigned_at')->nullable(); $table->timestamp('locked_at')->nullable(); - $table->timestamp('reported_at')->nullable(); + $table->timestamp('read_at')->nullable(); $table->timestamp('approved_at')->nullable(); $table->timestamp('archived_at')->nullable(); @@ -48,9 +48,9 @@ public function up(): void $table->unsignedSmallInteger('series_count')->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('reporting_physician_id')->nullable(); + $table->unsignedBigInteger('reading_physician_id')->nullable(); $table->unsignedBigInteger('approving_physician_id')->nullable(); $table->unsignedBigInteger('clinician_id')->nullable(); diff --git a/database/migrations/2025_01_11_699508_study_assignment.php b/database/migrations/2025_01_11_699508_study_assignment.php new file mode 100644 index 0000000..b516ce8 --- /dev/null +++ b/database/migrations/2025_01_11_699508_study_assignment.php @@ -0,0 +1,27 @@ +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'); + } +};