Exemplo n.º 1
0
    def test_transfer_syntax_good_uid(self):
        """ Check AE initialisation produces valid transfer syntaxes """
        ae = AE(scu_sop_class=['1.2.840.10008.1.1'],
                transfer_syntax=['1.2.840.10008.1.2'])
        self.assertTrue(ae.transfer_syntaxes == [UID('1.2.840.10008.1.2')])

        ae = AE(scu_sop_class=['1.2.840.10008.1.1'],
                transfer_syntax=['1.2.840.10008.1.2', '1.2.840.10008.1.1'])
        self.assertTrue(ae.transfer_syntaxes == [UID('1.2.840.10008.1.2')])

        ae = AE(scu_sop_class=['1.2.840.10008.1.1'],
                transfer_syntax=['1.2.840.10008.1.2', '1.2.840.10008.1.2.2'])
        self.assertTrue(ae.transfer_syntaxes ==
                        [UID('1.2.840.10008.1.2'),
                         UID('1.2.840.10008.1.2.2')])

        ae = AE(scu_sop_class=['1.2.840.10008.1.1'],
                transfer_syntax=[UID('1.2.840.10008.1.2')])
        self.assertTrue(ae.transfer_syntaxes == [UID('1.2.840.10008.1.2')])

        ae = AE(scu_sop_class=['1.2.840.10008.1.1'],
                transfer_syntax=[ImplicitVRLittleEndian])
        self.assertTrue(ae.transfer_syntaxes == [UID('1.2.840.10008.1.2')])
Exemplo n.º 2
0
    def test_on_c_store_called(self):
        """ Check that SCP AE.on_c_store(dataset) was called """
        self.scp = DummyStorageSCP()
        self.scp.start()

        ae = AE(scu_sop_class=[RTImageStorage])
        assoc = ae.associate('localhost', 11112)
        with patch.object(self.scp.ae, 'on_c_store') as mock:
            mock.return_value = 0x0000
            assoc.send_c_store(DATASET)
            self.assertTrue(mock.called)
        assoc.release()

        self.scp.stop()
Exemplo n.º 3
0
    def test_scp_callback_return_dataset(self):
        """Test on_c_store returning a Dataset status"""
        self.scp = DummyStorageSCP()
        self.scp.status = Dataset()
        self.scp.status.Status = 0x0001
        self.scp.start()

        ae = AE(scu_sop_class=[CTImageStorage])
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        rsp = assoc.send_c_store(DATASET)
        assert rsp.Status == 0x0001
        assoc.release()
        self.scp.stop()
Exemplo n.º 4
0
    def test_scp_callback_return_int(self):
        """Test on_c_echo returning an int status"""
        self.scp = DummyStorageSCP()
        self.scp.status = 0x0000
        self.scp.start()

        ae = AE(scu_sop_class=[CTImageStorage])
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        rsp = assoc.send_c_store(DATASET)
        assert rsp.Status == 0x0000
        assert not 'ErrorComment' in rsp
        assoc.release()
        self.scp.stop()
Exemplo n.º 5
0
    def test_scp_callback_return_invalid(self):
        """Test on_c_store returning a valid status"""
        self.scp = DummyStorageSCP()
        self.scp.status = 0xFFF0
        self.scp.start()

        ae = AE()
        ae.add_requested_context(HangingProtocolStorage)
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        rsp = assoc.send_c_store(DATASET)
        assert rsp.Status == 0xFFF0
        assoc.release()
        self.scp.stop()
Exemplo n.º 6
0
 def test_network_timeout(self):
     """ Check AE network timeout change produces good value """
     ae = AE(scu_sop_class=['1.2.840.10008.1.1'])
     self.assertTrue(ae.network_timeout == None)
     ae.network_timeout = None
     self.assertTrue(ae.network_timeout == None)
     ae.network_timeout = -100
     self.assertTrue(ae.network_timeout == None)
     ae.network_timeout = 'a'
     self.assertTrue(ae.network_timeout == None)
     ae.network_timeout = 0
     self.assertTrue(ae.network_timeout == 0)
     ae.network_timeout = 30
     self.assertTrue(ae.network_timeout == 30)
