Skip to content

Rtplan utils

rtplan_utils #

Functions:

Name Description
rtplan_reference_uids

Get the ReferencedSOPInstanceUIDs from an RTPLAN file

RTPLANRefStructSOP #

Bases: str

Represents a SOPInstanceUID pointing to a RTSTRUCT referenced by a RTPLAN file

extracted via ReferencedStructureSetSequence.ReferencedSOPInstanceUID

rtplan_reference_uids #

rtplan_reference_uids(
    rtplan: pydicom.dataset.Dataset,
) -> (
    imgtools.dicom.dicom_metadata.modality_utils.rtplan_utils.RTPLANRefStructSOP
)

Get the ReferencedSOPInstanceUIDs from an RTPLAN file

We assume RTPLAN only references a RTSTRUCT file.

Parameters:

Name Type Description Default

rtplan #

pydicom.dataset.Dataset

The RTPLAN file to extract the reference UIDs from Must be a pydicom.Dataset object

required
Example

match rtplan_reference_uids(rtplan): ... case RTPLANRefStructSOP(uid): ... print(f"SOPInstanceUID: {uid=}")

Source code in src/imgtools/dicom/dicom_metadata/modality_utils/rtplan_utils.py
def rtplan_reference_uids(
    rtplan: Dataset,
) -> RTPLANRefStructSOP:
    """Get the ReferencedSOPInstanceUIDs from an RTPLAN file

    We assume RTPLAN only references a `RTSTRUCT` file.

    Parameters
    ----------
    rtplan : Dataset
        The RTPLAN file to extract the reference UIDs from
        Must be a `pydicom.Dataset` object

    Example
    -------
    >>> match rtplan_reference_uids(rtplan):
    ...     case RTPLANRefStructSOP(uid):
    ...         print(f"SOPInstanceUID: {uid=}")
    """
    if "ReferencedStructureSetSequence" in rtplan:
        refs = [
            RTPLANRefStructSOP(seq.ReferencedSOPInstanceUID)
            for seq in rtplan.ReferencedStructureSetSequence
        ]
        if len(refs) > 1:
            warnmsg = (
                f"Found {len(refs)} RTSTRUCT references in {rtplan=}. "
                "Only the first one will be used."
            )
            logger.warning(warnmsg)
        return refs[0]

    return RTPLANRefStructSOP("")