feat(ai): Phase 2B 洞察→推送→反馈闭环 — 风险评分+通知+建议反馈
- 风险评分引擎 load_patient_data 实装(体征+化验异常)
- refresh_all_patients 高风险自动创建洞察+事件推送
- erp-message 订阅 copilot.insight.created 推送医护通知
- 每日 cron 增加洞察过期清理+建议过期清理
- POST /ai/suggestions/{id}/feedback 建议反馈端点
- SuggestionFeedbackService 反馈服务层
- 小程序健康页建议卡片增加采纳/忽略/咨询医生按钮
This commit is contained in:
@@ -352,14 +352,18 @@ impl ErpModule for AiModule {
|
||||
|
||||
// 每日凌晨 2:00 批量刷新所有在管患者风险快照
|
||||
let refresh_db = ctx.db.clone();
|
||||
let refresh_event_bus = ctx.event_bus.clone();
|
||||
tokio::spawn(async move {
|
||||
// 首次执行延迟到下一个凌晨 2:00(简单实现:延迟 6 小时后开始 24h 周期)
|
||||
tokio::time::sleep(std::time::Duration::from_secs(6 * 3600)).await;
|
||||
let mut interval = tokio::time::interval(std::time::Duration::from_secs(86400));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
match crate::service::risk_service::RiskService::refresh_all_patients(&refresh_db)
|
||||
.await
|
||||
match crate::service::risk_service::RiskService::refresh_all_patients(
|
||||
&refresh_db,
|
||||
Some(&refresh_event_bus),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(count) => {
|
||||
tracing::info!(patient_count = count, "每日风险快照刷新完成");
|
||||
@@ -368,6 +372,22 @@ impl ErpModule for AiModule {
|
||||
tracing::warn!(error = %e, "每日风险快照刷新失败");
|
||||
}
|
||||
}
|
||||
// 清理过期洞察 + 过期建议
|
||||
match crate::service::insight_service::InsightService::cleanup_expired(&refresh_db)
|
||||
.await
|
||||
{
|
||||
Ok(n) => tracing::info!(expired_count = n, "过期洞察清理完成"),
|
||||
Err(e) => tracing::warn!(error = %e, "过期洞察清理失败"),
|
||||
}
|
||||
match crate::service::suggestion::SuggestionService::expire_stale_all_tenants(
|
||||
&refresh_db,
|
||||
30,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(n) => tracing::info!(expired_count = n, "过期建议清理完成"),
|
||||
Err(e) => tracing::warn!(error = %e, "过期建议清理失败"),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -478,6 +498,10 @@ impl AiModule {
|
||||
"/ai/suggestions/{id}/comparison",
|
||||
axum::routing::get(crate::handler::suggestion_handler::get_comparison),
|
||||
)
|
||||
.route(
|
||||
"/ai/suggestions/{id}/feedback",
|
||||
axum::routing::post(crate::handler::suggestion_handler::submit_feedback),
|
||||
)
|
||||
.route(
|
||||
"/ai/dialysis/risk-assessment",
|
||||
axum::routing::post(crate::handler::assess_dialysis_risk),
|
||||
|
||||
Reference in New Issue
Block a user