minor
This commit is contained in:
parent
16307a4c19
commit
90d46b32f7
@ -16,7 +16,7 @@ protected static function reportCompleteQuery(Builder $query): Builder
|
|||||||
protected static function defaultSortQuery(Builder $query): Builder
|
protected static function defaultSortQuery(Builder $query): Builder
|
||||||
{
|
{
|
||||||
return $query
|
return $query
|
||||||
->orderBy('study_priority', 'desc')
|
->orderByDesc('study_priority')
|
||||||
->orderBy('received_at');
|
->orderBy('received_at');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,105 +0,0 @@
|
|||||||
<?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($user_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
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($user_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function assignedCompleted(?int $user_id = null): LengthAwarePaginator
|
|
||||||
{
|
|
||||||
return self::reportCompleteQuery(self::assignedStudiesQuery($user_id))
|
|
||||||
->paginate(user_per_page($user_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -30,11 +30,11 @@ protected function casts(): array
|
|||||||
|
|
||||||
public static function historyOnly(int $studyId): self
|
public static function historyOnly(int $studyId): self
|
||||||
{
|
{
|
||||||
return self::where('study_id', $studyId)->firstOrFail(['id', 'study_id', 'clinical_history', 'surgical_history', 'lab_results', 'clinical_diagnosis']);
|
return self::where('study_id', $studyId)->select(['id', 'study_id', 'clinical_history', 'surgical_history', 'lab_results', 'clinical_diagnosis'])->firstOrFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function seriesOnly(int $studyId): self
|
public static function seriesOnly(int $studyId): self
|
||||||
{
|
{
|
||||||
return self::where('study_id', $studyId)->firstOrFail(['id', 'study_id', 'series']);
|
return self::where('study_id', $studyId)->select(['id', 'study_id', 'series'])->firstOrFail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user