- SignalR Hub消息持久化+防重复+跨端广播 - 报告VLM+LLM真实AI流程(验证→提取→解读) - 医生审核页重构(严重程度/建议模板/综合评语) - 健康概览五合一趋势图(fl_chart+指标切换) - 用药提醒时区修复+跨午夜+过期提醒 - 运动打卡DayOfWeek映射修复+计划覆盖查询 - 体重与其他四指标同级(Abnormal检查/确认卡牌) - AI Agent支持多种类多时段批量录入 - 删除硬编码假数据(张三/假医生/假AI解读) - 随访/报告审核数据链路全部打通
240 lines
10 KiB
Dart
240 lines
10 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../core/navigation_provider.dart';
|
|
import 'report_pages.dart';
|
|
|
|
/// AI 解读页 — 从服务器获取真实报告数据
|
|
class AiAnalysisPage extends ConsumerStatefulWidget {
|
|
final String id;
|
|
const AiAnalysisPage({super.key, required this.id});
|
|
|
|
@override
|
|
ConsumerState<AiAnalysisPage> createState() => _AiAnalysisPageState();
|
|
}
|
|
|
|
class _AiAnalysisPageState extends ConsumerState<AiAnalysisPage> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
ref.read(reportProvider.notifier).loadReports();
|
|
ref.read(reportProvider.notifier).fetchReportDetail(widget.id);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final analysis = ref.watch(reportProvider.select((s) => s.currentAnalysis));
|
|
final reports = ref.watch(reportProvider.select((s) => s.reports));
|
|
final reportItem = reports.where((r) => r.id == widget.id).firstOrNull;
|
|
|
|
if (analysis == null) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('AI 解读')),
|
|
body: const Center(child: CircularProgressIndicator(color: Color(0xFF8B9CF7))),
|
|
);
|
|
}
|
|
|
|
return Scaffold(
|
|
backgroundColor: const Color(0xFFF8F9FC),
|
|
appBar: AppBar(
|
|
title: const Text('AI 智能解读'),
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back),
|
|
onPressed: () {
|
|
ref.read(reportProvider.notifier).clearAnalysis();
|
|
popRoute(ref);
|
|
},
|
|
),
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
// 报告标题
|
|
_buildHeader(analysis),
|
|
const SizedBox(height: 16),
|
|
// 审核状态
|
|
if (reportItem != null) _buildStatusBadge(reportItem),
|
|
if (reportItem != null) const SizedBox(height: 16),
|
|
// 指标分析
|
|
_buildIndicators(analysis),
|
|
const SizedBox(height: 16),
|
|
// AI 总结
|
|
_buildSummary(analysis),
|
|
const SizedBox(height: 16),
|
|
// 医生审核意见
|
|
if (reportItem != null && reportItem.status == 'DoctorReviewed')
|
|
_buildDoctorReview(reportItem),
|
|
]),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildHeader(ReportAnalysis analysis) {
|
|
return Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [BoxShadow(color: const Color(0xFF8B9CF7).withAlpha(10), blurRadius: 8)]),
|
|
child: Row(children: [
|
|
Container(width: 48, height: 48, decoration: BoxDecoration(color: const Color(0xFFF0F2FF), borderRadius: BorderRadius.circular(12)),
|
|
child: const Icon(Icons.auto_awesome, size: 24, color: Color(0xFF8B9CF7))),
|
|
const SizedBox(width: 14),
|
|
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text(analysis.reportType, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w700)),
|
|
const SizedBox(height: 4),
|
|
const Text('AI 预解读结果 · 待医生确认', style: TextStyle(fontSize: 13, color: Color(0xFF999999))),
|
|
])),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildStatusBadge(ReportItem report) {
|
|
final isReviewed = report.status == 'DoctorReviewed';
|
|
return Container(
|
|
width: double.infinity, padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: isReviewed ? const Color(0xFFDCFCE7) : const Color(0xFFFFF3E0),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
|
Icon(isReviewed ? Icons.check_circle : Icons.hourglass_empty, size: 18,
|
|
color: isReviewed ? const Color(0xFF43A047) : const Color(0xFFF59E0B)),
|
|
const SizedBox(width: 8),
|
|
Text(isReviewed ? '已通过医生审核' : '等待医生审核中',
|
|
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500,
|
|
color: isReviewed ? const Color(0xFF43A047) : const Color(0xFFF59E0B))),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildIndicators(ReportAnalysis analysis) {
|
|
return Container(
|
|
width: double.infinity,
|
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16)),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
const Padding(
|
|
padding: EdgeInsets.fromLTRB(16, 16, 16, 8),
|
|
child: Text('指标分析', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
|
|
),
|
|
...analysis.indicators.map((ind) => _buildIndicatorRow(ind)),
|
|
const SizedBox(height: 8),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildIndicatorRow(Indicator ind) {
|
|
final Color color;
|
|
final IconData icon;
|
|
switch (ind.status) {
|
|
case 'high': color = const Color(0xFFE53935); icon = Icons.arrow_upward; break;
|
|
case 'low': color = const Color(0xFFF9A825); icon = Icons.arrow_downward; break;
|
|
default: color = const Color(0xFF43A047); icon = Icons.check_circle;
|
|
}
|
|
return Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 16),
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
decoration: const BoxDecoration(border: Border(bottom: BorderSide(color: Color(0xFFF0F0F0)))),
|
|
child: Row(children: [
|
|
Expanded(
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text(ind.name, style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w500)),
|
|
if (ind.referenceRange != null && ind.referenceRange!.isNotEmpty)
|
|
Text('参考值: ${ind.referenceRange}', style: const TextStyle(fontSize: 12, color: Color(0xFF999999))),
|
|
]),
|
|
),
|
|
Column(crossAxisAlignment: CrossAxisAlignment.end, children: [
|
|
Text('${ind.value} ${ind.unit}',
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: color)),
|
|
Icon(icon, size: 14, color: color),
|
|
]),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildSummary(ReportAnalysis analysis) {
|
|
return Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(color: const Color(0xFFFEFCE8), borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: const Color(0xFFFDE68A))),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
const Row(children: [
|
|
Text('💡', style: TextStyle(fontSize: 18)),
|
|
SizedBox(width: 8),
|
|
Text('综合解读', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700, color: Color(0xFFD97706))),
|
|
]),
|
|
const SizedBox(height: 10),
|
|
Text(analysis.summary.isNotEmpty ? analysis.summary : '暂无 AI 解读结果',
|
|
style: const TextStyle(fontSize: 14, color: Color(0xFF92400E), height: 1.6)),
|
|
const SizedBox(height: 10),
|
|
Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(10),
|
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10)),
|
|
child: const Text('⚠️ AI 解读仅供参考,请以医生诊断为准',
|
|
style: TextStyle(fontSize: 12, color: Color(0xFFD97706))),
|
|
),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildDoctorReview(ReportItem report) {
|
|
return Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(color: const Color(0xFFDCFCE7), borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: const Color(0xFF86EFAC))),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
const Row(children: [
|
|
Text('✅', style: TextStyle(fontSize: 18)),
|
|
SizedBox(width: 8),
|
|
Text('医生审核意见', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700, color: Color(0xFF2E7D32))),
|
|
]),
|
|
if (report.doctorName != null) ...[
|
|
const SizedBox(height: 4),
|
|
Text('审核医生:${report.doctorName}', style: const TextStyle(fontSize: 13, color: Color(0xFF4CAF50))),
|
|
],
|
|
if (report.reviewedAt != null) ...[
|
|
const SizedBox(height: 2),
|
|
Text('审核时间:${report.reviewedAt!.toLocal().toString().substring(0, 16)}',
|
|
style: const TextStyle(fontSize: 12, color: Color(0xFF81C784))),
|
|
],
|
|
if (report.severity != null) ...[
|
|
const SizedBox(height: 8),
|
|
_severityBadge(report.severity!),
|
|
],
|
|
if (report.doctorComment != null && report.doctorComment!.isNotEmpty) ...[
|
|
const SizedBox(height: 10),
|
|
Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10)),
|
|
child: Text('💬 ${report.doctorComment!}',
|
|
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A), height: 1.5)),
|
|
),
|
|
],
|
|
if (report.doctorRecommendation != null && report.doctorRecommendation!.isNotEmpty) ...[
|
|
const SizedBox(height: 8),
|
|
Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10)),
|
|
child: Text('📝 ${report.doctorRecommendation!}',
|
|
style: const TextStyle(fontSize: 14, color: Color(0xFF333333), height: 1.5)),
|
|
),
|
|
],
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _severityBadge(String severity) {
|
|
final (label, color, bg) = switch (severity) {
|
|
'Normal' => ('🟢 正常', const Color(0xFF43A047), const Color(0xFFDCFCE7)),
|
|
'Abnormal' => ('🟡 轻度异常', const Color(0xFFF59E0B), const Color(0xFFFFF3E0)),
|
|
'Severe' => ('🟠 中度异常', const Color(0xFFFF7043), const Color(0xFFFEE2E2)),
|
|
'Critical' => ('🔴 重度异常', const Color(0xFFDC2626), const Color(0xFFFEE2E2)),
|
|
_ => (severity, Colors.grey, Colors.grey.withAlpha(30)),
|
|
};
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
|
decoration: BoxDecoration(color: bg, borderRadius: BorderRadius.circular(6)),
|
|
child: Text(label, style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500, color: color)),
|
|
);
|
|
}
|
|
}
|