radfusion/app/Filament/Resources/DicomServerResource.php
2025-01-30 00:28:48 +06:00

151 lines
5.2 KiB
PHP

<?php
namespace App\Filament\Resources;
use App\Filament\Resources\DicomServerResource\Pages;
use App\Models\Department;
use App\Models\DicomServer;
use App\Services\GeoLocation;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
class DicomServerResource extends Resource
{
protected static ?string $model = DicomServer::class;
protected static ?string $navigationIcon = 'heroicon-o-server-stack';
public static function form(Form $form): Form
{
return $form
->schema([
Toggle::make('is_active')
->label('Active?')
->required(),
TextInput::make('server_name')
->required()
->unique(ignoreRecord: true)
->maxLength(255),
Select::make('geo_code')
->required()
->label('GEO Location')
->options(GeoLocation::select()),
TextInput::make('host')
->required()
->maxLength(255),
TextInput::make('http_port')
->required()
->numeric(),
TextInput::make('dicom_port')
->required()
->numeric(),
TextInput::make('rest_api_endpoint')
->required()
->maxLength(255),
TextInput::make('ae_title')
->maxLength(24),
TextInput::make('username')
->maxLength(40),
TextInput::make('password')
->maxLength(40),
TextInput::make('wado_path')
->maxLength(255),
TextInput::make('stone_viewer_path')
->maxLength(255),
TextInput::make('ohif_viewer_path')
->maxLength(255),
TextInput::make('meddream_viewer_path')
->maxLength(255),
Select::make('organization_id')
->label('Organization')
->live()
->relationship('organization', 'name'),
Select::make('department_id')
->label('Department')
->options(function (Get $get) {
$organization_id = $get('organization_id');
$result = [];
if ($organization_id != null) {
$result = Department::active()->organization($organization_id)->pluck('name', 'id')->toArray();
}
return $result;
}),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
IconColumn::make('is_active')
->label('')
->boolean(),
TextColumn::make('server_name')
->label('Name')
->searchable(),
TextColumn::make('geo_code')
->label('GEO')
->searchable(),
TextColumn::make('host')
->searchable(),
TextColumn::make('http_port')
->label('WADO'),
TextColumn::make('dicom_port')
->label('DICOM'),
TextColumn::make('ae_title')
->label('AET')
->searchable(),
TextColumn::make('rest_api_endpoint')
->label('REST')
->url(fn (DicomServer $srv) => $srv->rest_api_endpoint, shouldOpenInNewTab: true)
->searchable(),
TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListDicomServers::route('/'),
'create' => Pages\CreateDicomServer::route('/create'),
'view' => Pages\ViewDicomServer::route('/{record}'),
'edit' => Pages\EditDicomServer::route('/{record}/edit'),
];
}
}