def test_conversion_rq(self):
        """ Check conversion to a -RQ PDU produces the correct output """
        primitive = N_ACTION()
        primitive.MessageID = 7
        primitive.RequestedSOPClassUID = '1.2.840.10008.5.1.4.1.1.2'
        primitive.RequestedSOPInstanceUID = '1.2.392.200036.9116.2.6.1.48'
        primitive.ActionTypeID = 1

        ds = Dataset()
        ds.PatientID = 'Test1101'
        ds.PatientName = "Tube HeNe"

        primitive.ActionInformation = BytesIO(encode(ds, True, True))

        dimse_msg = N_ACTION_RQ()
        dimse_msg.primitive_to_message(primitive)

        pdvs = []
        for fragment in dimse_msg.encode_msg(1, 16382):
            pdvs.append(fragment)

        assert len(pdvs) == 2
        cs_pdv = pdvs[0].presentation_data_value_list[0][1]
        ds_pdv = pdvs[1].presentation_data_value_list[0][1]

        assert cs_pdv == n_action_rq_cmd
        assert ds_pdv == n_action_rq_ds
示例#2
0
    def test_callback_receive_n_action(self):
        """Check callback for receiving DIMSE N-ACTION messages."""
        # N-ACTION-RQ
        msg = N_ACTION_RQ()
        self.dimse.debug_receive_n_action_rq(msg)

        # N-ACTION-RSP
        msg = N_ACTION_RQ()
        self.dimse.debug_receive_n_action_rsp(msg)
示例#3
0
    def test_message_to_primitive_n_action(self):
        """Test converting N_ACTION_RQ and _RSP to primitive."""
        # N-ACTION-RQ
        msg = N_ACTION_RQ()
        primitive = msg.message_to_primitive()
        assert isinstance(primitive, N_ACTION)

        # N-ACTION-RSP
        msg = N_ACTION_RSP()
        primitive = msg.message_to_primitive()
        assert isinstance(primitive, N_ACTION)
    def test_message_to_primitive_n_action(self):
        """Test converting N_ACTION_RQ and _RSP to primitive."""
        # N-ACTION-RQ
        msg = N_ACTION_RQ()
        for data in [n_action_rq_cmd, n_action_rq_ds]:
            p_data = P_DATA()
            p_data.presentation_data_value_list.append([0, data])
            msg.decode_msg(p_data)
        primitive = msg.message_to_primitive()
        assert isinstance(primitive, N_ACTION)
        assert primitive.RequestedSOPClassUID == UID(
            '1.2.840.10008.5.1.4.1.1.2')
        assert primitive.RequestedSOPInstanceUID == UID(
            '1.2.392.200036.9116.2.6.1.48')
        assert primitive.MessageID == 7
        assert primitive.ActionTypeID == 1

        ds = decode(primitive.ActionInformation, True, True)
        assert ds.PatientName == 'Tube HeNe'
        assert ds.PatientID == 'Test1101'

        # N-ACTION-RSP
        msg = N_ACTION_RSP()
        for data in [n_action_rsp_cmd, n_action_rsp_ds]:
            p_data = P_DATA()
            p_data.presentation_data_value_list.append([0, data])
            msg.decode_msg(p_data)
        primitive = msg.message_to_primitive()
        assert isinstance(primitive, N_ACTION)
        assert primitive.AffectedSOPClassUID == UID('1.2.4.10')
        assert primitive.AffectedSOPInstanceUID == UID('1.2.4.5.7.8')
        assert primitive.MessageIDBeingRespondedTo == 5
        assert primitive.ActionTypeID == 1
        assert primitive.Status == 0x0000

        ds = decode(primitive.ActionReply, True, True)
        assert ds.PatientName == 'Tube HeNe'
        assert ds.PatientID == 'Test1101'
