refactoring
This commit is contained in:
parent
85bdcc13f8
commit
227ad59e4b
@ -5,9 +5,9 @@
|
|||||||
use App\DAL\Studies\WorklistFactory;
|
use App\DAL\Studies\WorklistFactory;
|
||||||
use App\Models\Study;
|
use App\Models\Study;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Services\ACL\AccessControl;
|
|
||||||
use App\Services\ACL\WorklistButton;
|
use App\Services\ACL\WorklistButton;
|
||||||
use App\Services\ACL\WorklistColumn;
|
use App\Services\ACL\WorklistColumn;
|
||||||
|
use App\Services\ACL\WorklistGuard;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use Closure;
|
use Closure;
|
||||||
@ -105,7 +105,7 @@ public function html(): HtmlBuilder
|
|||||||
public function getColumns(): array
|
public function getColumns(): array
|
||||||
{
|
{
|
||||||
$columns = [];
|
$columns = [];
|
||||||
foreach (AccessControl::worklistColumns() as $col) {
|
foreach (WorklistGuard::worklistColumns() as $col) {
|
||||||
switch ($col) {
|
switch ($col) {
|
||||||
case WorklistColumn::Priority:
|
case WorklistColumn::Priority:
|
||||||
$columns[] = Column::make($col->value)
|
$columns[] = Column::make($col->value)
|
||||||
@ -206,7 +206,7 @@ private function customColumns(): array
|
|||||||
{
|
{
|
||||||
$columns = [];
|
$columns = [];
|
||||||
|
|
||||||
foreach (AccessControl::worklistColumns() as $col) {
|
foreach (WorklistGuard::worklistColumns() as $col) {
|
||||||
switch ($col) {
|
switch ($col) {
|
||||||
case WorklistColumn::PatientName:
|
case WorklistColumn::PatientName:
|
||||||
$columns[$col->value] = fn (Study $study) => $study->sanitizedPatientName();
|
$columns[$col->value] = fn (Study $study) => $study->sanitizedPatientName();
|
||||||
@ -269,7 +269,7 @@ private function renderButton(string $data_id, string $fa_icon, string $data_cla
|
|||||||
private function generateButtons(Study $study): string
|
private function generateButtons(Study $study): string
|
||||||
{
|
{
|
||||||
$btns = [];
|
$btns = [];
|
||||||
foreach (AccessControl::worklistButtons() as $button) {
|
foreach (WorklistGuard::worklistButtons() as $button) {
|
||||||
switch ($button) {
|
switch ($button) {
|
||||||
case WorklistButton::StudyMetadata:
|
case WorklistButton::StudyMetadata:
|
||||||
$btns[] = $this->renderButton($study->hash, 'fa-circle-info', 'showStudy btn-outline-facebook', 'Info');
|
$btns[] = $this->renderButton($study->hash, 'fa-circle-info', 'showStudy btn-outline-facebook', 'Info');
|
||||||
|
@ -120,6 +120,11 @@ public function isAssigned(int $rad_id): bool
|
|||||||
return $this->assigned_physician_id === $rad_id;
|
return $this->assigned_physician_id === $rad_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isActive(): bool
|
||||||
|
{
|
||||||
|
return $this->is_archived === false;
|
||||||
|
}
|
||||||
|
|
||||||
public function getReportStatusLedAttribute(): string
|
public function getReportStatusLedAttribute(): string
|
||||||
{
|
{
|
||||||
$color = match ($this->report_status) {
|
$color = match ($this->report_status) {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
final readonly class AccessControl
|
final readonly class WorklistGuard
|
||||||
{
|
{
|
||||||
public static function worklistColumns(?int $user_id = null): Collection
|
public static function worklistColumns(?int $user_id = null): Collection
|
||||||
{
|
{
|
86
app/Services/Workflow/Manager.php
Normal file
86
app/Services/Workflow/Manager.php
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Workflow;
|
||||||
|
|
||||||
|
use App\Models\Enums\Permission;
|
||||||
|
use App\Models\Enums\ReportStatus;
|
||||||
|
use App\Models\Study;
|
||||||
|
use App\Models\User;
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
final class Manager
|
||||||
|
{
|
||||||
|
private ?User $user = null;
|
||||||
|
|
||||||
|
public static function of(Study $study): self
|
||||||
|
{
|
||||||
|
return new self($study);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function checkUserPermission(Permission $permission): bool
|
||||||
|
{
|
||||||
|
if (is_null($this->user)) {
|
||||||
|
$this->user = auth()->user();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->user->may($permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function can(Permission $permission): bool
|
||||||
|
{
|
||||||
|
if (! $this->checkUserPermission($permission)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prop = 'can' . $permission->name;
|
||||||
|
if (! method_exists($this, $prop)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->{$prop}();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function activeStudy(Closure $fn): bool
|
||||||
|
{
|
||||||
|
if (! $this->study->isActive()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canAssignPhysician(): bool
|
||||||
|
{
|
||||||
|
return $this->activeStudy(fn () => $this->study->report_status <= ReportStatus::Draft);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canStudyHistoryEdit(): bool
|
||||||
|
{
|
||||||
|
return $this->activeStudy(fn () => $this->study->report_status <= ReportStatus::Draft);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canAttachmentUpload(): bool
|
||||||
|
{
|
||||||
|
return $this->activeStudy(fn () => $this->study->report_status <= ReportStatus::Draft);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canReportDownload(): bool
|
||||||
|
{
|
||||||
|
return $this->activeStudy(fn () => $this->study->report_status >= ReportStatus::Finalized);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct(private readonly Study $study) {}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user