-- 更新 qc_standard_factor 表结构
-- 添加缺失的字段

USE `pacsonline_new`;

-- 1. 添加 check_rule 字段（如果不存在）
ALTER TABLE `qc_standard_factor`
ADD COLUMN IF NOT EXISTS `check_rule` VARCHAR(500) COMMENT '检查规则' AFTER `factor_id`;

-- 2. 添加 pass_value 字段（如果不存在）
ALTER TABLE `qc_standard_factor`
ADD COLUMN IF NOT EXISTS `pass_value` TEXT COMMENT '通过值（可以是具体值或JSON）' AFTER `check_rule`;

-- 3. 更新现有数据（根据初始化SQL的数据）
-- 因子1：检查范围
UPDATE `qc_standard_factor`
SET `check_rule` = '检查范围必须为正常',
    `pass_value` = 'normal'
WHERE `factor_id` = 'FACTOR_001' AND `check_rule` IS NULL;

-- 因子2：体位
UPDATE `qc_standard_factor`
SET `check_rule` = '体位必须为标准',
    `pass_value` = 'standard'
WHERE `factor_id` = 'FACTOR_002' AND `check_rule` IS NULL;

-- 因子3：图像伪影
UPDATE `qc_standard_factor`
SET `check_rule` = '图像伪影必须为无伪影',
    `pass_value` = 'none'
WHERE `factor_id` = 'FACTOR_003' AND `check_rule` IS NULL;

-- 因子4：中心线
UPDATE `qc_standard_factor`
SET `check_rule` = '中心线必须为正常',
    `pass_value` = 'normal'
WHERE `factor_id` = 'FACTOR_004' AND `check_rule` IS NULL;

-- 因子5：图像质控等级
UPDATE `qc_standard_factor`
SET `check_rule` = '图像质控等级必须达到乙级/1级及以上',
    `pass_value` = '{"xr":2,"ct_mr":1}'
WHERE `factor_id` = 'FACTOR_005' AND `check_rule` IS NULL;

-- 验证更新结果
SELECT
    id,
    standard_id,
    factor_id,
    check_rule,
    pass_value,
    weight
FROM `qc_standard_factor`
WHERE standard_id = 'STD_IMAGE_001';
