Ejemplo n.º 1
0
    def test_decode(self):
        """Test decoding of a DIMSE message."""
        primitive = C_STORE()
        primitive.MessageID = 7
        primitive.AffectedSOPClassUID = '1.1.1'
        primitive.AffectedSOPInstanceUID = '1.2.1'
        primitive.Priority = 0x02
        primitive.MoveOriginatorApplicationEntityTitle = b'UNITTEST'
        primitive.MoveOriginatorMessageID = 3
        ds = Dataset()
        ds.PatientID = 'Test1101'
        ds.PatientName = 'Tube^HeNe'
        primitive.DataSet = BytesIO(encode(ds, True, True))
        dimse_msg = C_STORE_RQ()
        dimse_msg.primitive_to_message(primitive)

        # CMD: (1x4, 3x1), DS: (0x1, 2x1)
        p_data = dimse_msg.encode_msg(12, 24)

        # Command set decoding
        dimse_msg.decode_msg(next(p_data))  # MCHB 1
        dimse_msg.decode_msg(next(p_data))  # MCHB 1
        dimse_msg.decode_msg(next(p_data))  # MCHB 1
        dimse_msg.decode_msg(next(p_data))  # MCHB 1
        dimse_msg.decode_msg(next(p_data))  # MCHB 3 - end of command set
        assert dimse_msg.__class__ == C_STORE_RQ

        # Test decoded command set
        cs = dimse_msg.command_set
        assert cs.CommandGroupLength == 102
        assert cs.AffectedSOPClassUID == UID('1.1.1')
        assert cs.AffectedSOPInstanceUID == UID('1.2.1')
        assert cs.Priority == 2
        assert cs.CommandDataSetType == 1
        assert cs.CommandField == 1
        assert cs.MoveOriginatorApplicationEntityTitle == 'UNITTEST        '
        assert cs.MoveOriginatorMessageID == 3

        # Test decoded dataset
        dimse_msg.decode_msg(next(p_data))  # MCHB 1 # MCHB 0
        dimse_msg.decode_msg(next(p_data))  # MCHB 1 # MCHB 2
        assert dimse_msg.data_set.getvalue() == c_store_ds[1:]

        # Test returns false
        msg = C_STORE_RSP()
        assert not msg.decode_msg(c_store_rsp_cmd)
Ejemplo n.º 2
0
    def test_decode(self):
        """Test decoding of a DIMSE message."""
        primitive = C_STORE()
        primitive.MessageID = 7
        primitive.AffectedSOPClassUID = '1.1.1'
        primitive.AffectedSOPInstanceUID = '1.2.1'
        primitive.Priority = 0x02
        primitive.MoveOriginatorApplicationEntityTitle = b'UNITTEST'
        primitive.MoveOriginatorMessageID = 3
        ds = Dataset()
        ds.PatientID = 'Test1101'
        ds.PatientName = 'Tube^HeNe'
        primitive.DataSet = BytesIO(encode(ds, True, True))
        dimse_msg = C_STORE_RQ()
        dimse_msg.primitive_to_message(primitive)

        # CMD: (1x4, 3x1), DS: (0x1, 2x1)
        p_data_list = dimse_msg.encode_msg(12, 24)

        # Command set decoding
        for pdv in p_data_list[:4]:
            dimse_msg.decode_msg(pdv)  # MCHB 1
        dimse_msg.decode_msg(p_data_list[4])  # MCHB 3 - end of command set
        self.assertEqual(dimse_msg.__class__, C_STORE_RQ)

        # Test decoded command set
        cs = dimse_msg.command_set
        self.assertTrue(cs.CommandGroupLength == 102)
        self.assertTrue(cs.AffectedSOPClassUID == UID('1.1.1'))
        self.assertTrue(cs.AffectedSOPInstanceUID == UID('1.2.1'))
        self.assertTrue(cs.Priority == 2)
        self.assertTrue(cs.CommandDataSetType == 1)
        self.assertTrue(cs.CommandField == 1)
        # Bug in pydicom -> AEs not stripped of trailing spaces
        self.assertTrue(
            cs.MoveOriginatorApplicationEntityTitle == b'UNITTEST        ')
        self.assertTrue(cs.MoveOriginatorMessageID == 3)

        # Test decoded dataset
        dimse_msg.decode_msg(p_data_list[5])  # MCHB 0
        dimse_msg.decode_msg(p_data_list[6])  # MCHB 2
        self.assertTrue(dimse_msg.data_set.getvalue() == c_store_ds[1:])

        # Test returns false
        msg = C_STORE_RSP()
        self.assertFalse(msg.decode_msg(c_store_rsp_cmd))