fix(health): 修复 5 角色测试发现的 4 个共性问题
- 权限路由守卫:静默重定向改为显示 403 页面,使用 useLocation 替代 window.location.hash,补全缺失路由权限条目 - 随访状态筛选:usePaginatedData hook 添加 filters 变化监听自动刷新 - 告警操作:后端 acknowledge/dismiss/resolve 改返回 AlertResponse (含 patient_name),前端增加 active 状态兼容和错误反馈 - 咨询患者名:后端 create/get/close_session 增加 patient_name 和 doctor_name enrichment,前端 EntityName 空字符串处理
This commit is contained in:
@@ -88,6 +88,34 @@ pub async fn list_alerts(
|
||||
Ok((items, total))
|
||||
}
|
||||
|
||||
/// 将 alerts::Model 转换为 AlertResponse,并查找关联的患者名称。
|
||||
async fn enrich_alert_response(
|
||||
db: &DatabaseConnection,
|
||||
tenant_id: Uuid,
|
||||
model: alerts::Model,
|
||||
) -> HealthResult<AlertResponse> {
|
||||
let patient_name = patient::Entity::find_by_id(model.patient_id)
|
||||
.filter(patient::Column::TenantId.eq(tenant_id))
|
||||
.one(db)
|
||||
.await?
|
||||
.map(|p| p.name);
|
||||
Ok(AlertResponse {
|
||||
id: model.id,
|
||||
patient_id: model.patient_id,
|
||||
patient_name,
|
||||
rule_id: model.rule_id,
|
||||
severity: model.severity,
|
||||
title: model.title,
|
||||
detail: model.detail,
|
||||
status: model.status,
|
||||
acknowledged_by: model.acknowledged_by,
|
||||
acknowledged_at: model.acknowledged_at,
|
||||
resolved_at: model.resolved_at,
|
||||
created_at: model.created_at,
|
||||
version: model.version,
|
||||
})
|
||||
}
|
||||
|
||||
/// 查询指定医生负责的所有患者 ID 列表(通过 patient_doctor_relation 表)。
|
||||
async fn get_patient_ids_for_doctor(
|
||||
db: &DatabaseConnection,
|
||||
@@ -110,7 +138,7 @@ pub async fn acknowledge_alert(
|
||||
alert_id: Uuid,
|
||||
user_id: Uuid,
|
||||
version: i32,
|
||||
) -> HealthResult<alerts::Model> {
|
||||
) -> HealthResult<AlertResponse> {
|
||||
let alert = alerts::Entity::find_by_id(alert_id)
|
||||
.filter(alerts::Column::TenantId.eq(tenant_id))
|
||||
.filter(alerts::Column::DeletedAt.is_null())
|
||||
@@ -128,7 +156,8 @@ pub async fn acknowledge_alert(
|
||||
active.updated_at = Set(Utc::now());
|
||||
active.version = Set(version + 1);
|
||||
|
||||
Ok(active.update(&state.db).await?)
|
||||
let updated = active.update(&state.db).await?;
|
||||
enrich_alert_response(&state.db, tenant_id, updated).await
|
||||
}
|
||||
|
||||
pub async fn dismiss_alert(
|
||||
@@ -137,7 +166,7 @@ pub async fn dismiss_alert(
|
||||
alert_id: Uuid,
|
||||
user_id: Uuid,
|
||||
version: i32,
|
||||
) -> HealthResult<alerts::Model> {
|
||||
) -> HealthResult<AlertResponse> {
|
||||
let alert = alerts::Entity::find_by_id(alert_id)
|
||||
.filter(alerts::Column::TenantId.eq(tenant_id))
|
||||
.filter(alerts::Column::DeletedAt.is_null())
|
||||
@@ -154,7 +183,8 @@ pub async fn dismiss_alert(
|
||||
active.updated_at = Set(Utc::now());
|
||||
active.version = Set(version + 1);
|
||||
|
||||
Ok(active.update(&state.db).await?)
|
||||
let updated = active.update(&state.db).await?;
|
||||
enrich_alert_response(&state.db, tenant_id, updated).await
|
||||
}
|
||||
|
||||
pub async fn resolve_alert(
|
||||
@@ -162,7 +192,7 @@ pub async fn resolve_alert(
|
||||
tenant_id: Uuid,
|
||||
alert_id: Uuid,
|
||||
version: i32,
|
||||
) -> HealthResult<alerts::Model> {
|
||||
) -> HealthResult<AlertResponse> {
|
||||
let alert = alerts::Entity::find_by_id(alert_id)
|
||||
.filter(alerts::Column::TenantId.eq(tenant_id))
|
||||
.filter(alerts::Column::DeletedAt.is_null())
|
||||
@@ -179,7 +209,8 @@ pub async fn resolve_alert(
|
||||
active.updated_at = Set(Utc::now());
|
||||
active.version = Set(version + 1);
|
||||
|
||||
Ok(active.update(&state.db).await?)
|
||||
let updated = active.update(&state.db).await?;
|
||||
enrich_alert_response(&state.db, tenant_id, updated).await
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -35,6 +35,31 @@ fn model_to_session_resp(m: consultation_session::Model) -> SessionResp {
|
||||
}
|
||||
}
|
||||
|
||||
/// 查询单个会话的 patient_name 和 doctor_name 并填充到 SessionResp。
|
||||
async fn enrich_session_resp(
|
||||
db: &DatabaseConnection,
|
||||
tenant_id: Uuid,
|
||||
mut resp: SessionResp,
|
||||
) -> HealthResult<SessionResp> {
|
||||
let patient_name = patient::Entity::find_by_id(resp.patient_id)
|
||||
.filter(patient::Column::TenantId.eq(tenant_id))
|
||||
.one(db)
|
||||
.await?
|
||||
.map(|p| p.name);
|
||||
resp.patient_name = patient_name;
|
||||
|
||||
if let Some(did) = resp.doctor_id {
|
||||
let doctor_name = doctor_profile::Entity::find_by_id(did)
|
||||
.filter(doctor_profile::Column::TenantId.eq(tenant_id))
|
||||
.one(db)
|
||||
.await?
|
||||
.map(|d| d.name);
|
||||
resp.doctor_name = doctor_name;
|
||||
}
|
||||
|
||||
Ok(resp)
|
||||
}
|
||||
|
||||
pub async fn create_session(
|
||||
state: &HealthState,
|
||||
tenant_id: Uuid,
|
||||
@@ -92,7 +117,7 @@ pub async fn create_session(
|
||||
&state.db,
|
||||
).await;
|
||||
|
||||
Ok(model_to_session_resp(m))
|
||||
enrich_session_resp(&state.db, tenant_id, model_to_session_resp(m)).await
|
||||
}
|
||||
|
||||
/// 获取单个咨询会话
|
||||
@@ -110,7 +135,7 @@ pub async fn get_session(
|
||||
.await?
|
||||
.ok_or(HealthError::ConsultationNotFound)?;
|
||||
|
||||
Ok(model_to_session_resp(model))
|
||||
enrich_session_resp(&state.db, tenant_id, model_to_session_resp(model)).await
|
||||
}
|
||||
|
||||
pub async fn list_sessions(
|
||||
@@ -231,7 +256,7 @@ pub async fn close_session(
|
||||
&state.db,
|
||||
).await;
|
||||
|
||||
Ok(model_to_session_resp(m))
|
||||
enrich_session_resp(&state.db, tenant_id, model_to_session_resp(m)).await
|
||||
}
|
||||
|
||||
pub async fn export_sessions(
|
||||
|
||||
Reference in New Issue
Block a user