{{-- Standard HMIS clinician dropdown options. Renders the list of active users who can be assigned as the attending clinician on a visit, encounter, appointment, or any other patient-facing record. The pool is restricted to roles that actually see patients: Clinician · Nurse · Triage Nurse · Dental User Lab, Pharmacy, Imaging, Receptionist, and pure admin roles are intentionally NOT in this list — they don't take clinical responsibility for a patient. Like _department-options, the partial fetches its own data and memoises per request so no controller change is required at any call site. Usage in any parent @include('partials._clinician-options', [ 'selected' => $visit->clinician_id ?? null, // optional 'preferDentalTop' => false, // optional ]) Variables (all optional): $selected id of the currently selected user, used to apply the `selected` attribute $preferDentalTop true to float Dental Users to the top of the list (used on dental encounters so the dentist is the obvious first pick instead of being buried alphabetically among clinicians) --}} @php $selected = $selected ?? null; $preferDentalTop = $preferDentalTop ?? false; // Memoise per request — same pattern as _department-options. // The pool is small (typically <30 users at this clinic) so we // can grab the whole thing once and reuse it across every // dropdown rendered on the page. static $clinicianPool = null; if ($clinicianPool === null) { $clinicianPool = \App\Models\User::with('roles') ->whereHas('roles', function ($q) { // Roles that take clinical responsibility for a // patient. Triage Nurse is a Nurse sub-role — kept // explicit so adding it is intentional, not implicit. $q->whereIn('name', ['Clinician', 'Nurse', 'Triage Nurse', 'Dental User']); }) ->where('is_active', true) ->orderBy('name') ->get(['id', 'name']); } // Optional re-sort: float Dental Users to the top. Used on dental // encounters so the dentist is the obvious first pick. The base // alphabetical order is preserved within each group. $listToRender = $clinicianPool; if ($preferDentalTop) { $listToRender = $clinicianPool->sortBy(function ($u) { $isDental = $u->roles->contains('name', 'Dental User') ? 0 : 1; return $isDental . '|' . strtolower($u->name); })->values(); } @endphp @foreach($listToRender as $u) @endforeach