Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image refs to ups #49

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tdwii_plus_examples/rtbdi_creator/form.ui
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="checkbox_setup_photos">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Setup Photos</string>
</property>
Expand Down
2 changes: 1 addition & 1 deletion tdwii_plus_examples/rtbdi_creator/mainbdiwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _bdidir_button_clicked(self):
dialog.setFileMode(QFileDialog.Directory)
dialog.setOption(QFileDialog.ShowDirsOnly, True)
dialog.setLabelText(QFileDialog.Accept, "Select")
if dialog.exec_() == QFileDialog.Accepted:
if dialog.exec() == QFileDialog.Accepted:
Copy link
Owner Author

Choose a reason for hiding this comment

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

addresses a deprecation warning generated by PySide6

file_name = dialog.selectedFiles()[0]
if file_name:
path = Path(file_name)
Expand Down
64 changes: 56 additions & 8 deletions tdwii_plus_examples/rtbdi_creator/rtbdi_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,23 @@ def create_ups_from_plan_and_bdi(
)
patient_photo_reference_items.append(patient_photo_reference_item)

# This makes the assumption that the Study and Series Instance UIDs for the Setup images are the same as the plan
# That's not necessarily a safe assumption. It would be better to load the Setup images and pass those in.
# Search for the Study and Series Instance UIDs for the Setup images in the Common Instance Reference module
# If they are available, build up the reference for later inclusion in the InputInformationSequence
# If not... don't attempt to include them.
patient_setup_image_items = []
if enable_setup_image_ref and "ReferencedSetupImageSequence" in plan.PatientSetupSequence[0]:
for setup_image_seq_item in plan.PatientSetupSequence[0].ReferencedSetupImageSequence:
setup_image_reference_item = _create_referenced_instances_and_access_item(
setup_image_seq_item,
retrieve_ae_title,
study_instance_uid=plan.StudyInstanceUID,
series_instance_uid=plan.SeriesInstanceUID,
ref_study_uid, ref_series_uid = _get_study_and_series_for_referenced_instance(
plan, setup_image_seq_item.ReferencedSOPInstanceUID
)
patient_setup_image_items.append(setup_image_reference_item)
if ref_study_uid is not None and ref_series_uid is not None:
setup_image_reference_item = _create_referenced_instances_and_access_item(
setup_image_seq_item,
retrieve_ae_title,
study_instance_uid=ref_study_uid,
series_instance_uid=ref_series_uid,
)
patient_setup_image_items.append(setup_image_reference_item)

treatment_record_reference_items = []
for treatment_rec in treatment_records:
Expand Down Expand Up @@ -451,6 +456,49 @@ def _create_scheduled_station_name_code_sequence_item(plan: Dataset) -> Dataset:
return code_seq_item


def _get_study_and_series_for_referenced_instance(plan: Dataset, instance_uid: str) -> tuple[str, str]:
"""Searches Common Instance Reference Module for matching instance_uid

Args:
plan (Dataset): The plan containing the instance reference, e.g. setup images/photos, DRRs
instance_uid (str): The string representation of the SOP Instance UID whose Study and Series UID are desired

Returns:
tuple[str, str]: Study UID and Series UID as a tuple, with individual entries set to None if not found
"""
study_series_tuple = (None, None)
series_uid = None
study_uid = None
if "ReferencedSeriesSequence" in plan:
for series_seq_item in plan.ReferencedSeriesSequence:
for ref_instance_seq_item in series_seq_item:
if str(ref_instance_seq_item.ReferencedSOPInstanceUID) == instance_uid:
series_uid = str(series_seq_item.SeriesInstanceUID)
break
#
#
#
if series_uid is not None:
study_uid = plan.StudyInstanceUID
else:
# it's not in the same study as the plan.
if "StudiesContainingOtherReferencedInstancesSequence" in plan:
for study_seq_item in plan.StudiesContainingOtherReferencedInstancesSequence:
for series_seq_item in plan.ReferencedSeriesSequence:
for ref_instance_seq_item in series_seq_item:
if str(ref_instance_seq_item.ReferencedSOPInstanceUID) == instance_uid:
series_uid = str(series_seq_item.SeriesInstanceUID)
study_uid = str(study_seq_item.StudyInstanceUID)
break
#
#
#
#
study_series_tuple = (study_uid, series_uid)

return study_series_tuple


def main(args):
"""test harness for rtbdi factory

Expand Down
1 change: 1 addition & 0 deletions tdwii_plus_examples/rtbdi_creator/ui_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def setupUi(self, MainBDIWidget):

self.checkbox_setup_photos = QCheckBox(self.group_box_ups)
self.checkbox_setup_photos.setObjectName("checkbox_setup_photos")
self.checkbox_setup_photos.setEnabled(True)

self.gridLayout.addWidget(self.checkbox_setup_photos, 1, 2, 1, 1)

Expand Down
Loading