@php $flowPid=$flowPid ?? ''; $minutes=static fn($seconds)=>$seconds===null ? '—' : number_format($seconds/60,1).' min'; $arrivalLabels=['early'=>'8:30–10:30 AM','late_morning'=>'10:30 AM–12:00 PM','afternoon'=>'12:00–4:30 PM','outside'=>'Outside 8:30 AM–4:30 PM','unclassified'=>'Cannot classify']; $stageNames=['reception'=>'Reception','ncd'=>'NCD entry','dispensing'=>'Dispensing']; $intervalNames=['reception_ncd'=>'Reception → NCD entry','ncd_dispensing'=>'NCD entry → Dispensing','total'=>'Reception → Dispensing']; $reasonNames=['negative'=>'Timestamp order reversed','start_missing'=>'Start record missing','end_missing'=>'End record missing','start_duplicate'=>'Duplicate start records','end_duplicate'=>'Duplicate end records','start_missing_timestamp'=>'Start timestamp missing','end_missing_timestamp'=>'End timestamp missing','start_different_day'=>'Start entered on another date','end_different_day'=>'End entered on another date']; @endphp
input('flow')==='1') open @endif>

NCD clinic-time analysis

Expand / collapse

Recorded time gaps between reception entry, doctor’s NCD record and medicine dispensing.

@if($ran)@endif @foreach($filters['clinics'] as $connection)@endforeach @foreach(['from','to','pid','medicine','show'] as $field)@endforeach

Leave General ID blank for all NCD patients, or enter an exact General ID to see that patient’s timing on this date. The medicine audit’s filters do not limit this analysis. Doctor workload always covers the whole selected date. Times use created_at (first save), not later edits or a measured consultation start. Display timezone: Myanmar (UTC+06:30).

@if(!$flowRan)
Choose a date and click Analyse time. Running the medicine audit also loads timing for its To date.
@elseif(!$flow || !collect($flow['sources'])->contains(static fn($s)=>$s['ok'])) @else @if(collect($flow['sources'])->contains(static fn($s)=>!$s['ok']))@endif
{{ \Carbon\Carbon::parse($flowDate)->format('d-m-Y') }}@if($flowPid!=='')General ID: {{ $flowPid }}@endif{{ $flow['cohort'] }} NCD {{ $flow['cohort']===1 ? 'patient' : 'patients' }}{{ $flowPid!=='' ? ' matched' : '' }}{{ $flow['coverage']['reception'] }} reception records linked{{ $flow['coverage']['ncd'] }} NCD records linked{{ $flow['coverage']['dispensing'] }} dispensing records linked
@if($flowPid!=='')

Patient timing · General ID {{ $flowPid }}

@forelse($flow['patients'] as $patient)

{{ $clinics[$patient['clinic']] }} · {{ \Carbon\Carbon::parse($flowDate)->format('d-m-Y') }}

Arrival period: {{ $arrivalLabels[$patient['arrival_period'] ?? 'unclassified'] }}

@foreach($patient['stages'] as $stage=>$record)

{{ $stageNames[$stage] }} saved

{{ $record['time'] ?? '—' }}{{ $record['state']==='ok' ? 'First save time' : ucfirst(str_replace('_',' ',$record['state'])) }}
@endforeach
@if($patient['total']===null)

A reliable total clinic time cannot be calculated from these records. Missing, duplicate, other-day or reversed timestamps are shown in the details below.

@endif @empty
No NCD visit matched this General ID and date in the selected clinics. Check the date and General ID. The doctor table below still shows the whole day.
@endforelse
@endif
@foreach($intervalNames as $key=>$label) @php($stat=$flow['statistics'][$key])

{{ $label }}

{{ $minutes($stat['mean']) }}{{ $flowPid!=='' && $flow['cohort']===1 ? 'Recorded gap' : 'Average' }} · {{ $stat['count'] }} valid {{ $key==='total' ? 'completed visits' : 'patient pairs' }}@if($flowPid==='')
Median {{ $minutes($stat['median']) }}90th percentile {{ $minutes($stat['p90']) }}
@endif{{ $stat['excluded'] }} excluded / incomplete @if($stat['max']!==null) · longest {{ $minutes($stat['max']) }} @endif
@endforeach
@if($flowPid==='')

Percentage of valid gaps by duration

Each chart uses that interval’s valid patient pairs as its denominator. The two averages can have different sample counts. Zero-minute gaps are included.

@foreach(['reception_ncd','ncd_dispensing'] as $key) @php($stat=$flow['statistics'][$key])
{{ $intervalNames[$key] }}{{ $stat['count'] }} valid pairs
@if($stat['count']) @else
No valid patient pairs to graph.
@endif
    @foreach($stat['bands'] as $index=>$band)
  • {{ $band['label'] }} {{ $band['percent'] }}% ({{ $band['count'] }})
  • @endforeach
@endforeach
@endif @php($workload=$flow['workload'] ?? ['entries'=>0,'doctors'=>[],'doctor_columns_missing'=>[]])

NCD follow-up records by doctor

{{ $workload['entries'] }} records · {{ \Carbon\Carbon::parse($flowDate)->format('d-m-Y') }}

All patients in the selected clinics on this visit date, even when a General ID is entered above. Groups use Doctor Init saved in the NCD form; this is the assigned doctor, not a verified login audit trail. Counts include duplicate records and entries saved on another day.