Exemplo n.º 7
0
    def test_associate_establish_release(self):
        """ Check SCU Association with SCP """
        self.scp = DummyVerificationSCP()
        self.scp.start()

        ae = AE(scu_sop_class=[VerificationSOPClass])
        ae.acse_timeout = 5
        ae.dimse_timeout = 5
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        assoc.release()
        assert not assoc.is_established
        assert assoc.is_released

        self.scp.stop()
    def test_scp_callback_return_dataset(self):
        """Test on_c_echo returning a Dataset status"""
        self.scp = DummyVerificationSCP()
        self.scp.status = Dataset()
        self.scp.status.Status = 0x0001
        self.scp.start()

        ae = AE()
        ae.add_requested_context(VerificationSOPClass)
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        rsp = assoc.send_c_echo()
        assert rsp.Status == 0x0001
        assoc.release()
        self.scp.stop()
Exemplo n.º 9
0
    def test_get_scp(self):
        '''test the Get scp
        '''
        self.scp = GetSCP()
        self.scp.start()
        ds = get_patient()

        print("Generating a service class user to retrieve.")
        self.ae = AE(
            scu_sop_class=[PatientRootQueryRetrieveInformationModelGet])
        self.create_association()

        print("Running retrieval, checking for status 0 (success)")
        for (status, ds) in self.assoc.send_c_get(ds, query_model='P'):
            self.assertEqual(int(status), 0x0000)
Exemplo n.º 10
0
    def test_scp_callback_return_dataset_unknown(self):
        """Test a status ds with an unknown element."""
        self.scp = DummyVerificationSCP()
        self.scp.status = Dataset()
        self.scp.status.Status = 0x0001
        self.scp.status.PatientName = 'test name'
        self.scp.start()

        ae = AE(scu_sop_class=[VerificationSOPClass])
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        rsp = assoc.send_c_echo()
        assert rsp.Status == 0x0001
        assoc.release()
        self.scp.stop()
Exemplo n.º 11
0
    def test_storage_scp(self):
        '''test the storage scp
        '''

        print("Generating a Storage SCP, and starting.")
        self.scp = StorageSCP()
        self.scp.start()

        print("Generating a service class user to send dataset.")
        self.ae = AE(scu_sop_class=[RTImageStorage])
        self.create_association()

        print("Sending dataset %s" % os.path.basename(self.dataset.filename))
        response = self.assoc.send_c_store(self.dataset)
        print(response.__dict__)
    def test_scp_callback_return_int(self):
        """Test on_c_echo returning an int status"""
        self.scp = DummyStorageSCP()
        self.scp.status = 0x0000
        self.scp.start()

        ae = AE()
        ae.add_requested_context(HangingProtocolStorage)
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        rsp = assoc.send_c_store(DATASET)
        assert rsp.Status == 0x0000
        assert not 'ErrorComment' in rsp
        assoc.release()
        self.scp.stop()
Exemplo n.º 13
0
    def __init__(self,
                 port=11112,
                 name="ECHOSCP",
                 prefer_uncompr=True,
                 prefer_little=False,
                 prefer_big=False,
                 implicit=False,
                 timeout=None,
                 dimse_timeout=None,
                 acse_timeout=60,
                 pdu_max=16384,
                 start=False):
        '''
        :param port: the port to use, default is 11112.
        :param name: the title/name for the ae. 'ECHOSCP' is used if not defined.
        :param prefer_uncompr: prefer explicit VR local byte order (default)
        :param prefer_little: prefer explicit VR little endian TS
        :param perfer_big: prefer explicit VR big endian TS
        :param implicit: accept implicit VR little endian TS only
        :param timeout: timeout for connection requests (default None)
        :param acse_timeout: timeout for ACSE messages (default 60)
        :param dimse_timeout: timeout for the DIMSE messages (default None) 
        :param pdu_max: set max receive pdu to n bytes (4096..131072) default 16382
        :param start: if True, start the ae.
        '''
        self.port = port

        # Update preferences
        self.update_transfer_syntax(prefer_uncompr=prefer_uncompr,
                                    prefer_little=prefer_little,
                                    prefer_big=prefer_big,
                                    implicit=implicit)

        ae = AE(scp_sop_class=[VerificationSOPClass],
                scu_sop_class=[],
                port=self.port,
                transfer_syntax=self.transfer_syntax)

        # Set timeouts, name, transfer
        ae.ae_title = name
        ae.maximum_pdu_size = pdu_max
        ae.network_timeout = timeout
        ae.acse_timeout = acse_timeout
        ae.dimse_timeout = dimse_timeout
        BaseSCP.__init__(self, ae=ae)

        if start is True:
            self.run()
