Class: PlatePurpose::Input

Inherits:
PlatePurpose show all
Defined in:
app/models/plate_purpose/input.rb

Overview

Note:

Limber should probably make decisions about plate state itself. This would increase flexibility, such as by allowing library-manifest plates to pass straight in to the pipeline.

Input Plate purposes are the initial stock plates passing into external piplines. They have special behaviour governing their state. This essentially makes sure that all non-empty wells on a plate have requests out of them before the plate it ‘passed’. This is intended to ensure that submissions have been correctly built before a plate has processed.

  • Input plates are passed when all sample containing wells have requests out of them

Constant Summary collapse

UNREADY_STATE =
'pending'
READY_STATE =
'passed'
WELL_STATE_PRIORITY =
%w[pending started passed failed cancelled].freeze

Instance Method Summary collapse

Methods inherited from PlatePurpose

#asset_shape, #attached?, #cherrypick_completed, #cherrypick_in_rows?, #child_plate_purposes, #create!, #input_plate=, #plate_height, #plate_width, #pool_wells, #size, #source_wells_for, stock_plate_purpose

Methods included from Api::PlatePurposeIo::Extensions

included, #json_root

Methods included from Purpose::Relationship::Associations

included

Methods inherited from Purpose

#barcode_type, #prefix=, #set_default_barcode_prefix, #source_plate, #source_plates, #source_purpose_name=, #target_class

Methods included from Uuid::Uuidable

included, #unsaved_uuid!, #uuid

Methods included from SharedBehaviour::Named

included

Methods inherited from ApplicationRecord

alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

Instance Method Details

#state_of(plate) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/plate_purpose/input.rb', line 21

def state_of(plate)
  # If there are no wells with aliquots we're pending
  ids_of_wells_with_aliquots = plate.wells.with_aliquots.ids.uniq
  return UNREADY_STATE if ids_of_wells_with_aliquots.empty?

  # All of the wells with aliquots must have customer requests for us to consider the plate passed
  well_requests = CustomerRequest.where(asset_id: ids_of_wells_with_aliquots)

  wells_states =
    well_requests.group_by(&:asset_id).values.map { |requests| calculate_state_of_well(requests.map(&:state)) }

  return UNREADY_STATE unless wells_states.count == ids_of_wells_with_aliquots.count

  calculate_state_of_plate(wells_states)
end