示例#5
0
    def send_msg(self, primitive, context_id):
        """Send a DIMSE-C or DIMSE-N message to the peer AE.

        Parameters
        ----------
        primitive : pynetdicom3.dimse_primitives
            The DIMSE service primitive to send to the peer.
        context_id : int
            The ID of the presentation context to be sent under.
        """
        if primitive.__class__ == C_ECHO:
            if primitive.MessageID is not None:
                dimse_msg = C_ECHO_RQ()
            else:
                dimse_msg = C_ECHO_RSP()

        elif primitive.__class__ == C_STORE:
            if primitive.MessageID is not None:
                dimse_msg = C_STORE_RQ()
            else:
                dimse_msg = C_STORE_RSP()

        elif primitive.__class__ == C_FIND:
            if primitive.MessageID is not None:
                dimse_msg = C_FIND_RQ()
            else:
                dimse_msg = C_FIND_RSP()

        elif primitive.__class__ == C_GET:
            if primitive.MessageID is not None:
                dimse_msg = C_GET_RQ()
            else:
                dimse_msg = C_GET_RSP()

        elif primitive.__class__ == C_MOVE:
            if primitive.MessageID is not None:
                dimse_msg = C_MOVE_RQ()
            else:
                dimse_msg = C_MOVE_RSP()

        elif primitive.__class__ == C_CANCEL:
            dimse_msg = C_CANCEL_RQ()

        elif primitive.__class__ == N_EVENT_REPORT:
            if primitive.MessageID is not None:
                dimse_msg = N_EVENT_REPORT_RQ()
            else:
                dimse_msg = N_EVENT_REPORT_RSP()

        elif primitive.__class__ == N_GET:
            if primitive.MessageID is not None:
                dimse_msg = N_GET_RQ()
            else:
                dimse_msg = N_GET_RSP()

        elif primitive.__class__ == N_SET:
            if primitive.MessageID is not None:
                dimse_msg = N_SET_RQ()
            else:
                dimse_msg = N_SET_RSP()

        elif primitive.__class__ == N_ACTION:
            if primitive.MessageID is not None:
                dimse_msg = N_ACTION_RQ()
            else:
                dimse_msg = N_ACTION_RSP()

        elif primitive.__class__ == N_CREATE:
            if primitive.MessageID is not None:
                dimse_msg = N_CREATE_RQ()
            else:
                dimse_msg = N_CREATE_RSP()

        elif primitive.__class__ == N_DELETE:
            if primitive.MessageID is not None:
                dimse_msg = N_DELETE_RQ()
            else:
                dimse_msg = N_DELETE_RSP()

        # Convert DIMSE primitive to DIMSE Message
        dimse_msg.primitive_to_message(primitive)

        # Callbacks
        self.on_send_dimse_message(dimse_msg)

        # Split the full messages into P-DATA chunks,
        #   each below the max_pdu size
        pdata_pdu_list = dimse_msg.encode_msg(context_id,
                                              self.maximum_pdu_size)

        # Send the P-DATA PDUs to the peer via the DUL provider
        for pdata_pdu in pdata_pdu_list:
            self.dul.send_pdu(pdata_pdu)
示例#6
0
    def test_callback_receive_n_action(self):
        """Check callback for receiving DIMSE N-ACTION messages."""
        # N-ACTION-RQ
        primitive = N_ACTION()
        primitive.MessageID = 1
        primitive.RequestedSOPClassUID = '1.1.1'
        primitive.RequestedSOPInstanceUID = '1.1.1.1'
        primitive.ActionTypeID = 2
        msg = N_ACTION_RQ()
        msg.primitive_to_message(primitive)
        msg.ID = 1
        self.dimse.debug_receive_n_action_rq(msg)

        # User defined
        primitive.ActionInformation = BytesIO(n_action_rq_ds)
        msg = N_ACTION_RQ()
        msg.primitive_to_message(primitive)
        msg.ID = 1
        self.dimse.debug_receive_n_action_rq(msg)

        # N-ACTION-RSP
        primitive = N_ACTION()
        primitive.MessageIDBeingRespondedTo = 1
        primitive.Status = 0x0000
        msg = N_ACTION_RSP()
        msg.primitive_to_message(primitive)
        msg.ID = 1
        self.dimse.debug_receive_n_action_rsp(msg)

        # User defined
        primitive.AffectedSOPClassUID = '1.1.1'
        primitive.AffectedSOPInstanceUID = '1.1.1.1'
        primitive.ActionTypeID = 2
        primitive.ActionReply = BytesIO(n_action_rsp_ds)
        msg = N_ACTION_RSP()
        msg.primitive_to_message(primitive)
        msg.ID = 1
        self.dimse.debug_receive_n_action_rsp(msg)