@extends('layouts.app') @push('styles') @include('dashboard.styles') @endpush @section('content')
@if (!empty($clinicWarning ?? null))
{{ $clinicWarning }}
@endif @if (!empty($message ?? null))
{{ $message }}
@endif @if (!empty($cacheCleared ?? null))
Generated data cleared.
@endif

Clinic Leader Dr.

Clinic dashboard

@php $mode = $viewMode ?? 'none'; $isPeriod = in_array($mode, ['monthly', 'quarterly', 'yearly']); $heroCards = $mode === 'daily' ? $dailyChecks : ($isPeriod ? $monthlyChecks : []); $hasData = ($mode === 'daily' && !empty($dailyChecks)) || ($isPeriod && !empty($monthlyChecks)); $heroValue = $hasData ? ($heroCards[0]['value'] ?? 0) : null; $clinicLabel = $clinicConnection ?? 'Clinic'; $periodLabel = $hasData ? ($mode === 'daily' ? ($dailyDurationSummary['dateLabel'] ?? '') : ($selectedMonthLabel ?? $selectedQuarter ?? '')) : 'Select a view to load data'; $modeLabel = $hasData ? ucfirst($mode) : ''; @endphp

Pulse across reception, labs, and follow-ups tailored for {{ $clinicLeader }}.

Daily check Monthly report Mobile friendly
@php $statusMode = $viewMode ?? 'none'; $isDailyMode = $statusMode === 'daily'; $isGeneratedMode = in_array($statusMode, ['monthly', 'quarterly', 'yearly'], true); $cacheStamp = $cacheUpdatedAt ?? null; @endphp @if ($isDailyMode || $isGeneratedMode)
@if ($isDailyMode) Live Daily counts are live. @elseif ($cacheStamp) Generated Cached {{ $cacheStamp }}. @else Not generated Run Generate to build this period. @endif
@endif
Total Consultations
{{ $heroValue !== null ? $heroValue : '—' }}
@if($hasData)
patients • {{ $modeLabel }} • {{ $clinicLabel }} • {{ $periodLabel }}
@else
Choose Daily, Monthly, Quarterly, or Yearly and apply filters to load data.
@endif

NCD analytics

NCD program insights

Charts generated from `php artisan ncd:analyze` outputs.

@if (!empty($ncdAnalytics['lastUpdated'])) Last updated: {{ $ncdAnalytics['lastUpdated'] }} @endif
@csrf
@if (empty($ncdAnalytics['available']))
{{ $ncdAnalytics['message'] ?? 'NCD analytics outputs not found.' }}
@endif
@php $selectedClinic = $clinicConnection ?? config('database.default'); $currentYear = now()->year; $selectedYearUi = request('year', $currentYear); $quarterYears = array_reverse(range($currentYear - 5, $currentYear + 1)); $quartersByYear = []; foreach ($quarterYears as $y) { $quartersByYear[$y] = [ "{$y}-Q1" => "Q1 ({$y} Jan-Mar)", "{$y}-Q2" => "Q2 ({$y} Apr-Jun)", "{$y}-Q3" => "Q3 ({$y} Jul-Sep)", "{$y}-Q4" => "Q4 ({$y} Oct-Dec)", ]; } $reportMode = in_array(($viewMode ?? ''), ['daily', 'monthly', 'quarterly', 'yearly'], true) ? $viewMode : 'monthly'; @endphp
@php $selectedQuarterValue = $selectedQuarter ?? ''; $selectedQuarterLabel = $selectedQuarterValue; foreach ($quartersByYear as $year => $qList) { if (isset($qList[$selectedQuarterValue])) { $selectedQuarterLabel = $qList[$selectedQuarterValue]; break; } } @endphp Green = cached, Orange = old/legacy, Gray = not cached
@php $clinicParam = $selectedClinic; $exportMonthKey = ($viewMode === 'quarterly') ? ($monthInputValue ?? $selectedMonth) : ($selectedMonth ?? $monthInputValue); $exportQuarterKey = $selectedQuarter ?? ($periodKey ?? ''); $exportEnabled = in_array(($viewMode ?? ''), ['monthly', 'quarterly'], true); @endphp
@if (!empty($dailyChecks))

Daily report

Service summary (day)

