	<div class="table-responsive">
	<table class="table table-striped p-0 m-0 table-sm border-top border-bottom text-nowrap">
		<thead class="bg-light">
			<tr>
				<th class="border-0">#</th>
				<th class="border-0">Name</th>
				<th class="border-0">DOB</th>
				@if($pro->pro_type == 'ADMIN')
				<th class="border-0">Age</th>
				<th class="border-0">Sex</th>
				<th class="border-0">BMI</th>
				@endif
				<th class="border-0">Insurance</th>
				@if($pro->pro_type == 'ADMIN')
					<th class="border-0">MCP</th>
				@endif
				<th class="border-0"># Visits</th>
				<th class="border-0">Last Visit</th>
				<th class="border-0">Next Appt.</th>
				<th class="border-0">Status</th>

				@if($pro->pro_type !== 'ADMIN')
					<th class="border-0">Cellular BP</th>
					<th class="border-0">Last BP</th>
					<th class="border-0">Cellular Scale</th>
					<th class="border-0">Last Weight</th>
				@endif

				<th class="border-0">Eligible For RM</th>
				<th class="border-0">Enrolled In RM</th>
				<th class="border-0">RM Setup</th>

				@if($pro->pro_type !== 'ADMIN')
					<th class="border-0"># Meas. days this mt.</th>
					<th class="border-0">Spoken to this mt.?</th>
				@endif

			</tr>
		</thead>
		<tbody>
			@foreach($patients as $patient)
			<tr>
				<td>
					<a native target="_blank" href="{{route('patients.view.dashboard', $patient)}}">
						{{$patient->chart_number}}
					</a>
				</td>
				<td>{{$patient->displayName()}}</td>
				<td>{{ friendly_date_time($patient->dob, false) }}</td>
				@if($pro->pro_type == 'ADMIN')
				<td>{{ $patient->age_in_years ?  $patient->age_in_years : '-' }}</td>
				<td>{{ $patient->sex }}</td>
				<td>
					<div class="d-none d-dflex flex-column">
						@if($patient->usual_bmi_min && $patient->usual_bmi_max)
						<small class="text-muted">BMI (Usual): <b>{{ $patient->usual_bmi_min }}</b> {{ $patient->usual_bmi_min_category }} to <b>{{ $patient->usual_bmi_max }}</b> {{ $patient->usual_bmi_max_category }}</small>
						@endif
						@if($patient->ideal_bmi)
						<small class="text-muted">BMI (Ideal) <b>{{ $patient->ideal_bmi }}</b> {{ $patient->ideal_bmi_category }}</small>
						@endif
					</div>
				</td>
				@endif
				<td>
					@include('app.patient.coverage_column_renderer', ['patient'=>$patient])
				</td>
				@if($pro->pro_type == 'ADMIN')
					<td>{{$patient->mcp->display_name ?? '--'}}</td>
				@endif
				<td>
					{{count($patient->activeNotes)}}
				</td>
				<td>
					{{ friendly_date($patient->most_recent_completed_mcp_note_date) }}
					{{-- {{$patient->lastMcpAppointment ? friendly_date_time($patient->lastMcpAppointment->raw_date.' '.$patient->lastMcpAppointment->raw_start_time) : '-'}}--}}
				</td>
				<td>{{$patient->nextMcpAppointment ? friendly_date_time($patient->nextMcpAppointment->raw_date.' '.$patient->nextMcpAppointment->raw_start_time) : '-'}}</td>
				<td>{{$patient->nextMcpAppointment ? $patient->nextMcpAppointment->status : '-'}}</td>

				@if($pro->pro_type !== 'ADMIN')
				<td>
					<?php $bpDevice = $patient->firstCellularBPDevice(); ?>
					{{!!$bpDevice ? 'Yes' : 'No'}}
				</td>
				<td>
					@if(!!$bpDevice && $patient->most_recent_cellular_bp_dbp_mm_hg && $patient->most_recent_cellular_bp_sbp_mm_hg)
						{{ $patient->most_recent_cellular_bp_sbp_mm_hg }} / {{ $patient->most_recent_cellular_bp_dbp_mm_hg }}
					@else
						-
					@endif
				</td>
				<td>
					<?php $weightDevice = $patient->firstCellularWeightDevice(); ?>
					{{!!$weightDevice ? 'Yes' : 'No'}}
				</td>
				<td>
					@if(!!$weightDevice && $patient->most_recent_cellular_weight_value)
						{{ round($patient->most_recent_cellular_weight_value, 1) }}
					@else
						-
					@endif
				</td>
				@endif

				<td>
					<div>{{$patient->is_eligible_for_rm}}</div>
					@if(!$patient->is_eligible_for_rm)
						<div>
							@if($patient->why_not_eligible_for_rm_category)[{{$patient->why_not_eligible_for_rm_category}}] @endif {{$patient->why_not_eligible_for_rm_memo}}
						</div>
					@endif 
				</td>
				<td>
					<div>{{$patient->is_enrolled_in_rm}}</div> {{-- correct --}}
					@if(!$patient->is_enrolled_in_rm) {{-- correct --}}
						<div>
							@if($patient->why_not_enrolled_in_rm_category)[{{$patient->why_not_enrolled_in_rm_category}}] @endif {{$patient->why_not_enrolled_in_rm_memo}}
						</div>
					@endif 
				</td>
				<td>
					{{$patient->has_rm_setup_been_performed  ? 'YES': 'NO'}}
					@if($patient->has_rm_setup_been_performed && $patient->rmSetupCareMonth)
						<a href="{{route('patients.view.care-months.view.dashboard', ['patient' => $patient, 'careMonth' => $patient->rmSetupCareMonth])}}">RM Setup Care Month</a>
					@endif
				</td>

				@if($pro->pro_type !== 'ADMIN')
					<?php $currentCareMonth = $patient->currentCareMonth(); ?>
					<td>
						@if(!!$currentCareMonth && !is_null($currentCareMonth->number_of_days_with_remote_measurements))
							{{$currentCareMonth->number_of_days_with_remote_measurements}}
						@else
							0
						@endif
					</td>
					<td>
						@if(!!$currentCareMonth)
							{{$currentCareMonth->has_anyone_interacted_with_client_about_rm_outside_note ? 'Yes' : 'No'}}
						@else
							No
						@endif
					</td>
				@endif

			</tr>
			@endforeach

			@if(count($patients) === 0)
			<tr>
				<td colspan="24">No records found!</td>
			</tr>
			@endif
		</tbody>

	</table>
</div>
<div class="p-3">
	{{$patients->withQueryString()->links()}}
</div>
