69 lines
1.8 KiB
PHP
69 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\DAL;
|
|
|
|
use App\Domain\ACL\Role;
|
|
use App\Services\UserService;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final readonly class Radiologists
|
|
{
|
|
public static function worklist_stats(int $days, int $workflow_level)
|
|
{
|
|
$sql = <<<'SQL'
|
|
SELECT
|
|
users."id",
|
|
users.display_name,
|
|
COALESCE (cte.assign_counts, 0) AS workload
|
|
FROM
|
|
roles
|
|
INNER JOIN model_has_roles ON roles."id" = model_has_roles.role_id
|
|
INNER JOIN users ON users."id" = model_has_roles.model_id
|
|
LEFT JOIN (
|
|
SELECT
|
|
sa.user_id,
|
|
COUNT(sa.*) AS assign_counts
|
|
FROM
|
|
study_assignments AS sa
|
|
INNER JOIN studies st ON st.ID = sa.study_id
|
|
WHERE
|
|
--st.received_at :: DATE >= NOW() - INTERVAL '3 DAY'
|
|
st.received_at::DATE >= NOW() - INTERVAL '%d DAY'
|
|
AND st.workflow_level < %d
|
|
AND st.read_at IS NULL
|
|
GROUP BY
|
|
sa.user_id) AS cte ON cte.user_id = users."id"
|
|
WHERE
|
|
roles."name" = '%s'
|
|
AND users.is_active = TRUE
|
|
GROUP BY
|
|
users."id",
|
|
cte.assign_counts
|
|
ORDER BY
|
|
users.display_name
|
|
SQL;
|
|
|
|
$rows = DB::select(sprintf($sql, $days, $workflow_level, Role::Radiologist->value));
|
|
foreach ($rows as $row) {
|
|
$row->last_seen = UserService::getLastSeen((int) $row->id);
|
|
}
|
|
|
|
return $rows;
|
|
}
|
|
|
|
public static function activeRads(): array
|
|
{
|
|
return cache()
|
|
->remember('active_rads',
|
|
now()->addMinutes(5),
|
|
fn () => DB::table('users')
|
|
->join('model_has_roles', 'users.id', '=', 'model_has_roles.model_id')
|
|
->join('roles', 'model_has_roles.role_id', '=', 'roles.id')
|
|
->where('roles.name', Role::Radiologist->value)
|
|
->where('users.is_active', true)
|
|
->orderBy('users.display_name')
|
|
->pluck('users.display_name', 'users.id')
|
|
->toArray());
|
|
}
|
|
}
|