Class: RobotVerification

Inherits:
Object
  • Object
show all
Defined in:
app/models/robot_verification.rb

Direct Known Subclasses

Tecan

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors


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

def errors
  @errors
end

Instance Method Details

#expected_layout(batch, destination_plate_barcode) ⇒ Object


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

def expected_layout(batch, destination_plate_barcode)
  batch.tecan_layout_plate_barcodes(destination_plate_barcode)
end

#set_plate_types(plate_types_params) ⇒ Object


49
50
51
52
53
54
55
56
57
# File 'app/models/robot_verification.rb', line 49

def set_plate_types(plate_types_params)
  plate_types_params.each do |plate_barcode, plate_type|
    next if plate_barcode.blank? || plate_type.blank?

    plate = Plate.with_barcode(plate_barcode).first or raise "Unable to locate plate #{plate_barcode.inspect} for robot verification"
    plate.plate_type = plate_type
    plate.save!
  end
end

#valid_submission?(params) ⇒ Boolean

Returns:

  • (Boolean)

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/robot_verification.rb', line 17

def valid_submission?(params)
  destination_plate_barcode = params[:barcodes][:destination_plate_barcode]
  batch = Batch.find_by(id: params[:batch_id])
  robot = Robot.find_by(id: params[:robot_id])
  user = User.find_by(id: params[:user_id])

  @errors = []
  @errors << "Could not find batch #{params[:batch_id]}" if batch.nil?
  @eerors << 'Could not find robot' if robot.nil?
  @errors << 'Could not find user' if user.nil?
  @errors << 'No destination barcode specified' if destination_plate_barcode.blank?
  return false unless @errors.empty?

  expected_plate_layout = expected_layout(batch, destination_plate_barcode)

  if valid_plate_locations?(params, batch, robot, expected_plate_layout)
    batch.events.create(
      message: I18n.t('bed_verification.layout.valid', plate_barcode: destination_plate_barcode),
      created_by: user.
    )
  else
    batch.events.create(
      message: I18n.t('bed_verification.layout.invalid', plate_barcode: destination_plate_barcode),
      created_by: user.
    )
    @errors << 'Bed layout invalid'
    return false
  end

  true
end

#validate_barcode_params(barcode_hash) {|'Worksheet barcode invalid'| ... } ⇒ Object

Yields:

  • ('Worksheet barcode invalid')

4
5
6
7
8
9
10
11
# File 'app/models/robot_verification.rb', line 4

def validate_barcode_params(barcode_hash)
  return yield('No barcodes specified')      if barcode_hash.nil?

  yield('Worksheet barcode invalid')         if barcode_hash[:batch_barcode].blank?             or not Batch.valid_barcode?(barcode_hash[:batch_barcode])
  yield('Tecan robot barcode invalid')       if barcode_hash[:robot_barcode].blank?             or not Robot.valid_barcode?(barcode_hash[:robot_barcode])
  yield('User barcode invalid')              if barcode_hash[:user_barcode].blank?              or not User.find_with_barcode_or_swipecard_code(barcode_hash[:user_barcode])
  yield('Destination plate barcode invalid') if barcode_hash[:destination_plate_barcode].blank? or not Plate.with_barcode(barcode_hash[:destination_plate_barcode]).exists?
end