92 lines
2.5 KiB
PHP
92 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Domain\Report\ExportFormat;
|
|
use App\Domain\Report\ReportStatus;
|
|
use App\Services\Report\ReportStorage;
|
|
use Illuminate\Database\Eloquent\Concerns\HasTimestamps;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class StudyReport extends BaseModel
|
|
{
|
|
use HasTimestamps;
|
|
|
|
public function study(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Study::class);
|
|
}
|
|
|
|
public function radiologist(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'read_by_id');
|
|
}
|
|
|
|
public function approver(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'approved_by_id');
|
|
}
|
|
|
|
public function setStatus(ReportStatus $status, User|int|null $user = null): void
|
|
{
|
|
$user_id = me($user)->id;
|
|
$params = ['report_status' => $status->value];
|
|
switch ($status) {
|
|
case ReportStatus::Dictated:
|
|
$params['dictated_by_id'] = $user_id;
|
|
break;
|
|
case ReportStatus::Preliminary:
|
|
case ReportStatus::Finalized:
|
|
$params['read_by_id'] = $user_id;
|
|
break;
|
|
case ReportStatus::Approved:
|
|
$params['approved_by_id'] = $user_id;
|
|
break;
|
|
}
|
|
|
|
$this->update($params);
|
|
}
|
|
|
|
public function wordDownloadUrl(): string
|
|
{
|
|
return route('staff.report.download', ['uuid' => $this->accession_number, 'format' => ExportFormat::Word2007->value]);
|
|
}
|
|
|
|
public function pdfDownloadUrl(): string
|
|
{
|
|
return route('staff.report.download', ['uuid' => $this->accession_number, 'format' => ExportFormat::Pdf->value]);
|
|
}
|
|
|
|
public function htmlDownloadUrl(): string
|
|
{
|
|
return route('staff.report.download', ['uuid' => $this->accession_number, 'format' => ExportFormat::Html->value]);
|
|
}
|
|
|
|
public function viewUrl(): string
|
|
{
|
|
return route('staff.report.view', $this->accession_number);
|
|
}
|
|
|
|
public function saveContent(string $content): void
|
|
{
|
|
$this->file_path = ReportStorage::randomFilepath($this->study);
|
|
Storage::disk('public')->put($this->file_path, $content);
|
|
}
|
|
|
|
public function getContent(): ?string
|
|
{
|
|
return Storage::disk('public')->get($this->file_path);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'report_status' => ReportStatus::class,
|
|
];
|
|
}
|
|
}
|