Exemplo n.º 14
0
    def __init__(self, port=11112):
        self.ae = AE(port=port)
        self.ae.add_supported_context(
            PatientRootQueryRetrieveInformationModelMove)
        self.ae.add_supported_context(
            StudyRootQueryRetrieveInformationModelMove)
        self.ae.add_supported_context(
            PatientStudyOnlyQueryRetrieveInformationModelMove)
        self.ae.add_supported_context(CTImageStorage)
        self.ae.add_supported_context(RTImageStorage)
        self.ae.add_supported_context(MRImageStorage)
        self.ae.add_supported_context(HangingProtocolStorage)

        DummyBaseSCP.__init__(self)
        self.status = 0x0000
        self.raise_exception = False
Exemplo n.º 15
0
    def test_scp_callback_return_dataset_multi(self):
        """Test on_c_echo returning a Dataset status with other elements"""
        self.scp = DummyVerificationSCP()
        self.scp.status = Dataset()
        self.scp.status.Status = 0x0001
        self.scp.status.ErrorComment = 'Test'
        self.scp.start()

        ae = AE(scu_sop_class=[VerificationSOPClass])
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        rsp = assoc.send_c_echo()
        assert rsp.Status == 0x0001
        assert rsp.ErrorComment == 'Test'
        assoc.release()
        self.scp.stop()
    def test_scp_callback_exception(self):
        """Test on_c_store raising an exception"""
        self.scp = DummyStorageSCP()
        def on_c_store(ds, context, assoc_info):
            raise ValueError
        self.scp.ae.on_c_store = on_c_store
        self.scp.start()

        ae = AE()
        ae.add_requested_context(HangingProtocolStorage)
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        rsp = assoc.send_c_store(DATASET)
        assert rsp.Status == 0xC211
        assoc.release()
        self.scp.stop()
Exemplo n.º 17
0
    def test_on_c_move_called(self):
        """ Check that SCP AE.on_c_move(dataset) was called """
        self.scp = DummyMoveSCP()
        self.scp.start()

        ds = Dataset()
        ds.PatientName = '*'
        ds.QueryRetrieveLevel = "PATIENT"
        ae = AE(scu_sop_class=[PatientRootQueryRetrieveInformationModelMove])
        assoc = ae.associate('localhost', 11112)
        self.assertTrue(assoc.is_established)
        for (status, ds) in assoc.send_c_move(ds, query_model='P', move_aet=b'TEST'):
            self.assertEqual(int(status), 0x0000)
        assoc.release()

        self.scp.stop()
Exemplo n.º 18
0
 def __init__(self, port=11112):
     self.ae = AE(scp_sop_class=[
         PatientRootQueryRetrieveInformationModelGet,
         StudyRootQueryRetrieveInformationModelGet,
         PatientStudyOnlyQueryRetrieveInformationModelGet, CTImageStorage
     ],
                  scu_sop_class=[CTImageStorage],
                  port=port)
     DummyBaseSCP.__init__(self)
     self.statuses = [0x0000]
     ds = Dataset()
     ds.PatientName = 'Test'
     ds.SOPClassUID = CTImageStorage.UID
     ds.SOPInstanceUID = '1.2.3.4'
     self.datasets = [ds]
     self.no_suboperations = 1
     self.cancel = False
    def test_scp_callback_return_int(self):
        """Test on_n_get returning an int status"""
        self.scp = DummyGetSCP()
        self.scp.status = 0x0000
        self.scp.start()

        ae = AE()
        ae.add_requested_context(DisplaySystemSOPClass)
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        status, ds = assoc.send_n_get([(0x7fe0,0x0010)],
                                      DisplaySystemSOPClass,
                                      '1.2.840.10008.5.1.1.40.1')
        assert status.Status == 0x0000
        assert not 'ErrorComment' in status
        assoc.release()
        self.scp.stop()
