wip filtering

This commit is contained in:
Dr Masroor Ehsan 2025-01-20 13:49:55 +06:00
parent eb92cd64d6
commit 1c10b5b798
5 changed files with 71 additions and 35 deletions

View File

@ -18,6 +18,7 @@
use Yajra\DataTables\Html\Builder as HtmlBuilder;
use Yajra\DataTables\Html\Column;
use Yajra\DataTables\Html\SearchPane;
use Yajra\DataTables\QueryDataTable;
use Yajra\DataTables\Services\DataTable;
class WorklistDataTable extends DataTable
@ -69,29 +70,16 @@ public function dataTable(QueryBuilder $query): EloquentDataTable
});
}
// Apply date range filter
if ($sfrom = $this->request()->get('s_f')) {
$study_from = Carbon::parse($sfrom);
$sto = $this->request()->get('s_t');
if ($sto) {
$study_to = Carbon::parse($sto);
// Apply date range filters
$this->filterDateRange($dataTable, 'study_date',
$this->request()->get('study_from'),
$this->request()->get('study_to'));
if ($study_from->eq($study_to)) {
$dataTable->filter(function ($query) use ($study_from) {
$query->whereDate('study_date', $study_from);
});
} else {
$dataTable->filter(function ($query) use ($study_from, $study_to) {
$query->whereDate('study_date', '>=', $study_from)
->whereDate('study_date', '<=', $study_to);
});
}
} else {
$dataTable->filter(function ($query) use ($study_from) {
$query->whereDate('study_date', $study_from);
});
}
}
$this->filterDateRange($dataTable, 'received_at',
$this->request()->get('receive_from'),
$this->request()->get('receive_to'));
$this->filterModalities($dataTable, $this->request()->get('modality'));
$dataTable
->orderColumn(WorklistColumn::PatientName->value, sprintf('%s $1', WorklistColumn::PatientName->value))
@ -101,6 +89,44 @@ public function dataTable(QueryBuilder $query): EloquentDataTable
return $dataTable;
}
private function filterModalities(QueryDataTable $dataTable, ?string $request): void
{
if (blank($request)) {
return;
}
$modalities = collect(explode(',', $request))
->filter()
->each(fn ($m) => strtoupper($m))
->unique();
$dataTable->filter(function ($query) use ($modalities) {
$query->whereIn('modality', $modalities->toArray());
});
}
private function filterDateRange(QueryDataTable $dataTable, string $column, ?string $from, ?string $to): void
{
if (blank($from)) {
return;
}
$start = Carbon::parse($from);
$end = filled($to) ? Carbon::parse($to) : Carbon::today();
if ($start->eq($end)) {
$dataTable->filter(function ($query) use ($column, $start) {
$query->whereDate($column, $start);
});
} else {
$dataTable->filter(function ($query) use ($column, $start, $end) {
$query
->whereDate($column, '>=', $start)
->whereDate($column, '<=', $end);
});
}
}
/**
* Get the query source of dataTable.
*/

View File

@ -11,7 +11,8 @@ class WorklistController extends HashidControllerBase
public function index(WorklistDataTable $dataTable)
{
SessionHelper::setIntendedUrl();
$modalities = ['CT', 'MR', 'CR', 'MG', 'US', 'DX', 'XA'];
return $dataTable->render('staff.worklist.index');
return $dataTable->render('staff.worklist.index', compact('modalities'));
}
}

View File

@ -101,6 +101,10 @@
$(function () {
let _status, _study_from, _study_to, _receive_from, _receive_to, _modality, _read_by = null;
function resetParams() {
_status, _study_from, _study_to, _receive_from, _receive_to, _modality, _read_by = null;
}
function generateUrl() {
const url = new URL("{{ route('staff.worklist.index') }}");
if (_status) url.searchParams.set('status', _status);
@ -132,6 +136,8 @@ function (givenDate) {
const fp_receive = $('#receive_date_range').flatpickr(date_range_config);
$('#search_button').on('click', function () {
resetParams();
const study_range = fp_study.selectedDates;
if (study_range.length == 2) {
_study_from = formatDate(study_range[0]);
@ -144,6 +150,15 @@ function (givenDate) {
_receive_to = formatDate(receive_range[1]);
}
const modalityArray = [];
@foreach($modalities as $modality)
if ($('#chk_{{ $modality }}').is(':checked')) {
modalityArray.push('{{ $modality }}');
}
@endforeach
_modality = modalityArray.join(',');
filterTable();
});
@ -161,11 +176,8 @@ function filterTableStatus(status) {
table.ajax.url(generateUrl()).load();
}
function filterTableStudyDate(from, to) {
table.ajax.url(generateUrl()).load();
}
function filterTable() {
console.log(generateUrl());
table.ajax.url(generateUrl()).load();
}
@ -187,7 +199,7 @@ function formatDate(date) {
@section('content')
@include('staff.worklist.partials._stats')
@include('staff.worklist.partials._filter-panel')
@include('staff.worklist.partials._filter-panel', compact('modalities'))
@include('staff.worklist.partials._nav-top')

View File

@ -1,6 +1,6 @@
@php
if (!isset($id)) {
$id = 'chk_' . $value . '_' . random_int(100, 999);
$id = 'chk_' . $value; // . '_' . random_int(100, 999);
}
@endphp
<div class="form-check form-check-inline">

View File

@ -25,12 +25,9 @@
<div class="col-md p-2">
<small class="text-light fw-medium d-block">Study Modalities</small>
<div class="mt-4">
@include('staff.worklist.partials._check-inline', ['value' => 'CT'])
@include('staff.worklist.partials._check-inline', ['value' => 'MR'])
@include('staff.worklist.partials._check-inline', ['value' => 'CR'])
@include('staff.worklist.partials._check-inline', ['value' => 'DX'])
@include('staff.worklist.partials._check-inline', ['value' => 'US'])
@include('staff.worklist.partials._check-inline', ['value' => 'MG'])
@foreach($modalities as $modality)
@include('staff.worklist.partials._check-inline', ['value' => $modality])
@endforeach
</div>
</div>
</div>