File size: 1,485 Bytes
8fca640
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Metadata-only split checks before development payload access.

The frozen discovery audit establishes pairing. These checks independently reject
a mislabeled manifest participant before reading any image/segmentation payload.
This module is never imported by label-free inference.
"""

import pydicom
from src.io import safe_path
from src.protocol import split_for


def check_development_identity(row, root, expected_split):
    participant = str(row["participant_id"])
    if (
        expected_split not in ["train", "validation"]
        or split_for(participant) != expected_split
    ):
        raise ValueError("Development manifest split violation")
    classes = [
        ("oct_paths", "1.2.840.10008.5.1.4.1.1.77.1.5.4"),
        ("segmentation_paths", "1.2.840.10008.5.1.4.1.1.66.8"),
    ]
    for field, sop_class in classes:
        for relative in row[field]:
            header = pydicom.dcmread(
                safe_path(root, relative),
                stop_before_pixels=True,
                specific_tags=["PatientID", "SOPClassUID"],
            )
            actual = str(header.get("PatientID", ""))
            if actual != participant or split_for(actual) != expected_split:
                raise ValueError(
                    "DICOM participant identity/split differs from frozen manifest"
                )
            if str(header.get("SOPClassUID", "")) != sop_class:
                raise ValueError("Unexpected development source object class")