Exemplo n.º 20
0
    def test_scp_callback_exception(self):
        """Test on_c_echo raising an exception"""
        self.scp = DummyVerificationSCP()

        def on_c_echo(context, info):
            raise ValueError

        self.scp.ae.on_c_echo = on_c_echo
        self.scp.start()

        ae = AE(scu_sop_class=[VerificationSOPClass])
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        rsp = assoc.send_c_echo()
        assert rsp.Status == 0x0000
        assoc.release()
        self.scp.stop()
Exemplo n.º 21
0
    def __init__(self,
                 dicom_home,
                 port=11112,
                 name="MOVESCP",
                 prefer_uncompr=True,
                 prefer_little=False,
                 prefer_big=False,
                 implicit=False,
                 timeout=None,
                 dimse_timeout=None,
                 acse_timeout=60,
                 pdu_max=16384,
                 start=False):
        '''
        :param dicom_home: must be the base folder of dicom files **TODO: make this more robust
        :param port: TCP/IP port number to listen on
        :param name: the title/name for the ae. 'MOVESCP' is used if not defined.
        :param prefer_uncompr: prefer explicit VR local byte order (default)
        :param prefer_little: prefer explicit VR little endian TS
        :param perfer_big: prefer explicit VR big endian TS
        :param implicit: accept implicit VR little endian TS only
        :param timeout: timeout for connection requests (default None)
        :param acse_timeout: timeout for ACSE messages (default 60)
        :param dimse_timeout: timeout for the DIMSE messages (default None) 
        :param pdu_max: set max receive pdu to n bytes (4096..131072) default 16382
        '''
        self.port = port
        self.base = dicom_home

        ae = AE(ae_title=name,
                port=self.port,
                scu_sop_class=StorageSOPClassList,
                scp_sop_class=QueryRetrieveSOPClassList,
                transfer_syntax=self.transfer_syntax)

        BaseSCP.__init__(self, ae=ae)
        self.status = self.pending
        self.cancel = False

        self.ae.maximum_pdu_size = max_pdu
        self.ae.network_timeout = timeout
        self.ae.acse_timeout = acse_timeout
        self.ae.dimse_timeout = dimse_timeout

        if start is True:
            self.run()
Exemplo n.º 22
0
    def test_verification_scp(self):
        '''test the verification scp
        '''
        print("Generating a verification SCP, and starting.")
        self.scp = VerificationSCP()
        self.scp.start()

        print("Generating a service class user (ae) to send echo.")
        self.ae = AE(scu_sop_class=[VerificationSOPClass])
        self.create_association()

        print("Sending an echo.")
        echo = self.assoc.send_c_echo()
        print(echo.__dict__)

        self.release_association()
        self.assertTrue(self.assoc.is_established == False)
    def test_scp_callback_no_status(self):
        """Test on_n_get not returning a status"""
        self.scp = DummyGetSCP()
        self.scp.status = None
        self.scp.start()

        ae = AE()
        ae.add_requested_context(DisplaySystemSOPClass)
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        status, ds = assoc.send_n_get([(0x7fe0,0x0010)],
                                      DisplaySystemSOPClass,
                                      '1.2.840.10008.5.1.1.40.1')
        assert status.Status == 0xC002
        assert ds is None
        assoc.release()
        self.scp.stop()
