194 lines
6.8 KiB
PHP
194 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace App\DataTables;
|
|
|
|
use App\DAL\Studies\WorklistFactory;
|
|
use App\Models\Study;
|
|
use Carbon\Carbon;
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Database\Eloquent\Builder as QueryBuilder;
|
|
use Illuminate\Support\Str;
|
|
use Yajra\DataTables\EloquentDataTable;
|
|
use Yajra\DataTables\Html\Builder as HtmlBuilder;
|
|
use Yajra\DataTables\Html\Column;
|
|
use Yajra\DataTables\Html\SearchPane;
|
|
use Yajra\DataTables\Services\DataTable;
|
|
|
|
class WorklistDataTable extends DataTable
|
|
{
|
|
const DATE_FORMAT = 'd.m.Y H:i';
|
|
|
|
private static function dtFormat(Carbon|CarbonImmutable|null $dt): ?string
|
|
{
|
|
return $dt?->format(self::DATE_FORMAT);
|
|
}
|
|
|
|
public function dataTable(QueryBuilder $query): EloquentDataTable
|
|
{
|
|
return (new EloquentDataTable($query))
|
|
->addColumn('action', 'worklist.action')
|
|
->editColumn('patient_name', fn (Study $study) => $study->sanitizedPatientName())
|
|
->editColumn('study_description', fn (Study $study) => $study->sanitizedStudyDescription())
|
|
->editColumn('reader', function (Study $study) {
|
|
if ($study->readingPhysician == null) {
|
|
return '';
|
|
}
|
|
|
|
return '<img class="rounded-circle me-2" height="24px" width="24px" src="' . $study->readingPhysician->avatar() . '"></img>' . $study->readingPhysician->display_name;
|
|
})
|
|
->editColumn('images', function (Study $study) {
|
|
return $study->numInstances() . '<small class="text-muted ms-2 fw-lighter fs-xsmall">' . human_filesize($study->disk_size) . '</small>';
|
|
})
|
|
->editColumn('study_date', function (Study $study) {
|
|
return self::dtFormat($study->study_date);
|
|
})
|
|
->editColumn('reported_at', function (Study $study) {
|
|
return self::dtFormat($study->reported_at);
|
|
})
|
|
->editColumn('received_at', function (Study $study) {
|
|
return self::dtFormat($study->received_at);
|
|
})
|
|
->editColumn('show_study', function (Study $study) {
|
|
$btn = '<a href="#" data-id="' . _h($study->id) . '" class="btn btn-outline-facebook btn-xs showStudy">Show</a>';
|
|
$btn .= ' <a href="#" data-id="' . _h($study->id) . '" class="edit btn btn-primary btn-xs editStudy">Edit</a>';
|
|
$btn .= ' <a href="#" data-id="' . _h($study->id) . '" class="btn btn-danger btn-xs deleteStudy">Delete</a>';
|
|
|
|
return $btn;
|
|
})
|
|
->editColumn('history', function (Study $study) {
|
|
return sprintf('
|
|
<a href="#" class="btn btn-sm btn-outline-light" data-toggle="modal" data-target="#historyModal" data-study-id="#" data-url="#">
|
|
<i class="fa-light fa-file-prescription %s"></i>
|
|
</a>
|
|
', blank($study->body_part_examined) ? 'text-muted' : 'text-primary');
|
|
})
|
|
->orderColumn('patient_name', 'patient_name $1')
|
|
->rawColumns(['priority_icon', 'report_status_led', 'images', 'reader', 'history', 'show_study'])
|
|
->setRowId('id');
|
|
}
|
|
|
|
/**
|
|
* Get the query source of dataTable.
|
|
*/
|
|
public function query(Study $model): QueryBuilder
|
|
{
|
|
return WorklistFactory::getLister()->query();
|
|
// return $model->newQuery();
|
|
}
|
|
|
|
/**
|
|
* Optional method if you want to use the html builder.
|
|
*/
|
|
public function html(): HtmlBuilder
|
|
{
|
|
return $this->builder()
|
|
->setTableId('worklist-table')
|
|
->columns($this->getColumns())
|
|
->minifiedAjax()
|
|
->searchPanes(SearchPane::make(['show' => true, 'hideCount' => true]))
|
|
->parameters(
|
|
[
|
|
// 'dom' => 'Pfrtip',
|
|
// 'dom' => 'Bfrtip',
|
|
'buttons' => [
|
|
'searchPanes',
|
|
'excel',
|
|
// 'csv',
|
|
// 'pdf',
|
|
// 'print',
|
|
// 'reset',
|
|
// 'reload',
|
|
],
|
|
'order' => [
|
|
[0, 'desc'],
|
|
[8, 'desc'],
|
|
],
|
|
])
|
|
// ->selectStyleSingle()
|
|
->pageLength(15)
|
|
->lengthMenu([15, 25, 50, 100, 250]);
|
|
}
|
|
|
|
/**
|
|
* Get the dataTable columns definition.
|
|
*/
|
|
public function getColumns(): array
|
|
{
|
|
return [
|
|
Column::make('priority')->hidden(),
|
|
Column::make('priority_icon')
|
|
->searchable(false)
|
|
->orderable(false)
|
|
->addClass('text-center')
|
|
->width('20px')
|
|
->title(''),
|
|
|
|
Column::make('report_status_led')
|
|
->searchable(false)
|
|
->orderable(false)
|
|
->addClass('text-center')
|
|
->width('20px')
|
|
->title(''),
|
|
|
|
Column::make('history')
|
|
->searchable(false)
|
|
->orderable(false)
|
|
->addClass('text-center')
|
|
->width('20px')
|
|
->title(''),
|
|
|
|
Column::make('modality')->title('Mo'),
|
|
Column::make('patient_id')->title('MRN'),
|
|
Column::make('patient_name')->title('Patient'),
|
|
Column::make('sex_age')
|
|
->searchable(false)
|
|
->orderable(false)
|
|
->addClass('text-center')
|
|
->title('Age'),
|
|
|
|
Column::make('study_description')
|
|
->title('Study'),
|
|
|
|
Column::make('show_study')->searchable(false)
|
|
->orderable(false)
|
|
->addClass('text-center')
|
|
->width('20px')
|
|
->title(''),
|
|
|
|
Column::make('study_date')->searchable(false)->title('Scan Dt'),
|
|
Column::make('reader')
|
|
->searchable(false)
|
|
->title('Read by'),
|
|
Column::make('reported_at')->searchable(false)->title('Read At'),
|
|
// Column::make('body_part_examined'),
|
|
Column::make('images')
|
|
->searchable(false)
|
|
->orderable(false)
|
|
->addClass('text-center')
|
|
->title('Images'),
|
|
Column::make('received_at')->searchable(false)->title('Received'),
|
|
|
|
// Column::make('xxx'),
|
|
Column::computed('action')
|
|
->exportable(false)
|
|
->printable(false)
|
|
->width(60)
|
|
->addClass('text-center'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the filename for export.
|
|
*/
|
|
protected function filename(): string
|
|
{
|
|
$parts = [
|
|
config('app.name'),
|
|
'worklist',
|
|
date('YmdHi'),
|
|
];
|
|
|
|
return Str::slug(implode(' ', $parts), '_');
|
|
}
|
|
}
|