wip
This commit is contained in:
parent
1cb5e59133
commit
b54e2e4ba3
@ -9,6 +9,6 @@ final class AdminStudyLister extends UserStudyListerBase
|
|||||||
{
|
{
|
||||||
protected function buildQuery(?int $user_id = null): Builder
|
protected function buildQuery(?int $user_id = null): Builder
|
||||||
{
|
{
|
||||||
return self::defaultSortQuery(Study::active());
|
return self::applySortQuery(Study::active());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,12 @@
|
|||||||
|
|
||||||
interface IUserStudyLister
|
interface IUserStudyLister
|
||||||
{
|
{
|
||||||
|
public function setPageSize(int $size): void;
|
||||||
|
|
||||||
|
public function setSortColumn(string $column, string $dir): void;
|
||||||
|
|
||||||
|
public function setSearchTerm(string $search): void;
|
||||||
|
|
||||||
public function all(?int $user_id = null): LengthAwarePaginator;
|
public function all(?int $user_id = null): LengthAwarePaginator;
|
||||||
|
|
||||||
public function pending(?int $user_id = null): LengthAwarePaginator;
|
public function pending(?int $user_id = null): LengthAwarePaginator;
|
||||||
|
@ -11,7 +11,7 @@ protected function buildQuery(?int $user_id = null): Builder
|
|||||||
{
|
{
|
||||||
$user_id = (int) ($user_id ?? auth()->id());
|
$user_id = (int) ($user_id ?? auth()->id());
|
||||||
|
|
||||||
return self::defaultSortQuery(
|
return self::applySortQuery(
|
||||||
Study::active()->where('assigned_physician_id', $user_id)
|
Study::active()->where('assigned_physician_id', $user_id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ protected function buildQuery(?int $user_id = null): Builder
|
|||||||
{
|
{
|
||||||
$user_id = (int) ($user_id ?? auth()->id());
|
$user_id = (int) ($user_id ?? auth()->id());
|
||||||
|
|
||||||
return self::defaultSortQuery(
|
return self::applySortQuery(
|
||||||
Study::active()->where('referring_provider_id', $user_id)
|
Study::active()->where('referring_provider_id', $user_id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,6 @@ protected function buildQuery(?int $user_id = null): Builder
|
|||||||
$query = $query->where('institute_id', $institute_id);
|
$query = $query->where('institute_id', $institute_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::defaultSortQuery($query);
|
return self::applySortQuery($query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,25 @@
|
|||||||
|
|
||||||
abstract class UserStudyListerBase implements IUserStudyLister
|
abstract class UserStudyListerBase implements IUserStudyLister
|
||||||
{
|
{
|
||||||
|
private ?int $pageSize = null;
|
||||||
|
|
||||||
|
private ?string $sortColumn = null;
|
||||||
|
|
||||||
|
private ?string $sortDir = null;
|
||||||
|
|
||||||
|
private ?string $searchTerm = null;
|
||||||
|
|
||||||
protected static function reportCompleteQuery(Builder $query): Builder
|
protected static function reportCompleteQuery(Builder $query): Builder
|
||||||
{
|
{
|
||||||
return $query->where('report_status', '=', ReportStatus::Signed->value);
|
return $query->where('report_status', '=', ReportStatus::Signed->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function defaultSortQuery(Builder $query): Builder
|
protected function applySortQuery(Builder $query): Builder
|
||||||
{
|
{
|
||||||
|
if ($this->sortColumn) {
|
||||||
|
return $query->orderBy($this->sortColumn, $this->sortDir ?? 'ASC');
|
||||||
|
}
|
||||||
|
|
||||||
return $query
|
return $query
|
||||||
->orderByDesc('study_priority')
|
->orderByDesc('study_priority')
|
||||||
->orderByDesc('received_at');
|
->orderByDesc('received_at');
|
||||||
@ -30,18 +42,54 @@ abstract protected function buildQuery(?int $user_id = null): Builder;
|
|||||||
public function all(?int $user_id = null): LengthAwarePaginator
|
public function all(?int $user_id = null): LengthAwarePaginator
|
||||||
{
|
{
|
||||||
return $this->buildQuery($user_id)
|
return $this->buildQuery($user_id)
|
||||||
->paginate(user_per_page($user_id));
|
->paginate($this->getPageSize($user_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pending(?int $user_id = null): LengthAwarePaginator
|
public function pending(?int $user_id = null): LengthAwarePaginator
|
||||||
{
|
{
|
||||||
return self::reportPendingQuery(self::buildQuery($user_id))
|
return self::reportPendingQuery(self::buildQuery($user_id))
|
||||||
->paginate(user_per_page($user_id));
|
->paginate($this->getPageSize($user_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function completed(?int $user_id = null): LengthAwarePaginator
|
public function completed(?int $user_id = null): LengthAwarePaginator
|
||||||
{
|
{
|
||||||
return self::reportCompleteQuery(self::buildQuery($user_id))
|
return self::reportCompleteQuery(self::buildQuery($user_id))
|
||||||
->paginate(user_per_page($user_id));
|
->paginate($this->getPageSize($user_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPageSize(int $size): void
|
||||||
|
{
|
||||||
|
$this->pageSize = $size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSortColumn(string $column, string $dir): void
|
||||||
|
{
|
||||||
|
$this->sortColumn = $column;
|
||||||
|
$this->sortDir = $dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSearchTerm(string $search): void
|
||||||
|
{
|
||||||
|
$this->searchTerm = $search;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPageSize(?int $user_id = null): int
|
||||||
|
{
|
||||||
|
return $this->pageSize ?? $this->getPageSize($user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applySearch(Builder $query): Builder
|
||||||
|
{
|
||||||
|
if ($this->searchTerm) {
|
||||||
|
$search = "%{$this->searchTerm}%";
|
||||||
|
$query = $query->where(function ($query) use ($search) {
|
||||||
|
$query->orWhere('patient_name', 'like', $search);
|
||||||
|
$query->orWhere('patient_id', 'like', $search);
|
||||||
|
$query->orWhere('study_description', 'like', $search);
|
||||||
|
$query->orWhere('body_part_examined', 'like', $search);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
app/Jobs/UpdatePersonalAccessToken.php
Normal file
22
app/Jobs/UpdatePersonalAccessToken.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Models\CustomPersonalAccessToken;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Queue\Queueable;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
final readonly class UpdatePersonalAccessToken implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
public function __construct(private readonly CustomPersonalAccessToken $personalAccessToken, private readonly array $newAttributes) {}
|
||||||
|
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
DB::table($this->personalAccessToken->getTable())
|
||||||
|
->where('id', $this->personalAccessToken->id)
|
||||||
|
->update($this->newAttributes);
|
||||||
|
}
|
||||||
|
}
|
53
app/Models/CustomPersonalAccessToken.php
Normal file
53
app/Models/CustomPersonalAccessToken.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Jobs\UpdatePersonalAccessToken;
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Laravel\Sanctum\PersonalAccessToken;
|
||||||
|
|
||||||
|
class CustomPersonalAccessToken extends PersonalAccessToken
|
||||||
|
{
|
||||||
|
public static function findToken($token)
|
||||||
|
{
|
||||||
|
$token = Cache::remember("PersonalAccessToken::$token", 600,
|
||||||
|
function () use ($token) {
|
||||||
|
return parent::findToken($token) ?? '_null_';
|
||||||
|
});
|
||||||
|
if ($token === '_null_') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTokenableAttribute()
|
||||||
|
{
|
||||||
|
return Cache::remember("PersonalAccessToken::{$this->id}::tokenable", 600,
|
||||||
|
function () {
|
||||||
|
return parent::tokenable()->first();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function boot()
|
||||||
|
{
|
||||||
|
parent::boot();
|
||||||
|
// When updating, cancel normal update and manually update
|
||||||
|
// the table asynchronously every hour.
|
||||||
|
static::updating(function (self $personalAccessToken) {
|
||||||
|
try {
|
||||||
|
Cache::remember('PersonalAccessToken::lastUsgeUpdate', 3600, function () use ($personalAccessToken) {
|
||||||
|
dispatch(new UpdatePersonalAccessToken($personalAccessToken, $personalAccessToken->getDirty()));
|
||||||
|
|
||||||
|
return now();
|
||||||
|
});
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::critical($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -97,7 +97,6 @@ class="d-flex justify-content-between align-items-start border-end pb-4 pb-sm-0
|
|||||||
<th>Patient ID</th>
|
<th>Patient ID</th>
|
||||||
<th>Patient Name</th>
|
<th>Patient Name</th>
|
||||||
<th>Patient Sex</th>
|
<th>Patient Sex</th>
|
||||||
<th>Patient Birth Date</th>
|
|
||||||
<th>Modality</th>
|
<th>Modality</th>
|
||||||
<th>Study Date</th>
|
<th>Study Date</th>
|
||||||
<th>Receive Date</th>
|
<th>Receive Date</th>
|
||||||
@ -121,7 +120,6 @@ class="d-flex justify-content-between align-items-start border-end pb-4 pb-sm-0
|
|||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ $study->sexAge() }}</td>
|
<td>{{ $study->sexAge() }}</td>
|
||||||
<td>{{ $study->patient_birthdate }}</td>
|
|
||||||
<td>{{ $study->study_modality }}</td>
|
<td>{{ $study->study_modality }}</td>
|
||||||
<td>{{ $study->study_date }}</td>
|
<td>{{ $study->study_date }}</td>
|
||||||
<td>{{ $study->received_at }}</td>
|
<td>{{ $study->received_at }}</td>
|
||||||
|
Loading…
Reference in New Issue
Block a user