Class: Aker::Container

Inherits:
ApplicationRecord show all
Defined in:
app/models/aker/container.rb

Overview

Phisical container for the biomaterial

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Warren::BroadcastMessages

#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren

Class Method Details

.tube_address?(address) ⇒ Boolean

Returns:

  • (Boolean)

51
52
53
# File 'app/models/aker/container.rb', line 51

def self.tube_address?(address)
  (address =~ /^\d/) || address.nil?
end

Instance Method Details

#a_well?Boolean

Returns:

  • (Boolean)

43
44
45
46
47
48
49
# File 'app/models/aker/container.rb', line 43

def a_well?
  if asset
    asset.is_a? Well
  else
    !self.class.tube_address?(address)
  end
end

#aliquots?Boolean

Returns:

  • (Boolean)

74
75
76
# File 'app/models/aker/container.rb', line 74

def aliquots?
  asset.aliquots.count.positive?
end

#amountObject


29
30
31
32
33
# File 'app/models/aker/container.rb', line 29

def amount
  return (volume.to_f * concentration.to_f).to_s if volume && concentration

  nil
end

#as_json(_options = {}) ⇒ Object


55
56
57
58
59
60
# File 'app/models/aker/container.rb', line 55

def as_json(_options = {})
  {
    barcode: barcode,
    address: address
  }.compact
end

#concentrationObject


21
22
23
24
25
26
27
# File 'app/models/aker/container.rb', line 21

def concentration
  value = asset.get_qc_result_value_for('concentration')
  return value if value
  return asset.concentration unless a_well?

  asset.well_attribute.concentration
end

#contains_sample?(sample) ⇒ Boolean

Returns:

  • (Boolean)

70
71
72
# File 'app/models/aker/container.rb', line 70

def contains_sample?(sample)
  asset.aliquots.where(sample: sample).count.positive?
end

#not_change_addressObject


39
40
41
# File 'app/models/aker/container.rb', line 39

def not_change_address
  errors.add(:address, 'Cannot modify address') if persisted? && address_changed?
end

#not_change_barcodeObject


35
36
37
# File 'app/models/aker/container.rb', line 35

def not_change_barcode
  errors.add(:barcode, 'Cannot modify barcode') if persisted? && barcode_changed?
end

#put_sample_in_container(sample, study) ⇒ Object


62
63
64
65
66
67
68
# File 'app/models/aker/container.rb', line 62

def put_sample_in_container(sample, study)
  save if asset.nil?
  sample.update(container: self)
  raise 'The contents of this plate are not up to date with aker job message' if !contains_sample?(sample) && aliquots?

  asset.aliquots.create!(sample: sample, study: study) unless contains_sample?(sample)
end

#volumeObject


13
14
15
16
17
18
19
# File 'app/models/aker/container.rb', line 13

def volume
  value = asset.get_qc_result_value_for('volume')
  return value if value
  return asset.volume unless a_well?

  asset.well_attribute.current_volume
end