-- 验证手术表中所有名称字段的填充情况
SELECT 
    id,
    surgery_no,
    patient_id,
    patient_name,
    main_surgeon_id,
    main_surgeon_name,
    anesthetist_id,
    anesthetist_name,
    assistant_1_id,
    assistant_1_name,
    assistant_2_id,
    assistant_2_name,
    scrub_nurse_id,
    scrub_nurse_name,
    operating_room_id,
    operating_room_name,
    org_id,
    org_name,
    apply_doctor_id,
    apply_doctor_name,
    apply_dept_id,
    apply_dept_name,
    create_time
FROM public.cli_surgery
WHERE delete_flag = '0'
ORDER BY create_time DESC
LIMIT 10;

-- 统计名称字段的填充情况
SELECT 
    COUNT(*) as total_count,
    COUNT(patient_name) as has_patient_name_count,
    COUNT(main_surgeon_name) as has_main_surgeon_name_count,
    COUNT(anesthetist_name) as has_anesthetist_name_count,
    COUNT(assistant_1_name) as has_assistant_1_name_count,
    COUNT(assistant_2_name) as has_assistant_2_name_count,
    COUNT(scrub_nurse_name) as has_scrub_nurse_name_count,
    COUNT(operating_room_name) as has_operating_room_name_count,
    COUNT(org_name) as has_org_name_count,
    COUNT(apply_doctor_name) as has_apply_doctor_name_count,
    COUNT(apply_dept_name) as has_apply_dept_name_count,
    -- 计算填写率
    ROUND(COUNT(patient_name) * 100.0 / COUNT(*), 2) as patient_name_fill_rate,
    ROUND(COUNT(main_surgeon_name) * 100.0 / COUNT(*), 2) as main_surgeon_name_fill_rate,
    ROUND(COUNT(anesthetist_name) * 100.0 / COUNT(*), 2) as anesthetist_name_fill_rate,
    ROUND(COUNT(assistant_1_name) * 100.0 / COUNT(*), 2) as assistant_1_name_fill_rate,
    ROUND(COUNT(assistant_2_name) * 100.0 / COUNT(*), 2) as assistant_2_name_fill_rate,
    ROUND(COUNT(scrub_nurse_name) * 100.0 / COUNT(*), 2) as scrub_nurse_name_fill_rate,
    ROUND(COUNT(operating_room_name) * 100.0 / COUNT(*), 2) as operating_room_name_fill_rate,
    ROUND(COUNT(org_name) * 100.0 / COUNT(*), 2) as org_name_fill_rate,
    ROUND(COUNT(apply_doctor_name) * 100.0 / COUNT(*), 2) as apply_doctor_name_fill_rate,
    ROUND(COUNT(apply_dept_name) * 100.0 / COUNT(*), 2) as apply_dept_name_fill_rate
FROM public.cli_surgery
WHERE delete_flag = '0';