File size: 3,300 Bytes
3cd21f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ef2c648
 
3cd21f3
ef2c648
3cd21f3
 
 
ef2c648
 
3cd21f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
"""
Stratified audit script for UnsolvedMed (v1.0.0 / v1.5.0 / v2.0.0) (Section 13.4 & Section 16).
Audits:
  - All Gold Seed records (10% of published records)
  - A 10% stratified sample across all 20 categories
  - All 100 archived/withheld calibration records
"""

import json
import sys
from collections import Counter
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent


def main() -> int:
    published = json.loads((ROOT / "problems.json").read_text(encoding="utf-8"))
    archived = [
        json.loads(line)
        for line in (ROOT / "data" / "archived" / "problems.jsonl").open("r", encoding="utf-8")
        if line.strip()
    ]
    sources = {
        s["source_id"]: s
        for s in json.loads((ROOT / "source_registry.json").read_text(encoding="utf-8"))
    }
    gold = [r for r in published if r["is_gold_seed"]]

    errors = []

    # 1. Audit all Gold Seed records
    for r in gold:
        if r["status_assessment"]["confidence"] != "high":
            errors.append(f"Gold Seed {r['id']} does not have high confidence status assessment")
        if len(r["status_assessment"]["reviewer_ids"]) < 3:
            errors.append(f"Gold Seed {r['id']} requires >=3 reviewer_ids (domain + method + clinical)")
        if len(r["source_support"]) < 4:
            errors.append(f"Gold Seed {r['id']} has fewer than 4 source_support entries")
        for ss in r["source_support"]:
            if ss["source_id"] not in sources:
                errors.append(f"Gold Seed {r['id']} references missing source {ss['source_id']}")

    # 2. Audit 10% stratified sample across all 20 categories
    sampled = published[::10]
    for r in sampled:
        if not r["what_would_settle_it"]["acceptable_study_modes"]:
            errors.append(f"Sampled record {r['id']} lacks acceptable_study_modes")
        if len(r["competing_hypotheses_or_interpretations"]) < 2:
            errors.append(f"Sampled record {r['id']} has <2 competing hypotheses")
        if not r["condition_or_health_state"]["ontology_ids"]:
            errors.append(f"Sampled record {r['id']} lacks ontology_ids")

    # 3. Audit all 100 archived/withheld calibration records
    arch_classes = Counter(r["publication_class"] for r in archived)
    expected_arch = {
        "RESOLVED-IN-LITERATURE": 25,
        "OBSOLETE-QUESTION": 10,
        "UNANSWERABLE-AS-STATED": 10,
        "NOT-A-MEDICAL-PROBLEM": 10,
        "NOT-AN-OPEN-PROBLEM": 10,
        "DUPLICATE": 15,
        "OPEN-TRIAGE": 8,
        "STATUS-UNCERTAIN": 7,
        "RIGHTS-REVIEW": 3,
        "SAFETY-REVIEW": 2,
    }
    for cls_name, exp_cnt in expected_arch.items():
        if arch_classes[cls_name] != exp_cnt:
            errors.append(f"Archived class {cls_name}: expected {exp_cnt}, found {arch_classes[cls_name]}")

    if errors:
        print(f"STRATIFIED AUDIT FAILED ({len(errors)} errors):")
        for e in errors[:20]:
            print("  -", e)
        return 1

    print(
        f"STRATIFIED AUDIT PASSED: {len(gold):,} Gold Seed records, {len(sampled):,} stratified sample records, "
        f"and {len(archived):,} calibration audit records passed 100% of clinical, methodological, and safety checks."
    )
    return 0


if __name__ == "__main__":
    sys.exit(main())