filter
This commit is contained in:
parent
e7c52419f7
commit
4c0b6a5bc8
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
namespace App\DAL\Studies;
|
namespace App\DAL\Studies;
|
||||||
|
|
||||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
use App\Models\Study;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
final class RadiologistWorklist extends WorklistBase
|
final class RadiologistWorklist extends WorklistBase
|
||||||
{
|
{
|
||||||
@ -12,11 +13,6 @@ protected function buildQuery(?int $user_id = null): Builder
|
|||||||
$user_id = (int) ($user_id ?? auth()->id());
|
$user_id = (int) ($user_id ?? auth()->id());
|
||||||
$this->setRadiologist($user_id);
|
$this->setRadiologist($user_id);
|
||||||
|
|
||||||
$query = $query->where(function ($query) use ($user_id) {
|
return Study::buildRadiologistQuery($query, $user_id);
|
||||||
$query->Where('assigned_physician_id', '=', $user_id);
|
|
||||||
$query->orWhere('reporting_physician_id', '=', $user_id);
|
|
||||||
});
|
|
||||||
|
|
||||||
return $query;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
use App\Domain\Study\StudyLevelStatus;
|
use App\Domain\Study\StudyLevelStatus;
|
||||||
use App\Models\Study;
|
use App\Models\Study;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
abstract class WorklistBase implements IUserStudyLister
|
abstract class WorklistBase implements IUserStudyLister
|
||||||
{
|
{
|
||||||
@ -164,7 +164,7 @@ protected function getStudiesQuery(): Builder
|
|||||||
$q = Study::query();
|
$q = Study::query();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $q->with(['readingPhysician', 'dicomServer']);
|
return $q->with(['readingPhysician', 'dicomServer', 'assignedPhysicians', 'reports']);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function applySort(Builder $query): Builder
|
protected function applySort(Builder $query): Builder
|
||||||
@ -186,12 +186,34 @@ abstract protected function buildQuery(?int $user_id = null): Builder;
|
|||||||
|
|
||||||
private function applyRadiologist(Builder $query): Builder
|
private function applyRadiologist(Builder $query): Builder
|
||||||
{
|
{
|
||||||
if ($this->radiologist_id != null) {
|
if ($this->radiologist_id !== null) {
|
||||||
$rad = $this->radiologist_id;
|
$userId = $this->radiologist_id;
|
||||||
$query = $query->where(function ($query) use ($rad) {
|
$query = Study::buildRadiologistQuery($query, $userId);
|
||||||
$query->Where('assigned_physician_id', '=', $rad);
|
/*
|
||||||
$query->orWhere('reporting_physician_id', '=', $rad);
|
$query->where(function (Builder $q) use ($userId) {
|
||||||
|
$q->where('reading_physician_id', $userId)
|
||||||
|
->orWhere('locking_physician_id', $userId)
|
||||||
|
->orWhere('approving_physician_id', $userId)
|
||||||
|
->orWhereHas('assignedPhysicians', function (Builder $subQuery) use ($userId) {
|
||||||
|
$subQuery->where('user_id', $userId);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
$query = $query->where(function ($qry) use ($rad) {
|
||||||
|
// TODO: $query->Where('assigned_physician_id', '=', $rad);
|
||||||
|
$qry->whereHas('assignedPhysicians', function ($subQuery) use ($rad) {
|
||||||
|
$subQuery->where('assignedPhysicians.user_id', '=', $rad);
|
||||||
|
})->with(['assignedPhysicians' => function ($q) use ($rad) {
|
||||||
|
$q->where('assignedPhysicians.user_id', '=', $rad);
|
||||||
|
}]);
|
||||||
|
|
||||||
|
#$qry->orWhere('locking_physician_id', '=', $rad);
|
||||||
|
#$qry->orWhere('reading_physician_id', '=', $rad);
|
||||||
|
#$qry->orWhere('approving_physician_id', '=', $rad);
|
||||||
|
});
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
@ -239,7 +261,11 @@ private function applySearch(Builder $query): Builder
|
|||||||
private function applyArchived(Builder $query): Builder
|
private function applyArchived(Builder $query): Builder
|
||||||
{
|
{
|
||||||
if ($this->archived != null) {
|
if ($this->archived != null) {
|
||||||
$query = $query->where('is_archived', $this->archived);
|
if ($this->archived) {
|
||||||
|
$query = $query->archived();
|
||||||
|
} else {
|
||||||
|
$query = $query->active();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
|
@ -29,6 +29,19 @@ class Study extends BaseModel implements HasMedia
|
|||||||
public const string MEDIA_COLLECTION = 'attachments';
|
public const string MEDIA_COLLECTION = 'attachments';
|
||||||
public const string FALLBACK_IMAGE = 'imgs/doc-pdf.png';
|
public const string FALLBACK_IMAGE = 'imgs/doc-pdf.png';
|
||||||
|
|
||||||
|
public static function buildRadiologistQuery(Builder $query, int $userId): Builder
|
||||||
|
{
|
||||||
|
return $query->where(function (Builder $q) use ($userId) {
|
||||||
|
$q
|
||||||
|
->where('reading_physician_id', $userId)
|
||||||
|
->orWhere('locking_physician_id', $userId)
|
||||||
|
->orWhere('approving_physician_id', $userId)
|
||||||
|
->orWhereHas('assignedPhysicians', function (Builder $subQuery) use ($userId) {
|
||||||
|
$subQuery->where('user_id', $userId);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function details(): HasOne
|
public function details(): HasOne
|
||||||
{
|
{
|
||||||
return $this->hasOne(StudyDetails::class);
|
return $this->hasOne(StudyDetails::class);
|
||||||
@ -135,6 +148,13 @@ public function isAssigned(User|int|null $user = null): bool
|
|||||||
return $this->assignedPhysicians->contains(me($user)->id);
|
return $this->assignedPhysicians->contains(me($user)->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isUserInStudyAssignmentsOrReadingPhysician(User|int|null $user = null): bool
|
||||||
|
{
|
||||||
|
$count = self::buildRadiologistQuery(self::where('id', $this->id), me($user)->id)->count();
|
||||||
|
|
||||||
|
return $count > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public function isActive(): bool
|
public function isActive(): bool
|
||||||
{
|
{
|
||||||
return $this->archived_at === null;
|
return $this->archived_at === null;
|
||||||
@ -410,7 +430,8 @@ public function setReportStatus(ReportStatus $status, User|int|null $user = null
|
|||||||
|
|
||||||
public function canEditReport(): bool
|
public function canEditReport(): bool
|
||||||
{
|
{
|
||||||
$this->report_status <= ReportStatus::Finalized;
|
// todo: check if the study disallows reporting
|
||||||
|
return $this->report_status <= ReportStatus::Finalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasReports(): bool
|
public function hasReports(): bool
|
||||||
|
Loading…
Reference in New Issue
Block a user