{{-- Medication Competency Pack workspace. Full pack, grouped by visit: Visit 1 – assessment 1, knowledge, chosen competencies → sign off visit 1 Visit 2 – assessment 2 → sign off; Visit 3 – assessment 3 → sign off → mark complete. Competencies added later are done and signed on their own. A part is editable only while its visit is the current one (see MedicationCompetency::editable). Refresher: one form. From MedicationCompetencyController@show: $mc, $step --}} @extends('layouts.app') @section('title', 'Medication Competency Pack') @section('content') @include('partials.flash') @php use App\Support\MedicationCompetencyPack as Pack; $role = auth()->user()->primaryRole(); $r = fn ($n, $p = []) => route($role.'.medication-competency.'.$n, $p); $worker = $mc->user; $first = $worker->first_name ?: $worker->name; $locked = ! $mc->isOpen(); $resp = $mc->responses ?? []; $inputCls = 'w-full px-3 py-2 bg-surface-container rounded-lg border-none focus:ring-2 focus:ring-primary/20 text-body-md outline-none disabled:opacity-70'; $statusBadge = match ($mc->status) { 'competent' => ['bg-primary/10 text-primary', 'verified', 'Competent'.($mc->expires_at ? ' until '.$mc->expires_at->format('j M Y') : '')], 'not_competent' => ['bg-error-container text-error', 'block', 'Not yet competent'], default => ['bg-gold/20 text-[#8a6d3b]', 'pending', 'In progress'], }; // Full pack steps grouped by visit: group => [state, [key => [label, icon, done?, sub-label]]] $fmt = fn ($d) => \Carbon\Carbon::parse($d)->format('j M Y'); $groups = []; if ($mc->type === 'full') { $current = $mc->currentVisit(); foreach (range(1, Pack::VISITS) as $n) { $v = $mc->visit($n); $items = ["visit{$n}" => ["Assessment {$n}", 'visibility', $mc->visitPassed($n), $v ? $fmt($v['date']).($mc->visitNotMetCount($n) ? ' · '.$mc->visitNotMetCount($n).' not met' : '') : 'Observed medication round']]; if ($n === 1) { $items['knowledge'] = ['Underpinning knowledge', 'quiz', $mc->knowledgeDone(), isset($resp['knowledge']) ? 'Saved '.$fmt($resp['knowledge']['date']) : 'One-to-one questions']; foreach ($mc->visitOneLetters() as $l) { $items["section{$l}"] = [Pack::sectionLabel($l), 'medication', $mc->sectionDone($l), isset($resp['sections'][$l]) ? 'Saved '.$fmt($resp['sections'][$l]['date']) : 'Additional competency']; } } $so = $mc->visitSignoff($n); $items["signoff{$n}"] = ["Sign off visit {$n}", 'how_to_reg', (bool) $so, $so ? 'Signed '.$fmt($so['date']).' · '.$so['by'] : ($current === $n ? 'When this visit is met' : 'After visit '.($n - 1))]; $groups["Visit {$n}"] = [$so ? 'done' : ($current === $n && ! $locked ? 'current' : 'later'), $items]; } if ($added = $mc->addedLetters()) { $items = []; foreach ($added as $l) { $a = $mc->addition($l); $items["section{$l}"] = [Pack::sectionLabel($l), 'medication', $mc->additionSignedOff($l), $mc->additionSignedOff($l) ? 'Signed '.$fmt($a['signed_at']).' · '.$a['signed_by'] : 'Added '.$fmt($a['added_at']).' · to do']; } $groups['Added competencies'] = [$mc->pendingAdditions() ? 'current' : 'done', $items]; } $groups['Complete'] = [$locked ? 'done' : 'later', ['complete' => [$locked ? 'Outcome' : 'Mark complete', 'workspace_premium', $locked, $locked ? $statusBadge[2] : 'After all three visits']]]; $steps = collect($groups)->flatMap(fn ($g) => $g[1])->all(); $firstOpen = collect($steps)->keys()->first(fn ($k) => ! $steps[$k][2]) ?? 'complete'; $validStep = array_key_exists((string) $step, $steps) || ($step === 'add' && $mc->canAddCompetency()); $active = $validStep ? $step : ($locked ? ($mc->pendingAdditions() ? 'section'.$mc->pendingAdditions()[0] : 'complete') : $firstOpen); [$done, $total] = $mc->progress(); } @endphp arrow_back {{ $worker->name }}’s competency {{-- Header --}}
{{ $worker->initials() }}

{{ $worker->name }} · {{ $mc->typeLabel() }}

{{ $worker->location?->name ?? '—' }} @if($mc->details['designation'] ?? null) · {{ $mc->details['designation'] }} @endif @if($mc->details['elearning_completed_at'] ?? null) · {{ $mc->details['training']['title'] ?? 'Medication training' }} completed {{ \Carbon\Carbon::parse($mc->details['elearning_completed_at'])->format('j M Y') }} @endif @if($mc->details['reason'] ?? null) · Reason: {{ $mc->details['reason'] }} @endif

