feat(health): 随访模板系统 — follow_up_template + template_field 全栈
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

新增随访模板和模板字段两张表及完整 CRUD:
- 迁移 083: follow_up_template + follow_up_template_field
- Entity: 模板(名称/类型/适用范围/状态) + 字段(标签/键名/类型/选项/校验)
- DTO: 创建时内嵌字段列表、更新支持全量替换字段
- Service: 随访类型+字段类型校验、级联软删除
- Handler: 5 端点 + RBAC 权限
- 路由: /api/v1/health/follow-up-templates
This commit is contained in:
iven
2026-04-27 14:40:28 +08:00
parent ca96310a84
commit dc5879228e
13 changed files with 869 additions and 2 deletions

View File

@@ -0,0 +1,117 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use utoipa::{IntoParams, ToSchema};
use uuid::Uuid;
use erp_core::sanitize::sanitize_option;
// ── 模板字段 DTO ──
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct TemplateFieldReq {
pub label: String,
pub field_key: String,
/// text/number/date/select/checkbox/textarea/scale
pub field_type: String,
#[serde(default)]
pub required: bool,
pub options: Option<String>,
pub placeholder: Option<String>,
pub validation: Option<String>,
#[serde(default)]
pub sort_order: i32,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct TemplateFieldResp {
pub id: Uuid,
pub template_id: Uuid,
pub label: String,
pub field_key: String,
pub field_type: String,
pub required: bool,
pub options: Option<String>,
pub placeholder: Option<String>,
pub validation: Option<String>,
pub sort_order: i32,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub version: i32,
}
// ── 模板 DTO ──
#[derive(Debug, Clone, Deserialize, IntoParams)]
pub struct FollowUpTemplateListQuery {
pub page: Option<u64>,
pub page_size: Option<u64>,
pub follow_up_type: Option<String>,
pub status: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct CreateFollowUpTemplateReq {
pub name: String,
pub description: Option<String>,
/// phone/outpatient/home_visit/online/wechat
pub follow_up_type: String,
pub applicable_scope: Option<String>,
#[serde(default)]
pub fields: Vec<TemplateFieldReq>,
}
impl CreateFollowUpTemplateReq {
pub fn sanitize(&mut self) {
self.name = self.name.trim().to_string();
self.description = sanitize_option(self.description.take());
self.applicable_scope = sanitize_option(self.applicable_scope.take());
}
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct UpdateFollowUpTemplateReq {
pub name: Option<String>,
pub description: Option<String>,
pub follow_up_type: Option<String>,
pub applicable_scope: Option<String>,
pub status: Option<String>,
/// 全量替换字段列表
pub fields: Option<Vec<TemplateFieldReq>>,
}
impl UpdateFollowUpTemplateReq {
pub fn sanitize(&mut self) {
if let Some(ref mut n) = self.name {
*n = n.trim().to_string();
}
self.description = sanitize_option(self.description.take());
self.applicable_scope = sanitize_option(self.applicable_scope.take());
}
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct FollowUpTemplateResp {
pub id: Uuid,
pub name: String,
pub description: Option<String>,
pub follow_up_type: String,
pub applicable_scope: Option<String>,
pub status: String,
pub fields: Vec<TemplateFieldResp>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub version: i32,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct FollowUpTemplateListItemResp {
pub id: Uuid,
pub name: String,
pub description: Option<String>,
pub follow_up_type: String,
pub status: String,
pub field_count: i64,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub version: i32,
}

View File

@@ -10,6 +10,7 @@ pub mod dialysis_dto;
pub mod dialysis_prescription_dto;
pub mod doctor_dto;
pub mod follow_up_dto;
pub mod follow_up_template_dto;
pub mod health_data_dto;
pub mod patient_dto;
pub mod points_dto;