import { useMemo, useState } from "react"; import { Link } from "react-router-dom"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { AlertTriangle, ChevronDown, ChevronRight, Cpu, Download, FileSpreadsheet, HelpCircle, Info, Printer, RefreshCw, Sparkles, X, } from "lucide-react"; import { Bar, BarChart, CartesianGrid, Legend, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis, } from "recharts"; import { aiApi, type AIFilterParams, type AIHowCalculated, type AIMetric, type AINarrative, type AIPeriod, type AISectionKey, type AISuggestion, } from "@/api/ai"; import { categoriesApi, departmentsApi } from "@/api/masters"; import { useAuthStore } from "@/hooks/useAuth"; import { formatDateTime, formatINR } from "@/lib/format"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; function SectionSkeleton() { return (
{narrative.headline}
{narrative.bullets.length > 0 && ({howCalculated.latest_equipment_rule}
)} {howCalculated.missing_data_rule && ({howCalculated.missing_data_rule}
)} {howCalculated.settings_used && Object.keys(howCalculated.settings_used).length > 0 && (Active Settings
| Metric ID | Label | Value |
|---|---|---|
| {m.id} | {m.label} | {m.formatted} |
{suggestion.detail}
{suggestion.action_for_human}
{suggestion.evidence_metric_ids.length > 0 && ({eid}
{m?.label ?? ""}
{m?.formatted ?? "—"}
Deterministic cost, depreciation, efficiency, and breakdown analysis with evidence-grounded summaries.
Advisory items generated strictly from deterministic biomedical rules. Every decision remains with hospital staff.
Latest {comparisonQuery.data.summary.latest_count} equipment evaluated over a{" "} {comparisonQuery.data.horizon_years}-year horizon
| Asset | Purchase Price | In-House Cost | Outsourced Cost | Rent Cost | Lowest Option | Difference |
|---|---|---|---|---|---|---|
|
{r.asset_code}
{r.asset_name}
|
{r.purchase_value != null ? ( formatINR(r.purchase_value) ) : ( Insufficient data: purchase_value )} | {r.in_house_cost != null ? ( formatINR(r.in_house_cost) ) : ( {r.in_house_reason || "Insufficient data"} )} | {r.outsourced_cost != null ? ( formatINR(r.outsourced_cost) ) : ( {r.outsourced_reason || "Insufficient data"} )} | {r.rent_cost != null ? ( formatINR(r.rent_cost) ) : ( {r.rent_reason || "Insufficient data"} )} | {r.lowest_scenario_label ? ( {r.lowest_scenario_label} ) : ( Insufficient data )} | {r.savings_vs_next != null ? formatINR(r.savings_vs_next) : "—"} |
Current book value, accumulated depreciation, cumulative maintenance cost, and replacement review flags (≥{" "} {Math.round(depreciationQuery.data.summary.replacement_review_ratio * 100)}%)
| Asset | Purchase Value | Method | Book Value | Accum. Dep. | Maintenance Cost | Maint. Ratio | Lifetime Cost |
|---|---|---|---|---|---|---|---|
|
e.stopPropagation()}
className="font-mono text-xs font-semibold text-[#1e3a8a] hover:underline"
>
{r.asset_code}
{r.asset_name}
|
{r.purchase_value != null ? ( formatINR(r.purchase_value) ) : ( {r.depreciation_reason === "rented" ? "Rented" : "Insufficient data: purchase_value"} )} | {r.method ? ( r.method === "straight_line" ? "Straight Line" : "Written Down" ) : ( {r.depreciation_reason || "N/A"} )} | {r.book_value != null ? ( formatINR(r.book_value) ) : ( {r.depreciation_reason || "N/A"} )} | {r.accumulated_depreciation != null ? formatINR(r.accumulated_depreciation) : "—"} | {formatINR(r.maintenance_cost)} | {r.maintenance_ratio != null ? ( {(r.maintenance_ratio * 100).toFixed(1)}% ) : ( "—" )} | {r.lifetime_cost != null ? formatINR(r.lifetime_cost) : "—"} |
Weighted composite of uptime (50%), PM compliance (20%), SLA response (15%), and repeat-free reliability (15%)
| Group | Type | Assets | Uptime % | PM % | Response | Repeat-Free | Score |
|---|---|---|---|---|---|---|---|
| {r.group} |
|
{r.assets_in_scope} | {r.uptime_pct.toFixed(1)}% | {r.pm_compliance_pct.toFixed(1)}% | {r.response_score.toFixed(1)} | {r.repeat_free_score.toFixed(1)} | {r.efficiency_score.toFixed(1)} |
Total breakdowns, average per equipment (including zero-breakdown assets), top-10 equipment, and monthly trend
| Top-10 Equipment | Department | Category | Breakdowns | Avg Downtime (hrs) | Repeat Window | Repeat Flag |
|---|---|---|---|---|---|---|
|
{r.asset_code}
{r.asset_name}
|
{r.department_name} | {r.category_name} | {r.breakdown_count} | {r.avg_downtime_hours.toFixed(1)} | {r.repeat_window_count} | {r.repeat_failure ? ( Repeat Failure ) : ( Normal )} |