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\Builder as HtmlBuilder;
use Yajra\DataTables\Html\Column; use Yajra\DataTables\Html\Column;
use Yajra\DataTables\Html\SearchPane; use Yajra\DataTables\Html\SearchPane;
use Yajra\DataTables\QueryDataTable;
use Yajra\DataTables\Services\DataTable; use Yajra\DataTables\Services\DataTable;
class WorklistDataTable extends DataTable class WorklistDataTable extends DataTable
@ -69,29 +70,16 @@ public function dataTable(QueryBuilder $query): EloquentDataTable
}); });
} }
// Apply date range filter // Apply date range filters
if ($sfrom = $this->request()->get('s_f')) { $this->filterDateRange($dataTable, 'study_date',
$study_from = Carbon::parse($sfrom); $this->request()->get('study_from'),
$sto = $this->request()->get('s_t'); $this->request()->get('study_to'));
if ($sto) {
$study_to = Carbon::parse($sto);
if ($study_from->eq($study_to)) { $this->filterDateRange($dataTable, 'received_at',
$dataTable->filter(function ($query) use ($study_from) { $this->request()->get('receive_from'),
$query->whereDate('study_date', $study_from); $this->request()->get('receive_to'));
});
} else { $this->filterModalities($dataTable, $this->request()->get('modality'));
$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);
});
}
}
$dataTable $dataTable
->orderColumn(WorklistColumn::PatientName->value, sprintf('%s $1', WorklistColumn::PatientName->value)) ->orderColumn(WorklistColumn::PatientName->value, sprintf('%s $1', WorklistColumn::PatientName->value))
@ -101,6 +89,44 @@ public function dataTable(QueryBuilder $query): EloquentDataTable
return $dataTable; 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. * Get the query source of dataTable.
*/ */

View File

@ -11,7 +11,8 @@ class WorklistController extends HashidControllerBase
public function index(WorklistDataTable $dataTable) public function index(WorklistDataTable $dataTable)
{ {
SessionHelper::setIntendedUrl(); 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 () { $(function () {
let _status, _study_from, _study_to, _receive_from, _receive_to, _modality, _read_by = null; 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() { function generateUrl() {
const url = new URL("{{ route('staff.worklist.index') }}"); const url = new URL("{{ route('staff.worklist.index') }}");
if (_status) url.searchParams.set('status', _status); if (_status) url.searchParams.set('status', _status);
@ -132,6 +136,8 @@ function (givenDate) {
const fp_receive = $('#receive_date_range').flatpickr(date_range_config); const fp_receive = $('#receive_date_range').flatpickr(date_range_config);
$('#search_button').on('click', function () { $('#search_button').on('click', function () {
resetParams();
const study_range = fp_study.selectedDates; const study_range = fp_study.selectedDates;
if (study_range.length == 2) { if (study_range.length == 2) {
_study_from = formatDate(study_range[0]); _study_from = formatDate(study_range[0]);
@ -144,6 +150,15 @@ function (givenDate) {
_receive_to = formatDate(receive_range[1]); _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(); filterTable();
}); });
@ -161,11 +176,8 @@ function filterTableStatus(status) {
table.ajax.url(generateUrl()).load(); table.ajax.url(generateUrl()).load();
} }
function filterTableStudyDate(from, to) {
table.ajax.url(generateUrl()).load();
}
function filterTable() { function filterTable() {
console.log(generateUrl());
table.ajax.url(generateUrl()).load(); table.ajax.url(generateUrl()).load();
} }
@ -187,7 +199,7 @@ function formatDate(date) {
@section('content') @section('content')
@include('staff.worklist.partials._stats') @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') @include('staff.worklist.partials._nav-top')

View File

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

View File

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