@foreach(($dailyChecks ?? []) as $item) @php $accent = $item['accent'] ?? '#0ea5e9'; $rawValue = $item['value'] ?? 0; $value = is_numeric($rawValue) ? number_format((float) $rawValue) : $rawValue; @endphp
{{ $item['title'] ?? '' }} {{ $value }} @if (!empty($item['change'])) • {{ $item['change'] }} @endif
@endforeach
Counts are total visits for the selected day. “Reached lab/counsellor/dispensing” means a same-day record exists in that service module. Gender (headcount) counts unique patients.
@endif @php $dailyGenderBreakdown = array_values(array_filter($dailyGenderBreakdown ?? [], function ($item) { return ($item['title'] ?? '') !== 'Unknown'; })); $hasDailyGender = !empty($dailyGenderBreakdown ?? []); $hasDailyAge = !empty($dailyAgeSummary ?? []) && array_sum($dailyAgeSummary ?? []) > 0; $hasDailyKp = !empty($dailyKpBreakdown ?? []) && array_sum(array_column($dailyKpBreakdown ?? [], 'value')) > 0; $hasDailyDisease = !empty($dailyDiseaseCategories ?? []) && array_sum(array_column($dailyDiseaseCategories ?? [], 'value')) > 0; $hasDailyProgram = !empty($dailyProgramWorkloads ?? []) && array_sum(array_column($dailyProgramWorkloads ?? [], 'value')) > 0; @endphp @if ($hasDailyGender || $hasDailyAge || $hasDailyKp)
@if ($hasDailyGender)

Daily report

Gender (headcount) (day)

@endif @if ($hasDailyAge)

Daily report

Visits by age & status (day)

@endif @if ($hasDailyKp)

Daily report

Key populations (day)

Unknown risk is counted as “General patients”.
@endif
@endif @if ($hasDailyDisease || $hasDailyProgram)
@if ($hasDailyDisease)

Daily report

General diseases (day)

@endif @if ($hasDailyProgram)

Daily report

Program workloads (day)

@endif
@endif
@if (($viewMode ?? 'none') !== 'yearly')

Daily snapshot

Time-in-clinic

{{ $dailyDurationSummary['dateLabel'] }}
Average stay
{{ $dailyDurationSummary['average'] }} mins
Median {{ $dailyDurationSummary['median'] }} mins
90th percentile
{{ $dailyDurationSummary['p90'] }} mins
Long wait >90 mins: {{ $dailyDurationSummary['longWaitRate'] }}%
Long-wait patients
{{ $dailyDurationSummary['longWaiters'] }}
Reception → dispensing • Included {{ max(($dailyDurationSummary['dispensed'] ?? 0) - ($dailyDurationSummary['excludedAfterCutoff'] ?? 0), 0) }} of {{ $dailyDurationSummary['dispensed'] ?? 0 }} dispensed (cutoff {{ $dailyDurationSummary['cutoff'] ?? '16:30' }})
Calculation: start at reception check-in (`created_at` in followup_generals); end at first dispensing time (`created_at` in consumptions). Only PIDs that reached dispensing are included, and any reception/dispensing after 16:30 is excluded. Averages/median/p90 and long-wait (>90 mins) use those intervals per included PID.
@endif

Daily MDs

MD workload (day)

@if (($viewMode ?? 'none') !== 'yearly')

Daily report

Service populated hours (day)

@endif
@php $periodEyebrow = $viewMode === 'quarterly' ? 'Quarterly report' : ($viewMode === 'yearly' ? 'Yearly report' : 'Monthly report'); $periodGenderBreakdown = array_values(array_filter($periodGenderBreakdown ?? [], function ($item) { return ($item['title'] ?? '') !== 'Unknown'; })); $hasPeriodGender = !empty($periodGenderBreakdown ?? []) && array_sum(array_column($periodGenderBreakdown ?? [], 'value')) > 0; $hasPeriodAge = !empty($monthlyAgeSummary ?? []) && array_sum($monthlyAgeSummary ?? []) > 0; $hasPeriodKp = !empty($periodKpBreakdown ?? []) && array_sum(array_column($periodKpBreakdown ?? [], 'value')) > 0; @endphp @if (!empty($monthlyChecks))

{{ $periodEyebrow }}

{{ $viewMode === 'quarterly' ? 'Service summary (Quarter)' : ($viewMode === 'yearly' ? 'Service summary (Year)' : 'Service summary') }}

@if (!empty($periodIsPartial ?? false) && !empty($periodThroughLabel ?? null) && isset($periodRemainingDays))
Through {{ $periodThroughLabel }} • {{ $periodRemainingDays }} day{{ ((int) $periodRemainingDays) === 1 ? '' : 's' }} remaining
@endif
@foreach(($monthlyChecks ?? []) as $item) @php $accent = $item['accent'] ?? '#0ea5e9'; $rawValue = $item['value'] ?? 0; $value = is_numeric($rawValue) ? number_format((float) $rawValue) : $rawValue; @endphp
{{ $item['title'] ?? '' }} {{ $value }} @if (!empty($item['change'])) • {{ $item['change'] }} @endif
@endforeach
Counts are total visits for the selected period. “Reached lab/counsellor/dispensing” means a record exists in that module within the same period. Gender (headcount) counts unique patients.
@endif @if ($hasPeriodGender || $hasPeriodAge || $hasPeriodKp)
@if ($hasPeriodGender)

{{ $periodEyebrow }}

Gender (headcount)

@endif @if ($hasPeriodAge)

{{ $periodEyebrow }}

Visits by age & status

