removed report_status

This commit is contained in:
Dr Masroor Ehsan 2025-01-29 21:47:50 +06:00
parent 9e2315b89b
commit ba705bb98b
12 changed files with 59 additions and 90 deletions

View File

@ -2,7 +2,6 @@
namespace App\DAL\Studies;
use App\Domain\Report\ReportStatus;
use App\Domain\Study\WorkflowLevel;
use App\Models\Study;
use Carbon\Carbon;
@ -21,8 +20,6 @@ abstract class WorklistBase implements IUserStudyLister
private ?WorkflowLevel $workflowLevel = null;
private ?ReportStatus $reportStatus = null;
private ?bool $locked = null;
private ?bool $archived = null;
@ -41,7 +38,7 @@ abstract class WorklistBase implements IUserStudyLister
protected static function reportCompleteQuery(Builder $query): Builder
{
return $query->where('report_status', '=', ReportStatus::Approved->value);
return $query->where('workflow_level', '=', WorkflowLevel::Published->value);
}
public function setRadiologist(int $radiologist_id): self
@ -58,13 +55,6 @@ public function setWorkflowLevel(WorkflowLevel $status): self
return $this;
}
public function setReportStatus(ReportStatus $status): self
{
$this->reportStatus = $status;
return $this;
}
public function query(?int $user_id = null): Builder
{
$query = $this->buildQuery($user_id);
@ -236,15 +226,6 @@ private function applyWorkflowLevel(Builder $query): Builder
return $query;
}
private function applyReportStatus(Builder $query): Builder
{
if ($this->reportStatus != null) {
$query = $query->where('report_status', '=', $this->reportStatus->value);
}
return $query;
}
private function getPageSize(?int $user_id = null): int
{
return $this->perPage ?? user_per_page($user_id);

View File

@ -3,7 +3,7 @@
namespace App\DataTables;
use App\DAL\Studies\WorklistFactory;
use App\Domain\Report\ReportStatus;
use App\Domain\Study\WorkflowLevel;
use App\Models\Study;
use App\Services\ACL\WorklistButton;
use App\Services\ACL\WorklistColumn;
@ -330,10 +330,10 @@ private function filterStatus(QueryBuilder $query, ?string $status): void
switch ($status) {
case 'unread':
$query->where('report_status', '<', ReportStatus::Finalized->value);
$query->where('workflow_level', '<', WorkflowLevel::Finalized->value);
break;
case 'read':
$query->where('report_status', '>=', ReportStatus::Finalized->value);
$query->where('workflow_level', '>=', WorkflowLevel::Finalized->value);
break;
case 'progress':
$query->whereNotNull('locked_at');

View File

@ -1,14 +0,0 @@
<?php
namespace App\Domain\Report;
enum ReportStatus: int
{
case Unread = 0;
case Dictated = 10;
case Transcribed = 20;
case Preliminary = 30;
case Finalized = 40;
case Approved = 90;
case Cancelled = 199;
}

View File

@ -4,16 +4,18 @@
enum WorkflowLevel: int
{
case Received = 0;
case Unassigned = 10;
case Assigned = 20;
case Repetition = 30;
case ReadInProgress = 40;
case DraftAvailable = 50;
case Finalized = 60;
case UnderReview = 70;
case Published = 80;
case Archived = 160;
case Received = 10;
case Unassigned = 20;
case Assigned = 30;
case Dictated = 40;
case Transcribed = 50;
case Repetition = 60;
case ReadInProgress = 70;
case DraftAvailable = 80;
case Finalized = 90;
case UnderReview = 100;
case Published = 110;
case Archived = 200;
case Cancelled = 240;
public function description(): string
@ -22,13 +24,15 @@ public function description(): string
self::Received => 'Study Received',
self::Unassigned => 'Unassigned',
self::Assigned => 'Assigned',
self::Dictated => 'Dictated',
self::Transcribed => 'Transcribed',
self::Repetition => 'Repetition',
self::ReadInProgress => 'Read In Progress',
self::DraftAvailable => 'Draft Available',
self::Finalized => 'Finalized',
self::DraftAvailable => 'Draft interpretation available',
self::Finalized => 'Repoort finalized',
self::UnderReview => 'Under Review',
self::Published => 'Published',
self::Archived => 'Archived',
self::Published => 'Report published',
self::Archived => 'Study archived',
self::Cancelled => 'Cancelled',
};
}

View File

@ -3,7 +3,7 @@
namespace App\Http\Controllers\Staff;
use App\Domain\ACL\Permission;
use App\Domain\Report\ReportStatus;
use App\Domain\Study\WorkflowLevel;
use App\Http\Controllers\HashedStudyControllerBase;
use App\Http\Requests\StudyMetadataUpdateRequest;
use App\Models\Study;
@ -32,7 +32,7 @@ public function edit()
public function save(StudyMetadataUpdateRequest $request)
{
abort_unless(auth()->user()->may(Permission::StudyMetadataEdit), 403);
abort_unless(may(Permission::StudyMetadataEdit), 403);
$study = $this->getStudy();
if ($study->isReportReady()) {
return $this->lockedNotice();
@ -43,7 +43,7 @@ public function save(StudyMetadataUpdateRequest $request)
$payload['patient_sex'] = strtoupper($payload['patient_sex']);
if ($request->has('cancel_read')) {
// lock the study if report is not needed
$payload['report_status'] = ReportStatus::Cancelled->value;
$payload['workflow_level'] = WorkflowLevel::Cancelled->value;
$payload['locked_at'] = now();
unset($payload['cancel_read']);
}

View File

@ -2,7 +2,7 @@
namespace App\Http\Controllers\Staff;
use App\Domain\Report\ReportStatus;
use App\Domain\Study\WorkflowLevel;
use App\Http\Controllers\HashidControllerBase;
use App\Http\Requests\StoreReportRequest;
use App\Models\Study;
@ -39,10 +39,10 @@ public function save(StoreReportRequest $request)
ReportManager::ensureEditAccess();
$this->decodeKeys();
$manager = ReportManager::make($this->key);
$reportStatus = ReportStatus::from($request->integer('report_status'));
$report = $manager->createReport(request('content'), $reportStatus);
$workflow_level = WorkflowLevel::from($request->integer('report_status'));
$report = $manager->createReport(request('content'), $workflow_level);
if ($reportStatus->value === ReportStatus::Finalized->value) {
if ($workflow_level->value === WorkflowLevel::Finalized->value) {
$manager->finalizeReport($report);
}

View File

@ -2,7 +2,7 @@
namespace App\Http\Requests;
use App\Domain\Report\ReportStatus;
use App\Domain\Study\WorkflowLevel;
use App\Models\Study;
use App\Rules\ExistsByHash;
use Illuminate\Foundation\Http\FormRequest;
@ -22,7 +22,7 @@ public function rules(): array
'content' => 'required',
'report_status' => [
'required',
Rule::enum(ReportStatus::class)->only([ReportStatus::Preliminary, ReportStatus::Finalized, ReportStatus::Approved]),
Rule::enum(WorkflowLevel::class)->only([WorkflowLevel::DraftAvailable, WorkflowLevel::Finalized, WorkflowLevel::Published]),
],
];
}

View File

@ -457,18 +457,18 @@ public function canObtainLock(User|int|null $user = null): bool
return $this->isUnlocked() || $this->isLockedBy($user);
}
public function setReportStatus(ReportStatus $status, User|int|null $user = null): void
public function setReportWorkflowLevel(WorkflowLevel $level, User|int|null $user = null): void
{
$user_id = me($user)->id;
$params = ['report_status' => $status->value];
$params = ['workflow_level' => $level->value];
switch ($status) {
case ReportStatus::Finalized:
switch ($level) {
case WorkflowLevel::Finalized:
$params['reading_physician_id'] = $user_id;
$params['read_at'] = now();
break;
case ReportStatus::Approved:
case WorkflowLevel::Published:
if ($this->reading_physician_id === null) {
$params['reading_physician_id'] = $user_id;
$params['read_at'] = now();
@ -532,7 +532,6 @@ protected function casts(): array
{
return [
'workflow_level' => WorkflowLevel::class,
'report_status' => ReportStatus::class,
'priority' => Priority::class,
'archived_at' => 'immutable_datetime',
'approved_at' => 'immutable_datetime',

View File

@ -3,7 +3,6 @@
namespace App\Models;
use App\Domain\Report\ExportFormat;
use App\Domain\Report\ReportStatus;
use App\Domain\Study\WorkflowLevel;
use App\Services\Report\ReportStorage;
use Illuminate\Database\Eloquent\Builder;
@ -44,19 +43,19 @@ public function scopeForStudy(Builder $query, Study|int $study): Builder
return $query;
}
public function setStatus(ReportStatus $status, User|int|null $user = null): void
public function setWorkflowLevel(WorkflowLevel $level, User|int|null $user = null): void
{
$user_id = me($user)->id;
$params = ['report_status' => $status->value];
switch ($status) {
case ReportStatus::Dictated:
$params = ['workflow_level' => $level->value];
switch ($level) {
case WorkflowLevel::Dictated:
$params['dictated_by_id'] = $user_id;
break;
case ReportStatus::Preliminary:
case ReportStatus::Finalized:
case WorkflowLevel::DraftAvailable:
case WorkflowLevel::Finalized:
$params['read_by_id'] = $user_id;
break;
case ReportStatus::Approved:
case WorkflowLevel::Published:
$params['approved_by_id'] = $user_id;
break;
}
@ -138,7 +137,7 @@ public function isFinalized(): bool
protected function casts(): array
{
return [
'report_status' => ReportStatus::class,
'workflow_level' => WorkflowLevel::class,
];
}
}

View File

@ -9,13 +9,6 @@ final class RoleService
{
private static array $roles = [];
private static function initCache(): void
{
if (empty(self::$roles)) {
self::$roles = SpatieRole::pluck('id', 'name')->toArray();
}
}
public static function select(): array
{
// self::initCache();
@ -25,4 +18,11 @@ public static function select(): array
->mapWithKeys(fn (Role $r) => [$r->value => $r->name])
->toArray();
}
private static function initCache(): void
{
if (empty(self::$roles)) {
self::$roles = SpatieRole::pluck('id', 'name')->toArray();
}
}
}

View File

@ -3,7 +3,7 @@
namespace App\Services\Report;
use App\Domain\ACL\Permission;
use App\Domain\Report\ReportStatus;
use App\Domain\Study\WorkflowLevel;
use App\Models\Study;
use App\Models\StudyReport;
use App\Services\AuditTrail\Activity;
@ -41,13 +41,13 @@ public function getReports(): Collection
return $this->study->reports->sortByDesc('created_at');
}
public function createReport(string $content, ReportStatus $status): StudyReport
public function createReport(string $content, WorkflowLevel $level): StudyReport
{
$report = StudyReport::make([
'study_id' => $this->study->id,
'organization_id' => $this->study->organization_id,
'department_id' => $this->study->department_id,
'report_status' => $status->value,
'workflow_level' => $level->value,
'read_by_id' => me()->id,
]);
$report->saveContent($content);
@ -65,14 +65,14 @@ public function createReport(string $content, ReportStatus $status): StudyReport
public function finalizeReport(StudyReport $report): void
{
$report->setStatus(ReportStatus::Finalized);
$report->setWorkflowLevel(WorkflowLevel::Finalized);
audit()
->on($this->study)
->did(Activity::Report_Finalize)
->notes($report->accession_number)
->log();
$this->study->setReportStatus(ReportStatus::Finalized);
$this->study->setReportWorkflowLevel(WorkflowLevel::Finalized);
audit()
->on($this->study)
@ -123,7 +123,7 @@ public function lockStudyIfRequired(): void
public function latestReport(): ?StudyReport
{
return StudyReport::forStudy($this->study)
->where('report_status', ReportStatus::Preliminary->value)
->where('workflow_level', WorkflowLevel::DraftAvailable->value)
->select(['id', 'accession_number', 'file_path'])
->latest()
->first();

View File

@ -52,7 +52,7 @@ class="ck-editor editor-container editor-container_classic-editor fixed-containe
<div class="form-check form-check-success custom-option custom-option-basic">
<label class="form-check-label custom-option-content" for="radio_prelim">
<input name="report_status" class="form-check-input" type="radio"
value="{{ \App\Domain\Report\ReportStatus::Preliminary->value }}"
value="{{ \App\Domain\Study\WorkflowLevel::DraftAvailable->value }}"
id="radio_prelim" checked/>
<span class="custom-option-body">
@ -68,7 +68,7 @@ class="ck-editor editor-container editor-container_classic-editor fixed-containe
<div class="form-check form-check-success custom-option custom-option-basic">
<label class="form-check-label custom-option-content" for="radio_final">
<input name="report_status" class="form-check-input" type="radio"
value="{{ \App\Domain\Report\ReportStatus::Finalized->value }}"
value="{{ \App\Domain\Study\WorkflowLevel::Finalized->value }}"
id="radio_final"/>
<span class="custom-option-body">