feat(health): 随访模板系统 — follow_up_template + template_field 全栈
新增随访模板和模板字段两张表及完整 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:
117
crates/erp-health/src/dto/follow_up_template_dto.rs
Normal file
117
crates/erp-health/src/dto/follow_up_template_dto.rs
Normal 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,
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user