## 后端 - 健康档案: 新增手术状态字段 + EF 迁移; HealthArchiveService 新增查询方法 - 健康记录: HealthRecordService 新增批量/统计方法; 契约扩展 - 用药: 新增 MedicationScheduleStatus 枚举; MedicationService 排班逻辑调整 - 通知: EfUserNotificationPipeline 重构; 新增 EfReminderCatchUpService; 通知管线支持更多场景 - 用户: UserService 账号删除逻辑; 新增 local_account_file_cleanup; EfUserRepository 扩展 - AI: medication_agent_handler 微调; prompt_manager 优化; AiConversationService 上下文处理 - Endpoint: doctor/medication/exercise/health/notification/user 等多接口调整 - BackgroundService: health_record_reminder_service 重构, 提醒补漏逻辑 - 测试: 新增 account_deletion/doctor_endpoint/medication_schedule/medication_update/prompt_manager 测试 ## 前端 - UI 系统: app_theme 大幅重构; app_colors/app_design_tokens/app_module_visuals 调整; 二级页面色彩刷新 - 主页: home_page 背景渐变 + 消息列表提取 _HomeMessages + 通知检查逻辑; chat_messages_view 全面重构 - 用药: medication_list/edit/checkin 三页重构, 新增 medication_ui_logic 抽取 - 通知: notification_prefs_page 重构, 新增 notification_prefs_logic; notification_center 优化 - 设备: device_management 重构, 新增 device_sync_ui_logic; device_scan 优化 - 趋势图: trend_page 大幅重构 - 登录: login_page 重构 - 个人资料: 新增 profile_edit_page; profile_page 优化 - 运动: 新增 exercise/ 目录 + care_plan_ui_logic - 其他: remaining_pages/report_pages/health_drawer/admin/doctor 等多页面调整 - 组件: common_widgets/app_empty_state/app_error_state/app_future_view/app_toast/ai_content 优化 - Provider: chat_provider/consultation_provider/data_providers/auth_provider 调整 - AndroidManifest: 移除多余权限 - 测试: 新增 ai_content/care_plan/home_message/login_flow/medication_checkin/medication_ui/notification_prefs/profile_device/secondary_page/swipe_delete 等大量测试 ## 文档 - 新增 ui-design-system.md 设计系统文档 - 新增 secondary-page-color-refresh 计划 + specs 目录
452 lines
15 KiB
Dart
452 lines
15 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../core/app_colors.dart';
|
|
import '../../core/app_design_tokens.dart';
|
|
import '../../core/app_theme.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../core/navigation_provider.dart';
|
|
import '../../widgets/ai_content.dart';
|
|
import '../../widgets/app_error_state.dart';
|
|
import '../../widgets/common_widgets.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).fetchReportDetail(widget.id);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final reportState = ref.watch(reportProvider);
|
|
final analysis = reportState.currentAnalysis;
|
|
final reports = reportState.reports;
|
|
final reportItem = reports.where((r) => r.id == widget.id).firstOrNull;
|
|
|
|
if (reportState.isLoadingDetail) {
|
|
return GradientScaffold(
|
|
appBar: AppBar(
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back),
|
|
onPressed: () => popRoute(ref),
|
|
),
|
|
title: const Text('报告解读'),
|
|
),
|
|
body: const Center(
|
|
child: CircularProgressIndicator(color: AppColors.primary),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (analysis == null) {
|
|
return GradientScaffold(
|
|
appBar: AppBar(
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back),
|
|
onPressed: () => popRoute(ref),
|
|
),
|
|
title: const Text('报告解读'),
|
|
),
|
|
body: AppErrorState(
|
|
title: '报告详情加载失败',
|
|
subtitle: reportState.detailError ?? '暂时无法读取这份报告',
|
|
onRetry: () =>
|
|
ref.read(reportProvider.notifier).fetchReportDetail(widget.id),
|
|
),
|
|
);
|
|
}
|
|
|
|
final displayType = _displayName(analysis.reportType);
|
|
final aiStatus = reportItem?.aiStatus ?? analysis.aiStatus;
|
|
final reviewStatus = reportItem?.reviewStatus ?? analysis.reviewStatus;
|
|
final fileUrl = reportItem?.fileUrl ?? analysis.fileUrl;
|
|
final fileType = reportItem?.type ?? analysis.fileType;
|
|
final isPdf = isPdfReport(fileType, fileUrl ?? '');
|
|
final isReviewed = reviewStatus == 'Reviewed';
|
|
final isAnalyzing = aiStatus == 'Analyzing';
|
|
final isFailed = aiStatus == 'Failed';
|
|
|
|
return GradientScaffold(
|
|
appBar: AppBar(
|
|
title: Text(
|
|
displayType,
|
|
style: const TextStyle(
|
|
fontSize: 19,
|
|
fontWeight: FontWeight.w600,
|
|
color: AppColors.textPrimary,
|
|
),
|
|
),
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back, color: AppColors.textPrimary),
|
|
onPressed: () {
|
|
ref.read(reportProvider.notifier).clearAnalysis();
|
|
popRoute(ref);
|
|
},
|
|
),
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (reportState.detailError != null) ...[
|
|
_detailErrorBanner(reportState.detailError!),
|
|
const SizedBox(height: 12),
|
|
],
|
|
if (fileUrl != null && fileUrl.isNotEmpty) ...[
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: OutlinedButton.icon(
|
|
onPressed: () => pushRoute(
|
|
ref,
|
|
'reportOriginal',
|
|
params: {
|
|
'url': fileUrl,
|
|
'title': displayType,
|
|
'fileType': fileType,
|
|
},
|
|
),
|
|
icon: Icon(
|
|
isPdf
|
|
? Icons.picture_as_pdf_outlined
|
|
: Icons.image_outlined,
|
|
size: 18,
|
|
),
|
|
label: const Text('查看原始报告'),
|
|
style: OutlinedButton.styleFrom(
|
|
foregroundColor: AppColors.textPrimary,
|
|
backgroundColor: Colors.white,
|
|
side: const BorderSide(color: AppColors.border),
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: AppRadius.mdBorder,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
],
|
|
if (isAnalyzing || isFailed) ...[
|
|
_analysisStateCard(
|
|
isFailed
|
|
? (analysis.summary.isNotEmpty
|
|
? analysis.summary
|
|
: 'AI 分析失败,请重新上传或稍后重试')
|
|
: (reportState.pollingTimedOut
|
|
? '分析时间比预期更长,您可以稍后返回此页查看'
|
|
: 'AI 正在分析报告,请稍后刷新查看'),
|
|
isFailed: isFailed,
|
|
busy: reportState.reanalyzingReportId == widget.id,
|
|
onRetry: isFailed
|
|
? () => ref
|
|
.read(reportProvider.notifier)
|
|
.reanalyzeReport(widget.id)
|
|
: null,
|
|
),
|
|
const SizedBox(height: 20),
|
|
],
|
|
// 指标分析
|
|
if (!isAnalyzing &&
|
|
!isFailed &&
|
|
analysis.indicators.isNotEmpty) ...[
|
|
_sectionTitle('指标分析'),
|
|
const SizedBox(height: 8),
|
|
Container(
|
|
decoration: _cardDeco(),
|
|
child: Column(
|
|
children: analysis.indicators
|
|
.map((ind) => _indicatorRow(ind))
|
|
.toList(),
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
],
|
|
// 综合解读
|
|
if (!isAnalyzing && !isFailed) ...[
|
|
_sectionTitle('综合解读'),
|
|
const SizedBox(height: 8),
|
|
Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: _cardDeco(),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
AiMarkdownView(
|
|
data: analysis.summary.isNotEmpty
|
|
? analysis.summary
|
|
: 'AI 正在分析中,请稍后刷新查看',
|
|
),
|
|
const AiGeneratedNote(),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
],
|
|
if (!isAnalyzing && !isFailed) ...[
|
|
// 医生审核意见
|
|
_sectionTitle('医生审核意见'),
|
|
const SizedBox(height: 8),
|
|
if (isReviewed && reportItem != null)
|
|
_doctorReviewCard(reportItem)
|
|
else
|
|
Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: _cardDeco(),
|
|
child: const Row(
|
|
children: [
|
|
Icon(
|
|
Icons.hourglass_empty,
|
|
size: 18,
|
|
color: AppColors.textHint,
|
|
),
|
|
SizedBox(width: 8),
|
|
Text(
|
|
'待审核',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
color: AppColors.textSecondary,
|
|
),
|
|
),
|
|
Spacer(),
|
|
Text(
|
|
'AI 预解读',
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
color: AppColors.textHint,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
const SizedBox(height: 30),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
BoxDecoration _cardDeco() =>
|
|
BoxDecoration(color: Colors.white, borderRadius: AppRadius.lgBorder);
|
|
|
|
Widget _analysisStateCard(
|
|
String message, {
|
|
required bool isFailed,
|
|
bool busy = false,
|
|
VoidCallback? onRetry,
|
|
}) {
|
|
final color = isFailed ? AppColors.errorText : AppColors.primary;
|
|
return Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: _cardDeco(),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Icon(
|
|
isFailed ? Icons.error_outline : Icons.hourglass_empty,
|
|
color: color,
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Text(
|
|
message,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
height: 1.6,
|
|
color: isFailed
|
|
? AppColors.errorText
|
|
: AppColors.textPrimary,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
if (onRetry != null) ...[
|
|
const SizedBox(height: 14),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: AppGradientOutlineButton(
|
|
label: busy ? '正在重新分析...' : '重新分析',
|
|
loading: busy,
|
|
onPressed: busy ? null : onRetry,
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _detailErrorBanner(String message) {
|
|
return Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.errorLight,
|
|
borderRadius: AppRadius.mdBorder,
|
|
),
|
|
child: Row(
|
|
children: [
|
|
const Icon(Icons.error_outline, color: AppColors.errorText, size: 20),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Text(
|
|
message,
|
|
style: const TextStyle(
|
|
color: AppColors.errorText,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _sectionTitle(String text) => Row(
|
|
children: [
|
|
Container(
|
|
width: 4,
|
|
height: 16,
|
|
decoration: BoxDecoration(
|
|
color: AppColors.primary,
|
|
borderRadius: BorderRadius.circular(2),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
text,
|
|
style: const TextStyle(
|
|
fontSize: 17,
|
|
fontWeight: FontWeight.w700,
|
|
color: AppColors.textPrimary,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
|
|
Widget _indicatorRow(Indicator ind) {
|
|
final (color, icon) = switch (ind.status) {
|
|
'high' => (AppColors.errorText, Icons.arrow_upward),
|
|
'low' => (AppColors.warningText, Icons.arrow_downward),
|
|
_ => (AppColors.successText, Icons.check_circle),
|
|
};
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
decoration: const BoxDecoration(
|
|
border: Border(bottom: BorderSide(color: AppColors.borderLight)),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
ind.name,
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w500,
|
|
color: AppColors.textPrimary,
|
|
),
|
|
),
|
|
if (ind.referenceRange != null &&
|
|
ind.referenceRange!.isNotEmpty)
|
|
Text(
|
|
'参考值: ${ind.referenceRange}',
|
|
style: const TextStyle(
|
|
fontSize: 13,
|
|
color: AppColors.textHint,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Icon(icon, size: 14, color: color),
|
|
const SizedBox(width: 4),
|
|
Text(
|
|
'${ind.value} ${ind.unit}',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: color,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _doctorReviewCard(ReportItem report) {
|
|
return Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: _cardDeco(),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (report.doctorName != null)
|
|
Text(
|
|
'审核医生:${report.doctorName} | ${report.reviewedAt?.toLocal().toString().substring(0, 16) ?? ''}',
|
|
style: const TextStyle(fontSize: 14, color: AppColors.textHint),
|
|
),
|
|
if (report.doctorComment != null &&
|
|
report.doctorComment!.isNotEmpty) ...[
|
|
const SizedBox(height: 10),
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.cardInner,
|
|
borderRadius: AppRadius.mdBorder,
|
|
),
|
|
child: Text(
|
|
report.doctorComment!,
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
color: AppColors.textPrimary,
|
|
height: 1.5,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
if (report.doctorRecommendation != null &&
|
|
report.doctorRecommendation!.isNotEmpty) ...[
|
|
const SizedBox(height: 8),
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.cardInner,
|
|
borderRadius: AppRadius.mdBorder,
|
|
),
|
|
child: Text(
|
|
report.doctorRecommendation!,
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
color: AppColors.textPrimary,
|
|
height: 1.5,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
String _displayName(String t) => (t == 'Other' || t == 'other') ? '检查报告' : t;
|
|
}
|