From 1c10b5b7989f99e54d75f4243bcaefd0249dce5b Mon Sep 17 00:00:00 2001 From: Dr Masroor Ehsan Date: Mon, 20 Jan 2025 13:49:55 +0600 Subject: [PATCH] wip filtering --- app/DataTables/WorklistDataTable.php | 70 +++++++++++++------ .../Controllers/Staff/WorklistController.php | 3 +- .../views/staff/worklist/index.blade.php | 22 ++++-- .../worklist/partials/_check-inline.blade.php | 2 +- .../worklist/partials/_filter-panel.blade.php | 9 +-- 5 files changed, 71 insertions(+), 35 deletions(-) diff --git a/app/DataTables/WorklistDataTable.php b/app/DataTables/WorklistDataTable.php index 8e964ab..ffb9c69 100644 --- a/app/DataTables/WorklistDataTable.php +++ b/app/DataTables/WorklistDataTable.php @@ -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. */ diff --git a/app/Http/Controllers/Staff/WorklistController.php b/app/Http/Controllers/Staff/WorklistController.php index 62ef8bd..e9429d1 100644 --- a/app/Http/Controllers/Staff/WorklistController.php +++ b/app/Http/Controllers/Staff/WorklistController.php @@ -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')); } } diff --git a/resources/views/staff/worklist/index.blade.php b/resources/views/staff/worklist/index.blade.php index 7e67522..0f287db 100644 --- a/resources/views/staff/worklist/index.blade.php +++ b/resources/views/staff/worklist/index.blade.php @@ -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') diff --git a/resources/views/staff/worklist/partials/_check-inline.blade.php b/resources/views/staff/worklist/partials/_check-inline.blade.php index aee303c..432b1be 100644 --- a/resources/views/staff/worklist/partials/_check-inline.blade.php +++ b/resources/views/staff/worklist/partials/_check-inline.blade.php @@ -1,6 +1,6 @@ @php if (!isset($id)) { - $id = 'chk_' . $value . '_' . random_int(100, 999); + $id = 'chk_' . $value; // . '_' . random_int(100, 999); } @endphp
diff --git a/resources/views/staff/worklist/partials/_filter-panel.blade.php b/resources/views/staff/worklist/partials/_filter-panel.blade.php index 66ed2e5..ffb068f 100644 --- a/resources/views/staff/worklist/partials/_filter-panel.blade.php +++ b/resources/views/staff/worklist/partials/_filter-panel.blade.php @@ -25,12 +25,9 @@
Study Modalities
- @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