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

Clinic Leader Dr.

NCD analytics

NCD program analytics for {{ $clinicLeader }} and stakeholders.

Clinic
{{ $clinicConnection }}
@if (!empty($ncdAnalytics['lastUpdated']))
Updated {{ $ncdAnalytics['lastUpdated'] }}
@endif
@php $selectedDbs = $ncdConfig['databases'] ?? []; $dateRange = $ncdConfig['date_range'] ?? []; $thresholds = $ncdConfig['thresholds'] ?? []; $privacy = $ncdConfig['privacy'] ?? []; $maskIds = array_key_exists('mask_ids', $privacy) ? (bool) $privacy['mask_ids'] : true; $filterOptions = $ncdAnalytics['filterOptions'] ?? ['genders' => [], 'age_bands' => []]; $selectedFilters = $ncdAnalytics['filters'] ?? []; @endphp
@csrf
Analysis settings
@csrf
Ctrl/Cmd for multi-select.
@if (empty($ncdAnalytics['available']))
No NCD analytics outputs found. Run the analysis first.
@else
@foreach(($ncdAnalytics['kpiCards'] ?? []) as $card)

{{ $card['title'] }}

{{ $card['value'] }}

@if(in_array($card['key'] ?? '', ['bp_control', 'dm_control'], true)) @endif
@endforeach

How BP/DM control % is calculated

@php $rateDetails = $ncdAnalytics['controlRateDetails'] ?? []; @endphp
BP control %
Denominator ({{ number_format($rateDetails['bp_control']['denominator'] ?? 0) }}): all patients whose latest follow-up has a valid BP reading (SBP and DBP parsed from ncd_followups.own_clinic_Bp).
Numerator ({{ number_format($rateDetails['bp_control']['numerator'] ?? 0) }}): the subset of those patients whose latest SBP/DBP is controlled (SBP < {{ $rateDetails['bp_control']['sbp_threshold'] ?? 140 }} and DBP < {{ $rateDetails['bp_control']['dbp_threshold'] ?? 90 }}).
Latest follow-up per patient with valid SBP/DBP. Controlled when SBP < {{ $rateDetails['bp_control']['sbp_threshold'] ?? 140 }} and DBP < {{ $rateDetails['bp_control']['dbp_threshold'] ?? 90 }}.
Numerator: {{ number_format($rateDetails['bp_control']['numerator'] ?? 0) }} / Denominator: {{ number_format($rateDetails['bp_control']['denominator'] ?? 0) }}.
Excluded from denominator: {{ number_format($rateDetails['bp_control']['excluded'] ?? 0) }} of {{ number_format($rateDetails['bp_control']['total_patients'] ?? 0) }} patients. @php $invalidExamples = $rateDetails['bp_control']['invalid_format_examples'] ?? []; $invalidExampleText = ''; if (!empty($invalidExamples)) { $parts = []; foreach ($invalidExamples as $example) { $label = $example['label'] ?? ''; if ($label === '') { continue; } $count = $example['count'] ?? 0; $parts[] = $label . ': ' . number_format($count); } if (!empty($parts)) { $invalidExampleText = implode(', ', $parts); } } @endphp
  • Missing BP: {{ number_format($rateDetails['bp_control']['excluded_groups']['missing'] ?? 0) }}
  • Invalid format: {{ number_format($rateDetails['bp_control']['excluded_groups']['invalid_format'] ?? 0) }} @if($invalidExampleText !== '') (examples: {{ $invalidExampleText }}) @endif
  • Out of range (SBP 50-300 / DBP 30-200): {{ number_format($rateDetails['bp_control']['excluded_groups']['out_of_range'] ?? 0) }}
  • Other: {{ number_format($rateDetails['bp_control']['excluded_groups']['other'] ?? 0) }}