@if($workload['doctor_columns_missing'])
Doctor Init is unavailable in @foreach($workload['doctor_columns_missing'] as $clinic){{ $clinics[$clinic] }}{{ $loop->last ? '.' : ', ' }}@endforeach These records appear as Not recorded.
@endif
@forelse($workload['doctors'] as $doctor) @empty@endforelse
NCD record counts and percentage of all {{ $workload['entries'] }} records for the selected visit date
ClinicDoctor InitNCD recordsDistinct patientsShare of daily recordsFirst saved on visit dateOther / missing save date
{{ $clinics[$doctor['clinic']] }}{{ $doctor['doctor'] ?? 'Not recorded' }}{{ $doctor['entries'] }}{{ $doctor['patients'] }} {{ number_format($doctor['percent'],1) }}% {{ $doctor['same_day'] }}{{ $doctor['other_day'] }} other day{{ $doctor['missing_timestamp'] }} missing timestamp
No NCD follow-up records for this date in the loaded clinics.

Distinct patients are counted by General ID within each doctor’s group; the same patient can appear under more than one doctor. Percentages use NCD record counts, including Not recorded, and may differ slightly from 100% after rounding.

Data completeness and excluded intervals

The cohort includes patients marked NCD at reception or having an NCD follow-up on this visit date. General ID and date must match. Duplicate records, missing timestamps, records created on another day, and reversed time order are excluded from the affected interval. End-to-end timing requires all three stages in order. These are recording gaps, which may include waiting and consultation time.

  • {{ $flow['cohort']-$flow['coverage']['ncd'] }} patients without an NCD entry
  • {{ $flow['cohort']-$flow['coverage']['dispensing'] }} patients without dispensing
  • {{ $flow['cohort']-$flow['coverage']['reception'] }} patients without reception
  • {{ $flow['quality']['negative'] }} patients with reversed timestamps
  • {{ $flow['quality']['duplicate'] }} patients with duplicate stage records
  • {{ $flow['quality']['different_day'] }} patients with records created on another date
  • {{ $flow['quality']['missing_timestamp'] }} patients with missing timestamps
  • {{ array_sum($flow['unlinked']) }} source rows with invalid/unlinked General ID or visit date
@foreach($flow['exclusions'] as $key=>$reasons)
{{ $intervalNames[$key] }}: @forelse($reasons as $reason=>$count){{ $reasonNames[$reason] ?? $reason }}: {{ $count }}@if(!$loop->last) · @endif@empty No excluded pairs. @endforelse
@endforeach Percentages may not add to exactly 100% because of rounding. The 90th percentile uses the nearest-rank method.
Patient timing details · {{ count($flow['patients']) }} of {{ $flow['cohort'] }} patients

Up to 100 patients are shown, with incomplete/problem records first. All eligible patients are included in the summary calculations.

@forelse($flow['patients'] as $patient) @foreach($patient['stages'] as $key=>$stage)@if($key==='reception')@endif @endforeach @empty@endforelse
Clinic / General IDReception savedArrival periodNCD savedDispensing savedReception → NCDNCD → DispensingTotal clinic timeReview notes
{{ $clinics[$patient['clinic']] }}
{{ $patient['pid'] }}
{{ $stage['time'] ?? '—' }}{{ $stage['state']==='ok' ? 'Saved' : str_replace('_',' ',$stage['state']) }} · row{{ count($stage['ids'])===1 ? '' : 's' }} {{ $stage['ids'] ? '#'.implode(', #',$stage['ids']) : '—' }}{{ $arrivalLabels[$patient['arrival_period'] ?? 'unclassified'] }}{{ $minutes($patient['gaps']['reception_ncd']['seconds']) }}{{ $minutes($patient['gaps']['ncd_dispensing']['seconds']) }}{{ $minutes($patient['total']) }}@forelse($patient['issues'] as $issue){{ str_replace('_',' ',$issue) }}@empty Complete @endforelse
No NCD patients recorded for this date.
@if(isset($flow['arrivals'])) @php($arrivals=$flow['arrivals'])

Time in clinic by arrival period

Groups use Reception created_at in Myanmar time as the recorded arrival time. This comparison covers all {{ $arrivals['cohort'] }} NCD patients for {{ \Carbon\Carbon::parse($flowDate)->format('d-m-Y') }}, even when you search for one General ID.

@foreach($arrivals['groups'] as $group) @foreach(['reception_ncd','ncd_dispensing','total'] as $interval) @php($stat=$group['statistics'][$interval]) @endforeach @endforeach
Average recorded time for patients arriving in each period
Reception arrival periodNCD patientsAverage Reception → NCDAverage NCD → DispensingAverage total clinic time
{{ $group['label'] }}{{ $group['description'] }}{{ $group['patients'] }}{{ number_format($group['share_percent'],1) }}% of daily NCD patients{{ $minutes($stat['mean']) }}{{ $stat['count'] }} valid · {{ $stat['excluded'] }} excluded / incomplete

Compare average total clinic time

@if(collect($arrivals['groups'])->contains(static fn($group)=>$group['statistics']['total']['count']>0)) @foreach($arrivals['groups'] as $group)
{{ $group['label'] }}{{ $minutes($group['statistics']['total']['mean']) }}
@endforeach @else
No valid complete visits to compare for these arrival periods.
@endif

{{ $arrivals['grouped'] }} patients grouped · {{ $arrivals['outside'] }} outside 8:30 AM–4:30 PM · {{ $arrivals['unclassified'] }} cannot be grouped because reception is missing, duplicated, saved on another day or has no valid timestamp.

10:30 AM starts the second group; 12:00 PM starts the third. The third group includes the entire 4:30 PM minute. Patients outside the periods stay in the daily totals but are excluded from these three group averages. Each average divides that group’s summed valid time gaps by its valid patient count; incomplete or invalid gaps are excluded separately for each interval. Bar length compares average total minutes, not patient percentages.

@endif @endif