-- 送检信息配置与编辑状态
ALTER TABLE `patient`
  ADD COLUMN `sample_info_status` tinyint(1) DEFAULT 0 COMMENT '送检信息状态: 0可修改 1已生效' AFTER `sample_photos`;

INSERT INTO `sys_config` (`config_key`, `config_value`, `remark`) VALUES
('sample_receiver_info', '{"address":"武汉东湖新技术开发区花城大道8号武汉软件新城三期D2栋17层001室","receiver":"样本中心","phone":"027-6552 6665","contact_phone":""}', '送检收件信息配置')
ON DUPLICATE KEY UPDATE `remark` = VALUES(`remark`);

UPDATE `patient`
SET `sample_info_status` = CASE
  WHEN COALESCE(`sample_types`, '') <> ''
    OR COALESCE(`report_email`, '') <> ''
    OR COALESCE(`sample_tracking_no`, '') <> ''
    OR COALESCE(JSON_LENGTH(`sample_photos`), 0) > 0
  THEN 1
  ELSE 0
END
WHERE `is_deleted` = 0;
