elder-yudao-pro/mysql_script/health/V007__health_elderly_collection_remaining.sql

167 lines
11 KiB
SQL
Raw Permalink 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.

-- 老人信息采集步骤 3–7;仅增加可空字段,不改写既有数据。
-- 在 V000–V006 后执行;每一列均独立检查,支持重复执行和部分失败后重试。
-- 联系人仅用于紧急联系;本轮不创建家属账号、影子成员或家属授权。
SET NAMES utf8mb4;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'insurance_type') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN insurance_type tinyint NULL COMMENT ''1 职工医保、2 居民医保、3 新农合、4 无、5 不清楚''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'income_range') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN income_range tinyint NULL COMMENT ''0 无收入、1 一万以下、2 一至三万、3 三至五万、4 五万以上、5 不方便''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'medical_insurance_number') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN medical_insurance_number varchar(512) NULL COMMENT ''医保卡号 AES 密文''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'care_level') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN care_level tinyint NULL COMMENT ''1 自理、2 半自理、3 失能''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'disabled') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN disabled bit(1) NULL COMMENT ''是否残疾''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'disability_type') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN disability_type varchar(32) NULL COMMENT ''残疾类型代码''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'disability_reason') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN disability_reason varchar(500) NULL COMMENT ''致残原因''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'chronic_disease_status') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN chronic_disease_status tinyint NULL COMMENT ''1 有、2 无、3 记不清、4 不想说''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'chronic_diseases') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN chronic_diseases text NULL COMMENT ''慢病 JSON AES 密文''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'father_alive') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN father_alive tinyint NULL COMMENT ''1 健在、2 已故、3 不方便、4 跳过''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'mother_alive') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN mother_alive tinyint NULL COMMENT ''1 健在、2 已故、3 不方便、4 跳过''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'father_death_reason') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN father_death_reason tinyint NULL COMMENT ''1 自然、2 疾病、3 意外、4 其他、5 不方便、6 跳过''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'mother_death_reason') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN mother_death_reason tinyint NULL COMMENT ''1 自然、2 疾病、3 意外、4 其他、5 不方便、6 跳过''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'father_death_reason_detail') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN father_death_reason_detail varchar(500) NULL COMMENT ''父亲死亡原因补充''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'mother_death_reason_detail') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN mother_death_reason_detail varchar(500) NULL COMMENT ''母亲死亡原因补充''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'emergency_contacts') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN emergency_contacts text NULL COMMENT ''紧急联系人 JSON AES 密文;仅用于联系,不建立家属授权''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'collector_id') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN collector_id bigint NULL COMMENT ''管理员采集人 ID,由服务端写入''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'collector_type') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN collector_type tinyint NULL COMMENT ''4 管理员,由服务端写入''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'collect_time') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN collect_time datetime NULL COMMENT ''最近正式采集时间''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'collection_completed_time') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN collection_completed_time datetime NULL COMMENT ''首次完成全部七步的时间''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'consent_confirmed') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN consent_confirmed bit(1) NULL COMMENT ''知情同意采集确认,不等同于电子签名''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'consent_confirm_time') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN consent_confirm_time datetime NULL COMMENT ''知情同意确认时间,由服务端写入''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;
SET @health_step7_sql = IF((SELECT COUNT(*) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'consent_collector_id') = 0,
'ALTER TABLE health_elderly_profile ADD COLUMN consent_collector_id bigint NULL COMMENT ''知情同意确认管理员 ID,由服务端写入''', 'DO 0');
PREPARE health_step7_stmt FROM @health_step7_sql;
EXECUTE health_step7_stmt;
DEALLOCATE PREPARE health_step7_stmt;