Files
hospital_performance/.qoder/repowiki/zh/content/数据库设计/数据字典/指标模板字段.md
2026-02-28 15:16:15 +08:00

18 KiB
Raw Blame History

指标模板字段

**本文档引用的文件** - [models.py](file://backend/app/models/models.py) - [schemas.py](file://backend/app/schemas/schemas.py) - [templates.py](file://backend/app/api/v1/templates.py) - [template_service.py](file://backend/app/services/template_service.py) - [002_template.py](file://backend/alembic/versions/002_template.py) - [init_templates.py](file://backend/app/scripts/init_templates.py) - [init_indicator_templates.py](file://backend/init_indicator_templates.py) - [Templates.vue](file://frontend/src/views/basic/Templates.vue) - [template.js](file://frontend/src/api/template.js)

目录

  1. 简介
  2. 项目结构
  3. 核心组件
  4. 架构总览
  5. 详细组件分析
  6. 依赖分析
  7. 性能考虑
  8. 故障排查指南
  9. 结论

简介

本文件聚焦于指标模板相关字段的数据字典,覆盖以下核心实体与关系:

  • 指标模板表IndicatorTemplate
  • 模板指标关联表TemplateIndicator
  • 模板类型枚举TemplateType
  • 指标与模板的多对多关联关系
  • 维度权重配置与指标分类管理
  • 模板版本管理与继承关系设计
  • 激活状态与使用范围约束

本文件同时提供字段定义、约束说明、数据流向与前后端交互示例,帮助开发者与运维人员快速理解与使用模板系统。

项目结构

模板系统由后端模型与服务、API路由、前端页面与接口组成形成“模型-服务-接口-视图”的完整链路。

graph TB
subgraph "后端"
M["models.py<br/>数据模型"]
S["template_service.py<br/>服务层"]
A["templates.py<br/>API路由"]
SC["schemas.py<br/>Pydantic模式"]
ALEMBIC["002_template.py<br/>迁移脚本"]
end
subgraph "前端"
V["Templates.vue<br/>模板管理页面"]
API["template.js<br/>模板API封装"]
end
V --> API
API --> A
A --> S
S --> M
M --> ALEMBIC
SC --> A

图表来源

章节来源

核心组件

  • 指标模板表IndicatorTemplate

    • 字段id、template_name、template_code、template_type、description、dimension_weights、assessment_cycle、is_active、created_at、updated_at
    • 关系:与模板指标关联表一对多
    • 约束唯一索引template_code、索引template_type、is_active
  • 模板指标关联表TemplateIndicator

    • 字段id、template_id、indicator_id、category、target_value、target_unit、weight、scoring_method、scoring_params、sort_order、remark、created_at、updated_at
    • 关系:与模板表、指标表多对一
    • 约束唯一索引template_id, indicator_id、索引template_id、indicator_id
  • 模板类型枚举TemplateType

    • 类型general、surgical、nonsurgical_ward、nonsurgical_noward、medical_tech、nursing、admin、logistics
  • 指标表Indicator

    • 字段id、name、code、indicator_type、bs_dimension、weight、max_score、target_value、target_unit、calculation_method、assessment_method、deduction_standard、data_source、applicable_dept_types、is_veto、is_active、created_at、updated_at
    • 约束CheckConstraint(weight > 0)

章节来源

架构总览

模板系统采用“模板-指标”多对多关系,通过模板指标关联表实现灵活配置。模板类型决定适用科室范围,维度权重用于汇总计算,指标分类用于二级归类,权重与评分方法用于最终得分计算。

erDiagram
INDICATOR_TEMPLATE {
int id PK
string template_name
string template_code UK
string template_type
text description
text dimension_weights
string assessment_cycle
boolean is_active
datetime created_at
datetime updated_at
}
TEMPLATE_INDICATOR {
int id PK
int template_id FK
int indicator_id FK
string category
numeric target_value
string target_unit
numeric weight
string scoring_method
text scoring_params
int sort_order
text remark
datetime created_at
datetime updated_at
}
INDICATOR {
int id PK
string name
string code UK
string indicator_type
string bs_dimension
numeric weight
numeric max_score
numeric target_value
string target_unit
text calculation_method
text assessment_method
text deduction_standard
string data_source
text applicable_dept_types
boolean is_veto
boolean is_active
datetime created_at
datetime updated_at
}
INDICATOR_TEMPLATE ||--o{ TEMPLATE_INDICATOR : "包含"
INDICATOR ||--o{ TEMPLATE_INDICATOR : "被包含"

图表来源

详细组件分析

指标模板表IndicatorTemplate字段字典

  • id

    • 类型:整数
    • 主键:是
    • 描述:模板主键
    • 约束:自增
    • 章节来源
  • template_name

    • 类型字符串最大长度200
    • 描述:模板名称
    • 章节来源
  • template_code

  • template_type

    • 类型枚举TemplateType
    • 描述:模板类型
    • 取值general、surgical、nonsurgical_ward、nonsurgical_noward、medical_tech、nursing、admin、logistics
    • 章节来源
  • description

  • dimension_weights

    • 类型文本JSON
    • 描述:维度权重配置(财务、客户、内部流程、学习与成长)
    • 示例:{"financial": 35, "customer": 30, "internal_process": 25, "learning_growth": 10}
    • 章节来源
  • assessment_cycle

  • is_active

  • created_at/updated_at

  • 关系与索引

模板指标关联表TemplateIndicator字段字典

  • id

    • 类型:整数
    • 主键:是
    • 描述:模板指标关联主键
    • 章节来源
  • template_id

  • indicator_id

  • category

    • 类型字符串最大长度100
    • 描述:指标分类(二级指标分类)
    • 示例:收支管理、患者满意度、质量与安全
    • 章节来源
  • target_value/target_unit

  • weight

  • scoring_method/scoring_params

    • 类型:字符串/文本
    • 描述评分方法与参数JSON
    • 方法range、target、deduction、bonus、veto
    • 章节来源
  • sort_order

  • remark

    • 类型:文本
    • 描述:备注
    • 章节来源
  • created_at/updated_at

    • 类型:日期时间
    • 描述:创建与更新时间
    • 章节来源
  • 关系与索引

    • 关系:与模板表、指标表多对一
    • 索引template_id、indicator_id、(template_id, indicator_id)唯一
    • 章节来源

模板类型枚举TemplateType

  • 取值与含义
    • general通用模板
    • surgical手术临床科室
    • nonsurgical_ward非手术有病房科室
    • nonsurgical_noward非手术无病房科室
    • medical_tech医技科室
    • nursing护理单元
    • admin行政科室
    • logistics后勤科室
  • 使用场景
    • 用于区分模板适用科室类型,配合指标的适用科室类型字段实现过滤
  • 章节来源

指标分类管理与维度权重配置

  • 指标分类category

    • 作用:对模板内的指标进行二级分类,便于统计与展示
    • 示例:收支管理、患者满意度、质量与安全、内部服务效率等
    • 章节来源
  • 维度权重dimension_weights

    • 结构JSON对象键为维度标识值为百分比
    • 维度financial、customer、internal_process、learning_growth
    • 用途:用于模板层面的维度汇总与权重分配
    • 章节来源
  • 指标维度bs_dimension

模板与指标的多对多关联与权重分配机制

  • 关联关系
    • 通过 TemplateIndicator 实现模板与指标的多对多绑定
    • 每个模板内的指标可独立设置权重、目标值、评分方法等
  • 权重分配
    • 模板维度权重:用于模板层面的维度汇总
    • 指标权重:用于模板内指标的加权计算
  • 章节来源

模板版本管理与继承关系

  • 版本字段
    • 当前模型未内置版本字段;如需版本管理,可在模板表中扩展 version 字段
  • 继承关系
    • 可通过模板类型与指标适用科室类型实现“继承”效果:通用模板可作为特定模板的父模板,再叠加差异字段
  • 章节来源

激活状态与使用范围约束

  • 激活状态is_active
    • 控制模板是否可用
    • 前端通过开关切换,后端接口支持批量更新
  • 使用范围
    • 模板类型template_type限定适用科室类型
    • 指标的适用科室类型applicable_dept_types进一步限制
  • 章节来源

依赖分析

模板系统的关键依赖关系如下:

graph LR
ENUM["TemplateType 枚举"] --> IT["IndicatorTemplate 模型"]
IT --> TI["TemplateIndicator 模型"]
IND["Indicator 模型"] --> TI
SVC["TemplateService 服务"] --> IT
SVC --> TI
API["templates.py 路由"] --> SVC
SCHEMA["schemas.py 模式"] --> API
FRONT["Templates.vue 页面"] --> API
API --> FRONT

图表来源

章节来源

性能考虑

  • 查询优化
    • 模板列表按 template_type 与 is_active 进行过滤,建议保持索引有效
    • 模板详情加载时使用 selectinload 预加载关联指标,避免 N+1 查询
  • 写入优化
    • 批量添加模板指标时,服务层会自动设置排序,减少重复计算
  • 前端渲染
    • 前端对维度权重进行 JSON 解析与可视化展示,注意空值处理与错误捕获

故障排查指南

  • 模板编码冲突

    • 现象:创建模板时报错“模板编码已存在”
    • 排查:检查唯一索引约束与迁移脚本
    • 章节来源
  • 指标重复添加

  • 维度权重解析失败

    • 现象:前端维度权重显示异常
    • 排查:确认 JSON 格式正确,服务端/前端均做容错处理
    • 章节来源
  • 指标权重校验

    • 现象指标权重小于等于0导致异常
    • 排查:数据库层有 CheckConstraint前端也应限制输入范围
    • 章节来源

结论

指标模板系统通过清晰的模型设计与严格的约束,实现了模板类型、维度权重、指标分类与权重分配的灵活配置。模板与指标的多对多关系通过关联表实现解耦,支持按科室类型与适用范围进行精细化管理。建议后续在模板表中增加版本字段以完善版本管理能力,并在前端增强对 JSON 参数的校验与提示,提升系统的稳定性与易用性。