Class: ExtractionAttribute
Defined Under Namespace
Classes: SampleTubeNotExists, WellAlreadyHasSample, WellNotExists
Instance Method Summary
collapse
included, #unsaved_uuid!, #uuid
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
#attributes_update_with_resources ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'app/models/extraction_attribute.rb', line 39
def attributes_update_with_resources
attributes_update.map do |attr_well|
resources = {
'resource' => find_resources(attr_well, 'uuid'),
'sample_tube_resource' => find_resources(attr_well, 'sample_tube_uuid')
}.compact
attr_well.merge(resources)
end
end
|
#disallow_wells_with_multiple_samples!(destination_well, samples) ⇒ Object
61
62
63
|
# File 'app/models/extraction_attribute.rb', line 61
def disallow_wells_with_multiple_samples!(destination_well, samples)
raise WellAlreadyHasSample if (destination_well.samples.count > 0) && (destination_well.samples != samples)
end
|
#find_resources(attr_well, attr_well_uuid_key) ⇒ Object
33
34
35
36
37
|
# File 'app/models/extraction_attribute.rb', line 33
def find_resources(attr_well, attr_well_uuid_key)
return unless attr_well
Uuid.find_by(external_id: attr_well[attr_well_uuid_key]).resource if attr_well[attr_well_uuid_key]
end
|
#is_reracking?(well_info) ⇒ Boolean
26
27
28
29
30
31
|
# File 'app/models/extraction_attribute.rb', line 26
def is_reracking?(well_info)
well = well_info['resource']
return false unless well
(well.plate != target) || (well.map_description != well_info['location'])
end
|
#location_wells ⇒ Object
57
58
59
|
# File 'app/models/extraction_attribute.rb', line 57
def location_wells
target.wells.includes(:map, :samples, :aliquots).index_by(&:map_description)
end
|
#rack_well(well_data) ⇒ Object
rubocop:todo Metrics/MethodLength
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'app/models/extraction_attribute.rb', line 77
def rack_well(well_data) return unless well_data && well_data['sample_tube_uuid']
raise SampleTubeNotExists unless well_data['sample_tube_resource']
sample_tube = well_data['sample_tube_resource']
aliquots = sample_tube.aliquots.map(&:dup)
samples = sample_tube.samples
location = well_data['location']
destination_well = location_wells[location]
if validate_well_for_racking_samples!(destination_well, samples)
destination_well.aliquots << aliquots
AssetLink.create_edge(sample_tube, destination_well)
end
end
|
#rerack_well(well_data) ⇒ Object
rubocop:todo Metrics/AbcSize
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'app/models/extraction_attribute.rb', line 93
def rerack_well(well_data) return unless well_data
well = well_data['resource']
actual_parent = target
location = well_data['location']
actual_well_in_same_position_at_rack = target.wells.located_at(location).first
actual_map = target.maps.detect { |m| m.description == location }
raise WellNotExists if actual_map.nil?
actual_well_in_same_position_at_rack&.update!(plate: nil)
well.labware_id_will_change!
well.update!(plate: actual_parent, map: actual_map)
end
|
#validate_well_for_racking_samples!(destination_well, samples) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/models/extraction_attribute.rb', line 65
def validate_well_for_racking_samples!(destination_well, samples)
unless destination_well
raise WellNotExists
end
disallow_wells_with_multiple_samples!(destination_well, samples)
samples.all? { |sample| destination_well.samples.exclude?(sample) }
end
|