-- 验证手术指征字段的数据
-- 执行时间：2025-01-06
-- 说明：查询手术数据,验证surgery_indication字段是否有值

-- 1. 查询最近的手术记录,检查surgery_indication字段
SELECT 
    id,
    surgery_no,
    surgery_name,
    surgery_indication,
    patient_name,
    apply_doctor_name,
    status_enum,
    create_time
FROM cli_surgery
WHERE delete_flag = '0'
ORDER BY create_time DESC
LIMIT 5;

-- 2. 检查surgery_indication字段是否为NULL
SELECT 
    COUNT(*) as total_count,
    COUNT(surgery_indication) as has_surgery_indication_count,
    COUNT(*) - COUNT(surgery_indication) as null_count,
    ROUND(COUNT(surgery_indication) * 100.0 / COUNT(*), 2) as fill_rate
FROM cli_surgery
WHERE delete_flag = '0';

-- 3. 查询有surgery_indication数据的记录
SELECT 
    id,
    surgery_no,
    surgery_name,
    surgery_indication,
    LENGTH(surgery_indication) as text_length,
    SUBSTRING(surgery_indication, 1, 100) as preview_text
FROM cli_surgery
WHERE delete_flag = '0'
AND surgery_indication IS NOT NULL
AND surgery_indication != ''
ORDER BY create_time DESC
LIMIT 3;

-- 4. 验证Mapper XML中的SQL查询
-- 模拟getSurgeryDetail接口的查询
SELECT 
    s.id,
    s.surgery_no,
    s.surgery_name,
    s.surgery_indication,
    s.patient_id,
    p.name as patient_name,
    s.apply_doctor_id,
    s.apply_doctor_name,
    s.status_enum
FROM cli_surgery s
LEFT JOIN adm_patient p ON s.patient_id = p.id
WHERE s.id = (SELECT id FROM cli_surgery WHERE delete_flag = '0' ORDER BY create_time DESC LIMIT 1)
AND s.delete_flag = '0';
