Files
hospital_performance/docs/database.md
2026-02-28 15:02:08 +08:00

10 KiB
Raw Permalink Blame History

数据库设计

ER图

┌──────────────┐       ┌──────────────┐
│ departments  │       │    users     │
├──────────────┤       ├──────────────┤
│ id (PK)      │       │ id (PK)      │
│ name         │       │ username     │
│ code         │       │ password_hash│
│ dept_type    │       │ staff_id(FK) │
│ parent_id(FK)│       │ role         │
│ level        │       │ is_active    │
│ sort_order   │       └──────┬───────┘
│ is_active    │              │
│ description  │              │
└──────┬───────┘              │
       │                      │
       │ 1:N                  │ N:1
       │                      │
       ▼                      │
┌──────────────┐              │
│    staff     │◀─────────────┘
├──────────────┤
│ id (PK)      │
│ employee_id  │
│ name         │
│ department_id│──┐
│ position     │  │
│ title        │  │
│ base_salary  │  │
│ perf_ratio   │  │
│ status       │  │
└──────┬───────┘  │
       │          │
       │ 1:N      │
       ▼          │
┌──────────────┐  │
│ assessments  │  │
├──────────────┤  │
│ id (PK)      │  │
│ staff_id(FK) │──┼──────────┐
│ period_year  │  │          │
│ period_month │  │          │
│ total_score  │  │          │
│ status       │  │          │
│ assessor_id  │──┼──┐       │
│ reviewer_id  │──┼──┼──┐    │
└──────┬───────┘  │  │  │    │
       │          │  │  │    │
       │ 1:N      │  │  │    │
       ▼          │  │  │    │
┌──────────────┐  │  │  │    │
│assessment_   │  │  │  │    │
│   details    │  │  │  │    │
├──────────────┤  │  │  │    │
│ id (PK)      │  │  │  │    │
│ assessment_id│──┘  │  │    │
│ indicator_id │──┐  │  │    │
│ actual_value │  │  │  │    │
│ score        │  │  │  │    │
└──────────────┘  │  │  │    │
                  │  │  │    │
┌──────────────┐  │  │  │    │
│  indicators  │◀─┘  │  │    │
├──────────────┤     │  │    │
│ id (PK)      │     │  │    │
│ name         │     │  │    │
│ code         │     │  │    │
│ indicator_type│    │  │    │
│ weight       │     │  │    │
│ max_score    │     │  │    │
│ target_value │     │  │    │
└──────────────┘     │  │    │
                     │  │    │
┌──────────────┐     │  │    │
│salary_records│     │  │    │
├──────────────┤     │  │    │
│ id (PK)      │     │  │    │
│ staff_id(FK) │◀────┘  │    │
│ period_year  │        │    │
│ period_month │        │    │
│ base_salary  │        │    │
│ perf_score   │        │    │
│ perf_bonus   │        │    │
│ deduction    │        │    │
│ allowance    │        │    │
│ total_salary │        │    │
│ status       │        │    │
└──────────────┘        │    │
                        │    │
       └────────────────┴────┘
              (自关联到staff)

数据表详解

departments (科室表)

字段 类型 约束 说明
id INTEGER PK, AUTO 主键
name VARCHAR(100) NOT NULL 科室名称
code VARCHAR(20) UNIQUE, NOT NULL 科室编码
dept_type ENUM NOT NULL 科室类型: clinical/medical_tech/medical_auxiliary/admin/logistics
parent_id INTEGER FK 上级科室ID
level INTEGER DEFAULT 1 层级 (1-5)
sort_order INTEGER DEFAULT 0 排序
is_active BOOLEAN DEFAULT TRUE 是否启用
description TEXT 描述
created_at DATETIME 创建时间
updated_at DATETIME 更新时间

索引: idx_dept_type, idx_dept_parent

staff (员工表)

字段 类型 约束 说明
id INTEGER PK, AUTO 主键
employee_id VARCHAR(20) UNIQUE, NOT NULL 工号
name VARCHAR(50) NOT NULL 姓名
department_id INTEGER FK, NOT NULL 所属科室
position VARCHAR(50) NOT NULL 职位
title VARCHAR(50) 职称
phone VARCHAR(20) 联系电话
email VARCHAR(100) 邮箱
base_salary DECIMAL(10,2) DEFAULT 0 基本工资
performance_ratio DECIMAL(5,2) DEFAULT 1.0 绩效系数 (0-5)
status ENUM DEFAULT active 状态: active/leave/resigned/retired
hire_date DATETIME 入职日期
created_at DATETIME 创建时间
updated_at DATETIME 更新时间

