feat(health+message): 关怀已送达通知管道 — care.action.performed 事件 + 温暖消息推送
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

- 新增 CARE_ACTION_PERFORMED 事件常量(care.action.performed)
- care_plan_service 在护理项完成、测量数据更新、干预项创建时发布关怀行动事件
- erp-message 新增 care_plan.activated/completed + care.action.performed 消息处理
- 温暖消息文案:护理计划启动/完成通知、关怀已送达、健康数据已更新
- 事件测试覆盖新常量、payload 契约、通知分支逻辑
This commit is contained in:
iven
2026-05-04 18:56:52 +08:00
parent 0a5290aee4
commit 3ff17382ff
3 changed files with 321 additions and 5 deletions

View File

@@ -962,6 +962,116 @@ async fn handle_workflow_event(
"医生在线状态变更"
);
}
// 关怀计划激活 — 温暖通知患者
"care_plan.activated" => {
let patient_id = event
.payload
.get("patient_id")
.and_then(|v| v.as_str())
.and_then(|s| uuid::Uuid::parse_str(s).ok());
if let Some(pid) = patient_id {
if should_skip_for_dnd(event.tenant_id, pid, "normal", db).await {
return Ok(());
}
let _ = crate::service::message_service::MessageService::send_system(
event.tenant_id,
pid,
"护理计划已启动".to_string(),
"您的护理计划已启动,我们将持续关注您的健康状况。如有任何疑问,请随时咨询您的护理团队。".to_string(),
"normal",
Some("care_plan".to_string()),
event.payload.get("plan_id").and_then(|v| v.as_str()).and_then(|s| uuid::Uuid::parse_str(s).ok()),
db,
event_bus,
)
.await
.map_err(|e| e.to_string())?;
}
}
// 关怀计划完成 — 温暖通知患者
"care_plan.completed" => {
let patient_id = event
.payload
.get("patient_id")
.and_then(|v| v.as_str())
.and_then(|s| uuid::Uuid::parse_str(s).ok());
if let Some(pid) = patient_id {
if should_skip_for_dnd(event.tenant_id, pid, "normal", db).await {
return Ok(());
}
let _ = crate::service::message_service::MessageService::send_system(
event.tenant_id,
pid,
"护理计划已完成".to_string(),
"您的护理计划已完成,感谢您这段时间的配合!我们将继续关注您的健康。".to_string(),
"normal",
Some("care_plan".to_string()),
event.payload.get("plan_id").and_then(|v| v.as_str()).and_then(|s| uuid::Uuid::parse_str(s).ok()),
db,
event_bus,
)
.await
.map_err(|e| e.to_string())?;
}
}
// 关怀行动执行 — 温暖通知患者(护理项完成、测量数据记录等)
"care.action.performed" => {
let patient_id = event
.payload
.get("patient_id")
.and_then(|v| v.as_str())
.and_then(|s| uuid::Uuid::parse_str(s).ok());
let action = event
.payload
.get("action")
.and_then(|v| v.as_str())
.unwrap_or("");
if let Some(pid) = patient_id {
if should_skip_for_dnd(event.tenant_id, pid, "low", db).await {
return Ok(());
}
let (title, body) = match action {
"item_completed" => {
let item_title = event.payload.get("item_title").and_then(|v| v.as_str()).unwrap_or("护理项目");
(
"关怀已送达".to_string(),
format!("您的护理团队已完成「{}」,感谢您的配合。", item_title),
)
}
"outcome_measured" => {
let metric = event.payload.get("metric").and_then(|v| v.as_str()).unwrap_or("健康指标");
(
"健康数据已更新".to_string(),
format!("您的{}数据已记录,护理团队正在持续关注。", metric),
)
}
_ => {
(
"关怀已送达".to_string(),
"您的护理团队正在关注您的健康状况。".to_string(),
)
}
};
let _ = crate::service::message_service::MessageService::send_system(
event.tenant_id,
pid,
title,
body,
"low",
Some("care_action".to_string()),
event.payload.get("plan_id").and_then(|v| v.as_str()).and_then(|s| uuid::Uuid::parse_str(s).ok()),
db,
event_bus,
)
.await
.map_err(|e| e.to_string())?;
}
}
_ => {}
}
Ok(())