Class: IlluminaHtp::MxTubePurpose

Inherits:
Tube::Purpose
  • Object
show all
Defined in:
app/models/illumina_htp/mx_tube_purpose.rb

Instance Method Summary collapse

Instance Method Details

#customer_requests(tube) ⇒ Object


19
20
21
# File 'app/models/illumina_htp/mx_tube_purpose.rb', line 19

def customer_requests(tube)
  tube.requests_as_target.for_billing.where(state: Request::Statemachine::OPENED_STATE)
end

#library_source_plates(tube) ⇒ Object


31
32
33
# File 'app/models/illumina_htp/mx_tube_purpose.rb', line 31

def library_source_plates(tube)
  source_plate_scope(tube).map(&:source_plate)
end

#source_plate(tube) ⇒ Object


27
28
29
# File 'app/models/illumina_htp/mx_tube_purpose.rb', line 27

def source_plate(tube)
  super || source_plate_scope(tube).first
end

#source_plate_scope(tube) ⇒ Object


35
36
37
38
39
40
41
42
# File 'app/models/illumina_htp/mx_tube_purpose.rb', line 35

def source_plate_scope(tube)
  Plate
    .joins(wells: :requests)
    .where(requests: {
             target_asset_id: tube.id,
             sti_type: [Request::Multiplexing, Request::AutoMultiplexing, Request::LibraryCreation, *Request::LibraryCreation.descendants].map(&:name)
           }).distinct
end

#stock_plate(tube) ⇒ Object


23
24
25
# File 'app/models/illumina_htp/mx_tube_purpose.rb', line 23

def stock_plate(tube)
  tube.requests_as_target.where.not(requests: { asset_id: nil }).first&.asset&.plate
end

#transition_customer_requests(tube, state, user, customer_accepts_responsibility) ⇒ Object


9
10
11
12
13
14
15
16
17
# File 'app/models/illumina_htp/mx_tube_purpose.rb', line 9

def transition_customer_requests(tube, state, user, customer_accepts_responsibility)
  orders = Set.new
  customer_requests(tube).each do |request|
    request.customer_accepts_responsibility! if customer_accepts_responsibility
    request.transition_to(state)
    orders << request.order.id
  end
  generate_events_for(tube, orders, user) if state == 'passed'
end

#transition_to(tube, state, user, _ = nil, customer_accepts_responsibility = false) ⇒ Object


4
5
6
7
# File 'app/models/illumina_htp/mx_tube_purpose.rb', line 4

def transition_to(tube, state, user, _ = nil, customer_accepts_responsibility = false)
  transition_customer_requests(tube, mappings[state], user, customer_accepts_responsibility) if mappings[state]
  tube.transfer_requests_as_target.each { |request| request.transition_to(state) }
end