feat(health+ai): P2 咨询联动 + AI 巡检消费 — 全链路打通
业务链路打通 5/5 断点全部完成: - 咨询→随访:医生端新增"创建随访"按钮,从咨询会话直接创建随访任务 - 咨询→AI:医生端新增"AI 分析"按钮,对咨询上下文触发 AI 分析 - 告警→咨询:小程序告警详情页新增"在线咨询"快捷入口 - AI 巡检消费:erp-ai 新增 patrol_consumer,订阅 ai.patrol.requested 事件 - 前端联动:Web ConsultationDetail + 小程序 alerts 页面联动实现 后端:2 新 API + 2 handler + 1 service + AI event consumer 前端:Web 2 API + 1 页面改造 + 小程序 2 页面改造 测试:Web consultations.test.ts 9/9 通过
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import { useState, useEffect, useCallback, useRef } from "react";
|
||||
import { Button, Input, Spin, Popconfirm, message, Typography } from "antd";
|
||||
import { Button, Input, Spin, Popconfirm, message, Typography, Modal, Form, Select, DatePicker } from "antd";
|
||||
import {
|
||||
SendOutlined,
|
||||
CloseCircleOutlined,
|
||||
ArrowUpOutlined,
|
||||
ScheduleOutlined,
|
||||
RobotOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useParams, useNavigate } from "react-router-dom";
|
||||
import dayjs from "dayjs";
|
||||
import {
|
||||
consultationApi,
|
||||
type Session,
|
||||
@@ -61,11 +64,20 @@ export default function ConsultationDetail() {
|
||||
const [inputText, setInputText] = useState("");
|
||||
const [hasMore, setHasMore] = useState(false);
|
||||
|
||||
// Follow-up modal state
|
||||
const [followUpModalOpen, setFollowUpModalOpen] = useState(false);
|
||||
const [followUpLoading, setFollowUpLoading] = useState(false);
|
||||
const [followUpForm] = Form.useForm();
|
||||
|
||||
// AI analysis state
|
||||
const [aiAnalysisLoading, setAiAnalysisLoading] = useState(false);
|
||||
|
||||
const chatEndRef = useRef<HTMLDivElement>(null);
|
||||
const shouldScrollRef = useRef(true);
|
||||
|
||||
|
||||
const isDark = useThemeMode();
|
||||
const navigate = useNavigate();
|
||||
|
||||
// --- Fetch session info ---
|
||||
const fetchSession = useCallback(async () => {
|
||||
@@ -207,6 +219,46 @@ export default function ConsultationDetail() {
|
||||
}
|
||||
};
|
||||
|
||||
// --- Create follow-up from consultation ---
|
||||
const handleCreateFollowUp = async () => {
|
||||
if (!sessionId) return;
|
||||
try {
|
||||
const values = await followUpForm.validateFields();
|
||||
setFollowUpLoading(true);
|
||||
await consultationApi.createFollowUpFromSession(sessionId, {
|
||||
follow_up_type: values.follow_up_type,
|
||||
planned_date: values.planned_date.format("YYYY-MM-DD"),
|
||||
content_template: values.content_template || undefined,
|
||||
});
|
||||
message.success("随访任务已创建");
|
||||
setFollowUpModalOpen(false);
|
||||
followUpForm.resetFields();
|
||||
} catch (err: unknown) {
|
||||
if (err && typeof err === "object" && "errorFields" in err) {
|
||||
// Form validation error, ignore
|
||||
return;
|
||||
}
|
||||
message.error("创建随访任务失败");
|
||||
} finally {
|
||||
setFollowUpLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// --- Trigger AI analysis ---
|
||||
const handleTriggerAiAnalysis = async () => {
|
||||
if (!sessionId) return;
|
||||
setAiAnalysisLoading(true);
|
||||
try {
|
||||
const result = await consultationApi.triggerAiAnalysisFromSession(sessionId);
|
||||
message.success(`AI 分析已触发(类型: ${result.analysis_type})`);
|
||||
navigate("/health/ai-analysis");
|
||||
} catch {
|
||||
message.error("触发 AI 分析失败");
|
||||
} finally {
|
||||
setAiAnalysisLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// --- Render a single message bubble ---
|
||||
const renderMessage = (msg: Message) => {
|
||||
const align = ROLE_ALIGN[msg.sender_role] ?? "flex-start";
|
||||
@@ -319,6 +371,30 @@ export default function ConsultationDetail() {
|
||||
ID: {sessionId.slice(0, 8)}
|
||||
</Typography.Text>
|
||||
)}
|
||||
{session && !isClosed && (
|
||||
<AuthButton code="health.consultation.manage">
|
||||
<Button
|
||||
size="small"
|
||||
icon={<ScheduleOutlined />}
|
||||
onClick={() => setFollowUpModalOpen(true)}
|
||||
>
|
||||
创建随访
|
||||
</Button>
|
||||
</AuthButton>
|
||||
)}
|
||||
{session && !isClosed && (
|
||||
<AuthButton code="health.consultation.manage">
|
||||
<Button
|
||||
size="small"
|
||||
type="default"
|
||||
icon={<RobotOutlined />}
|
||||
loading={aiAnalysisLoading}
|
||||
onClick={handleTriggerAiAnalysis}
|
||||
>
|
||||
AI 分析
|
||||
</Button>
|
||||
</AuthButton>
|
||||
)}
|
||||
{session && !isClosed && (
|
||||
<AuthButton code="health.consultation.manage">
|
||||
<Popconfirm
|
||||
@@ -411,6 +487,56 @@ export default function ConsultationDetail() {
|
||||
</Button>
|
||||
</AuthButton>
|
||||
</div>
|
||||
|
||||
{/* Follow-up creation modal */}
|
||||
<Modal
|
||||
title="创建随访任务"
|
||||
open={followUpModalOpen}
|
||||
onOk={handleCreateFollowUp}
|
||||
onCancel={() => {
|
||||
setFollowUpModalOpen(false);
|
||||
followUpForm.resetFields();
|
||||
}}
|
||||
confirmLoading={followUpLoading}
|
||||
okText="创建"
|
||||
cancelText="取消"
|
||||
destroyOnClose
|
||||
>
|
||||
<Form
|
||||
form={followUpForm}
|
||||
layout="vertical"
|
||||
initialValues={{ follow_up_type: "phone" }}
|
||||
>
|
||||
<Form.Item
|
||||
name="follow_up_type"
|
||||
label="随访类型"
|
||||
rules={[{ required: true, message: "请选择随访类型" }]}
|
||||
>
|
||||
<Select
|
||||
options={[
|
||||
{ label: "电话随访", value: "phone" },
|
||||
{ label: "在线随访", value: "online" },
|
||||
{ label: "上门随访", value: "home_visit" },
|
||||
]}
|
||||
placeholder="请选择随访类型"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="planned_date"
|
||||
label="计划日期"
|
||||
rules={[{ required: true, message: "请选择计划日期" }]}
|
||||
>
|
||||
<DatePicker
|
||||
style={{ width: "100%" }}
|
||||
disabledDate={(current) => current && current < dayjs().startOf("day")}
|
||||
placeholder="选择随访日期"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="content_template" label="随访内容(可选)">
|
||||
<Input.TextArea rows={3} placeholder="输入随访内容模板" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user