def test_conversion_rsp(self):
        """ Check conversion to a -RSP PDU produces the correct output """
        primitive = N_CREATE()
        primitive.MessageIDBeingRespondedTo = 5
        primitive.AffectedSOPClassUID = '1.2.4.10'
        primitive.AffectedSOPInstanceUID = '1.2.4.5.7.8'
        primitive.Status = 0x0000

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

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

        dimse_msg = N_CREATE_RSP()
        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_create_rsp_cmd
        assert ds_pdv == n_create_rsp_ds
Exemple #2
0
    def test_message_to_primitive_n_create(self):
        """Test converting N_CREATE_RQ and _RSP to primitive."""
        # N-CREATE-RQ
        msg = N_CREATE_RQ()
        primitive = msg.message_to_primitive()
        assert isinstance(primitive, N_CREATE)

        # N-CREATE-RSP
        msg = N_CREATE_RSP()
        primitive = msg.message_to_primitive()
        assert isinstance(primitive, N_CREATE)
Exemple #3
0
    def test_callback_receive_n_create(self):
        """Check callback for receiving DIMSE N-CREATE messages."""
        # N-CREATE-RQ
        primitive = N_CREATE()
        primitive.MessageID = 1
        primitive.AffectedSOPClassUID = '1.1.1'
        msg = N_CREATE_RQ()
        msg.primitive_to_message(primitive)
        msg.ID = 1
        self.dimse.debug_receive_n_create_rq(msg)

        # User defined
        primitive.AffectedSOPInstanceUID = '1.1.1.1'
        primitive.AttributeList = BytesIO(n_create_rq_ds)
        msg = N_CREATE_RQ()
        msg.primitive_to_message(primitive)
        msg.ID = 1
        self.dimse.debug_receive_n_create_rq(msg)

        # N-CREATE-RSP
        primitive = N_CREATE()
        primitive.MessageIDBeingRespondedTo = 1
        primitive.Status = 0x0000
        msg = N_CREATE_RSP()
        msg.primitive_to_message(primitive)
        msg.ID = 1
        self.dimse.debug_receive_n_create_rsp(msg)

        # User defined
        primitive.AffectedSOPClassUID = '1.1.1'
        primitive.AffectedSOPInstanceUID = '1.1.1.1'
        primitive.AttributeList = BytesIO(n_create_rsp_ds)
        msg = N_CREATE_RSP()
        msg.primitive_to_message(primitive)
        msg.ID = 1
        self.dimse.debug_receive_n_create_rsp(msg)
    def test_message_to_primitive_n_create(self):
        """Test converting N_CREATE_RQ and _RSP to primitive."""
        # N-CREATE-RQ
        msg = N_CREATE_RQ()
        for data in [n_create_rq_cmd, n_create_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_CREATE)
        assert primitive.AffectedSOPClassUID == UID(
            '1.2.840.10008.5.1.4.1.1.2')
        assert primitive.AffectedSOPInstanceUID == UID(
            '1.2.392.200036.9116.2.6.1.48')
        assert primitive.MessageID == 7

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

        # N-ACTION-RSP
        msg = N_CREATE_RSP()
        for data in [n_create_rsp_cmd, n_create_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_CREATE)
        assert primitive.AffectedSOPClassUID == UID('1.2.4.10')
        assert primitive.AffectedSOPInstanceUID == UID('1.2.4.5.7.8')
        assert primitive.MessageIDBeingRespondedTo == 5
        assert primitive.Status == 0x0000

        ds = decode(primitive.AttributeList, True, True)
        assert ds.PatientName == 'Tube HeNe'
        assert ds.PatientID == 'Test1101'
Exemple #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)