Module: Submission::AssetSubmissionFinder

Included in:
BulkSubmission
Defined in:
app/models/submission/asset_submission_finder.rb

Instance Method Summary collapse

Instance Method Details

#find_all_assets_by_name_including_samples!(names) ⇒ Object


10
11
12
13
14
15
# File 'app/models/submission/asset_submission_finder.rb', line 10

def find_all_assets_by_name_including_samples!(names)
  Receptacle.for_bulk_submission.named(names).tap do |found|
    missing = names - found.map(&:name)
    raise ActiveRecord::RecordNotFound, "Could not find Labware with names #{missing.inspect}" if missing.present?
  end
end

#find_tubes_including_samples_for!(details) ⇒ Object


31
32
33
34
35
36
# File 'app/models/submission/asset_submission_finder.rb', line 31

def find_tubes_including_samples_for!(details)
  Receptacle.on_a(Tube).for_bulk_submission.with_barcode(details['barcode']).tap do |found|
    missing = details['barcode'].reject { |barcode| found.any? { |tube| tube.any_barcode_matching?(barcode) } }
    raise ActiveRecord::RecordNotFound, "Could not find Tubes with barcodes #{missing.inspect}" if missing.present?
  end
end

#find_wells_including_samples_for!(details) ⇒ Object

Raises:

  • (StandardError)

17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/submission/asset_submission_finder.rb', line 17

def find_wells_including_samples_for!(details)
  barcodes, well_list = details['barcode'], details['plate well']
  errors.add(:spreadsheet, 'You can only specify one plate per asset group') unless barcodes.uniq.one?
  barcode = barcodes.first
  plate = Plate.find_from_barcode(barcode)
  raise StandardError, "Cannot find plate with barcode #{barcode} for #{details['rows']}" if plate.nil?

  well_locations = well_list.map(&:strip)
  wells = plate.wells.for_bulk_submission.located_at(well_locations)
  raise StandardError, "Too few wells found for #{details['rows']}: #{wells.map(&:map).map(&:description).inspect}" if wells.length != well_locations.size

  wells
end

#is_plate?(details) ⇒ Boolean


2
3
4
# File 'app/models/submission/asset_submission_finder.rb', line 2

def is_plate?(details)
  details['barcode'].present? && details['plate well'].present?
end

#is_tube?(details) ⇒ Boolean


6
7
8
# File 'app/models/submission/asset_submission_finder.rb', line 6

def is_tube?(details)
  details['barcode'].present? && details['plate well'].blank?
end