DAL
This commit is contained in:
parent
3ac07d8853
commit
609b6dc462
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
namespace App\DAL;
|
namespace App\DAL;
|
||||||
|
|
||||||
|
use App\Models\Enums\ReportStatus;
|
||||||
use App\Models\Study;
|
use App\Models\Study;
|
||||||
use Cache;
|
use Cache;
|
||||||
use DB;
|
use DB;
|
||||||
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Database\Query\Builder;
|
use Illuminate\Database\Query\Builder;
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
final readonly class Studies
|
final readonly class Studies
|
||||||
{
|
{
|
||||||
@ -19,7 +20,7 @@ public static function getStudyIdByOrthancUuid(string $orthanc_uuid): ?int
|
|||||||
->value('id'));
|
->value('id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function assignedQuery(?int $user_id = null): Builder
|
private static function assignedStudiesQuery(?int $user_id = null): Builder
|
||||||
{
|
{
|
||||||
$user_id = (int) ($user_id ?? auth()->id());
|
$user_id = (int) ($user_id ?? auth()->id());
|
||||||
|
|
||||||
@ -29,41 +30,59 @@ private static function assignedQuery(?int $user_id = null): Builder
|
|||||||
->orderBy('received_at', 'asc');
|
->orderBy('received_at', 'asc');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAllAssignedStudies(?int $user_id = null): Collection
|
public static function getAllAssignedStudies(?int $user_id = null): LengthAwarePaginator
|
||||||
{
|
{
|
||||||
$user_id = (int) ($user_id ?? auth()->id());
|
return self::assignedStudiesQuery($user_id)
|
||||||
$per_page = settings()->get("user.{$user_id}.pagination.per_page", config('app.pagination.per_page'));
|
->paginate(user_per_page());
|
||||||
|
|
||||||
return Study::active()
|
|
||||||
->where('assigned_physician_id', $user_id)
|
|
||||||
->orderBy('study_priority', 'desc')
|
|
||||||
->orderBy('received_at', 'asc')
|
|
||||||
->paginate($per_page);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPendingAssignedStudies(?int $user_id = null): Collection
|
public static function getPendingAssignedStudies(?int $user_id = null): LengthAwarePaginator
|
||||||
{
|
{
|
||||||
$user_id = (int) ($user_id ?? auth()->id());
|
return self::assignedStudiesQuery($user_id)
|
||||||
$per_page = settings()->get("user.{$user_id}.pagination.per_page", config('app.pagination.per_page'));
|
|
||||||
|
|
||||||
return Study::active()
|
|
||||||
->where('assigned_physician_id', $user_id)
|
|
||||||
->where('report_status', '<', ReportStatus::Finalized->value)
|
->where('report_status', '<', ReportStatus::Finalized->value)
|
||||||
->orderBy('study_priority', 'desc')
|
->paginate(user_per_page());
|
||||||
->orderBy('received_at', 'asc')
|
|
||||||
->paginate($per_page);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getCompletedAssignedStudies(?int $user_id = null): Collection
|
public static function getCompletedAssignedStudies(?int $user_id = null): LengthAwarePaginator
|
||||||
{
|
{
|
||||||
$user_id = (int) ($user_id ?? auth()->id());
|
return self::assignedStudiesQuery($user_id)
|
||||||
$per_page = settings()->get("user.{$user_id}.pagination.per_page", config('app.pagination.per_page'));
|
|
||||||
|
|
||||||
return Study::active()
|
|
||||||
->where('assigned_physician_id', $user_id)
|
|
||||||
->where('report_status', '=', ReportStatus::Signed->value)
|
->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('study_priority', 'desc')
|
||||||
->orderBy('received_at', 'asc')
|
->orderBy('received_at', 'asc');
|
||||||
->paginate($per_page);
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,3 +38,12 @@ function sync_agent_id(): int
|
|||||||
fn () => User::where('username', '$$_pacs_sync_$$')->first()->id);
|
fn () => User::where('username', '$$_pacs_sync_$$')->first()->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! function_exists('user_per_page')) {
|
||||||
|
function user_per_page(?int $user_id = null): int
|
||||||
|
{
|
||||||
|
$user_id = (int) ($user_id ?? auth()->id());
|
||||||
|
|
||||||
|
return settings()->get("user.{$user_id}.pagination.per_page", config('app.pagination.per_page'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user