def time_create_single_transfer_syntax(self): """Time creating contexts with a single transfer syntax""" for x in range(500): cx = PresentationContext() cx.context_id = 1 cx.abstract_syntax = '1.2.840.10008.5.1.4.1.1.2' cx.transfer_syntax = ['1.2.840.10008.1.2']
def time_create_double_transfer_syntax(self): """Time creating context with two transfer syntaxes.""" for x in range(500): cx = PresentationContext() cx.context_id = 1 cx.abstract_syntax = '1.2.840.10008.5.1.4.1.1.2' cx.transfer_syntax = ['1.2.840.10008.1.2', '1.2.840.10008.1.2.1']
def send_c_store(ae: AE, dcm_path: str, scp_address: Tuple[str, int], idx: int) -> None: host, port = scp_address logger.debug( f"Establishing an association with DIMSE C-STORE SCP ({host}, {port})") dataset = read_file(dcm_path) abstract_syntax = dataset.file_meta[0x00020002].value transfer_syntax = dataset.file_meta[0x00020010].value context = PresentationContext() context.abstract_syntax = abstract_syntax context.transfer_syntax = [transfer_syntax] assoc = ae.associate(host, port, contexts=[context]) if not assoc.is_established: logger.error("Failed to associate with SCP. Exiting...") assoc.release() return try: response = assoc.send_c_store(dataset) status = response[0x00000900].value dcm_file_name = os.path.basename(dcm_path) association_syntax = f"{abstract_syntax}{transfer_syntax}" logger.info( f"({idx}) Sent C-STORE '{dcm_file_name}' - syntax={association_syntax} - status={status}" ) finally: assoc.release()
def test_unknown_sop_class(): """Test that starting the QR SCP with an unknown SOP Class raises""" service = SubstanceAdministrationQueryServiceClass(None) context = PresentationContext() context.abstract_syntax = '1.2.3.4' context.add_transfer_syntax('1.2') msg = (r'The supplied abstract syntax is not valid for use with the ' r'Substance Administration Query Service Class') with pytest.raises(ValueError, match=msg): service.SCP(C_FIND(), context)
def setup(self): self.contexts = [] for x in range(500): cx = PresentationContext() cx.context_id = 1 cx.abstract_syntax = '1.2.840.10008.5.1.4.1.1.2' cx.transfer_syntax = [ '1.2.840.10008.1.2', '1.2.840.10008.1.2.1', '1.2.840.10008.1.2.2' ] self.contexts.append(cx)
def time_create_triple_transfer_syntax(self): """Time creating context with three transfer syntaxes.""" for x in range(500): cx = PresentationContext() cx.context_id = 1 cx.abstract_syntax = "1.2.840.10008.5.1.4.1.1.2" cx.transfer_syntax = [ "1.2.840.10008.1.2", "1.2.840.10008.1.2.1", "1.2.840.10008.1.2.2", ]
def time_create_from_sop(self): """Test the time taken to create a PresentationContext from every available standard DICOM UID. """ for uid in UID_dictionary: cx = PresentationContext() cx.context_id = 1 cx.abstract_syntax = uid cx.transfer_syntax = [ '1.2.840.10008.1.2', '1.2.840.10008.1.2.1', '1.2.840.10008.1.2.2' ]
def setup(self): # Requestor presentation contexts - max 128 self.requestor_contexts = [] for ii, cx in enumerate(StoragePresentationContexts): cx.context_id = ii * 2 + 1 self.requestor_contexts.append(cx) # Acceptor presentation contexts - no max self.acceptor_contexts = [] for uid in UID_dictionary: cx = PresentationContext() cx.abstract_syntax = uid cx.transfer_syntax = [ '1.2.840.10008.1.2', '1.2.840.10008.1.2.1', '1.2.840.10008.1.2.2' ] self.acceptor_contexts.append(cx)
def setup(self): # Requestor presentation contexts - max 126 self.requestor_contexts = [] for ii, cx in enumerate(StoragePresentationContexts): cx.context_id = ii * 2 + 1 cx.SCP = True cx.SCU = True self.requestor_contexts.append(cx) # Acceptor presentation contexts - no max self.acceptor_contexts = [] for uid in UID_dictionary: context = PresentationContext() context.context_id = 1 context.abstract_syntax = uid context.transfer_syntax = ['1.2.840.10008.1.2'] context.Result = 0x00 context.SCP = True context.SCU = True self.acceptor_contexts.append(context)
def test_conversion(self): """ Check conversion to a PDU produces the correct output """ assoc = A_ASSOCIATE() assoc.application_context_name = "1.2.840.10008.3.1.1.1" assoc.calling_ae_title = 'ECHOSCU' assoc.called_ae_title = 'ANY-SCP' assoc.maximum_length_received = 16382 assoc.implementation_class_uid = '1.2.826.0.1.3680043.9.3811.0.9.0' imp_ver_name = ImplementationVersionNameNotification() imp_ver_name.implementation_version_name = 'PYNETDICOM_090' assoc.user_information.append(imp_ver_name) pc = PresentationContext() pc.context_id = 1 pc.abstract_syntax = '1.2.840.10008.1.1' pc.transfer_syntax = ['1.2.840.10008.1.2'] assoc.presentation_context_definition_list = [pc] pdu = A_ASSOCIATE_RQ() pdu.from_primitive(assoc) data = pdu.encode() assert data == ( b"\x01\x00\x00\x00\x00\xd1\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43" b"\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43\x48\x4f\x53\x43" b"\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00" b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e" b"\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e" b"\x31\x2e\x31\x20\x00\x00\x2e\x01\x00\x00\x00\x30\x00\x00\x11\x31" b"\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x31" b"\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30" b"\x38\x2e\x31\x2e\x32\x50\x00\x00\x3e\x51\x00\x00\x04\x00\x00\x3f" b"\xfe\x52\x00\x00\x20\x31\x2e\x32\x2e\x38\x32\x36\x2e\x30\x2e\x31" b"\x2e\x33\x36\x38\x30\x30\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e" b"\x30\x2e\x39\x2e\x30\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49" b"\x43\x4f\x4d\x5f\x30\x39\x30" )
def setup(self): # Requestor presentation contexts - max 126 self.requestor_contexts = [] for ii, cx in enumerate(StoragePresentationContexts): cx.context_id = ii * 2 + 1 cx.scp_role = True cx.scu_role = True self.requestor_contexts.append(cx) # Acceptor presentation contexts - no max self.acceptor_contexts = [] for uid in UID_dictionary: cx = PresentationContext() cx.abstract_syntax = uid cx.transfer_syntax = [ "1.2.840.10008.1.2", "1.2.840.10008.1.2.1", "1.2.840.10008.1.2.2", ] self.acceptor_contexts.append(cx) self.ac_roles = {uid: (True, False) for uid in UID_dictionary}
def test_assignment(self): """ Check assignment works correctly """ assoc = A_ASSOCIATE() with pytest.raises(AttributeError): assoc.mode = "test value" with pytest.raises(AttributeError): assoc.presentation_requirements = "test value2" with pytest.raises(AttributeError): assoc.session_requirements = "test value3" assoc.application_context_name = "1.2.840.10008.3.1.1.1" assert assoc.application_context_name == UID('1.2.840.10008.3.1.1.1') assoc.application_context_name = b"1.2.840.10008.3.1.1.1" assert assoc.application_context_name == UID('1.2.840.10008.3.1.1.1') assoc.application_context_name = UID("1.2.840.10008.3.1.1.1") assert assoc.application_context_name == UID('1.2.840.10008.3.1.1.1') assoc.calling_ae_title = 'ABCD1234ABCD12345' assert assoc.calling_ae_title == b'ABCD1234ABCD1234' assoc.called_ae_title = 'ABCD1234ABCD12345' assert assoc.called_ae_title == b'ABCD1234ABCD1234' assert assoc.responding_ae_title == b'ABCD1234ABCD1234' max_length = MaximumLengthNotification() max_length.maximum_length_received = 31222 assoc.user_information.append(max_length) assert assoc.user_information[0].maximum_length_received == 31222 assoc.user_information = ['a', max_length] assert assoc.user_information == [max_length] assoc.result = 0 assert assoc.result == 0 assoc.result = 1 assert assoc.result == 1 assoc.result = 2 assert assoc.result == 2 assoc.result_source = 1 assert assoc.result_source == 1 assoc.result_source = 2 assert assoc.result_source == 2 assoc.result_source = 3 assert assoc.result_source == 3 assoc.diagnostic = 1 assert assoc.diagnostic == 1 assoc.diagnostic = 2 assert assoc.diagnostic == 2 assoc.diagnostic = 3 assert assoc.diagnostic == 3 assoc.diagnostic = 7 assert assoc.diagnostic == 7 assoc.calling_presentation_address = ('10.40.94.43', 105) assert assoc.calling_presentation_address == ('10.40.94.43', 105) assoc.called_presentation_address = ('10.40.94.44', 106) assert assoc.called_presentation_address == ('10.40.94.44', 106) pc = PresentationContext() pc.context_id = 1 assoc.presentation_context_definition_list = [pc] assert assoc.presentation_context_definition_list == [pc] assoc.presentation_context_definition_list = ['a', pc] assert assoc.presentation_context_definition_list == [pc] assoc.presentation_context_definition_results_list = [pc] assert assoc.presentation_context_definition_results_list == [pc] assoc.presentation_context_definition_results_list = ['a', pc] assert assoc.presentation_context_definition_results_list == [pc] assoc = A_ASSOCIATE() # No maximum_length_received set assert assoc.maximum_length_received is None # No MaximumLengthNotification present assoc.maximum_length_received = 31223 assert assoc.user_information[0].maximum_length_received == 31223 assert assoc.maximum_length_received == 31223 # MaximumLengthNotification already present assoc.maximum_length_received = 31224 assert assoc.maximum_length_received == 31224 # No ImplementationClassUIDNotification present assoc.implementation_class_uid = '1.1.2.3.4' assert assoc.user_information[1].implementation_class_uid == UID( '1.1.2.3.4') assert assoc.implementation_class_uid == UID('1.1.2.3.4') # ImplementationClassUIDNotification already present assoc.implementation_class_uid = '1.1.2.3.4' assert assoc.implementation_class_uid == UID('1.1.2.3.4')
def test_assignment(self): """Check assignment works correctly""" assoc = A_ASSOCIATE() with pytest.raises(AttributeError): assoc.mode = "test value" with pytest.raises(AttributeError): assoc.presentation_requirements = "test value2" with pytest.raises(AttributeError): assoc.session_requirements = "test value3" assoc.application_context_name = None assert assoc.application_context_name is None assoc.application_context_name = "1.2.840.10008.3.1.1.1" assert assoc.application_context_name == UID("1.2.840.10008.3.1.1.1") assoc.application_context_name = b"1.2.840.10008.3.1.1.1" assert assoc.application_context_name == UID("1.2.840.10008.3.1.1.1") assoc.application_context_name = UID("1.2.840.10008.3.1.1.1") assert assoc.application_context_name == UID("1.2.840.10008.3.1.1.1") msg = "'Calling AE Title' must be str, not 'NoneType'" with pytest.raises(TypeError, match=msg): assoc.calling_ae_title = None assoc.calling_ae_title = "ABCDEF1234567890" assert assoc.calling_ae_title == "ABCDEF1234567890" msg = "'Called AE Title' must be str, not 'NoneType'" with pytest.raises(TypeError, match=msg): assoc.called_ae_title = None assert assoc.responding_ae_title == assoc.called_ae_title assoc.called_ae_title = "1234567890ABCDEF" assert assoc.called_ae_title == "1234567890ABCDEF" assert assoc.responding_ae_title == assoc.called_ae_title max_length = MaximumLengthNotification() max_length.maximum_length_received = 31222 assoc.user_information.append(max_length) assert assoc.user_information[0].maximum_length_received == 31222 assoc.user_information = ["a", max_length] assert assoc.user_information == [max_length] assoc.result = None assert assoc.result is None assoc.result = 0 assoc.result = 1 assert assoc.result == 1 assoc.result = 2 assert assoc.result == 2 assoc.result_source = None assert assoc.result_source is None assoc.result_source = 1 assert assoc.result_source == 1 assoc.result_source = 2 assert assoc.result_source == 2 assoc.result_source = 3 assert assoc.result_source == 3 assoc.diagnostic = None assert assoc.diagnostic is None assoc.diagnostic = 1 assert assoc.diagnostic == 1 assoc.diagnostic = 2 assert assoc.diagnostic == 2 assoc.diagnostic = 3 assert assoc.diagnostic == 3 assoc.diagnostic = 7 assert assoc.diagnostic == 7 assoc.calling_presentation_address = None assert assoc.calling_presentation_address is None assoc.calling_presentation_address = ("10.40.94.43", 105) assert assoc.calling_presentation_address == ("10.40.94.43", 105) assoc.called_presentation_address = None assert assoc.called_presentation_address is None assoc.called_presentation_address = ("10.40.94.44", 106) assert assoc.called_presentation_address == ("10.40.94.44", 106) pc = PresentationContext() pc.context_id = 1 assoc.presentation_context_definition_list = [pc] assert assoc.presentation_context_definition_list == [pc] assoc.presentation_context_definition_list = ["a", pc] assert assoc.presentation_context_definition_list == [pc] assoc.presentation_context_definition_results_list = [pc] assert assoc.presentation_context_definition_results_list == [pc] assoc.presentation_context_definition_results_list = ["a", pc] assert assoc.presentation_context_definition_results_list == [pc] assoc = A_ASSOCIATE() # No maximum_length_received set assert assoc.maximum_length_received is None # No MaximumLengthNotification present assoc.maximum_length_received = 31223 assert assoc.user_information[0].maximum_length_received == 31223 assert assoc.maximum_length_received == 31223 # MaximumLengthNotification already present assoc.maximum_length_received = 31224 assert assoc.maximum_length_received == 31224 # No ImplementationClassUIDNotification present assoc.implementation_class_uid = "1.1.2.3.4" assert assoc.user_information[1].implementation_class_uid == UID("1.1.2.3.4") assert assoc.implementation_class_uid == UID("1.1.2.3.4") # ImplementationClassUIDNotification already present assoc.implementation_class_uid = "1.1.2.3.4" assert assoc.implementation_class_uid == UID("1.1.2.3.4")
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from pynetdicom.presentation import PresentationContext from pynetdicom import build_context cx = PresentationContext() cx.context_id = 1 # 1.2.840.10008.1.1 - Verification SOP Class # 1.2.840.10008.5.1.4.1.1 - CT Image Storage cx.abstract_syntax = '1.2.840.10008.1.1' # 1.2.840.10008.1.2 - Implicit VR Little Endian # 1.2.840.10008.1.2.4.50 - JPEG Baseline cx.transfer_syntax = ['1.2.840.10008.1.2', '1.2.840.10008.1.2.4.50'] print(cx) cx1 = build_context( '1.2.840.10008.1.1', ['1.2.840.10008.5.1.4.1.1.3.1'] ) print(cx1) cx2 = build_context('1.2.840.10008.1.1') print(cx2)