fix(health): 身份证号18位校验位验证 + 手机号1[3-9]格式校验
后端:
- validation.rs: 新增 validate_id_number(含加权校验位)和 validate_phone(1[3-9]\d{9})
- patient_dto.rs: CreatePatientReq/UpdatePatientReq/FamilyMemberReq 添加 Validate derive
- patient_handler.rs: create/update/family_member handler 调用格式校验
前端:
- PatientList/PatientDetail/FamilyMembersTab: Form.Item 添加 pattern rules + maxLength
测试:15 个新测试用例全部通过
This commit is contained in:
@@ -68,12 +68,19 @@ where
|
||||
{
|
||||
require_permission(&ctx, "health.patient.manage")?;
|
||||
let mut req = req;
|
||||
req.validate()
|
||||
.map_err(|e| AppError::Validation(e.to_string()))?;
|
||||
req.sanitize();
|
||||
if req.name.trim().is_empty() {
|
||||
return Err(AppError::Validation("患者姓名不能为空".into()));
|
||||
}
|
||||
if req.name.len() > 255 {
|
||||
return Err(AppError::Validation("患者姓名长度不能超过255个字符".into()));
|
||||
if let Some(ref id_num) = req.id_number {
|
||||
crate::service::validation::validate_id_number(id_num)
|
||||
.map_err(|e| AppError::Validation(e.to_string()))?;
|
||||
}
|
||||
if let Some(ref phone) = req.emergency_contact_phone {
|
||||
crate::service::validation::validate_phone(phone)
|
||||
.map_err(|e| AppError::Validation(e.to_string()))?;
|
||||
}
|
||||
if let Some(ref bd) = req.birth_date
|
||||
&& *bd > chrono::Utc::now().date_naive()
|
||||
@@ -126,7 +133,18 @@ where
|
||||
status: req.status,
|
||||
verification_status: req.verification_status,
|
||||
};
|
||||
update
|
||||
.validate()
|
||||
.map_err(|e| AppError::Validation(e.to_string()))?;
|
||||
update.sanitize();
|
||||
if let Some(ref id_num) = update.id_number {
|
||||
crate::service::validation::validate_id_number(id_num)
|
||||
.map_err(|e| AppError::Validation(e.to_string()))?;
|
||||
}
|
||||
if let Some(ref phone) = update.emergency_contact_phone {
|
||||
crate::service::validation::validate_phone(phone)
|
||||
.map_err(|e| AppError::Validation(e.to_string()))?;
|
||||
}
|
||||
if let Some(ref bd) = update.birth_date
|
||||
&& *bd > chrono::Utc::now().date_naive()
|
||||
{
|
||||
@@ -215,7 +233,13 @@ where
|
||||
{
|
||||
require_permission(&ctx, "health.patient.manage")?;
|
||||
let mut req = req;
|
||||
req.validate()
|
||||
.map_err(|e| AppError::Validation(e.to_string()))?;
|
||||
req.sanitize();
|
||||
if let Some(ref phone) = req.phone {
|
||||
crate::service::validation::validate_phone(phone)
|
||||
.map_err(|e| AppError::Validation(e.to_string()))?;
|
||||
}
|
||||
let result =
|
||||
patient_service::create_family_member(&state, ctx.tenant_id, id, Some(ctx.user_id), req)
|
||||
.await?;
|
||||
|
||||
Reference in New Issue
Block a user