Skip to content

Commit

Permalink
add notification of UPS creation (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwikler authored Mar 24, 2024
1 parent 8c78505 commit c7ce765
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _restart_scp(self):
self.ppvs_scp.run()
self.watch_scu = WatchSCU(self.ui.ppvs_ae_line_edit.text())
ip_addr = "127.0.0.1"
port = 11113
port = 11114
self.watch_scu.set_subscription_ae(self.ui.ups_ae_line_edit.text(), ip_addr=ip_addr,port=port)


Expand All @@ -78,7 +78,7 @@ def _subscribe_to_ups(self, match_on_step_state=False, match_on_beam_number=Fals
watch_scu = WatchSCU(my_ae_title)
# hard code for the moment, deal with configuration of AE's soon
ip_addr = "127.0.0.1"
port = 11113
port = 11114
upsscp_ae_title = self.ui.ups_ae_line_edit.text()
watch_scu.set_subscription_ae(upsscp_ae_title, ip_addr=ip_addr,port=port)
else:
Expand All @@ -101,7 +101,7 @@ def _unsubscribe_from_ups(self):
watch_scu = WatchSCU(my_ae_title)
# hard code for the moment, deal with configuration of AE's soon
ip_addr = "127.0.0.1"
port = 11113
port = 11114
upsscp_ae_title = self.ui.ups_ae_line_edit.text()
watch_scu.set_subscription_ae(upsscp_ae_title, ip_addr=ip_addr,port=port)
else:
Expand Down
42 changes: 42 additions & 0 deletions tdwii_plus_examples/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
UPSFilteredGlobalSubscriptionInstance,
UPSGlobalSubscriptionInstance,
)
from pynetdicom import AE, Association, UnifiedProcedurePresentationContexts

# from recursive_print_ds import print_ds
from sqlalchemy import create_engine
Expand Down Expand Up @@ -771,4 +772,45 @@ def handle_ncreate(event, storage_dir, db_path, cli_config, logger):
finally:
session.close()

# Database successfully updated, notify any globally subscriber
for globalsubscriber in _global_subscribers:
# Request association with subscriber
# get AET of UPS Event SCP (which is the AET if UPS Watch SCP)
acceptor = event.assoc.acceptor
logger.info(f"UPS Event SCP AET: {acceptor.ae_title}")

ae = AE(ae_title=acceptor.ae_title)
# hard code for the moment, deal with configuration of AE's soon
assoc = ae.associate(
"127.0.0.1",
11112,
contexts=UnifiedProcedurePresentationContexts,
ae_title=globalsubscriber,
max_pdu=16382,
)

if assoc.is_established:
try:
logger.info(f"Send UPS State Report: {ds.SOPInstanceUID}, {ds.ProcedureStepState}")
event_info = Dataset()
event_info.ProcedureStepState = ds.ProcedureStepState
event_info.InputReadinessState = ds.InputReadinessState

assoc.send_n_event_report(event_info, 1, UnifiedProcedureStepPush, ds.SOPInstanceUID)

logger.info(f"Notified global subscriber: {globalsubscriber}")

except InvalidDicomError:
logger.error("Bad DICOM: ")
except Exception as exc:
logger.error(
"UPS State Report as Event Notification (N-EVENT-REPORT-RQ) failed"
)
logger.exception(exc)

assoc.release()

else:
logger.error(f"Failed to establish assocation with subscriber: {globalsubscriber}")

return 0x0000, ds

0 comments on commit c7ce765

Please sign in to comment.