From 5a4d7ce7b46fd2194f5ecb4cb4f3f60775c8ed38 Mon Sep 17 00:00:00 2001 From: Masroor Ehsan Date: Tue, 31 Dec 2024 16:17:01 +0600 Subject: [PATCH] wip --- app/DAL/Studies/AdminStudyLister.php | 14 +++++++ app/DAL/Studies/IUserStudyLister.php | 14 +++++++ app/DAL/Studies/RadiologistStudyLister.php | 18 +++++++++ app/DAL/Studies/TechnicianStudyLister.php | 23 +++++++++++ app/DAL/Studies/UserStudyListerBase.php | 47 ++++++++++++++++++++++ app/DAL/Studies/UserStudyListerFactory.php | 24 +++++++++++ 6 files changed, 140 insertions(+) create mode 100644 app/DAL/Studies/AdminStudyLister.php create mode 100644 app/DAL/Studies/IUserStudyLister.php create mode 100644 app/DAL/Studies/RadiologistStudyLister.php create mode 100644 app/DAL/Studies/TechnicianStudyLister.php create mode 100644 app/DAL/Studies/UserStudyListerBase.php create mode 100644 app/DAL/Studies/UserStudyListerFactory.php diff --git a/app/DAL/Studies/AdminStudyLister.php b/app/DAL/Studies/AdminStudyLister.php new file mode 100644 index 0000000..a8e63ad --- /dev/null +++ b/app/DAL/Studies/AdminStudyLister.php @@ -0,0 +1,14 @@ +id()); + + return self::defaultSortQuery( + Study::active()->where('assigned_physician_id', $user_id) + ); + } +} diff --git a/app/DAL/Studies/TechnicianStudyLister.php b/app/DAL/Studies/TechnicianStudyLister.php new file mode 100644 index 0000000..d69fd10 --- /dev/null +++ b/app/DAL/Studies/TechnicianStudyLister.php @@ -0,0 +1,23 @@ +user()->facility_id; + if ($facility_id) { + $query = $query->where('facility_id', $facility_id); + } else { + $institute_id = auth()->user()->institute_id; + $query = $query->where('institute_id', $institute_id); + } + + return self::defaultSortQuery($query); + } +} diff --git a/app/DAL/Studies/UserStudyListerBase.php b/app/DAL/Studies/UserStudyListerBase.php new file mode 100644 index 0000000..8fd6649 --- /dev/null +++ b/app/DAL/Studies/UserStudyListerBase.php @@ -0,0 +1,47 @@ +where('report_status', '=', ReportStatus::Signed->value); + } + + protected static function defaultSortQuery(Builder $query): Builder + { + return $query + ->orderBy('study_priority', 'desc') + ->orderBy('received_at', 'asc'); + } + + protected static function reportPendingQuery(Builder $query): Builder + { + return $query->where('report_status', '<', ReportStatus::Finalized->value); + } + + abstract protected static function defaultQuery(?int $user_id = null): Builder; + + public function all(?int $user_id = null): LengthAwarePaginator + { + return self::defaultQuery($user_id) + ->paginate(user_per_page($user_id)); + } + + public function pending(?int $user_id = null): LengthAwarePaginator + { + return self::reportPendingQuery(self::defaultQuery($user_id)) + ->paginate(user_per_page($user_id)); + } + + public function completed(?int $user_id = null): LengthAwarePaginator + { + return self::reportCompleteQuery(self::defaultQuery($user_id)) + ->paginate(user_per_page($user_id)); + } +} diff --git a/app/DAL/Studies/UserStudyListerFactory.php b/app/DAL/Studies/UserStudyListerFactory.php new file mode 100644 index 0000000..d223517 --- /dev/null +++ b/app/DAL/Studies/UserStudyListerFactory.php @@ -0,0 +1,24 @@ +user()->user_role; + + return match (UserRole::from($user_role)) { + UserRole::Admin => new AdminStudyLister, + UserRole::Technician => new TechnicianStudyLister, + UserRole::Radiologist => new RadiologistStudyLister, + default => throw new Exception("Unknown user role: $user_role"), + }; + } +}