Module: Tasks::PlateTransferHandler

Included in:
WorkflowsController
Defined in:
app/models/tasks/plate_transfer_handler.rb

Defined Under Namespace

Classes: InvalidBatch

Instance Method Summary collapse

Instance Method Details

#do_plate_transfer_task(_task, _params) ⇒ Object


55
56
57
58
# File 'app/models/tasks/plate_transfer_handler.rb', line 55

def do_plate_transfer_task(_task, _params)
  target_plate.transition_to('passed', current_user) unless target_plate.state == 'passed'
  true
end

#find_or_create_target(task) ⇒ Object

Raises:


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/tasks/plate_transfer_handler.rb', line 14

def find_or_create_target(task)
  return target_plate if target_plate.present?

  # We only eager load the request stuff if we actually need it.
  batch_requests = @batch.requests.includes(includes_for_plate_creation)
  source_wells = batch_requests.map(&:asset)
  raise InvalidBatch if unsuitable_wells?(source_wells)

  task.purpose.create!.tap do |target|
    well_map = Hash[target.wells.map { |well| [well.map_id, well] }]

    batch_requests.each do |outer_request|
      source = outer_request.asset
      TransferRequest.create!(
        asset: source,
        target_asset: well_map[source.map_id],
        submission_id: outer_request.submission_id
      )
      TransferRequest.create!(
        asset: well_map[source.map_id],
        target_asset: outer_request.target_asset,
        submission_id: outer_request.submission_id
      )
    end
  end
end

#includes_for_plate_creationObject


10
11
12
# File 'app/models/tasks/plate_transfer_handler.rb', line 10

def includes_for_plate_creation
  [{ asset: [:map, { plate: [:plate_purpose, :barcodes] }, :aliquots] }, { target_asset: [] }]
end

#render_plate_transfer_task(task, _params) ⇒ Object


4
5
6
7
8
# File 'app/models/tasks/plate_transfer_handler.rb', line 4

def render_plate_transfer_task(task, _params)
  ActiveRecord::Base.transaction do
    @target = find_or_create_target(task)
  end
end

#target_plateObject


41
42
43
44
45
46
47
48
# File 'app/models/tasks/plate_transfer_handler.rb', line 41

def target_plate
  transfer = TransferRequest.for_request(@batch.requests.first)
                            .where(submission_id: @batch.requests.first.submission_id)
                            .includes(target_asset: :plate).first
  return nil unless transfer.present?

  transfer.target_asset.plate
end