feat(core+health): HealthDataProvider 扩展趋势分析预计算数据
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

- erp-core: 新增 get_trend_analysis_data() trait 方法和配套 DTO
  (TrendAnalysisDto, MetricTrendAnalysis, RegressionStats, AnomalyInfo)
- erp-health: 实现 get_trend_analysis_data(),查询 vital_signs 时间序列
  后调用 trend_stats 模块计算线性回归和异常检测,返回结构化统计摘要
This commit is contained in:
iven
2026-04-28 19:55:06 +08:00
parent 8aac96b62f
commit 1c9e7ccf1d
2 changed files with 172 additions and 2 deletions

View File

@@ -37,6 +37,15 @@ pub trait HealthDataProvider: Send + Sync {
tenant_id: Uuid,
report_id: Uuid,
) -> AppResult<HealthReportDto>;
/// 获取趋势分析预计算数据(统计摘要 + 异常检测)
async fn get_trend_analysis_data(
&self,
tenant_id: Uuid,
patient_id: Uuid,
metrics: &[String],
range: &TimeRange,
) -> AppResult<TrendAnalysisDto>;
}
// === DTO 定义 ===
@@ -97,3 +106,56 @@ pub struct ReportSectionDto {
pub findings: Vec<String>,
pub abnormal_items: Vec<String>,
}
// === 趋势分析 DTO ===
/// 趋势方向
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum TrendDirection {
Rising,
Falling,
Stable,
}
/// 趋势分析整体 DTO
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TrendAnalysisDto {
pub patient_id: Uuid,
pub period_start: String,
pub period_end: String,
pub metrics: Vec<MetricTrendAnalysis>,
}
/// 单个指标的趋势分析结果
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MetricTrendAnalysis {
pub metric: String,
pub unit: String,
pub data_point_count: usize,
/// 线性回归统计(数据不足时为 None
pub regression: Option<RegressionStats>,
/// 检测到的异常点
pub anomalies: Vec<AnomalyInfo>,
}
/// 线性回归统计摘要
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegressionStats {
pub slope: f64,
pub intercept: f64,
pub r_squared: f64,
pub direction: TrendDirection,
pub daily_change: f64,
pub period_change: f64,
}
/// 异常点信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnomalyInfo {
pub date: String,
pub value: f64,
pub mean: f64,
pub std_dev: f64,
pub deviation: f64,
}