{{-- One block of a PACS report format. $mode = 'edit' (inputs) | 'print' (exact layout). $b = block, $data = values. Field notation is parsed by App\Support\ReportFormData::field(). --}} @php $F = fn ($def) => \App\Support\ReportFormData::field($def); $edit = $mode === 'edit'; $val = fn ($k) => $data[$k] ?? ''; $show = function ($f) use ($data) { $v = $data[$f['key']] ?? ''; if ($f['type'] === 'date' && $v) { try { return \Carbon\Carbon::parse($v)->format('d/m/Y'); } catch (\Exception $e) { return $v; } } return $v; }; $input = function ($f, $extra = '') use ($data) { $n = 'f[' . $f['key'] . ']'; $v = e($data[$f['key']] ?? ''); if ($f['type'] === 'sig') return '(signed on the printed copy)'; if ($f['type'] === 'ta') return ''; if ($f['type'] === 'date') return ''; return ''; }; $ro = $edit && empty($editable) ? 'disabled' : ''; @endphp @if($b['type'] === 'heading')
{{ $b['label'] }}
@elseif($b['type'] === 'lines')
@foreach($b['fields'] as $def) @php $f = $F($def); @endphp @if($edit)
{!! $input($f, $ro) !!}
@else
{{ $f['label'] }}: {{ $f['type'] === 'sig' ? '' : $show($f) }}
@endif @endforeach
@elseif($b['type'] === 'grid' || $b['type'] === 'rows') @php $cols = $b['type'] === 'rows' ? 1 : ($b['cols'] ?? 2); $cells = array_map($F, $b['fields']); while (count($cells) % $cols) $cells[] = $F('_'); @endphp @if(!empty($b['title']))@endif @foreach(array_chunk($cells, $cols) as $row) @foreach($row as $f) @if($f['blank']) @else @endif @endforeach @endforeach
{{ $b['title'] }}
{{ $f['label'] }} @if($edit){!! $input($f, $ro) !!}@else
{{ $f['type'] === 'sig' ? '' : $show($f) }}
@endif
@elseif($b['type'] === 'section')
{{ $b['label'] }}
@if($edit) @else
{{ $val($b['key']) }}
@endif
@elseif($b['type'] === 'choice')
{{ $b['label'] }}
@foreach($b['options'] as $ok => $ol) @if($edit)
@else
{{ $ok }}. {{ $ol }} ( {{ $val($b['key']) === $ok ? '✓' : ' ' }} )
@endif @endforeach
@if(!empty($b['reason']))
{{ $b['reason'] }}: @if($edit) @else{{ $val($b['key'] . '_reason') }}@endif
@endif
@elseif($b['type'] === 'repeat') @php $rowsData = array_values((array) ($data[$b['key']] ?? [])); $n = max($b['rows'] ?? 3, count($rowsData) + ($edit ? 1 : 0)); $cols = $b['columns']; @endphp @if(count($cols) > 1) @if(!empty($b['numbered']))@endif @foreach($cols as $ck => $cl)@endforeach @endif @for($i = 0; $i < $n; $i++) @if(!empty($b['numbered']))@endif @foreach($cols as $ck => $cl) @endforeach @endfor
{{ $b['label'] }}
({{ $cl }})
{{ $i + 1 }}. @if($edit) @else
{{ $rowsData[$i][$ck] ?? '' }}
@endif
@if($edit && empty($ro))@endif @elseif($b['type'] === 'letter') @php $fields = collect($b['fields'])->map($F)->keyBy('key'); @endphp @if($edit)
{{ $b['text'] }}
@foreach($fields as $f)
{!! $input($f, $ro) !!}
@endforeach
@else

{!! preg_replace_callback('/\{(\w+)\}/', function ($m) use ($fields, $show) { $f = $fields[$m[1]] ?? null; $v = $f ? $show($f) : ''; return '' . e($v !== '' && $v !== null ? $v : '……………') . ''; }, e($b['text'])) !!}

@endif @endif