Skip to content

Commit

Permalink
Connect get ups button (#55)
Browse files Browse the repository at this point in the history
* add upscfind code, including decoding (flattening) to a dictionary of the key data for a TDW-II UPS.
add loopback based AE Titles to json file
populate QTreeWidget with data from UPS C-FIND-RSP
put QTreeWidget inside a scrollable canvas

* cleanup based on flake8 complaints

* correct docstring summary for create_ups_query

* fix docstring for get_ups
  • Loading branch information
sjswerdloff authored Jun 18, 2024
1 parent 6b975a8 commit 7856d69
Show file tree
Hide file tree
Showing 5 changed files with 629 additions and 280 deletions.
35 changes: 35 additions & 0 deletions ApplicationEntities.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,40 @@
"AETitle": "TDWII_SCP",
"IPAddr": "10.11.255.8",
"Port": 10404
},
{
"AETitle": "OST",
"IPAddr": "127.0.0.1",
"Port": 11112
},
{
"AETitle": "QRSCP",
"IPAddr": "127.0.0.1",
"Port": 11112
},
{
"AETitle": "TMS",
"IPAddr": "127.0.0.1",
"Port": 11114
},
{
"AETitle": "UPSSCP",
"IPAddr": "127.0.0.1",
"Port": 11114
},
{
"AETitle": "PPVS_SCP",
"IPAddr": "127.0.0.1",
"Port": 11115
},
{
"AETitle": "NEVENT_RECEIVER",
"IPAddr": "127.0.0.1",
"Port": 11115
},
{
"AETitle": "TDD",
"IPAddr": "127.0.0.1",
"Port": 11113
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

import tomli
from ppvsscp import PPVS_SCP
from pydicom.valuerep import VR
from PySide6.QtCore import QDateTime, Qt, Slot # pylint: disable=no-name-in-module
from PySide6.QtWidgets import QApplication, QFileDialog, QWidget
from PySide6.QtWidgets import QApplication, QFileDialog, QTreeWidgetItem, QWidget

# Important:
# You need to run the following command to generate the ui_form.py file
# pyside6-uic form.ui -o ui_form.py, or
# pyside2-uic form.ui -o ui_form.py
from ui_tdwii_ppvs_subscriber import Ui_MainPPVSSubscriberWidget
from upsfindscu import create_ups_query, get_ups, response_content_to_dict
from watchscu import WatchSCU

from tdwii_plus_examples import tdwii_config
Expand All @@ -26,6 +28,8 @@ def __init__(self, parent=None):
self.ui.setupUi(self)
self.ui.import_staging_directory_push_button.clicked.connect(self._import_staging_dir_clicked)
self.ui.ppvs_restart_push_button.clicked.connect(self._restart_scp)
self.ui.push_button_get_ups.clicked.connect(self._get_ups)
self.ui.ups_response_tree_widget.setColumnCount(3)
self.ppvs_scp = None
self.ui.soonest_date_time_edit.setDateTime(QDateTime.currentDateTime().addSecs(-3600))
self.ui.latest_date_time_edit.setDateTime(QDateTime.currentDateTime().addSecs(3600))
Expand Down Expand Up @@ -100,10 +104,51 @@ def _restart_scp(self):
self.watch_scu.set_subscription_ae(upsscp_ae_title, ip_addr=ip_addr, port=port)

@Slot()
def _get_ups(self):
def _get_ups(self, ups_uid: str = ""):
# do C-FIND-RQ
my_ae_title = self.ui.ppvs_ae_line_edit.text()
upsscp_ae_title = self.ui.ups_ae_line_edit.text()
machine_name = self.ui.machine_name_line_edit.text()
soonest_datetime_widget = self.ui.soonest_date_time_edit

query_ds = create_ups_query(
ups_uid=ups_uid,
machine_name=machine_name,
scheduled_no_sooner_than=soonest_datetime_widget.dateTime().toString("yyyyMMddhhmm"),
scheduled_no_later_than=self.ui.latest_date_time_edit.dateTime().toString("yyyyMMddhhmm"),
)
responses = get_ups(query_ds, my_ae_title, upsscp_ae_title)

self.ui.ups_response_tree_widget.clear()
for response_content in responses:
ups_item = QTreeWidgetItem(self.ui.ups_response_tree_widget)
displayable_responses = response_content_to_dict(response_content)
print(displayable_responses)
ups_item.setText(0, response_content.SOPInstanceUID)
for key, value in displayable_responses.items():
if key in response_content:
tag_label = str(response_content[key].tag)
else:
tag_label = ""
ups_child_item = QTreeWidgetItem(ups_item)
ups_child_item.setText(0, tag_label)
ups_child_item.setText(1, key)
ups_child_item.setText(2, value)
for elem in response_content:
if elem.VR != VR.SQ and elem.name not in displayable_responses.keys():
ups_child_item = QTreeWidgetItem(ups_item)
ups_child_item.setText(0, str(elem.tag))
ups_child_item.setText(1, elem.name)
ups_child_item.setText(2, elem.repval)

# for elemName in ["PatientName", "PatientID"]:
# if elemName in response_content:
# ups_child_item = QTreeWidgetItem(ups_item)
# ups_child_item.setText(0, str(response_content[elemName].tag))
# ups_child_item.setText(1, response_content[elemName].name)
# ups_child_item.setText(2, response_content[elemName].repval)

pass
return

def _subscribe_to_ups(self, match_on_step_state=False, match_on_beam_number=False) -> bool:
if self.watch_scu is None:
Expand Down Expand Up @@ -146,6 +191,7 @@ def _unsubscribe_from_ups(self):

def _nevent_callback(self, **kwargs):
logger = None
ups_uid = ""
if "logger" in kwargs.keys():
logger = kwargs["logger"]
if logger:
Expand All @@ -162,12 +208,14 @@ def _nevent_callback(self, **kwargs):
if logger:
logger.info("Dataset in N-EVENT-REPORT-RQ: ")
logger.info(f"{information_ds}")
if "SOPInstanceUID" in information_ds:
ups_uid = information_ds.SOPInstanceUID
# TODO: replace if/elif with dict of {event_type_id,application_response_functions}
if event_type_id == 1:
if logger:
logger.info("UPS State Report")
logger.info("Probably time to do a C-FIND-RQ")
self._get_ups()
self._get_ups(ups_uid=str(ups_uid))
elif event_type_id == 2:
if logger:
logger.info("UPS Cancel Request")
Expand All @@ -176,7 +224,7 @@ def _nevent_callback(self, **kwargs):
if logger:
logger.info("UPS Progress Report")
logger.info("Probably time to see if the Beam (number) changed, or if adaptation is taking or took place")
self._get_ups()
self._get_ups(ups_uid=str(ups_uid))
elif event_type_id == 4:
if logger:
logger.info("SCP Status Change")
Expand Down
Loading

0 comments on commit 7856d69

Please sign in to comment.