70 lines
2.4 KiB
PHP
70 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\DAL;
|
|
|
|
use App\Models\Study;
|
|
use Cache;
|
|
use DB;
|
|
use Illuminate\Database\Query\Builder;
|
|
use Illuminate\Support\Collection;
|
|
|
|
final readonly class Studies
|
|
{
|
|
public static function getStudyIdByOrthancUuid(string $orthanc_uuid): ?int
|
|
{
|
|
return Cache::remember("studies.orthanc_uuid.{$orthanc_uuid}",
|
|
now()->addHours(1),
|
|
fn () => DB::table('studies')
|
|
->where('orthanc_uuid', strtolower($orthanc_uuid))
|
|
->value('id'));
|
|
}
|
|
|
|
private static function assignedQuery(?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): Collection
|
|
{
|
|
$user_id = (int) ($user_id ?? auth()->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)
|
|
->orderBy('study_priority', 'desc')
|
|
->orderBy('received_at', 'asc')
|
|
->paginate($per_page);
|
|
}
|
|
|
|
public static function getPendingAssignedStudies(?int $user_id = null): Collection
|
|
{
|
|
$user_id = (int) ($user_id ?? auth()->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)
|
|
->orderBy('study_priority', 'desc')
|
|
->orderBy('received_at', 'asc')
|
|
->paginate($per_page);
|
|
}
|
|
|
|
public static function getCompletedAssignedStudies(?int $user_id = null): Collection
|
|
{
|
|
$user_id = (int) ($user_id ?? auth()->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)
|
|
->orderBy('study_priority', 'desc')
|
|
->orderBy('received_at', 'asc')
|
|
->paginate($per_page);
|
|
}
|
|
}
|