-- ============================================================
-- 质控因子初始数据
-- ============================================================
USE `qconline`;

-- 清空质控因子表
TRUNCATE TABLE `qc_factor`;

-- ============================================
-- 1. 数据质控因子
-- ============================================

INSERT INTO `qc_factor` VALUES
('DATA_001', 'DATA_001', '患者姓名完整性', 1, 'string', '检查患者姓名是否完整',
 '{"operator":"notEmpty"}', 'patient_name', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('DATA_002', 'DATA_002', '患者ID完整性', 1, 'string', '检查患者ID是否完整',
 '{"operator":"notEmpty"}', 'patient_id', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('DATA_003', 'DATA_003', '检查日期', 1, 'date', '检查日期是否存在',
 '{"operator":"notNull"}', 'study_date', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('DATA_004', 'DATA_004', '检查方式', 1, 'string', '检查方式是否填写',
 '{"operator":"notEmpty"}', 'modality', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('DATA_005', 'DATA_005', '检查部位', 1, 'string', '检查部位是否填写',
 '{"operator":"notEmpty"}', 'body_part', 1, NOW(), NOW());

-- ============================================
-- 2. 影像质控因子（技术质控）
-- ============================================

INSERT INTO `qc_factor` VALUES
('IMAGE_001', 'IMAGE_001', '检查范围', 2, 'string', '检查范围是否完整',
 '{"operator":"notEmpty"}', 'body_part', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('IMAGE_002', 'IMAGE_002', '体位', 2, 'string', '体位是否正确',
 '{"operator":"in","value":["正位","侧位","斜位","仰卧位","俯卧位"]}', 'position', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('IMAGE_003', 'IMAGE_003', '图像伪影', 2, 'string', '图像是否存在伪影',
 '{"operator":"equals","value":"无"}', 'artifact', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('IMAGE_004', 'IMAGE_004', '中心线', 2, 'string', '中心线是否居中',
 '{"operator":"equals","value":"居中"}', 'centerline', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('IMAGE_005', 'IMAGE_005', '图像等级', 2, 'number', '图像质量等级评分（1-5）',
 '{"operator":">=","value":3}', 'image_grade', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('IMAGE_006', 'IMAGE_006', '图像数量', 2, 'number', '图像数量是否充足',
 '{"operator":">=","value":10}', 'image_count', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('IMAGE_007', 'IMAGE_007', '序列数量', 2, 'number', '序列数量是否充足',
 '{"operator":">=","value":1}', 'series_count', 1, NOW(), NOW());

-- ============================================
-- 3. 报告质控因子（诊断质控）
-- ============================================

INSERT INTO `qc_factor` VALUES
('REPORT_001', 'REPORT_001', '影像所见完整性', 3, 'string', '影像所见描述是否完整',
 '{"operator":"notEmpty"}', 'findings', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('REPORT_002', 'REPORT_002', '影像所见字数', 3, 'number', '影像所见字数是否充足',
 '{"operator":">=","value":50}', 'findings_length', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('REPORT_003', 'REPORT_003', '诊断结论完整性', 3, 'string', '诊断结论是否填写',
 '{"operator":"notEmpty"}', 'diagnosis', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('REPORT_004', 'REPORT_004', '诊断结论字数', 3, 'number', '诊断结论字数是否充足',
 '{"operator":">=","value":10}', 'diagnosis_length', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('REPORT_005', 'REPORT_005', '报告时效性', 3, 'number', '报告时间距检查时间（小时）',
 '{"operator":"<=","value":24,"unit":"小时"}', 'report_timeliness', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('REPORT_006', 'REPORT_006', '报告医生', 3, 'string', '报告医生是否填写',
 '{"operator":"notEmpty"}', 'report_doctor_name', 1, NOW(), NOW());

INSERT INTO `qc_factor` VALUES
('REPORT_007', 'REPORT_007', '审核医生', 3, 'string', '审核医生是否填写',
 '{"operator":"notEmpty"}', 'audit_doctor_name', 1, NOW(), NOW());

-- ============================================
-- 插入预制结果默认配置
-- ============================================
INSERT INTO `qc_preset_config` VALUES
('DEFAULT_CONFIG', '默认预制配置', 100, 75, 25,
'[
  {"factorId":"IMAGE_003","factorName":"图像伪影","rate":0.40},
  {"factorId":"IMAGE_004","factorName":"中心线","rate":0.32},
  {"factorId":"IMAGE_005","factorName":"图像等级","rate":0.28}
]',
NOW(), NOW());
