def perform_send(objects)
      objects.each_with_index do |dcm, index|
        # Gather necessary information from the object (SOP Class & Instance UID):
        sop_class = dcm.value("0008,0016")
        sop_instance = dcm.value("0008,0018")
        if sop_class and sop_instance
          # Only send the image if its sop_class has been accepted by the receiver:
          if @approved_syntaxes[sop_class]
            # Set the command array to be used:
            message_id = index + 1
            set_command_fragment_store(sop_class, sop_instance, message_id)
            # Find context id and transfer syntax:
            presentation_context_id = @approved_syntaxes[sop_class][0]
            selected_transfer_syntax = @approved_syntaxes[sop_class][1]
            # Encode our DICOM object to a binary string which is split up in pieces, sufficiently small to fit within the specified maximum pdu length:
            # Set the transfer syntax of the DICOM object equal to the one accepted by the SCP:
            dcm.transfer_syntax = selected_transfer_syntax
            # Remove the Meta group, since it doesn't belong in a DICOM file transfer:
            dcm.delete_group(META_GROUP)
            max_header_length = 14
            data_packages = dcm.encode_segments(@max_pdu_length - max_header_length, selected_transfer_syntax)
            @link.build_command_fragment(PDU_DATA, presentation_context_id, COMMAND_LAST_FRAGMENT, @command_elements)
            @link.transmit
            # Transmit all but the last data strings:
            last_data_package = data_packages.pop
            data_packages.each do |data_package|
              @link.build_storage_fragment(PDU_DATA, presentation_context_id, DATA_MORE_FRAGMENTS, data_package)
              @link.transmit
            end
            # Transmit the last data string:
            @link.build_storage_fragment(PDU_DATA, presentation_context_id, DATA_LAST_FRAGMENT, last_data_package)
            @link.transmit
            # Receive confirmation response:
            segments = @link.receive_single_transmission
            process_returned_data(segments)
          end
        else
          logger.error("Unable to extract SOP Class UID and/or SOP Instance UID for this DICOM object. File will not be sent to its destination.")
        end
      end
    end
def perform_send(objects)
      objects.each_with_index do |dcm, index|
        # Gather necessary information from the object (SOP Class & Instance UID):
        sop_class = dcm.value("0008,0016")
        sop_instance = dcm.value("0008,0018")
        if sop_class and sop_instance
          # Only send the image if its sop_class has been accepted by the receiver:
          if @approved_syntaxes[sop_class]
            # Set the command array to be used:
            message_id = index + 1
            set_command_fragment_store(sop_class, sop_instance, message_id)
            # Find context id and transfer syntax:
            presentation_context_id = @approved_syntaxes[sop_class][0]
            selected_transfer_syntax = @approved_syntaxes[sop_class][1]
            # Encode our DICOM object to a binary string which is split up in pieces, sufficiently small to fit within the specified maximum pdu length:
            # Set the transfer syntax of the DICOM object equal to the one accepted by the SCP:
            dcm.transfer_syntax = selected_transfer_syntax
            # Remove the Meta group, since it doesn't belong in a DICOM file transfer:
            dcm.delete_group(META_GROUP)
            max_header_length = 14
            data_packages = dcm.encode_segments(@max_pdu_length - max_header_length, selected_transfer_syntax)
            @link.build_command_fragment(PDU_DATA, presentation_context_id, COMMAND_LAST_FRAGMENT, @command_elements)
            @link.transmit
            # Transmit all but the last data strings:
            last_data_package = data_packages.pop
            data_packages.each do |data_package|
              @link.build_storage_fragment(PDU_DATA, presentation_context_id, DATA_MORE_FRAGMENTS, data_package)
              @link.transmit
            end
            # Transmit the last data string:
            @link.build_storage_fragment(PDU_DATA, presentation_context_id, DATA_LAST_FRAGMENT, last_data_package)
            @link.transmit
            # Receive confirmation response:
            segments = @link.receive_single_transmission
            process_returned_data(segments)
          end
        else
          logger.error("Unable to extract SOP Class UID and/or SOP Instance UID for this DICOM object. File will not be sent to its destination.")
        end
      end
    end
Handles the communication involved in DICOM C-STORE.
 For each file, builds and sends command fragment, then builds and sends the data fragments that
 conveys the information from the selected DICOM file.