-- 添加病史相关字段和血糖血压记录表
-- 执行此SQL前请备份数据

-- 1. 添加病史字段到诊单表
ALTER TABLE `zyt_tcm_diagnosis` 
ADD COLUMN `trauma_history` tinyint(1) DEFAULT 0 COMMENT '外伤史：0-无 1-有' AFTER `fatty_liver_degree`,
ADD COLUMN `surgery_history` tinyint(1) DEFAULT 0 COMMENT '手术史：0-无 1-有' AFTER `trauma_history`,
ADD COLUMN `allergy_history` tinyint(1) DEFAULT 0 COMMENT '过敏史：0-无 1-有' AFTER `surgery_history`,
ADD COLUMN `family_history` tinyint(1) DEFAULT 0 COMMENT '家族病史：0-无 1-有' AFTER `allergy_history`,
ADD COLUMN `pregnancy_history` tinyint(1) DEFAULT 0 COMMENT '妊娠哺乳史：0-无 1-有' AFTER `family_history`,
ADD COLUMN `tongue_images` text COMMENT '舌苔照片（JSON数组）' AFTER `pregnancy_history`,
ADD COLUMN `report_files` text COMMENT '检查报告（JSON数组）' AFTER `tongue_images`;

-- 2. 创建每日血糖血压记录表
CREATE TABLE IF NOT EXISTS `zyt_tcm_blood_record` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `diagnosis_id` int(11) unsigned NOT NULL COMMENT '诊单ID',
  `patient_id` int(11) unsigned NOT NULL COMMENT '患者ID',
  `record_date` int(10) NOT NULL COMMENT '记录日期',
  `record_time` varchar(10) DEFAULT '' COMMENT '记录时间（如：08:00）',
  `blood_sugar` decimal(5,2) DEFAULT NULL COMMENT '血糖值（mmol/L）',
  `systolic_pressure` int(3) DEFAULT NULL COMMENT '收缩压（高压）mmHg',
  `diastolic_pressure` int(3) DEFAULT NULL COMMENT '舒张压（低压）mmHg',
  `remark` varchar(255) DEFAULT '' COMMENT '备注',
  `create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
  `update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
  `delete_time` int(10) unsigned DEFAULT NULL COMMENT '删除时间',
  PRIMARY KEY (`id`),
  KEY `idx_diagnosis_id` (`diagnosis_id`),
  KEY `idx_patient_id` (`patient_id`),
  KEY `idx_record_date` (`record_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='每日血糖血压记录表';

-- 验证字段添加
DESC zyt_tcm_diagnosis;
DESC zyt_tcm_blood_record;