Exemplo n.º 24
0
    def __init__(self,name=None):
        '''
        :param name: the title/name for the ae. 'MOVESCU' is used if not defined.
        :param model: the query information model
        '''
        if name is None:
            name = 'MOVESCU'

        ae = AE(ae_title=name,
                port=0,
                scu_sop_class=QueryRetrieveSOPClassList,
                scp_sop_class=StorageSOPClassList,
                transfer_syntax=[ExplicitVRLittleEndian])

        BaseSCU.__init__(self,ae=ae)
        self.status = self.pending
        self.cancel = False
Exemplo n.º 25
0
    def run(self):
        ae = AE(ae_title=self.aet,
                port=self.incoming_port,
                scu_sop_class=QueryRetrieveSOPClassList)

        ('Requesting Association with the peer')
        assoc = ae.associate(addr=self.peer_address,
                             port=self.peer_port,
                             ae_title=self.aec)
        if assoc.is_established:
            logging.debug('Association accepted by the peer')
            dataset = create_dataset(self.accession_number, self.study_uid)
            with self.output().open('w') as out:
                out.write('StudyInstanceUID,SeriesInstanceUID\n')
                for s_uid, series_uid in [x for x in search(assoc, dataset)]:
                    out.write('{},{}\n'.format(s_uid, series_uid))
        assoc.release()
Exemplo n.º 26
0
    def test_on_c_echo_called(self):
        """ Check that SCP AE.on_c_echo() was called """
        self.scp = DummyVerificationSCP()
        self.scp.start()

        ae = AE(scu_sop_class=[VerificationSOPClass])
        assoc = ae.associate('localhost', 11112)
        status = assoc.send_c_echo()
        assert isinstance(status, Dataset)
        assert 'Status' in status
        assert status.Status == 0x0000

        assoc.release()
        assert assoc.is_released
        assert not assoc.is_established

        self.scp.stop()
Exemplo n.º 27
0
    def test_find_scp(self):
        '''test the find scp
        '''

        print("Generating a Find SCP, and starting.")
        self.scp = FindSCP()
        self.scp.status = self.scp.success
        self.scp.start()
        ds = get_patient()

        print("Generating a service class user to query.")
        self.ae = AE(
            scu_sop_class=[PatientRootQueryRetrieveInformationModelFind])
        self.create_association()

        print("Running queries, checking for status 0 (success)")
        for (status, ds) in self.assoc.send_c_find(ds, query_model='P'):
            self.assertEqual(int(status), 0x0000)
Exemplo n.º 28
0
    def test_on_c_store_called(self):
        """ Check that SCP AE.on_c_store(dataset) was called """
        self.scp = DummyStorageSCP()
        self.scp.start()

        ae = AE(scu_sop_class=[RTImageStorage])
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        status = assoc.send_c_store(DATASET)
        assert isinstance(status, Dataset)
        assert 'Status' in status
        assert status.Status == 0x0000

        assoc.release()
        assert assoc.is_released
        assert not assoc.is_established

        self.scp.stop()
    def test_callback_status_none(self):
        """Test SCP handles on_c_find not yielding a status"""
        self.scp = DummyFindSCP()
        self.scp.statuses = [None]
        self.scp.start()

        ae = AE()
        ae.add_requested_context(GeneralRelevantPatientInformationQuery)
        ae.acse_timeout = 5
        ae.dimse_timeout = 5
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        result = assoc.send_c_find(self.query, query_model='G')
        status, identifier = next(result)
        assert status.Status == 0xC002
        pytest.raises(StopIteration, next, result)
        assoc.release()
        self.scp.stop()
Exemplo n.º 30
0
    def test_on_c_get_called(self):
        """ Check that SCP AE.on_c_get(dataset) was called """
        self.scp = DummyGetSCP()
        self.scp.start()

        ds = Dataset()
        ds.PatientName = '*'
        ds.QueryRetrieveLevel = "PATIENT"
        ae = AE(scu_sop_class=[PatientRootQueryRetrieveInformationModelGet])
        ae.acse_timeout = 5
        ae.dimse_timeout = 5
        assoc = ae.associate('localhost', 11112)
        assert assoc.is_established
        for (status, ds) in assoc.send_c_get(ds, query_model='P'):
            assert status.Status == 0x0000
        assoc.release()

        self.scp.stop()