docs: 修正测试策略 spec 的事实性错误
修正 spec review 发现的问题: - C-1: TestDb 实际是本地 PostgreSQL 隔离,非 Testcontainers - C-2: E2E 已有 4 spec/10 测试,非零测试 - 补充 6 个遗漏的 service(alert/daily_monitoring/critical_value_threshold 等) - 增加 Phase 0 基础设施搭建 - 修正 CI 配置(增加 PostgreSQL service、验证链) - 补充 5 个遗漏风险项和回退策略 - 统一"全量 80%"目标的准确含义
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: 数据库迁移与模式
|
||||
updated: 2026-04-25
|
||||
updated: 2026-04-26
|
||||
status: stable
|
||||
tags: [database, seaorm, migration, multi-tenant]
|
||||
---
|
||||
@@ -24,7 +24,7 @@ tags: [database, seaorm, migration, multi-tenant]
|
||||
| 文件 | 职责 |
|
||||
|------|------|
|
||||
| `crates/erp-server/migration/src/lib.rs` | Migrator 注册所有迁移 |
|
||||
| `crates/erp-server/migration/src/m*.rs` | 50 个迁移文件 |
|
||||
| `crates/erp-server/migration/src/m*.rs` | 72 个迁移文件 |
|
||||
| `crates/erp-core/src/types.rs` | BaseFields 标准字段定义 |
|
||||
|
||||
### 迁移命名规则
|
||||
@@ -34,34 +34,53 @@ m{YYYYMMDD}_{6位序号}_{描述}.rs
|
||||
例: m20260410_000001_create_tenant.rs
|
||||
```
|
||||
|
||||
### 当前表概览(48 张)
|
||||
### 当前表概览(67+ 张)
|
||||
|
||||
| 模块 | 表 |
|
||||
|------|-----|
|
||||
| 基础 | tenant |
|
||||
| 基础 | tenant, tenant_crypto_keys |
|
||||
| 认证 (auth) | users, user_credentials, user_tokens, roles, permissions, role_permissions, user_roles, organizations, departments, positions, user_departments |
|
||||
| 配置 (config) | dictionaries, dictionary_items, menus, menu_roles, settings, numbering_rules |
|
||||
| 工作流 (workflow) | process_definitions, process_instances, tokens, tasks, process_variables |
|
||||
| 消息 (message) | message_templates, messages, message_subscriptions |
|
||||
| 审计 | audit_logs, domain_events |
|
||||
| 插件 (plugin) | plugins, entity_registry, plugin_market, plugin_user_views |
|
||||
| **健康 (health)** | patient, patient_family_member, patient_tag, patient_tag_relation, patient_doctor_relation, doctor_profile, health_record, vital_signs, lab_report, health_trend, appointment, doctor_schedule, follow_up_task, follow_up_record, consultation_session, consultation_message |
|
||||
| **健康 (health)** | patient, patient_family_member, patient_tag, patient_tag_relation, patient_doctor_relation, doctor_profile, health_record, vital_signs, daily_monitoring, lab_report, health_trend, diagnosis, dialysis_record, critical_value_thresholds, consent, appointment, doctor_schedule, follow_up_task, follow_up_record, consultation_session, consultation_message |
|
||||
| **内容 (article)** | article, article_category, article_tag, article_article_tag, article_revision |
|
||||
| **积分 (points)** | points_account, points_rule, points_product, points_order, points_transaction, points_checkin |
|
||||
| **线下活动** | offline_event, offline_event_registration |
|
||||
| **AI (ai)** | ai_prompt, ai_analysis, ai_usage |
|
||||
| **微信 (wechat)** | wechat_users |
|
||||
| **内容 (article)** | article |
|
||||
|
||||
### 健康模块迁移(m000042 - m000050)
|
||||
### 健康模块迁移(m000042 - m000072)
|
||||
|
||||
| 迁移 | 变更 |
|
||||
|------|------|
|
||||
| m000042 | 创建 17 张健康业务表(patient/doctor/appointment/schedule/vital_signs/lab_report/health_record/health_trend/follow_up_task/follow_up_record/consultation_session/consultation_message/patient_tag/patient_tag_relation/patient_family_member/patient_doctor_relation) |
|
||||
| m000042 | 创建 17 张健康业务表 |
|
||||
| m000043 | 创建 wechat_users 表 |
|
||||
| m000044 | 创建 article 表 |
|
||||
| m000045 | 健康模块索引优化 |
|
||||
| m000046 | 健康模块约束修复 |
|
||||
| m000047 | 健康模块索引修复 |
|
||||
| m000048 | 添加 patient.id_number_hash 列(HMAC-SHA256 哈希身份证) |
|
||||
| m000049 | 拓宽 patient.id_number 列(VARCHAR 加密存储需要更长字段) |
|
||||
| m000050 | 添加 appointment.doctor_name 列(冗余提升查询性能) |
|
||||
| m000048 | 添加 patient.id_number_hash 列 |
|
||||
| m000049 | 拓宽 patient.id_number 列 |
|
||||
| m000050 | 添加 appointment.doctor_name 列 |
|
||||
| m000051 | 透析/化验增强字段 |
|
||||
| m000052 | 创建 AI 分析表(ai_prompt/ai_analysis/ai_usage) |
|
||||
| m000053 | 创建积分商城表(points_account/rule/product/order/transaction) |
|
||||
| m000054 | 创建日常监测表(daily_monitoring) |
|
||||
| m000055 | 积分签到标准字段 |
|
||||
| m000056 | 创建诊断表(diagnosis) |
|
||||
| m000057 | 重命名 points_transaction 类型列 |
|
||||
| m000058 | 合并 daily_monitoring 到 vital_signs |
|
||||
| m000059 | 种子菜单数据 |
|
||||
| m000060 | 创建危急值阈值表 |
|
||||
| m000061 | 创建知情同意表 |
|
||||
| m000062 | 创建租户加密密钥表(tenant_crypto_keys) |
|
||||
| m000063 | 内容管理表(article_category/article_tag/article_article_tag/article_revision) |
|
||||
| m000064-000068 | PII 加密扩展(patient/consultation/follow_up/family_member/doctor_profile) |
|
||||
| m000069-000071 | 加密字段 key_version(dialysis_record/lab_report/diagnosis) |
|
||||
| m000072 | 拓宽加密手机号列 |
|
||||
|
||||
### 集成契约
|
||||
|
||||
@@ -70,7 +89,7 @@ m{YYYYMMDD}_{6位序号}_{描述}.rs
|
||||
| 消费 ← | [[erp-server]] | 启动时自动运行 `Migrator::up()` |
|
||||
| 依赖 ← | [[erp-core]] | BaseFields 定义标准字段规范 |
|
||||
| 提供 → | 所有业务模块 | 表结构供 SeaORM Entity 使用 |
|
||||
| 提供 → | [[erp-health]] | 18 张健康业务表 |
|
||||
| 提供 → | [[erp-health]] | 34 张健康业务表 |
|
||||
|
||||
## 3. 代码逻辑
|
||||
|
||||
@@ -112,6 +131,7 @@ m{YYYYMMDD}_{6位序号}_{描述}.rs
|
||||
|
||||
| 日期 | 变更 |
|
||||
|------|------|
|
||||
| 2026-04-26 | 更新至 72 迁移、67+ 表,新增积分商城/透析/诊断/内容管理/线下活动/PII 加密扩展等 22 个迁移 |
|
||||
| 2026-04-25 | 更新至 50 迁移、48 表,新增健康模块迁移(m000042-m000050)和 18 张健康业务表 |
|
||||
| 2026-04-23 | 重构为 5 节结构,更新表清单至 41 个迁移 |
|
||||
| 2026-04-19 | CRM 权限码修复迁移 (m000038) |
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
title: erp-health 健康管理模块
|
||||
updated: 2026-04-26
|
||||
status: implemented
|
||||
tags: [health, patient, appointment, follow-up, consultation, content]
|
||||
tags: [health, patient, appointment, follow-up, consultation, content, points, dialysis, offline-events]
|
||||
---
|
||||
|
||||
# erp-health 健康管理模块
|
||||
@@ -47,28 +47,33 @@ crates/erp-health/
|
||||
│ ├── state.rs ← HealthState { db, event_bus, crypto }
|
||||
│ ├── crypto.rs ← AES-256-GCM 加密 + HMAC-SHA256 (PII 保护)
|
||||
│ ├── event.rs ← 事件处理器 (订阅 workflow/message 事件)
|
||||
│ ├── entity/ ← 21 个 SeaORM Entity
|
||||
│ ├── service/ ← 14 个业务 service
|
||||
│ ├── handler/ ← 9 个路由 handler
|
||||
│ ├── entity/ ← 34 个 SeaORM Entity
|
||||
│ ├── service/ ← 14 个业务 service + validation + masking + trend
|
||||
│ ├── handler/ ← 16 个路由 handler
|
||||
│ ├── dto/ ← 7 个请求/响应 DTO
|
||||
│ ├── validation.rs ← 输入验证逻辑 (302 行, 57 纯函数测试)
|
||||
│ ├── masking.rs ← PII 数据脱敏 (手机号/身份证)
|
||||
│ └── seed.rs ← 租户种子数据 + 软删除清理
|
||||
```
|
||||
|
||||
### 实体模型(21 个实体)
|
||||
### 实体模型(34 个实体)
|
||||
|
||||
| 域 | 实体 |
|
||||
|----|------|
|
||||
| 患者管理 | patient, patient_family_member, patient_tag, patient_tag_relation, patient_doctor_relation |
|
||||
| 患者管理 | patient, patient_family_member, patient_tag, patient_tag_relation, patient_doctor_relation, consent |
|
||||
| 医护管理 | doctor_profile |
|
||||
| 健康数据 | health_record, vital_signs, lab_report, health_trend |
|
||||
| 日常监测 | daily_monitoring, critical_value_threshold |
|
||||
| 诊断管理 | diagnosis |
|
||||
| 透析管理 | dialysis_record |
|
||||
| 预约排班 | appointment, doctor_schedule |
|
||||
| 随访管理 | follow_up_task, follow_up_record |
|
||||
| 咨询管理 | consultation_session, consultation_message |
|
||||
| 内容管理 | article, article_category, article_tag, article_article_tag, article_revision |
|
||||
| 积分商城 | points_account, points_rule, points_product, points_order, points_transaction, points_checkin |
|
||||
| 线下活动 | offline_event, offline_event_registration |
|
||||
|
||||
### 权限码(15 个)
|
||||
### 权限码(15+ 个)
|
||||
|
||||
| 权限码 | 说明 |
|
||||
|--------|------|
|
||||
@@ -96,11 +101,14 @@ crates/erp-health/
|
||||
### API 前缀: `/api/v1/health/`
|
||||
|
||||
关键端点分组:
|
||||
- `/patients` — 患者列表/详情/标签管理/健康摘要/家庭成团/医生关联
|
||||
- `/patients` — 患者列表/详情/标签管理/健康摘要/家庭成员/医生关联/知情同意
|
||||
- `/patients/{id}/vital-signs` — 日常监测数据(血压/心率/体重/血糖)
|
||||
- `/patients/{id}/lab-reports` — 化验报告(JSONB 指标数据)
|
||||
- `/patients/{id}/health-records` — 健康档案
|
||||
- `/patients/{id}/trends` — 健康趋势报告(自动/手动生成,时间序列查询)
|
||||
- `/patients/{id}/diagnoses` — 诊断记录
|
||||
- `/patients/{id}/dialysis-records` — 透析记录
|
||||
- `/patients/{id}/daily-monitoring` — 日常监测记录
|
||||
- `/vital-signs/trend` — 小程序趋势(JWT user → patient)
|
||||
- `/vital-signs/today` — 小程序当日体征摘要
|
||||
- `/appointments` — 预约管理 + 状态变更(pending→confirmed→completed/cancelled/no_show)
|
||||
@@ -120,6 +128,13 @@ crates/erp-health/
|
||||
- `/articles/{id}/view` — 增加阅读计数
|
||||
- `/article-categories` — 分类 CRUD
|
||||
- `/article-tags` — 标签 CRUD
|
||||
- `/points/rules` — 积分规则 CRUD
|
||||
- `/points/products` — 积分商品 CRUD
|
||||
- `/points/orders` — 积分订单
|
||||
- `/points/accounts` — 积分账户 + 签到
|
||||
- `/offline-events` — 线下活动 CRUD + 报名
|
||||
- `/stats/*` — 统计概览(透析/化验/预约/体征上报率)
|
||||
- `/critical-value-thresholds` — 危急值阈值管理
|
||||
|
||||
### 预约并发控制
|
||||
|
||||
@@ -169,7 +184,7 @@ draft → pending_review → published → draft (撤回)
|
||||
|
||||
### 当前状态: ✅ 已完成
|
||||
|
||||
21 实体、15 权限、19 Web 页面、20 小程序页面,全链路流通性验证通过。
|
||||
34 实体、16 个 handler(~148 个 pub fn)、15+ 权限、22 Web 页面 + 11 组件,17k 行 Rust 代码。状态转换验证统一到 validation 模块(83 纯函数测试)。
|
||||
|
||||
### 待优化
|
||||
|
||||
@@ -195,6 +210,7 @@ draft → pending_review → published → draft (撤回)
|
||||
|
||||
| 日期 | 变更 |
|
||||
|------|------|
|
||||
| 2026-04-26 | 全面更新:34 实体(+13 积分/透析/诊断/日常监测/线下活动/危急值/知情同意)、16 handler、stats 统计端点、validation 统一模块(83 测试)、PII 加密扩展(doctor_profile/dialysis_record/lab_report/diagnosis key_version) |
|
||||
| 2026-04-26 | 新增内容管理:article_category/article_tag/article_article_tag/article_revision 4 实体、审核状态机 |
|
||||
| 2026-04-25 | 全面更新为已实现状态:18 实体、14 权限、全链路验证通过 |
|
||||
| 2026-04-26 | 新增内容管理:article_category/article_tag/article_article_tag/article_revision 4 实体、审核状态机、分类/标签 CRUD、富文本编辑器(+4 实体 = 21 总实体,+1 权限 = 15 总权限,+4 前端页面 = 19 总页面) |
|
||||
| 2026-04-23 | 创建模块 wiki 页,设计规格确认 |
|
||||
|
||||
@@ -6,18 +6,19 @@
|
||||
|
||||
| 指标 | 值 |
|
||||
|------|-----|
|
||||
| Rust crate | 16 个(erp-core + 6 基础业务 + erp-health + erp-ai + 6 插件 + erp-plugin-prototype) |
|
||||
| 数据库表 | 30 基础表 + 22 健康业务表 + 3 AI 表(已实现) |
|
||||
| 数据库迁移 | 55 个 |
|
||||
| Rust crate | 15 个(erp-core + 5 基础业务 + erp-health + erp-ai + erp-plugin + 4 插件 + erp-plugin-prototype) |
|
||||
| 数据库表 | 30 基础表 + 34 健康业务表 + 3 AI 表(已实现) |
|
||||
| 数据库迁移 | 72 个 |
|
||||
| 核心模块 | 5 基础 (auth/config/workflow/message/plugin) + 2 业务 (health + ai) |
|
||||
| Web 前端页面 | 66 个 TSX 组件(含 19 健康管理页面) |
|
||||
| 健康模块组件 | 12 个共享组件(StatusTag/PatientSelect/DoctorSelect/VitalSignsChart 等) |
|
||||
| 微信小程序 | Taro 4.2 + React 18,27 个页面 |
|
||||
| erp-health 实体 | 34 个 Entity(17k 行 Rust) |
|
||||
| erp-ai 实体 | 3 个 Entity(1.7k 行 Rust) |
|
||||
| Web 前端 | 77 个 TSX + 56 个 TS = 133 个源文件(48 个页面 + 22 健康页面 + 11 健康组件) |
|
||||
| 微信小程序 | Taro 4.2 + React 18,12 个页面 |
|
||||
| 前端单元测试 | 3 个(vitest)+ 4 E2E spec(playwright) |
|
||||
| 后端测试 | 36 个(workspace)+ 57 validation 纯函数测试 |
|
||||
| 总代码量 | Rust ~57k 行 + 前端 TSX/TS ~174 文件 |
|
||||
| 后端测试 | 36 个(workspace)+ 83 validation 纯函数测试 |
|
||||
| 总代码量 | Rust ~63k 行 + 前端 TSX/TS ~133 文件 + 小程序 ~7.5k 行 |
|
||||
| API 文档 | `http://localhost:3000/api/docs/openapi.json` |
|
||||
| Git 提交 | 273 次 |
|
||||
| Git 提交 | 297 次 |
|
||||
|
||||
## 症状导航
|
||||
|
||||
@@ -52,8 +53,8 @@
|
||||
- erp-plugin — WASM 运行时 · 动态表 · 热更新(HMS 保留但非主要扩展方式)
|
||||
|
||||
### 核心业务层(HMS 专属)
|
||||
- [[erp-health]] — **患者管理 · 健康数据 · 预约排班 · 随访管理 · 咨询管理 · 内容管理**(原生 Rust 模块,已实现)
|
||||
- [[erp-ai]] — **AI 智能分析 · 化验单解读 · 趋势分析 · 报告摘要**(原生 Rust 模块,开发中)
|
||||
- [[erp-health]] — **患者管理 · 健康数据 · 预约排班 · 随访管理 · 咨询管理 · 内容管理 · 积分商城 · 透析管理 · 线下活动 · 日常监测**(原生 Rust 模块,34 实体,已实现)
|
||||
- [[erp-ai]] — **AI 智能分析 · 化验单解读 · 趋势分析 · 报告摘要**(原生 Rust 模块,3 实体,Phase 1 MVP)
|
||||
|
||||
### 组装层
|
||||
- [[erp-server]] — Axum 入口 · AppState · 7 模块注册 · 后台任务 · 优雅关闭
|
||||
@@ -63,8 +64,8 @@
|
||||
|
||||
### 基础设施
|
||||
- [[infrastructure]] — 连接信息 · 环境变量 · 一键启动 (**单一真相源**)
|
||||
- [[database]] — SeaORM 迁移 · 多租户表结构
|
||||
- [[frontend]] — React 19 SPA · 健康管理页面(19 页面 + 12 组件)
|
||||
- [[database]] — SeaORM 迁移 · 多租户表结构(72 迁移)
|
||||
- [[frontend]] — React 19 SPA · 健康管理页面(22 页面 + 11 组件)
|
||||
- [[testing]] — 验证清单 · 测试分布 · 性能基准
|
||||
|
||||
## 核心架构问答
|
||||
@@ -82,8 +83,13 @@
|
||||
| 类型 | 位置 |
|
||||
|------|------|
|
||||
| 健康模块设计规格 | `docs/superpowers/specs/2026-04-23-health-management-module-design.md` |
|
||||
| QA 审计计划 | `plans/qa-review-brainstorm-floofy-finch.md` |
|
||||
| 设计规格 | `docs/superpowers/specs/` |
|
||||
| 实施计划 | `docs/superpowers/plans/` |
|
||||
| AI 模块设计规格 | `docs/superpowers/specs/2026-04-25-erp-ai-module-design.md` |
|
||||
| 内容管理设计规格 | `docs/superpowers/specs/2026-04-26-content-management-design.md` |
|
||||
| PII 加密扩展规格 | `docs/superpowers/specs/2026-04-26-pii-encryption-expansion-design.md` |
|
||||
| 实时体征管线探讨 | `docs/superpowers/specs/2026-04-26-realtime-vital-signs-pipeline-design.md` |
|
||||
| 平台复盘与演进 | `docs/superpowers/specs/2026-04-26-platform-retrospective-and-evolution-design.md` |
|
||||
| 设计规格(全量) | `docs/superpowers/specs/` (23 份) |
|
||||
| 实施计划(全量) | `docs/superpowers/plans/` (18 份) |
|
||||
| 讨论记录 | `docs/discussions/` (6 份) |
|
||||
| 协作规则 | `CLAUDE.md` |
|
||||
| 插件制作指南 | `.claude/skills/plugin-development/SKILL.md` |
|
||||
|
||||
Reference in New Issue
Block a user