{{-- Standard HMIS department dropdown options. Renders the canonical 8 main departments + the Specialized Clinics submenu (as ) in one consistent order: Outpatient · Laboratory · Radiology · Inpatient · Maternity · Dental · MCH / FP · Specialized Clinics └── Diabetes / Gynecology / Hypertension / Orthopedic / Pediatric / Physiotherapy / Psychiatric Clinic The partial fetches its own data via Department::activeGrouped() and caches per request, so no controller needs to be changed for the dropdown to work consistently across the system. Usage in any parent @include('partials._department-options', [ 'selected' => $appointment->department_id ?? null, // optional 'matchCode' => 'OPD', // optional 'flat' => false, // optional 'excludeDirect' => false, // optional ]) Variables (all optional): $selected id of the currently selected department, used to apply the `selected` attribute $matchCode pre-select by code (e.g. 'OPD') when no $selected id is provided — handy for "new visit" forms that default to Outpatient $flat true to render every department in a single flat list (children indented with non-breaking spaces), no . Use this for filter dropdowns where a single tap should let the receptionist pick a specific sub-clinic without expanding the group. $excludeDirect true to hide Laboratory and Radiology. Pass this on any OPD / ANC / consultation context where the department dropdown lets the user CORRECT the routing of an existing encounter. Lab and Radiology are not valid corrections in those contexts because choosing them would require creating a completely different direct-encounter visit type — that flow lives on the queue page's "Start New Visit" modal, not on the encounter form itself. --}} @php $selected = $selected ?? null; $matchCode = $matchCode ?? null; $flat = $flat ?? false; $excludeDirect = $excludeDirect ?? false; // Codes that the excludeDirect flag should strip from the list. // These map to the encounter types that have their own dedicated // workflow (direct_lab / direct_radiology) and are not valid // routings for a consultation visit. $excludedCodes = $excludeDirect ? ['LAB', 'RAD'] : []; // Memoise the full tree per request — the partial is rendered on // lots of pages and there is no point re-querying for each form. // The same memo is used regardless of $excludeDirect: we just // filter at render time below, which is cheap. static $deptTree = null; if ($deptTree === null) { $deptTree = \App\Models\Department::activeGrouped(); } $isSelected = function ($dept) use ($selected, $matchCode) { if ($selected !== null && $selected !== '') { return (int) $selected === (int) $dept->id; } if ($matchCode !== null) { return $dept->code === $matchCode; } return false; }; @endphp @foreach($deptTree as $dept) @continue(in_array($dept->code, $excludedCodes, true)) @if($dept->children->isNotEmpty() && ! $flat) {{-- Specialized Clinics: parent is selectable AND opens an optgroup of children, so a clinician can either book into "Specialized Clinics" generically or pick a specific sub-clinic. --}} @foreach($dept->children as $child) @continue(in_array($child->code, $excludedCodes, true)) @endforeach @else @if($flat && $dept->children->isNotEmpty()) @foreach($dept->children as $child) @continue(in_array($child->code, $excludedCodes, true)) @endforeach @endif @endif @endforeach