This commit is contained in:
Masroor Ehsan 2025-01-08 17:16:52 +06:00
parent 1d123b845a
commit f5628a9d54
3 changed files with 37 additions and 23 deletions

View File

@ -149,7 +149,7 @@ public function getReportStatusLedAttribute(): string
public function getArchiveLink(): ?string
{
if (auth()->user()->may(Permission::StudyDownload)) {
if (me_or_other()->may(Permission::StudyDownload)) {
return PacsUrlGen::archive($this->study_instance_uid);
}
@ -158,7 +158,7 @@ public function getArchiveLink(): ?string
public function getStoneLink(): ?string
{
if (auth()->user()->may(Permission::StudyDownload)) {
if (me_or_other()->may(Permission::StudyDownload)) {
return PacsUrlGen::stoneViewer($this->study_instance_uid);
}
@ -167,7 +167,7 @@ public function getStoneLink(): ?string
public function getOhifLink(): ?string
{
if (auth()->user()->may(Permission::StudyDownload)) {
if (me_or_other()->may(Permission::StudyDownload)) {
return PacsUrlGen::ohifViewer($this->study_instance_uid);
}
@ -176,7 +176,7 @@ public function getOhifLink(): ?string
public function getOhifSegmentationLink(): ?string
{
if (auth()->user()->may(Permission::StudyDownload)) {
if (me_or_other()->may(Permission::StudyDownload)) {
return PacsUrlGen::ohifSegmentation($this->study_instance_uid);
}
@ -185,7 +185,7 @@ public function getOhifSegmentationLink(): ?string
public function getOhifMprLink(): ?string
{
if (auth()->user()->may(Permission::StudyDownload)) {
if (me_or_other()->may(Permission::StudyDownload)) {
return PacsUrlGen::ohifViewerMpr($this->study_instance_uid);
}
@ -293,11 +293,16 @@ public function isLocked(): bool
return $this->locked_at !== null;
}
public function lockStudy(?User $user = null): void
public function isUnlocked(): bool
{
return $this->locked_at === null;
}
public function lockStudy(User|int|null $user = null): void
{
$this->update(
[
'locking_physician_id' => $user?->id ?? auth()->id(),
'locking_physician_id' => me_or_other($user)->id,
'locked_at' => now(),
]
);
@ -368,12 +373,13 @@ protected function casts(): array
];
}
public function isLockedBy(?User $user): bool
public function isLockedBy(User|int|null $user = null): bool
{
if ($user === null) {
$user = auth()->user();
}
return $this->locking_physician_id === me_or_other($user)->id;
}
return $this->locking_physician_id === $user->id;
public function isAssignedTo(User|int|null $user = null): bool
{
return $this->assigned_physician_id === me_or_other($user)->id;
}
}

View File

@ -21,13 +21,7 @@ public static function of(Study $study): self
public function by(User|int|null $user): self
{
if (is_int($user)) {
$this->user = User::find($user);
} elseif ($user instanceof User) {
$this->user = $user;
} else {
$this->user = auth()->user();
}
$this->user = me_or_other($user);
return $this;
}
@ -68,16 +62,17 @@ public function canReportDownload(): bool
public function canReportEdit(): bool
{
return $this->activeStudy(fn () => $this->study->isLocked() === false &&
return $this->activeStudy(fn () => $this->study->isUnlocked() &&
$this->study->report_status <= ReportStatus::Preliminary &&
$this->study->assigned_physician_id === $this->user->id
$this->study->isAssignedTo($this->user)
);
}
public function canUnlockReport(): bool
{
return $this->activeStudy(fn () => $this->study->isLocked()
&& $this->study->locking_physician_id === $this->user->id);
return $this->activeStudy(fn () => $this->study->isLocked() &&
$this->study->isLockedBy($this->user)
);
}
private function checkUserPermission(Permission $permission): bool

View File

@ -111,3 +111,16 @@ function thumb_url(Media $media): string
return $media->getUrl('tn') ?? asset('imgs/pdf.png');
}
}
if (! function_exists('me_or_other')) {
function me_or_other(User|int|null $user = null): User
{
if (is_int($user) && $user > 0) {
return User::find($user);
} elseif ($user instanceof User) {
return $user;
} else {
return auth()->user();
}
}
}