DAL
This commit is contained in:
parent
609b6dc462
commit
0bf7da28b1
@ -2,12 +2,8 @@
|
||||
|
||||
namespace App\DAL;
|
||||
|
||||
use App\Models\Enums\ReportStatus;
|
||||
use App\Models\Study;
|
||||
use Cache;
|
||||
use DB;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
final readonly class Studies
|
||||
{
|
||||
@ -19,70 +15,4 @@ public static function getStudyIdByOrthancUuid(string $orthanc_uuid): ?int
|
||||
->where('orthanc_uuid', strtolower($orthanc_uuid))
|
||||
->value('id'));
|
||||
}
|
||||
|
||||
private static function assignedStudiesQuery(?int $user_id = null): Builder
|
||||
{
|
||||
$user_id = (int) ($user_id ?? auth()->id());
|
||||
|
||||
return Study::active()
|
||||
->where('assigned_physician_id', $user_id)
|
||||
->orderBy('study_priority', 'desc')
|
||||
->orderBy('received_at', 'asc');
|
||||
}
|
||||
|
||||
public static function getAllAssignedStudies(?int $user_id = null): LengthAwarePaginator
|
||||
{
|
||||
return self::assignedStudiesQuery($user_id)
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
|
||||
public static function getPendingAssignedStudies(?int $user_id = null): LengthAwarePaginator
|
||||
{
|
||||
return self::assignedStudiesQuery($user_id)
|
||||
->where('report_status', '<', ReportStatus::Finalized->value)
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
|
||||
public static function getCompletedAssignedStudies(?int $user_id = null): LengthAwarePaginator
|
||||
{
|
||||
return self::assignedStudiesQuery($user_id)
|
||||
->where('report_status', '=', ReportStatus::Signed->value)
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
|
||||
private static function institutedStudiesQuery(): Builder
|
||||
{
|
||||
$query = Study::active();
|
||||
$facility_id = auth()->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 $query
|
||||
->orderBy('study_priority', 'desc')
|
||||
->orderBy('received_at', 'asc');
|
||||
}
|
||||
|
||||
public static function getAllInstituteStudies(?int $user_id = null): LengthAwarePaginator
|
||||
{
|
||||
return self::institutedStudiesQuery($user_id)
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
|
||||
public static function getPendingInstituteStudies(?int $user_id = null): LengthAwarePaginator
|
||||
{
|
||||
return self::institutedStudiesQuery($user_id)
|
||||
->where('report_status', '<', ReportStatus::Finalized->value)
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
|
||||
public static function getCompletedInstituteStudies(?int $user_id = null): LengthAwarePaginator
|
||||
{
|
||||
return self::institutedStudiesQuery($user_id)
|
||||
->where('report_status', '=', ReportStatus::Signed->value)
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
}
|
||||
|
105
app/DAL/UserStudies.php
Normal file
105
app/DAL/UserStudies.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\DAL;
|
||||
|
||||
use App\Models\Enums\ReportStatus;
|
||||
use App\Models\Study;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
final readonly class UserStudies
|
||||
{
|
||||
private static function assignedStudiesQuery(?int $user_id = null): Builder
|
||||
{
|
||||
$user_id = (int) ($user_id ?? auth()->id());
|
||||
|
||||
return self::defaultSortQuery(
|
||||
Study::active()->where('assigned_physician_id', $user_id)
|
||||
);
|
||||
}
|
||||
|
||||
public static function assignedAll(?int $user_id = null): LengthAwarePaginator
|
||||
{
|
||||
return self::assignedStudiesQuery($user_id)
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
|
||||
private static function reportCompleteQuery(Builder $query): Builder
|
||||
{
|
||||
return $query->where('report_status', '=', ReportStatus::Signed->value);
|
||||
}
|
||||
|
||||
private static function defaultSortQuery(Builder $query): Builder
|
||||
{
|
||||
return $query
|
||||
->orderBy('study_priority', 'desc')
|
||||
->orderBy('received_at', 'asc');
|
||||
}
|
||||
|
||||
private static function reportPendingQuery(Builder $query): Builder
|
||||
{
|
||||
return $query->where('report_status', '<', ReportStatus::Finalized->value);
|
||||
}
|
||||
|
||||
public static function assignedPending(?int $user_id = null): LengthAwarePaginator
|
||||
{
|
||||
return self::reportPendingQuery(self::assignedStudiesQuery($user_id))
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
|
||||
public static function assignedCompleted(?int $user_id = null): LengthAwarePaginator
|
||||
{
|
||||
return self::reportCompleteQuery(self::assignedStudiesQuery($user_id))
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
|
||||
private static function institutedStudiesQuery(): Builder
|
||||
{
|
||||
$query = Study::active();
|
||||
$facility_id = auth()->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);
|
||||
}
|
||||
|
||||
public static function technicianAll(): LengthAwarePaginator
|
||||
{
|
||||
return self::institutedStudiesQuery()
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
|
||||
public static function technicianPending(): LengthAwarePaginator
|
||||
{
|
||||
return self::reportPendingQuery(self::institutedStudiesQuery())
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
|
||||
public static function technicianCompleted(): LengthAwarePaginator
|
||||
{
|
||||
return self::reportCompleteQuery(self::institutedStudiesQuery())
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
|
||||
public static function adminAll(): LengthAwarePaginator
|
||||
{
|
||||
return self::defaultSortQuery(Study::active())
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
|
||||
public static function adminPending(): LengthAwarePaginator
|
||||
{
|
||||
return self::reportPendingQuery(Study::active())
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
|
||||
public static function adminCompleted(): LengthAwarePaginator
|
||||
{
|
||||
return self::reportCompleteQuery(Study::active())
|
||||
->paginate(user_per_page());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user