@endif @if ($hasPeriodKp)

{{ $periodEyebrow }}

Key populations

@endif
@endif
@if (!empty($diseaseCategories))

{{ $periodEyebrow ?? ($viewMode === 'quarterly' ? 'Quarterly report' : ($viewMode === 'yearly' ? 'Yearly report' : 'Monthly report')) }}

General diseases ({{ $selectedMonthLabel }})

@endif @if (!empty($programCategories))

{{ $periodEyebrow ?? ($viewMode === 'quarterly' ? 'Quarterly report' : ($viewMode === 'yearly' ? 'Yearly report' : 'Monthly report')) }}

Program workloads

@endif

{{ $periodEyebrow ?? ($viewMode === 'quarterly' ? 'Quarterly report' : ($viewMode === 'yearly' ? 'Yearly report' : 'Monthly report')) }}

Planned vs unplanned

Appointments
@php $showDataEntryCharts = false; @endphp @if ($showDataEntryCharts && !empty($monthlyClerkSummary))

Monthly report

Data entry workload (month)

Monthly report

Data entry populated hours (month)

@endif @if ($isPeriod)

{{ $periodEyebrow }}

MD workload ({{ $selectedMonthLabel }})

@endif @if (!empty($ncdAnalytics['available']))

NCD workload

Monthly registrations and follow-ups

BP control trend

Latest visit per patient (rate %)

Diabetes control trend

Latest visit per patient (rate %)

Quality of care coverage

Lab monitoring rates (%)

Therapy patterns

Medication counts (latest follow-up)

Visit interval distribution

Days between visits @if (!empty($ncdAnalytics['visitIntervals']['median'])) • Median {{ $ncdAnalytics['visitIntervals']['median'] }}d @endif @if (!empty($ncdAnalytics['visitIntervals']['mean'])) • Mean {{ $ncdAnalytics['visitIntervals']['mean'] }}d @endif

Risk-outcome linkage

@foreach(($ncdAnalytics['riskOutcome']['cvd'] ?? []) as $row) @endforeach
Group Patients BP control % DM control %
{{ $row['label'] }} {{ $row['patients'] }} {{ $row['bp_control_rate'] }} {{ $row['dm_control_rate'] }}
@foreach(($ncdAnalytics['riskOutcome']['ckd'] ?? []) as $row) @endforeach
Group Patients BP control % DM control %
{{ $row['label'] }} {{ $row['patients'] }} {{ $row['bp_control_rate'] }} {{ $row['dm_control_rate'] }}

Medication change vs control

@foreach(($ncdAnalytics['medChange'] ?? []) as $row) @endforeach
Group Patients BP control % DM control %
{{ $row['label'] }} {{ $row['patients'] }} {{ $row['bp_control_rate'] }} {{ $row['dm_control_rate'] }}

Equity by sex

@foreach(($ncdAnalytics['equity']['sex'] ?? []) as $row) @endforeach
Sex Patients BP control % DM control % LTFU %
{{ $row['label'] }} {{ $row['patients'] }} {{ $row['bp_control_rate'] }} {{ $row['dm_control_rate'] }} {{ $row['ltfu_rate'] }}

Equity by age band

@foreach(($ncdAnalytics['equity']['age'] ?? []) as $row) @endforeach
Age band Patients BP control % DM control % LTFU %
{{ $row['label'] }} {{ $row['patients'] }} {{ $row['bp_control_rate'] }} {{ $row['dm_control_rate'] }} {{ $row['ltfu_rate'] }}

Outcomes

Latest follow-up outcomes

Referrals & transfers

Referral locations and transfers

@endif

Reference

How counts are calculated (edit this text)

Edit this section to explain how each metric is counted and which tables it uses.

  • Service summary: followup_generals (Visit Date, New_Old, Unplan) + lab modules (Lab, Rprtest, LabGeneralTest, LabHbcTest, Urine, Labstitest, Lab_oi) + counsellor_records + consumptions.
  • Visits by age & status: followup_generals + pt_configs/patients (DOB, Agey/Agem). New = Reg Date in the same month as the selected day.
  • Gender (headcount): pt_configs/patients (unique PIDs).
  • Key populations: pt_configs/patients Main Risk/Sub Risk for PIDs in followup_generals.
  • General diseases: ConsultationReportService fields from followup_generals (ugen_*, ogen_*, etc.).
  • Program workloads: ncd_followups, stimales, stifemales, coulsellings, anc_follow_ups, feeding_centerfups, cervicalcancer1s/cervicalcancers, cmvs, mental__healths, prevention_logsheets, prevention_c_b_s, pre_tb_records/pre_t_b_s, tb_register_o3_s, tbipts.
  • Planned vs unplanned: followup_generals.Unplan.
  • MD workload: followup_generals.Current_MD.
  • Time-in-clinic: timestamps from followup_generals + lab modules + counsellor_records + consumptions.
@endsection @push('scripts') @endpush