索引: idx_staff_dept, idx_staff_status

indicators (考核指标表)

字段 类型 约束 说明
id INTEGER PK, AUTO 主键
name VARCHAR(100) NOT NULL 指标名称
code VARCHAR(20) UNIQUE, NOT NULL 指标编码
indicator_type ENUM NOT NULL 类型: quality/quantity/efficiency/service/cost
weight DECIMAL(5,2) DEFAULT 1.0 权重 (需>0)
max_score DECIMAL(5,2) DEFAULT 100 最高分值
target_value DECIMAL(10,2) 目标值
unit VARCHAR(20) 计量单位
calculation_method TEXT 计算方法说明
description TEXT 描述
is_active BOOLEAN DEFAULT TRUE 是否启用
created_at DATETIME 创建时间
updated_at DATETIME 更新时间

索引: idx_indicator_type 约束: ck_indicator_weight (weight > 0)

assessments (考核记录表)

字段 类型 约束 说明
id INTEGER PK, AUTO 主键
staff_id INTEGER FK, NOT NULL 被考核员工
period_year INTEGER NOT NULL 考核年度
period_month INTEGER NOT NULL 考核月份
period_type VARCHAR(20) DEFAULT monthly 周期类型
total_score DECIMAL(5,2) DEFAULT 0 总分
weighted_score DECIMAL(5,2) DEFAULT 0 加权得分
status ENUM DEFAULT draft 状态: draft/submitted/reviewed/finalized/rejected
assessor_id INTEGER FK 考核人
reviewer_id INTEGER FK 审核人
submit_time DATETIME 提交时间
review_time DATETIME 审核时间
remark TEXT 备注
created_at DATETIME 创建时间
updated_at DATETIME 更新时间

索引: idx_assessment_staff, idx_assessment_period, idx_assessment_status

assessment_details (考核明细表)

字段 类型 约束 说明
id INTEGER PK, AUTO 主键
assessment_id INTEGER FK, NOT NULL 考核记录ID
indicator_id INTEGER FK, NOT NULL 指标ID
actual_value DECIMAL(10,2) 实际值
score DECIMAL(5,2) DEFAULT 0 得分
evidence TEXT 佐证材料
remark TEXT 备注
created_at DATETIME 创建时间
updated_at DATETIME 更新时间

索引: idx_detail_assessment, idx_detail_indicator

salary_records (工资核算表)

字段 类型 约束 说明
id INTEGER PK, AUTO 主键
staff_id INTEGER FK, NOT NULL 员工ID
period_year INTEGER NOT NULL 年度
period_month INTEGER NOT NULL 月份
base_salary DECIMAL(10,2) DEFAULT 0 基本工资
performance_score DECIMAL(5,2) DEFAULT 0 绩效得分
performance_bonus DECIMAL(10,2) DEFAULT 0 绩效奖金
deduction DECIMAL(10,2) DEFAULT 0 扣款
allowance DECIMAL(10,2) DEFAULT 0 补贴
total_salary DECIMAL(10,2) DEFAULT 0 应发工资
status VARCHAR(20) DEFAULT pending 状态: pending/confirmed/paid
remark TEXT 备注
created_at DATETIME 创建时间
updated_at DATETIME 更新时间

索引: idx_salary_staff, idx_salary_period

users (系统用户表)

字段 类型 约束 说明
id INTEGER PK, AUTO 主键
username VARCHAR(50) UNIQUE, NOT NULL 用户名
password_hash VARCHAR(255) NOT NULL 密码哈希
staff_id INTEGER FK 关联员工
role VARCHAR(20) DEFAULT staff 角色: admin/manager/staff
is_active BOOLEAN DEFAULT TRUE 是否启用
last_login DATETIME 最后登录时间
created_at DATETIME 创建时间
updated_at DATETIME 更新时间

索引: idx_user_username

枚举类型

DeptType (科室类型)

说明
clinical 临床科室
medical_tech 医技科室
medical_auxiliary 医辅科室
admin 行政科室
logistics 后勤科室

StaffStatus (员工状态)

说明
active 在职
leave 休假
resigned 离职
retired 退休

AssessmentStatus (考核状态)

说明
draft 草稿
submitted 已提交
reviewed 已审核
finalized 已确认
rejected 已驳回

IndicatorType (指标类型)

说明
quality 质量指标
quantity 数量指标
efficiency 效率指标
service 服务指标
cost 成本指标

数据库迁移

使用Alembic进行数据库版本管理

# 生成迁移文件
alembic revision --autogenerate -m "description"

# 执行迁移
alembic upgrade head

# 回滚迁移
alembic downgrade -1