{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-bar-diagnoses",
  "title": "Length of stay bar chart",
  "description": "Length of stay for the top diagnoses against a benchmark, as a dumbbell chart.",
  "dependencies": [
    "recharts@^3.8.0"
  ],
  "registryDependencies": [
    "card",
    "badge",
    "chart"
  ],
  "files": [
    {
      "path": "registry/base-nova/charts/chart-bar-diagnoses.tsx",
      "content": "\"use client\"\n\nimport {\n  Bar,\n  CartesianGrid,\n  ComposedChart,\n  Scatter,\n  XAxis,\n  YAxis,\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  \"Length of stay for the top diagnoses against a benchmark, as a dumbbell chart\"\n\n// The most common diagnoses at discharge this quarter, with the median stay\n// in days and the stay expected for the case mix. Illustrative, not a real\n// hospital's.\nconst diagnoses = [\n  { diagnosis: \"Pneumonia\", discharges: 186, stay: 6.1, expected: 5.2 },\n  { diagnosis: \"Heart failure\", discharges: 152, stay: 8.4, expected: 9.0 },\n  { diagnosis: \"Sepsis\", discharges: 137, stay: 7.9, expected: 6.5 },\n  { diagnosis: \"COPD\", discharges: 113, stay: 4.2, expected: 4.6 },\n  { diagnosis: \"Hip fracture\", discharges: 89, stay: 14.5, expected: 15.0 },\n]\n\n// Each row joins the expected stay to the actual one, so the gap reads as a\n// line: long when the stay runs over.\nconst chartData = diagnoses.map((row) => ({\n  ...row,\n  gap: [Math.min(row.stay, row.expected), Math.max(row.stay, row.expected)],\n  over: row.stay > row.expected,\n}))\n\nconst chartConfig = {\n  stay: {\n    label: \"Median stay\",\n    color: \"var(--chart-2)\",\n  },\n  expected: {\n    label: \"Expected\",\n    color: \"var(--muted-foreground)\",\n  },\n  gap: {\n    label: \"Gap\",\n    color: \"var(--muted-foreground)\",\n  },\n} satisfies ChartConfig\n\nconst over = chartData.filter((row) => row.over)\n// The diagnosis whose extra days, across all its patients, cost most beds.\nconst costliest = over.reduce(\n  (a, b) =>\n    (b.stay - b.expected) * b.discharges > (a.stay - a.expected) * a.discharges\n      ? b\n      : a,\n  over[0] ?? chartData[0]!\n)\nconst bedDays = Math.round(\n  (costliest.stay - costliest.expected) * costliest.discharges\n)\n\nexport function ChartBarDiagnoses() {\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle>Length of stay</CardTitle>\n        <CardDescription>Top diagnoses this quarter, in days</CardDescription>\n        <CardAction className=\"flex flex-col items-end gap-1.5\">\n          <div className=\"text-2xl leading-none font-semibold\">\n            {over.length}{\" \"}\n            <span className=\"text-sm font-normal text-muted-foreground\">\n              of {chartData.length} over\n            </span>\n          </div>\n          <Badge variant=\"outline\">\n            {over.length ? (\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              <IconPlaceholder\n                lucide=\"CheckIcon\"\n                tabler=\"IconCheck\"\n                hugeicons=\"Tick02Icon\"\n                phosphor=\"CheckIcon\"\n                remixicon=\"RiCheckLine\"\n                data-icon=\"inline-start\"\n              />\n            )}\n            {over.length ? \"Over benchmark\" : \"Within benchmark\"}\n          </Badge>\n        </CardAction>\n      </CardHeader>\n      <CardContent>\n        <ChartContainer config={chartConfig}>\n          <ComposedChart\n            accessibilityLayer\n            data={chartData}\n            layout=\"vertical\"\n            margin={{ left: 8, right: 16 }}\n          >\n            <CartesianGrid horizontal={false} />\n            <XAxis\n              type=\"number\"\n              domain={[0, 16]}\n              ticks={[0, 4, 8, 12, 16]}\n              tickLine={false}\n              axisLine={false}\n              tickMargin={8}\n            />\n            <YAxis\n              type=\"category\"\n              dataKey=\"diagnosis\"\n              tickLine={false}\n              axisLine={false}\n              tickMargin={8}\n              width={88}\n            />\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-[10rem] gap-1 rounded-lg border bg-background px-2.5 py-1.5 text-xs shadow-xl\">\n                    <div className=\"font-medium\">{row.diagnosis}</div>\n                    <div className=\"flex items-baseline justify-between gap-4\">\n                      <span className=\"text-muted-foreground\">Median stay</span>\n                      <span className=\"font-mono font-medium tabular-nums\">\n                        {row.stay} days\n                      </span>\n                    </div>\n                    <div className=\"flex items-baseline justify-between gap-4\">\n                      <span className=\"text-muted-foreground\">Expected</span>\n                      <span className=\"font-mono tabular-nums\">\n                        {row.expected} days\n                      </span>\n                    </div>\n                    <div className=\"flex items-baseline justify-between gap-4\">\n                      <span className=\"text-muted-foreground\">Discharges</span>\n                      <span className=\"font-mono tabular-nums\">\n                        {row.discharges}\n                      </span>\n                    </div>\n                  </div>\n                )\n              }}\n            />\n            <Bar\n              dataKey=\"gap\"\n              fill=\"var(--color-gap)\"\n              fillOpacity={0.4}\n              barSize={3}\n              legendType=\"none\"\n              tooltipType=\"none\"\n            />\n            <Scatter\n              dataKey=\"expected\"\n              fill=\"var(--background)\"\n              stroke=\"var(--color-expected)\"\n              strokeWidth={2}\n            />\n            <Scatter dataKey=\"stay\" fill=\"var(--color-stay)\" />\n          </ComposedChart>\n        </ChartContainer>\n        <div className=\"flex items-center justify-center gap-4 pt-3 text-xs\">\n          <div className=\"flex items-center gap-1.5\">\n            <div\n              className=\"size-2.5 rounded-full\"\n              style={{ background: chartConfig.stay.color }}\n            />\n            {chartConfig.stay.label}\n          </div>\n          <div className=\"flex items-center gap-1.5\">\n            <div\n              className=\"size-2.5 rounded-full border-2\"\n              style={{ borderColor: chartConfig.expected.color }}\n            />\n            {chartConfig.expected.label}\n          </div>\n        </div>\n      </CardContent>\n      <CardFooter className=\"flex-col items-start gap-2 text-sm\">\n        <div className=\"flex items-center gap-2 leading-none font-medium\">\n          {over.length\n            ? `${costliest.diagnosis} runs about ${bedDays} bed days over`\n            : \"Every diagnosis within its expected stay\"}\n        </div>\n        <div className=\"leading-none text-muted-foreground\">\n          Expected stay is for the case mix; illustrative data\n        </div>\n      </CardFooter>\n    </Card>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "docs": "Length of stay bar chart: https://organui.com/charts/bar#chart-bar-diagnoses",
  "categories": [
    "charts",
    "charts-bar"
  ],
  "type": "registry:block"
}