Class: LabwareCreators::PooledTubesFromWholeTubes

Inherits:
Base
  • Object
show all
Includes:
CustomPage, SupportParent::TubeOnly
Defined in:
app/models/labware_creators/pooled_tubes_from_whole_tubes.rb

Overview

Pools one or more source tubes into a single tube. Provides an inbox list on the left hand side of the page listing available tubes (tubes of the correct type).

Defined Under Namespace

Classes: SubmissionFailure

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from LabwareCreators::Base

Instance Attribute Details

#barcodesObject

Returns the value of attribute barcodes.



13
14
15
# File 'app/models/labware_creators/pooled_tubes_from_whole_tubes.rb', line 13

def barcodes
  @barcodes
end

#childObject (readonly)

Returns the value of attribute child.



13
14
15
# File 'app/models/labware_creators/pooled_tubes_from_whole_tubes.rb', line 13

def child
  @child
end

#tube_transferObject (readonly)

Returns the value of attribute tube_transfer.



13
14
15
# File 'app/models/labware_creators/pooled_tubes_from_whole_tubes.rb', line 13

def tube_transfer
  @tube_transfer
end

Instance Method Details

#available_tubesObject

TODO: This should probably be asynchronous



36
37
38
39
40
41
42
# File 'app/models/labware_creators/pooled_tubes_from_whole_tubes.rb', line 36

def available_tubes
  @search_options = OngoingTube.new(purpose_names: [parent.purpose.name], include_used: false)
  @search_results =
    Sequencescape::Api::V2::Tube.find_all(
      **@search_options.v2_search_parameters.merge({ includes: 'purpose', paginate: @search_options.v2_pagination })
    )
end

#create_labware!Object



20
21
22
23
24
25
26
27
28
29
# File 'app/models/labware_creators/pooled_tubes_from_whole_tubes.rb', line 20

def create_labware!
  # Create a single tube
  # TODO: This should link to multiple parents in production
  tc = api.tube_from_tube_creation.create!(user: user_uuid, parent: parent_uuid, child_purpose: purpose_uuid)

  @child = tc.child

  # Transfer EVERYTHING into it
  api.transfer_request_collection.create!(user: user_uuid, transfer_requests: transfer_request_attributes)
end

#number_of_parent_labwaresObject



57
58
59
60
# File 'app/models/labware_creators/pooled_tubes_from_whole_tubes.rb', line 57

def number_of_parent_labwares
  # default to 4 if value not found in config
  purpose_config.fetch(:number_of_parent_labwares, 4)
end

#parentObject Originally defined in module SupportParent::TubeOnly

#parentsObject



44
45
46
# File 'app/models/labware_creators/pooled_tubes_from_whole_tubes.rb', line 44

def parents
  @parents ||= Sequencescape::Api::V2::Tube.find_all(barcode: barcodes, includes: [])
end

#parents_suitableObject



48
49
50
51
52
53
54
55
# File 'app/models/labware_creators/pooled_tubes_from_whole_tubes.rb', line 48

def parents_suitable
  # Plate#barcode =~ ensures different 'flavours' of the same barcode still match.
  # Ie. EAN13 encoded versions will match the Code39 encoded versions.
  missing_barcodes = barcodes.reject { |scanned_bc| parents.any? { |p| p.barcode =~ scanned_bc } }
  return if missing_barcodes.empty?

  errors.add(:barcodes, "could not be found: #{missing_barcodes}")
end