-- 检查指定机构和时间范围内的已治理数据
USE `pacsonline_new`;

-- 查询 INST001 机构在 2025-12-01 到 2025-12-31 之间的已治理数据
SELECT
    study_id,
    patient_id,
    modality,
    study_date,
    institution_id,
    govern_status,
    upload_time
FROM study_info
WHERE institution_id = 'INST001'
  AND study_date >= '2025-12-01'
  AND study_date <= '2025-12-31'
  AND govern_status = 1
ORDER BY upload_time DESC;

-- 查询 INST001 机构的所有已治理数据（不限时间）
SELECT COUNT(*) as count
FROM study_info
WHERE institution_id = 'INST001'
  AND govern_status = 1;

-- 查询所有已治理的数据（不限机构和时间）
SELECT
    institution_id,
    COUNT(*) as count,
    MIN(study_date) as min_date,
    MAX(study_date) as max_date
FROM study_info
WHERE govern_status = 1
GROUP BY institution_id;

-- 查询所有数据（不限治理状态）
SELECT
    institution_id,
    govern_status,
    COUNT(*) as count
FROM study_info
GROUP BY institution_id, govern_status
ORDER BY institution_id, govern_status;

-- 如果没有已治理的数据，可以执行以下语句将一些数据设置为已治理
-- UPDATE study_info SET govern_status = 1 WHERE institution_id = 'INST001' LIMIT 10;