DM control %
Denominator ({{ number_format($rateDetails['dm_control']['denominator'] ?? 0) }}): all patients whose latest follow-up has a diabetes test value (priority: HbA1c -> 2HPP -> FBS -> RBS).
Numerator ({{ number_format($rateDetails['dm_control']['numerator'] ?? 0) }}): the subset of those patients whose latest test is controlled (HbA1c < {{ $rateDetails['dm_control']['hba1c_threshold'] ?? 7.0 }}, 2HPP < {{ $rateDetails['dm_control']['t2hpp_threshold'] ?? 180 }}, FBS < {{ $rateDetails['dm_control']['fbs_threshold'] ?? 126 }}, or RBS < {{ $rateDetails['dm_control']['rbs_threshold'] ?? 200 }}).
Latest follow-up per patient with a diabetes test (priority: HbA1c -> 2HPP -> FBS -> RBS). Controlled when HbA1c < {{ $rateDetails['dm_control']['hba1c_threshold'] ?? 7.0 }}, 2HPP < {{ $rateDetails['dm_control']['t2hpp_threshold'] ?? 180 }}, FBS < {{ $rateDetails['dm_control']['fbs_threshold'] ?? 126 }}, or RBS < {{ $rateDetails['dm_control']['rbs_threshold'] ?? 200 }}.
Numerator: {{ number_format($rateDetails['dm_control']['numerator'] ?? 0) }} / Denominator: {{ number_format($rateDetails['dm_control']['denominator'] ?? 0) }}.
Excluded from denominator: {{ number_format($rateDetails['dm_control']['excluded'] ?? 0) }} of {{ number_format($rateDetails['dm_control']['total_patients'] ?? 0) }} patients. @php $dmInvalidExamples = $rateDetails['dm_control']['invalid_value_examples'] ?? []; $dmInvalidExampleText = ''; if (!empty($dmInvalidExamples)) { $dmParts = []; foreach ($dmInvalidExamples as $example) { $label = $example['label'] ?? ''; if ($label === '') { continue; } $count = $example['count'] ?? 0; $dmParts[] = $label . ': ' . number_format($count); } if (!empty($dmParts)) { $dmInvalidExampleText = implode(', ', $dmParts); } } @endphp
  • Missing test: {{ number_format($rateDetails['dm_control']['excluded_groups']['missing_test'] ?? 0) }}
  • Invalid value: {{ number_format($rateDetails['dm_control']['excluded_groups']['invalid_value'] ?? 0) }} @if($dmInvalidExampleText !== '') (examples: {{ $dmInvalidExampleText }}) @endif
  • Other: {{ number_format($rateDetails['dm_control']['excluded_groups']['other'] ?? 0) }}

Summary

Key rates for selected filters

@foreach(($ncdAnalytics['summaryRows'] ?? []) as $row) @endforeach
Metric Value
{{ $row['metric'] }} {{ $row['value'] }}

Age distribution

Latest age at report end

BP/DM control by sex

Latest follow-up rates

Monthly workload

New registrations vs follow-ups

BP control trend

Latest visit per patient (rate %)

BP stage distribution

Latest follow-up BP stage

Diabetes control trend

Latest visit per patient (rate %)

Diabetes tests used

Latest test per patient

How continuity metrics are calculated

Missed appointment
For each active patient, every visit with Next_Appointment is compared to the next visit date. If the next visit date is not exactly the appointment date (or there is no next visit), that appointment is missed. A patient is counted if they missed at least one appointment in the selected period. If the last visit has a Next_Appointment after the report end date and no matching visit is observed, it is still counted as missed. Inactive patients are excluded. The visit-based missed rate uses total follow-up visits as the denominator.

Active caseload
Latest follow-up per patient: visit_date is within the last {{ $thresholds['active_days'] ?? 90 }} days of the report end date.

LTFU
Latest follow-up per patient: no visit recorded or visit_date is earlier than the report end date minus {{ $thresholds['ltfu_days'] ?? 90 }} days.

Late visit
Latest follow-up per patient: Late_visit or Late_follow is marked yes.

Continuity rates (%)

Late visits, missed appointments, LTFU

@php $missedStats = $ncdAnalytics['missedAppointmentStats'] ?? ['missed_visits' => 0, 'total_visits' => 0, 'rate' => 0]; @endphp
Missed appointment visits: {{ number_format($missedStats['missed_visits'] ?? 0) }} / {{ number_format($missedStats['total_visits'] ?? 0) }} ({{ $missedStats['rate'] ?? 0 }}%)

Quality of care

Lab coverage metrics (%)

Other medications (Foth_medi_spec)

Most common entries

Top medications

@foreach(($ncdAnalytics['otherMeds'] ?? []) as $row) @endforeach
Medication Count
{{ $row['medication'] ?? $row['title'] ?? '' }} {{ $row['count'] ?? $row['value'] ?? '' }}

Control improvement

Baseline uncontrolled -> latest controlled

@foreach(($ncdAnalytics['controlImprovement']['rows'] ?? []) as $row) @endforeach
Metric Eligible Improved Rate %
{{ $row['metric'] }} {{ $row['eligible'] }} {{ $row['improved'] }} {{ $row['rate'] }}

Sustained control

Controlled in the last two visits

@foreach(($ncdAnalytics['sustainedControl']['rows'] ?? []) as $row) @endforeach
Metric Eligible Sustained Rate %
{{ $row['metric'] }} {{ $row['eligible'] }} {{ $row['sustained'] }} {{ $row['rate'] }}

Therapy patterns

Medication counts

Regimen size

Number of meds per patient

Visit interval distribution

Days between visits

@if(!empty($ncdAnalytics['visitIntervals']['median']))
Median interval: {{ $ncdAnalytics['visitIntervals']['median'] }} days | Mean interval: {{ $ncdAnalytics['visitIntervals']['mean'] }}
@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
Back to clinic dashboard
@endsection @push('scripts') @endpush