Class: UatActions::TubeSubmission

Inherits:
UatActions show all
Defined in:
app/uat_actions/uat_actions/tube_submission.rb

Overview

This UAT Action will generates a basic submission for tubes. Initially, it has been designed for generating scRNA Core Donor Pooling and cDNA Prep submissions on LRC Bank Seq/Spare tubes.

Constant Summary

Constants inherited from UatActions

CATEGORY_LIST

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from UatActions

all, category, find, form_field, form_fields, #form_fields, grouped_and_sorted_uat_actions, id, inherited, permitted, #report, #save, to_partial_path, uat_actions

Class Method Details

.compatible_submission_templatesArray<String>

Returns the submission templates which are compatible with the UAT action. These are submission templates which have a tube as an input asset type.

Returns:

  • (Array<String>)

    The names of the compatible submission templates



67
68
69
70
71
72
73
74
75
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 67

def self.compatible_submission_templates
  SubmissionTemplate
    .visible
    .each_with_object([]) do |submission_template, compatible|
      next unless submission_template.input_asset_type.constantize <= Tube

      compatible << submission_template.name
    end
end

.defaultUatActions::TestSubmission

Returns a default copy of the UatAction which will be used to fill in the form

Returns:



59
60
61
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 59

def self.default
  new
end

Instance Method Details

#assetsArray<Tube>

Returns the tubes to use for the submission

Returns:

  • (Array<Tube>)

    The tubes to use for the submission



122
123
124
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 122

def assets
  @assets ||= select_assets
end

#custom_request_optionsHash

Returns the custom request options to use for the submission

Returns:

  • (Hash)

    The custom request options from the form



160
161
162
163
164
165
166
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 160

def custom_request_options
  options = {}
  options[:library_type] = library_type_name if library_type_name.present?
  options[:number_of_samples_per_pool] = number_of_samples_per_pool.presence
  options[:cells_per_chip_well] = cells_per_chip_well.presence
  options
end

#default_request_optionsHash

Returns the default request options to use for the submission

Returns:

  • (Hash)

    The default request options to use for the submission



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 143

def default_request_options
  submission_template
    .input_field_infos
    .each_with_object({}) do |ifi, options|
      options[ifi.key] = (
        if ifi.default_value.nil?
          ifi.selection&.first.presence || ifi.max.presence || ifi.min
        else
          ifi.default_value
        end
      )
    end
end

#fill_report(order) ⇒ Void

Fills the report with the information from the submission

rubocop:disable Metrics/AbcSize

Returns:

  • (Void)


98
99
100
101
102
103
104
105
106
107
108
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 98

def fill_report(order)
  report['tube_barcodes'] = assets.map(&:human_barcode)
  report['submission_id'] = order.submission.id
  report['library_type'] = order.request_options[:library_type] if order.request_options[:library_type].present?
  report['number_of_samples_per_pool'] = order.request_options[:number_of_samples_per_pool] if order.request_options[
    :number_of_samples_per_pool
  ].present?
  report['cells_per_chip_well'] = order.request_options[:cells_per_chip_well] if order.request_options[
    :cells_per_chip_well
  ].present?
end

#order_request_optionsHash

Returns the request options to use for the submission

Returns:

  • (Hash)

    The request options to use for the submission



136
137
138
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 136

def order_request_options
  default_request_options.merge(custom_request_options)
end

#performBoolean

Generates tube submission for the given template.

Returns:

  • (Boolean)

    true if the submission was successfully created



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 80

def perform
  order =
    submission_template.create_with_submission!(
      study: study,
      project: project,
      user: user,
      assets: assets,
      request_options: order_request_options
    )
  fill_report(order)
  order.submission.built!
  true
end

#projectProject

Returns the project to use for UAT

Returns:

  • (Project)

    The project to use for UAT



178
179
180
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 178

def project
  UatActions::StaticRecords.project
end

#select_assetsArray<Tube>

Returns the tubes from the specified barcodes in the form field

Returns:

  • (Array<Tube>)

    The tubes to use for the submission



129
130
131
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 129

def select_assets
  tube_barcodes.gsub(/(\\[trfvn])+/, ' ').split.map { |barcode| Tube.find_by_barcode(barcode) }
end

#studyStudy

Returns the study to use for UAT

Returns:

  • (Study)

    The study to use for UAT



171
172
173
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 171

def study
  UatActions::StaticRecords.study
end

#submission_templateSubmissionTemplate

Returns the submisssion template to use for the submission

Returns:



115
116
117
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 115

def submission_template
  @submission_template = SubmissionTemplate.find_by(name: submission_template_name)
end

#userUser

Returns the uat user

Returns:

  • (User)

    The UAT user can be used in any places where a user is expected.



186
187
188
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 186

def user
  UatActions::StaticRecords.user
end