{{-- ═══════════════════════════════════════════════════════════════════════ Queue routing helper — include anywhere that renders a visit row with an "Open" action. Routes based on visit_type and enrollment state: ANC visit + AncRegistration (active) → maternity.anc.show ANC visit + NO AncRegistration → maternity.anc.register?patient_id=… (guides user to enroll instead of dumping in OPD) Everything else → visits.show (OPD encounter) Usage: @include('partials._queue-routing-helper') Open The if (!function_exists(...)) guard lets this be included multiple times per request without redeclaration errors. ═══════════════════════════════════════════════════════════════════════ --}} @php if (!function_exists('queueOpenUrl')) { function queueOpenUrl($visit) { if ($visit->visit_type === 'anc' && $visit->patient_id) { $ancReg = \App\Models\AncRegistration::where('patient_id', $visit->patient_id) ->where('status', 'active')->first(); if ($ancReg) return route('maternity.anc.show', $ancReg); // Unenrolled ANC visit → send to enrollment with patient pre-filled return route('maternity.anc.register', ['patient_id' => $visit->patient_id]); } return route('visits.show', $visit); } } @endphp