elderly-health-platform/sql/mysql/elderly_phase2.sql
2026-10-16 20:17:14 +08:00

70 lines
3.7 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ============================================================================
-- Phase 2:老年人健康数据采集与基础分析 —— 数据库增量升级脚本
--
-- 设计背景:
-- Phase 1 的 elderly_person 表示「老人身份 + 相对稳定的基础档案」,
-- Phase 2 新增 elderly_health_record 表示「某个老人在某个时间点的一次健康测量」,
-- 同一老人可以有多条记录,从而支持历史记录与趋势分析。
--
-- 重要:
-- 1. 本脚本是增量升级脚本,只做 ADD,不会 DROP / 清空 elderly_person 等 Phase 1 数据
-- 2. 与 Phase 1 的 sql/mysql/elderly.sql(初始化脚本,会重建表)用途不同,请勿混用
-- 3. elderly_person.height / weight 继续作为建档基础值保留;
-- 健康趋势与最新健康数据一律以 elderly_health_record 为准
-- ============================================================================
SET NAMES utf8mb4;
-- ----------------------------
-- Table structure for elderly_health_record
--
-- 说明:
-- bmi / bmi_level / bp_level 均由后端计算后写入,App 只提交
-- height、weight、systolic_pressure、diastolic_pressure 等原始测量值
-- ----------------------------
CREATE TABLE IF NOT EXISTS `elderly_health_record` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
`elderly_id` bigint NOT NULL COMMENT '老人档案编号(elderly_person.id)',
`member_user_id` bigint NOT NULL COMMENT 'App 会员用户编号(member_user.id)',
`measure_time` datetime NOT NULL COMMENT '测量时间',
`height` decimal(5,1) NULL DEFAULT NULL COMMENT '身高(cm)',
`weight` decimal(5,1) NULL DEFAULT NULL COMMENT '体重(kg)',
`bmi` decimal(4,2) NULL DEFAULT NULL COMMENT 'BMI=体重(kg)/身高²(m),由后端计算',
`bmi_level` varchar(32) NULL DEFAULT NULL COMMENT 'BMI 分类,由后端计算',
`systolic_pressure` int NULL DEFAULT NULL COMMENT '收缩压(mmHg)',
`diastolic_pressure` int NULL DEFAULT NULL COMMENT '舒张压(mmHg)',
`bp_level` varchar(32) NULL DEFAULT NULL COMMENT '血压筛查参考(由后端判定)',
`heart_rate` int NULL DEFAULT NULL COMMENT '心率(次/分钟)',
`waist_circumference` decimal(5,1) NULL DEFAULT NULL COMMENT '腰围(cm)',
`calf_circumference` decimal(5,1) NULL DEFAULT NULL COMMENT '小腿围(cm)',
`remark` varchar(500) NULL DEFAULT NULL COMMENT '备注',
`creator` varchar(64) NULL DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) NULL DEFAULT '' COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
`tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
PRIMARY KEY (`id`),
KEY `idx_elderly_id` (`elderly_id`),
KEY `idx_member_user_id` (`member_user_id`),
KEY `idx_measure_time` (`measure_time`),
KEY `idx_tenant_id` (`tenant_id`)
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COMMENT = '老人健康测量记录表';
-- ============================================================================
-- 管理后台菜单:老人档案 → 健康记录(只读)
-- ============================================================================
DELETE FROM `system_menu` WHERE `id` IN (6503);
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`,
`component`, `component_name`, `status`, `creator`, `updater`) VALUES
(6503, '健康记录', 'elderly:health-record:query', 3, 1, 6502, '', '',
NULL, NULL, 0, 'admin', 'admin');