Skip to content

KeyObjectSelectionDocument silently drops evidence from a second study instead of raising #502

Closed

Description

@DG47

KeyObjectSelectionDocument.__init__ contains a check that is supposed to reject documents referencing instances from multiple studies ("Key Object Selection Documents that reference instances from multiple studies are not supported."). Since the evidence collection change in #373 the check compares the number of other-study evidence groups against 1 rather than 0, so with evidence from exactly two studies no error is raised. The other-study instances are omitted from the Current Requested Procedure Evidence Sequence although the content still references them, which violates the Type 1 requirement of the Key Object Document Module (PS3.3 C.17.6.2: "List of all Composite SOP Instances referenced in the Content Sequence"), and resolve_reference() then fails for those instances.

Minimal reproduction

from pydicom.dataset import Dataset
from pydicom.sr.codedict import codes
from pydicom.uid import CTImageStorage, generate_uid
import highdicom as hd

def make(study_uid):
    ds = Dataset()
    ds.SOPClassUID = CTImageStorage
    ds.SOPInstanceUID = generate_uid()
    ds.StudyInstanceUID = study_uid
    ds.SeriesInstanceUID = generate_uid()
    ds.PatientID = 'P'
    ds.PatientName = 'Doe^Jane'
    ds.PatientBirthDate = ''
    ds.PatientSex = ''
    ds.AccessionNumber = ''
    ds.StudyID = ''
    ds.StudyDate = ''
    ds.StudyTime = ''
    ds.Rows = 10
    ds.Columns = 10
    return ds

a = make(generate_uid())
b = make(generate_uid())  # different study

content = hd.ko.KeyObjectSelection(
    document_title=codes.DCM.OfInterest,
    referenced_objects=[a, b],
)
kos = hd.ko.KeyObjectSelectionDocument(
    evidence=[a, b],
    content=content,
    series_instance_uid=generate_uid(),
    series_number=1,
    sop_instance_uid=generate_uid(),
    instance_number=1,
    manufacturer='Manufacturer',
)
print([i.StudyInstanceUID for i in kos.CurrentRequestedProcedureEvidenceSequence])
# only study A is listed, although the content references an instance of study B
kos.resolve_reference(b.SOPInstanceUID)
# ValueError: Could not find any evidence for SOP Instance UID "..." in KOS document.

Expected

A ValueError stating that documents referencing instances from multiple studies are not supported (the message that already exists in the code), rather than a document whose evidence sequence is incomplete.

Actual

The document is constructed without error, the study-B instance is missing from CurrentRequestedProcedureEvidenceSequence, and resolve_reference() raises for it. Providing evidence from three or more studies does raise, which shows the threshold is off by one.

Environment

  • highdicom master (1a05012, version 0.28.2)
  • pydicom 3.0.2
  • Python 3.12.13, macOS

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions