{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-radar-news2",
  "title": "NEWS2 radar chart",
  "description": "A NEWS2 early warning score, scored from raw observations, as a radar of each parameter's points.",
  "dependencies": [
    "recharts@^3.8.0"
  ],
  "registryDependencies": [
    "card",
    "badge",
    "chart"
  ],
  "files": [
    {
      "path": "registry/base-nova/charts/chart-radar-news2.tsx",
      "content": "\"use client\"\n\nimport {\n  PolarAngleAxis,\n  PolarGrid,\n  PolarRadiusAxis,\n  Radar,\n  RadarChart,\n} from \"recharts\"\n\nimport {\n  Card,\n  CardAction,\n  CardContent,\n  CardDescription,\n  CardFooter,\n  CardHeader,\n  CardTitle,\n} from \"@/components/ui/card\"\nimport { Badge } from \"@/components/ui/badge\"\nimport {\n  ChartContainer,\n  ChartTooltip,\n  type ChartConfig,\n} from \"@/components/ui/chart\"\nimport { IconPlaceholder } from \"@/icons/icon-placeholder\"\n\nexport const description =\n  \"A NEWS2 early warning score, as a radar of each parameter's points\"\n\n// One set of observations for a fictional patient on a ward.\nconst observations = {\n  respirationRate: 22,\n  oxygenSaturation: 94,\n  onOxygen: false,\n  systolic: 104,\n  pulse: 98,\n  alert: true,\n  temperature: 38.4,\n}\n\n// Points for a value against NEWS2 bands, each [upper limit, points] in\n// order; a value above every limit scores the last band's points.\nfunction band(value: number, bands: [number, number][], above: number) {\n  return bands.find(([limit]) => value <= limit)?.[1] ?? above\n}\n\n// The Royal College of Physicians' NEWS2 chart, with SpO2 scale 1. Check it\n// against the chart your organisation uses before relying on it.\nconst chartData = [\n  {\n    parameter: \"Respiration rate\",\n    short: \"RR\",\n    reading: `${observations.respirationRate}/min`,\n    points: band(\n      observations.respirationRate,\n      [\n        [8, 3],\n        [11, 1],\n        [20, 0],\n        [24, 2],\n      ],\n      3\n    ),\n  },\n  {\n    parameter: \"Oxygen saturation\",\n    short: \"SpO₂\",\n    reading: `${observations.oxygenSaturation}%`,\n    points: band(\n      observations.oxygenSaturation,\n      [\n        [91, 3],\n        [93, 2],\n        [95, 1],\n      ],\n      0\n    ),\n  },\n  {\n    parameter: \"Air or oxygen\",\n    short: \"O₂\",\n    reading: observations.onOxygen ? \"Oxygen\" : \"Air\",\n    points: observations.onOxygen ? 2 : 0,\n  },\n  {\n    parameter: \"Systolic blood pressure\",\n    short: \"SBP\",\n    reading: `${observations.systolic} mmHg`,\n    points: band(\n      observations.systolic,\n      [\n        [90, 3],\n        [100, 2],\n        [110, 1],\n        [219, 0],\n      ],\n      3\n    ),\n  },\n  {\n    parameter: \"Pulse\",\n    short: \"Pulse\",\n    reading: `${observations.pulse}/min`,\n    points: band(\n      observations.pulse,\n      [\n        [40, 3],\n        [50, 1],\n        [90, 0],\n        [110, 1],\n        [130, 2],\n      ],\n      3\n    ),\n  },\n  {\n    parameter: \"Consciousness\",\n    short: \"ACVPU\",\n    reading: observations.alert ? \"Alert\" : \"New confusion or less\",\n    points: observations.alert ? 0 : 3,\n  },\n  {\n    parameter: \"Temperature\",\n    short: \"Temp\",\n    reading: `${observations.temperature} °C`,\n    points: band(\n      observations.temperature,\n      [\n        [35, 3],\n        [36, 1],\n        [38, 0],\n        [39, 1],\n      ],\n      2\n    ),\n  },\n]\n\nconst chartConfig = {\n  points: {\n    label: \"Points\",\n    color: \"var(--chart-2)\",\n  },\n} satisfies ChartConfig\n\n// The clinical risk NEWS2 assigns: a total of 7 or more is high, 5 or more\n// is medium, and any single parameter scoring 3 raises a low total to\n// low–medium.\nconst total = chartData.reduce((sum, { points }) => sum + points, 0)\nconst anyThree = chartData.some(({ points }) => points === 3)\nconst risk =\n  total >= 7 ? \"High\" : total >= 5 ? \"Medium\" : anyThree ? \"Low–medium\" : \"Low\"\nconst highest = chartData.reduce((a, b) => (b.points > a.points ? b : a))\n\nexport function ChartRadarNews2() {\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle>NEWS2</CardTitle>\n        <CardDescription>\n          Early warning score, latest observations\n        </CardDescription>\n        <CardAction className=\"flex flex-col items-end gap-1.5\">\n          <div className=\"text-2xl leading-none font-semibold\">\n            {total}{\" \"}\n            <span className=\"text-sm font-normal text-muted-foreground\">\n              points\n            </span>\n          </div>\n          <Badge variant=\"outline\">\n            {risk === \"Low\" ? (\n              <IconPlaceholder\n                lucide=\"CheckIcon\"\n                tabler=\"IconCheck\"\n                hugeicons=\"Tick02Icon\"\n                phosphor=\"CheckIcon\"\n                remixicon=\"RiCheckLine\"\n                data-icon=\"inline-start\"\n              />\n            ) : (\n              <IconPlaceholder\n                lucide=\"TriangleAlertIcon\"\n                tabler=\"IconAlertTriangle\"\n                hugeicons=\"Alert02Icon\"\n                phosphor=\"WarningIcon\"\n                remixicon=\"RiAlertLine\"\n                data-icon=\"inline-start\"\n              />\n            )}\n            {risk} risk\n          </Badge>\n        </CardAction>\n      </CardHeader>\n      <CardContent className=\"pb-0\">\n        <ChartContainer\n          config={chartConfig}\n          className=\"mx-auto aspect-square max-h-[250px]\"\n        >\n          <RadarChart data={chartData} outerRadius=\"66%\">\n            <ChartTooltip\n              cursor={false}\n              content={({ active, payload }) => {\n                const row = payload?.[0]?.payload as\n                  (typeof chartData)[number] | undefined\n                if (!active || !row) return null\n                return (\n                  <div className=\"grid min-w-[9rem] gap-1 rounded-lg border bg-background px-2.5 py-1.5 text-xs shadow-xl\">\n                    <div className=\"font-medium\">{row.parameter}</div>\n                    <div className=\"flex items-baseline justify-between gap-4\">\n                      <span className=\"text-muted-foreground\">\n                        {row.reading}\n                      </span>\n                      <span className=\"font-mono font-medium tabular-nums\">\n                        {row.points} pts\n                      </span>\n                    </div>\n                  </div>\n                )\n              }}\n            />\n            {/* The short names the NEWS2 chart prints; the tooltip gives each in\n                full. */}\n            <PolarAngleAxis dataKey=\"short\" />\n            {/* Rings at 1, 2 and 3 points, the most one parameter scores. */}\n            <PolarRadiusAxis\n              domain={[0, 3]}\n              tickCount={4}\n              tick={false}\n              axisLine={false}\n            />\n            <PolarGrid />\n            <Radar\n              dataKey=\"points\"\n              fill=\"var(--color-points)\"\n              fillOpacity={0.6}\n              dot={{ r: 4, fillOpacity: 1 }}\n            />\n          </RadarChart>\n        </ChartContainer>\n      </CardContent>\n      <CardFooter className=\"flex-col gap-2 text-sm\">\n        <div className=\"flex items-center gap-2 leading-none font-medium\">\n          {highest.points\n            ? `${highest.parameter} scores most, ${highest.points} points`\n            : \"Every parameter scores 0\"}\n        </div>\n        <div className=\"leading-none text-muted-foreground\">\n          Follow your local escalation policy; a fictional patient\n        </div>\n      </CardFooter>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "docs": "NEWS2 radar chart: https://organui.com/charts/radar#chart-radar-news2",
  "categories": [
    "charts",
    "charts-radar"
  ],
  "type": "registry:block"
}