Skip to content

Conversation

Copy link

Copilot AI commented Nov 9, 2025

Addresses review feedback on #92 regarding silent exception swallowing in DICOM metadata loading. The previous implementation caught both AttributeError and IndexError, masking potential data quality issues when the sequence exists but is empty.

Changes

  • Replace try-except with explicit hasattr() and len() checks following pattern established in cycle_loader.py, dicom_ingest.py
  • Emit warning when RadiopharmaceuticalInformationSequence exists but is empty (likely data quality issue)
  • Provide specific messages for each failure case (missing attribute, empty sequence, missing dose field)
  • Maintain backward compatibility: all paths default to 7400 MBq as expected by existing tests

Before

try:
    injected_activity = (
        dicom_slices[0]
        .RadiopharmaceuticalInformationSequence[0]
        .RadionuclideTotalDose
    )
except (AttributeError, IndexError):
    print("Injected activity not found in DICOM header. Using default: 7400 MBq")
    injected_activity = 7400.0

After

injected_activity = None

if hasattr(dicom_slices[0], "RadiopharmaceuticalInformationSequence"):
    rp_seq = dicom_slices[0].RadiopharmaceuticalInformationSequence
    if len(rp_seq) > 0:
        try:
            injected_activity = rp_seq[0].RadionuclideTotalDose
        except AttributeError:
            print("RadiopharmaceuticalInformationSequence found but RadionuclideTotalDose is missing.")
    else:
        print("Warning: RadiopharmaceuticalInformationSequence is empty. This may indicate a data quality issue.")

if injected_activity is None:
    print("Using default injected activity: 7400 MBq")
    injected_activity = 7400.0

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: carluri <3673343+carluri@users.noreply.github.com>
Copilot AI changed the title [WIP] Update documentation, testing, and data handling based on feedback Improve RadiopharmaceuticalInformationSequence exception handling to surface data quality issues Nov 9, 2025
Copilot AI requested a review from carluri November 9, 2025 05:15
Copy link
Collaborator

@carluri carluri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

@carluri carluri marked this pull request as ready for review November 9, 2025 14:01
@carluri carluri merged commit 775a8a1 into improvements Nov 9, 2025
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants