feat: complete admission workspace
This commit is contained in:
@@ -1,167 +1,196 @@
|
||||
import {
|
||||
Activity,
|
||||
AlertTriangle,
|
||||
BedDouble,
|
||||
CheckCircle2,
|
||||
Clock3,
|
||||
HeartPulse,
|
||||
ShieldAlert,
|
||||
Users,
|
||||
} from "lucide-react";
|
||||
import { Activity, AlertTriangle, BedDouble, CheckCircle2, HeartPulse, Users } from "lucide-react";
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Table } from "@/components/ui/table";
|
||||
import type { AdmissionStatus, BedStatus, IncidentSeverity } from "@/modules/core/types";
|
||||
import { BedOccupancyChart, type BedOccupancyDatum } from "@/modules/dashboard/components/BedOccupancyChart";
|
||||
|
||||
type Metric = {
|
||||
export type DashboardMetric = {
|
||||
label: string;
|
||||
value: string;
|
||||
trend: string;
|
||||
icon: LucideIcon;
|
||||
icon: "users" | "beds" | "admissions" | "incidents";
|
||||
};
|
||||
|
||||
const metrics: Metric[] = [
|
||||
{ label: "在院", value: "126", trend: "+6 本周", icon: Users },
|
||||
{ label: "床位", value: "82%", trend: "28 空闲", icon: BedDouble },
|
||||
{ label: "任务", value: "184", trend: "142 完成", icon: CheckCircle2 },
|
||||
{ label: "异常", value: "9", trend: "3 待复核", icon: HeartPulse },
|
||||
];
|
||||
export type DashboardAdmission = {
|
||||
id: string;
|
||||
elderName: string;
|
||||
bedLabel: string;
|
||||
status: AdmissionStatus;
|
||||
admittedAt: string;
|
||||
dischargedAt?: string;
|
||||
};
|
||||
|
||||
const taskRows = [
|
||||
{ name: "晨间生命体征记录", owner: "护理一组", status: "进行中", due: "09:30" },
|
||||
{ name: "二楼失能老人巡检", owner: "护理二组", status: "待执行", due: "10:00" },
|
||||
{ name: "高血压老人复测", owner: "医护组", status: "需复核", due: "10:30" },
|
||||
{ name: "晚间护理计划生成", owner: "护理主管", status: "待派发", due: "16:00" },
|
||||
];
|
||||
export type DashboardIncident = {
|
||||
id: string;
|
||||
severity: IncidentSeverity;
|
||||
status: string;
|
||||
title: string;
|
||||
source: string;
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
const alerts = [
|
||||
{ label: "任务逾期", count: "4", tone: "warning" },
|
||||
{ label: "设备故障", count: "2", tone: "danger" },
|
||||
{ label: "应急处理中", count: "1", tone: "danger" },
|
||||
{ label: "未读通知", count: "18", tone: "success" },
|
||||
] as const;
|
||||
type DashboardHomeProps = {
|
||||
metrics: DashboardMetric[];
|
||||
occupancyData: BedOccupancyDatum[];
|
||||
recentAdmissions: DashboardAdmission[];
|
||||
incidents: DashboardIncident[];
|
||||
};
|
||||
|
||||
export function DashboardHome(): React.ReactElement {
|
||||
const metricIcons: Record<DashboardMetric["icon"], LucideIcon> = {
|
||||
users: Users,
|
||||
beds: BedDouble,
|
||||
admissions: CheckCircle2,
|
||||
incidents: HeartPulse,
|
||||
};
|
||||
|
||||
const admissionStatusLabels: Record<AdmissionStatus, string> = {
|
||||
active: "在住",
|
||||
transferred: "已换床",
|
||||
discharged: "已退住",
|
||||
};
|
||||
|
||||
const bedStatusLabels: Record<BedStatus, string> = {
|
||||
available: "空闲",
|
||||
occupied: "占用",
|
||||
maintenance: "维修",
|
||||
disabled: "停用",
|
||||
};
|
||||
|
||||
function formatDateTime(value: string): string {
|
||||
return new Date(value).toLocaleString("zh-CN");
|
||||
}
|
||||
|
||||
function incidentVariant(severity: IncidentSeverity): "secondary" | "warning" | "danger" {
|
||||
switch (severity) {
|
||||
case "critical":
|
||||
return "danger";
|
||||
case "warning":
|
||||
return "warning";
|
||||
case "info":
|
||||
return "secondary";
|
||||
}
|
||||
}
|
||||
|
||||
export function DashboardHome({
|
||||
metrics,
|
||||
occupancyData,
|
||||
recentAdmissions,
|
||||
incidents,
|
||||
}: DashboardHomeProps): React.ReactElement {
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-7xl flex-col gap-6">
|
||||
<section className="grid gap-5 border-b pb-5 lg:grid-cols-[1.15fr_0.85fr]">
|
||||
<div className="flex flex-col justify-end gap-4">
|
||||
<Badge variant="success">一期</Badge>
|
||||
<div>
|
||||
<h1 className="text-3xl font-semibold tracking-normal md:text-4xl">运营看板</h1>
|
||||
<p className="mt-2 text-sm text-muted-foreground">照护、床位、预警一屏处理。</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button>
|
||||
<Users className="size-4" aria-hidden="true" />
|
||||
老人建档
|
||||
</Button>
|
||||
<Button variant="outline">
|
||||
<ShieldAlert className="size-4" aria-hidden="true" />
|
||||
处理应急事件
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-3 rounded-lg border bg-white/72 p-4 shadow-sm">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm font-medium">今日闭环</p>
|
||||
</div>
|
||||
<Activity className="size-5 text-primary" aria-hidden="true" />
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
{["档案", "床位", "健康", "护理", "应急"].map((item, index) => (
|
||||
<div key={item} className="flex items-center gap-3">
|
||||
<span className="w-9 text-xs font-medium text-muted-foreground">{item}</span>
|
||||
<div className="h-2 flex-1 rounded-full bg-muted">
|
||||
<div
|
||||
className="h-2 rounded-full bg-primary"
|
||||
style={{ width: `${88 - index * 9}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="w-14 text-right text-xs text-muted-foreground">
|
||||
{88 - index * 9}%
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<section className="flex flex-col gap-4 border-b pb-5 lg:flex-row lg:items-end lg:justify-between">
|
||||
<div>
|
||||
<Badge variant="success">实时数据</Badge>
|
||||
<h1 className="mt-3 text-3xl font-semibold tracking-normal md:text-4xl">运营看板</h1>
|
||||
<p className="mt-2 text-sm text-muted-foreground">老人、床位、入住和系统故障概况。</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="grid gap-4 md:grid-cols-2 xl:grid-cols-4">
|
||||
{metrics.map((metric) => (
|
||||
<Card key={metric.label}>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0">
|
||||
<CardDescription>{metric.label}</CardDescription>
|
||||
<metric.icon className="size-4 text-primary" aria-hidden="true" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<CardTitle className="text-3xl">{metric.value}</CardTitle>
|
||||
<p className="mt-2 text-xs text-muted-foreground">{metric.trend}</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
{metrics.map((metric) => {
|
||||
const Icon = metricIcons[metric.icon];
|
||||
|
||||
return (
|
||||
<Card key={metric.label}>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0">
|
||||
<CardDescription>{metric.label}</CardDescription>
|
||||
<Icon className="size-4 text-primary" aria-hidden="true" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<CardTitle className="text-3xl">{metric.value}</CardTitle>
|
||||
<p className="mt-2 text-xs text-muted-foreground">{metric.trend}</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</section>
|
||||
|
||||
<section className="grid gap-4 xl:grid-cols-[1.25fr_0.75fr]">
|
||||
<section className="grid gap-4 xl:grid-cols-[0.95fr_1.05fr]">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>今日护理任务</CardTitle>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<Activity className="size-5 text-primary" aria-hidden="true" />
|
||||
床位状态分布
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{occupancyData.map((item) => `${bedStatusLabels[item.label as BedStatus] ?? item.label} ${item.count}`).join(" / ")}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="overflow-hidden rounded-md border">
|
||||
<Table className="w-full text-sm">
|
||||
<BedOccupancyChart data={occupancyData} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>最近入住记录</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="overflow-x-auto rounded-md border">
|
||||
<Table className="w-full min-w-[620px] text-sm">
|
||||
<Table.Header className="bg-secondary text-left text-xs text-muted-foreground">
|
||||
<Table.Row>
|
||||
<Table.Head className="px-4 py-3 font-medium">任务</Table.Head>
|
||||
<Table.Head className="px-4 py-3 font-medium">负责</Table.Head>
|
||||
<Table.Head className="px-4 py-3 font-medium">老人</Table.Head>
|
||||
<Table.Head className="px-4 py-3 font-medium">床位</Table.Head>
|
||||
<Table.Head className="px-4 py-3 font-medium">状态</Table.Head>
|
||||
<Table.Head className="px-4 py-3 text-right font-medium">截止</Table.Head>
|
||||
<Table.Head className="px-4 py-3 font-medium">时间</Table.Head>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body className="divide-y bg-card">
|
||||
{taskRows.map((task) => (
|
||||
<Table.Row key={task.name}>
|
||||
<Table.Cell className="px-4 py-3 font-medium">{task.name}</Table.Cell>
|
||||
<Table.Cell className="px-4 py-3 text-muted-foreground">{task.owner}</Table.Cell>
|
||||
{recentAdmissions.map((admission) => (
|
||||
<Table.Row key={admission.id}>
|
||||
<Table.Cell className="px-4 py-3 font-medium">{admission.elderName}</Table.Cell>
|
||||
<Table.Cell className="px-4 py-3 text-muted-foreground">{admission.bedLabel}</Table.Cell>
|
||||
<Table.Cell className="px-4 py-3">
|
||||
<Badge variant={task.status === "需复核" ? "warning" : "secondary"}>
|
||||
{task.status}
|
||||
<Badge variant={admission.status === "active" ? "success" : "secondary"}>
|
||||
{admissionStatusLabels[admission.status]}
|
||||
</Badge>
|
||||
</Table.Cell>
|
||||
<Table.Cell className="px-4 py-3 text-right text-muted-foreground">{task.due}</Table.Cell>
|
||||
<Table.Cell className="px-4 py-3 text-muted-foreground">
|
||||
{formatDateTime(admission.dischargedAt ?? admission.admittedAt)}
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
{recentAdmissions.length === 0 ? (
|
||||
<Table.Row>
|
||||
<Table.Cell className="px-4 py-8 text-center text-muted-foreground" colSpan={4}>
|
||||
暂无入住记录
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
) : null}
|
||||
</Table.Body>
|
||||
</Table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>预警与工单</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
{alerts.map((alert) => (
|
||||
<div key={alert.label} className="flex items-center justify-between rounded-md border p-3">
|
||||
<div className="flex items-center gap-3">
|
||||
{alert.tone === "danger" ? (
|
||||
<AlertTriangle className="size-4 text-red-600" aria-hidden="true" />
|
||||
) : (
|
||||
<Clock3 className="size-4 text-amber-600" aria-hidden="true" />
|
||||
)}
|
||||
<span className="text-sm font-medium">{alert.label}</span>
|
||||
</div>
|
||||
<Badge variant={alert.tone}>{alert.count}</Badge>
|
||||
</div>
|
||||
))}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</section>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>系统故障</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="grid gap-3 md:grid-cols-2 xl:grid-cols-3">
|
||||
{incidents.map((incident) => (
|
||||
<div key={incident.id} className="flex items-start justify-between gap-3 rounded-md border p-3">
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<AlertTriangle className="size-4 shrink-0 text-amber-600" aria-hidden="true" />
|
||||
<p className="truncate text-sm font-medium">{incident.title}</p>
|
||||
</div>
|
||||
<p className="mt-1 text-xs text-muted-foreground">
|
||||
{incident.source} / {formatDateTime(incident.createdAt)}
|
||||
</p>
|
||||
</div>
|
||||
<Badge variant={incidentVariant(incident.severity)}>{incident.status}</Badge>
|
||||
</div>
|
||||
))}
|
||||
{incidents.length === 0 ? <p className="text-sm text-muted-foreground">暂无未关闭故障</p> : null}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user