{{ $statusBadge[1] }} {{ $statusBadge[2] }} print Print record @if($mc->isOpen()) {{-- Reset (keep the setup, clear what's recorded) / Start over (set it up again) --}} @if(! empty($mc->responses))
@csrf
@endif
@csrf @method('DELETE')
@endif
@if($mc->type === 'full')
{{ $done }} of {{ $total }} sign-offs done{{ $mc->isOpen() && $current ? ' · now on visit '.$current : '' }}{{ $total ? round($done / $total * 100) : 0 }}%
@endif
@if($mc->type === 'full')
{{-- Step list --}}
{{-- ── Observed assessments ── --}} @foreach(range(1, Pack::VISITS) as $n) @php $v = $mc->visit($n) ?? []; $old = fn ($k, $f) => old("results.$k.$f", $v['results'][$k][$f] ?? null); $ro = ! $mc->editable("visit{$n}"); @endphp
@csrf
@include('management.medication-competency._part-lock', ['visitNo' => $n])

Visit {{ $n }} · Observation assessment {{ $n }} of {{ Pack::VISITS }}

Observe {{ $first }} on a medication round. Mark each criterion Met or Not met and how it was assessed — D direct observation or Q questioning. All three occasions must be met for competency to be signed off.

@unless($ro)
@endunless @php $group = null; @endphp @foreach(Pack::observation() as $key => $row) @if($row['group'] !== $group) @php $group = $row['group']; @endphp

{{ $group }}

@endif

{{ $loop->iteration }}. {{ $row['title'] }}

@if($row['points'])
    @foreach($row['points'] as $p)
  • {{ $p }}
  • @endforeach
@endif
@foreach(['met' => ['Met', 'peer-checked:bg-primary peer-checked:text-on-primary peer-checked:border-primary'], 'not_met' => ['Not met', 'peer-checked:bg-error peer-checked:text-on-primary peer-checked:border-error']] as $val => [$lbl, $on]) @endforeach
@endforeach
@if($v)

Last saved by {{ $v['assessor'] }} on {{ \Carbon\Carbon::parse($v['saved_at'])->format('j M Y, H:i') }}.

@endif
@unless($ro)
@endunless
@endforeach {{-- ── Underpinning knowledge ── --}} @php $k = $resp['knowledge'] ?? []; $ro = ! $mc->editable('knowledge'); @endphp
@csrf
@include('management.medication-competency._part-lock', ['visitNo' => 1])

Visit 1 · Underpinning knowledge assessment

Ask {{ $first }} each question one-to-one and write down their answer. All questions must be answered satisfactorily for competency to be signed off — note any further training needs.

@php $group = null; @endphp @foreach(Pack::knowledge() as $key => $q) @if($q['group'] !== $group) @php $group = $q['group']; @endphp

{{ $group }}

@endif
@if($q['hint'] ?? null)

{{ $q['hint'] }}

@endif
@endforeach

Service-specific question (optional — e.g. bowel management, alcohol issues, refusal)

Assessed as competent in the above questions? @foreach(['yes' => 'Yes', 'no' => 'No'] as $val => $lbl) @endforeach @if($k)Signed: {{ $k['assessor'] }} · {{ \Carbon\Carbon::parse($k['date'])->format('j M Y') }}@endif
@unless($ro)
@endunless
{{-- ── Additional competencies ── --}} @foreach($mc->sectionLetters() as $letter) @php $sec = Pack::sections()[$letter]; $sv = $resp['sections'][$letter] ?? []; $ro = ! $mc->editable("section{$letter}"); $add = $mc->addition($letter); @endphp
@csrf
@if($add)

Added by {{ $add['by'] }} on {{ $fmt($add['added_at']) }}{{ $mc->additionSignedOff($letter) ? ' · signed off by '.$add['signed_by'].' on '.$fmt($add['signed_at']) : ' — only this competency needs completing and signing off to update the record.' }}

@else @include('management.medication-competency._part-lock', ['visitNo' => 1]) @endif

{{ $letter }} – Competency assessment for {{ $sec['title'] }} (additional competencies)

For each step, write {{ $first }}’s explanation of its purpose as evidence of their understanding, then sign it as competent.

@if($sec['note'] ?? null)

NB: {{ $sec['note'] }}

@endif
@unless($ro) @endunless
@php $group = null; $i = 0; @endphp @foreach($sec['rows'] as $key => $row) @php $i++; @endphp @if($row['group'] && $row['group'] !== $group) @php $group = $row['group']; @endphp

{{ $group }}

@endif

{{ $i }}. {{ $row['title'] }}

@if($row['points'])
    @foreach($row['points'] as $p)
  • {{ $p }}
  • @endforeach
@endif
@endforeach
@if($sv) Signed by {{ $sv['assessor'] }} · {{ \Carbon\Carbon::parse($sv['date'])->format('j M Y') }} @else Signed as {{ auth()->user()->name }} when you save. @endif
@unless($ro)
@endunless
@if($add && ! $mc->additionSignedOff($letter) && ! $ro)
@csrf

how_to_reg Sign off {{ $letter }} – {{ $sec['title'] }}

@unless($mc->sectionDone($letter))

Save the competency above with every row signed as competent first.

@endunless
@endif
@endforeach {{-- ── Visit sign-offs ── --}} @foreach(range(1, Pack::VISITS) as $n) @php $so = $mc->visitSignoff($n); $vTodo = $mc->visitOutstanding($n); $canSign = $mc->editable("visit{$n}"); @endphp

how_to_reg Sign off visit {{ $n }}

Visit {{ $n }} covers {{ $n === 1 ? 'assessment 1, the underpinning knowledge questions and '.implode(', ', $mc->visitOneLetters()) : 'assessment '.$n }}. @if($n < Pack::VISITS) Signing it off locks these parts and opens visit {{ $n + 1 }}. @else Signing it off lets you mark the pack complete. @endif

@if($so)

task_alt Signed off by {{ $so['by'] }} ({{ $so['designation'] }}) — visit date {{ $fmt($so['date']) }}

@if($so['notes'])

{{ $so['notes'] }}

@endif @elseif(! $canSign)

lock {{ $locked ? 'This assessment is closed.' : 'Available once visit '.($n - 1).' is signed off.' }}

@else @if($vTodo)

Still to do on this visit:

    @foreach($vTodo as $t)
  • {{ $t }}
  • @endforeach
@else

task_alt Everything on visit {{ $n }} is complete and met.

@endif
@csrf
@endif
@endforeach {{-- ── Add a competency ── --}} @if($mc->canAddCompetency()) @php $afterV1 = $mc->visitSignedOff(1) || $locked; @endphp
@csrf

add_circle Add a competency

@if($afterV1) {{ $first }}’s {{ $locked ? 'signed-off record' : 'visit 1' }} stays as it is — only the competency you add needs completing and signing off, then the record is updated. @else It’s added to visit 1, alongside the competencies already chosen. @endif

@foreach($mc->addableLetters() as $l) @endforeach
@error('sections')

{{ $message }}

@enderror
@endif {{-- ── Mark complete / outcome ── --}}
@if($locked)
{{ $mc->status === 'competent' ? 'verified' : 'block' }}

{{ $mc->status === 'competent' ? 'Competent to administer medication' : 'Not yet competent — further supervision or training needed' }}

{{ $mc->signer?->name ? 'Signed off by '.$mc->signer->name : '' }} {{ $mc->signed_off_at ? 'on '.$mc->signed_off_at->format('j M Y') : '' }} @if($mc->expires_at) · valid until {{ $mc->expires_at->format('j M Y') }} @endif

@if($mc->outcome_notes)

{{ $mc->outcome_notes }}

@endif
@else @php $todo = $mc->outstanding(); @endphp

workspace_premium Mark the pack complete

@if($todo)

Still to do before completing:

    @foreach($todo as $t)
  • {{ $t }}
  • @endforeach
@else

task_alt All three visits are signed off.

@endif
@csrf

Not yet competent?

If {{ $first }} needs further supervision or training before administering medication unsupervised, record it here. Start a new full assessment when they’re ready.

@csrf
@if(! empty($mc->responses))
@csrf
@endif
@csrf @method('DELETE')
@endif
@else {{-- ── Annual refresher ── --}} @php $rf = $resp['refresher'] ?? []; @endphp
@csrf

Medication administration competency — annual refresher / spot check

Only for staff whose initial competency was passed and who have had no medication administration error since their last full assessment. Observe a medication round and answer each question.

@php $group = null; @endphp @foreach(Pack::refresher() as $key => $q) @if($q['group'] !== $group) @php $group = $q['group']; @endphp

{{ $group }}

@endif @php $ans = old("answers.$key", $rf['answers'][$key] ?? null); @endphp

{{ $q['question'] }} @if($key === 'r2')If yes, the staff member signs to confirm.@endif

@foreach(Pack::answerChoices($q['answers']) as $val => $lbl) @endforeach
@if($key === 'r18')

Tick the medicine forms you witnessed being administered:

@foreach(Pack::MEDICINE_FORMS as $fk => $fl) @endforeach
@endif @endforeach

Outcome of assessment

@php $outcome = old('outcome', $mc->outcome); @endphp @foreach(Pack::REFRESHER_OUTCOMES as $ok => $ol) @endforeach

Assessor: {{ $rf['assessor'] ?? auth()->user()->name }} ({{ auth()->user()->roleLabel() }}). @if($mc->expires_at) This assessment must be refreshed by {{ $mc->expires_at->format('j M Y') }}, or sooner if circumstances change. @else When submitted as competent it must be refreshed within 12 months, or sooner if circumstances change. @endif

@unless($locked)
@if(! empty($mc->responses)) @endif
@endunless
@unless($locked)
@csrf @method('DELETE')
@csrf
@endunless @endif @endsection