Class: Labware
Overview
Labware represents a physical object which moves around the lab.
It has one or more receptacles.
rubocop:disable Metrics/ClassLength
Defined Under Namespace
Classes: CommentsController
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included
included
included, #unsaved_uuid!, #uuid
#after_comment_addition
Methods inherited from Asset
#asset_type_for_request_types, #barcode_number, #compatible_purposes, #contained_samples, #details, #generate_barcode, #get_qc_result_value_for, #has_stock_asset?, #label, #label=, #original_stock_plates, #prefix, #printable?, #printable_target, #register_stock!, #request_types, #type, #update_from_qc
#has_many_events, #has_many_lab_events, #has_one_event_with_family
#event_date, #fluidigm_stamp_date, #gel_qc_date, #pico_date, #qc_started_date, #sequenom_stamp_date
alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!
Methods included from Squishify
extended
Instance Attribute Details
#storage_location_service ⇒ Object
Returns the value of attribute storage_location_service.
12
13
14
|
# File 'app/models/labware.rb', line 12
def storage_location_service
@storage_location_service
end
|
Class Method Details
.find_by_barcode(source_barcode) ⇒ Object
Also known as:
find_from_barcode
335
336
337
|
# File 'app/models/labware.rb', line 335
def find_by_barcode(source_barcode)
with_barcode(source_barcode).first
end
|
.find_from_any_barcode(source_barcode) ⇒ Object
324
325
326
327
328
329
330
331
332
333
|
# File 'app/models/labware.rb', line 324
def find_from_any_barcode(source_barcode)
if source_barcode.blank?
nil
elsif /\A[0-9]{1,7}\z/.match?(source_barcode)
joins(:barcodes).order(:id).find_by('barcodes.barcode LIKE "__?_"', source_barcode)
else
find_by_barcode(source_barcode)
end
end
|
.labwhere_locations(labware_barcodes) ⇒ Object
Bulk retrieves locations for multiple labwares at once
Returns hash { labware barcode => location string, .. } e.g. { 'DN1234' => 'Sanger - Room 1 - Shelf 2' }
Hash has blank values where location was not found for a particular barcode
Or raises LabWhereClient::LabwhereException if Labwhere response is unexpected
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
# File 'app/models/labware.rb', line 305
def labwhere_locations(labware_barcodes) info_from_labwhere = LabWhereClient::LabwareSearch.find_locations_by_barcodes(labware_barcodes)
if info_from_labwhere.blank?
raise LabWhereClient::LabwhereException, 'Labwhere service did not return information'
end
barcodes_to_parentage =
info_from_labwhere.labwares.each_with_object({}) { |info, obj| obj[info.barcode] = info.location.location_info }
unless labware_barcodes.count == barcodes_to_parentage.count
labware_barcodes.each do |barcode|
barcodes_to_parentage[barcode] ||= ''
end
end
barcodes_to_parentage
end
|
.map_retention_instructions(values) ⇒ Object
158
159
160
161
162
|
# File 'app/models/labware.rb', line 158
def self.map_retention_instructions(values)
return if values.blank?
values.filter_map { |v| Labware.retention_instructions[v] }
end
|
.search_for_count_of_labware(params) ⇒ Object
176
177
178
179
180
181
182
183
184
|
# File 'app/models/labware.rb', line 176
def self.search_for_count_of_labware(params)
(params[:faculty_sponsor_ids] || nil)
.with_study_id(params[:study_id] || nil)
.with_plate_purpose_ids(params[:plate_purpose_ids] || nil)
.created_between(params[:start_date], params[:end_date])
.filter_by_barcode(params[:barcodes] || nil)
.distinct
.count
end
|
.search_for_labware(params) ⇒ Object
164
165
166
167
168
169
170
171
172
173
174
|
# File 'app/models/labware.rb', line 164
def self.search_for_labware(params)
(params[:faculty_sponsor_ids] || nil)
.with_study_id(params[:study_id] || nil)
.with_plate_purpose_ids(params[:plate_purpose_ids] || nil)
.created_between(params[:start_date], params[:end_date])
.filter_by_barcode(params[:barcodes] || nil)
.with_retention_instructions(
map_retention_instructions(params[:retention_instructions])
)
.distinct
end
|
Instance Method Details
#ancestor_of_purpose(ancestor_purpose_id) ⇒ Object
227
228
229
230
231
|
# File 'app/models/labware.rb', line 227
def ancestor_of_purpose(ancestor_purpose_id)
return self if plate_purpose_id == ancestor_purpose_id
ancestors.order(id: :desc).find_by(plate_purpose_id: ancestor_purpose_id)
end
|
#ancestors_of_purpose(ancestor_purpose_id) ⇒ Object
233
234
235
236
237
|
# File 'app/models/labware.rb', line 233
def ancestors_of_purpose(ancestor_purpose_id)
return [self] if plate_purpose_id == ancestor_purpose_id
ancestors.order(id: :desc).where(plate_purpose_id: ancestor_purpose_id)
end
|
#child ⇒ Object
345
346
347
|
# File 'app/models/labware.rb', line 345
def child
children.last
end
|
#display_name ⇒ Object
266
267
268
|
# File 'app/models/labware.rb', line 266
def display_name
name.presence || "#{sti_type} #{id}"
end
|
#external_identifier ⇒ Object
223
224
225
|
# File 'app/models/labware.rb', line 223
def external_identifier
"#{sti_type}#{id}"
end
|
#generate_name(new_name) ⇒ Object
Note:
Overridden on subclasses to append the asset id to the name
via on_create callbacks
Assigns name
262
263
264
|
# File 'app/models/labware.rb', line 262
def generate_name(new_name)
self.name = new_name
end
|
#labware ⇒ Object
Labware reflects the physical piece of plastic corresponding to an asset
275
276
277
|
# File 'app/models/labware.rb', line 275
def labware
self
end
|
#labwhere_location ⇒ Object
270
271
272
|
# File 'app/models/labware.rb', line 270
def labwhere_location
@labwhere_location ||= lookup_labwhere_location
end
|
#parent ⇒ Object
341
342
343
|
# File 'app/models/labware.rb', line 341
def parent
parents.first
end
|
#received_date ⇒ Object
287
288
289
290
291
292
293
|
# File 'app/models/labware.rb', line 287
def received_date
asset_audits &.where('`key` = ? AND message LIKE ?', 'slf_receive_plates', '%Reception fridge%')
&.order(:created_at)
&.last
&.created_at
end
|
#retention_instructions ⇒ Object
295
296
297
|
# File 'app/models/labware.rb', line 295
def retention_instructions
@retention_instructions ||= obtain_retention_instructions
end
|
#role ⇒ Object
247
248
249
|
# File 'app/models/labware.rb', line 247
def role
(requests_as_source.first || in_progress_requests.first)&.role
end
|
#scanned_in_date ⇒ Object
283
284
285
|
# File 'app/models/labware.rb', line 283
def scanned_in_date
scanned_into_lab_event.try(:content) || ''
end
|
#source_plate ⇒ Object
251
252
253
|
# File 'app/models/labware.rb', line 251
def source_plate
@source_plate ||= purpose&.source_plate(self)
end
|
#source_plates ⇒ Object
255
256
257
|
# File 'app/models/labware.rb', line 255
def source_plates
@source_plates ||= purpose&.source_plates(self)
end
|
#spiked_in_buffer ⇒ Object
Gets the relevant SpikedBuffer tube, if one exists, by using the two associations.
A direct parent SpikedBuffer tube is used if it exists, otherwise the most recent ancestor.
This was necessary to avoid affecting historical data, for which the direct parent should be used,
even though there is another ancestor that was created more recently.
243
244
245
|
# File 'app/models/labware.rb', line 243
def spiked_in_buffer
direct_spiked_in_buffer || most_recent_spiked_in_buffer
end
|
#state ⇒ Object
Provided for API compatibility
219
220
221
|
# File 'app/models/labware.rb', line 219
def state
nil
end
|
#storage_location ⇒ Object
279
280
281
|
# File 'app/models/labware.rb', line 279
def storage_location
@storage_location ||= obtain_storage_location
end
|