@php $scopeOptions = [ '' => 'All runs', 'deviations' => 'Deviations only', 'open' => 'Open (no corrective action yet)', ]; @endphp {{ $stats['runs'] }} run(s) today · {{ $stats['deviations'] }} open deviation(s) {{-- ------------------------------------------------------------ stats --}}

Runs today

{{ $stats['runs'] }}

Controls, calibrations, maintenance checks

Open deviations

{{ $stats['deviations'] }}

{{ $stats['deviations'] > 0 ? 'Rejects awaiting a corrective action' : 'Nothing awaiting action' }}

Rejected, last 30 days

{{ $stats['rejected30'] }}

Runs pulled off patient samples

In maintenance

{{ $stats['maintenance'] }}

Analyzers off the bench right now

{{-- ------------------------------------------------ Levey-Jennings --}} @if ($chart) Last {{ $chart->count() }} QC run(s) on this machine and test — normalised to SD @php $w = 720; $h = 240; $pad = 46; $mid = 120; $scale = 27; $step = $chart->count() > 1 ? ($w - 2 * $pad) / ($chart->count() - 1) : 0; $pointColor = ['accepted' => '#059669', 'warning' => '#d97706', 'rejected' => '#dc2626']; @endphp
{{-- action zone beyond ±3 SD --}} {{-- warning band ±2 SD --}} {{-- mean and fences --}} {{-- axis labels --}} 0 +2 -2 +3 -3 {{-- run polyline --}} @if ($chart->count() > 1) @endif {{-- run points --}} @foreach ($chart as $i => $point) @php $cx = $pad + $i * $step; $cy = $mid - $point['z'] * $scale; $color = $pointColor[$point['status']] ?? '#64748b'; @endphp {{ $point['label'] }} — z {{ $point['z'] }} ({{ $point['status'] }}) @if ($chart->count() <= 12 || $i % max(intdiv($chart->count(), 8), 1) === 0) {{ $point['label'] }} @endif @endforeach

Green: in control · Amber: outside ±2 SD — watch the next run · Red: outside ±3 SD or tolerance breached — the machine comes off patient samples until the deviation is closed out.

@endif
{{-- --------------------------------------------------- filters --}} {{ $records->total() }} record(s)
Reset
@forelse ($records as $record) @php $open = $record->is_deviation && ! $record->corrective_action; @endphp @empty @endforelse
When Machine · test Type Expected Measured z Status
{{ $record->performed_at?->format('d M H:i') }} {{ $record->performedBy?->name }} {{ $record->analyzer?->name ?? '—' }} {{ $record->labTest?->name ?? 'General' }} {{ $record->record_type_label }} @if ($record->control_level) · {{ $record->control_level_label }} @endif @if ($record->lot_number) lot {{ $record->lot_number }} @endif {{ $record->expected_value }} {{ $record->measured_value }} {{ $record->z_score !== null ? number_format((float) $record->z_score, 2) : '—' }} @if ($record->rule_evaluated) {{ $record->rule_label }} @endif @if ($open) @elseif ($record->corrective_action) Resolved @endif
No control runs match — loosen the filters, or record the first run.
@if ($records->hasPages())
{{ $records->links() }}
@endif
{{-- ------------------------------------------------- record a run --}}
@can('lab.qc-manage') The z-score, rule and deviation flag are judged as you save
@csrf

A reject flags a deviation: the machine comes off patient samples until the deviation is closed out with the corrective action below.

@endcan
z-score
(measured − mean) ÷ SD. Beyond ±2 SD warns; beyond ±3 SD, or past the tolerance, rejects.
Westgard 1₂s / 1₃s
The rule broken by the run is stored on the record — the monthly review reads it, not a memory.
Deviations
Every reject is a deviation. It stays on the record even after the corrective action — compliance wants the scar, not a clean page.
{{-- ------------------------------------------------- resolve modals --}} @foreach ($records as $record) @if ($record->is_deviation && ! $record->corrective_action)
@csrf @method('PATCH')

Close out the deviation

{{ $record->analyzer?->name }} · {{ $record->labTest?->name ?? 'general' }} — expected {{ $record->expected_value }}, measured {{ $record->measured_value }}, z {{ $record->z_score !== null ? number_format((float) $record->z_score, 2) : '—' }} on {{ $record->performed_at?->format('d M Y H:i') }}.

@endif @endforeach