Class: Labware

Inherits:
Asset show all
Includes:
AssetLink::Associations, Commentable, SharedBehaviour::Named, Uuid::Uuidable
Defined in:
app/models/labware.rb

Overview

Labware represents a physical object which moves around the lab. It has one or more receptacles.

Direct Known Subclasses

Fragment, Lane::Labware, Plate, Tube, TubeRack

Defined Under Namespace

Classes: CommentsController

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedBehaviour::Named

included

Methods included from AssetLink::Associations

included

Methods included from Uuid::Uuidable

included, #unsaved_uuid!, #uuid

Methods included from Commentable

#after_comment_addition

Methods inherited from Asset

#add_parent, #asset_type_for_request_types, #assign_relationships, #barcode_number, #compatible_purposes, #contained_samples, #details, #external_identifier, #generate_barcode, #get_qc_result_value_for, #has_stock_asset?, #label, #label=, #original_stock_plates, #prefix, #printable?, #printable_target, #register_stock!, #request_types, #spiked_in_buffer, #summary_hash, #type, #update_from_qc

Methods included from EventfulRecord

#has_many_events, #has_many_lab_events, #has_one_event_with_family

Methods included from Event::PlateEvents

#event_date, #fluidigm_stamp_date, #gel_qc_date, #pico_date, #qc_started_date, #sequenom_stamp_date

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

Methods included from Warren::BroadcastMessages

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

Instance Attribute Details

#storage_location_serviceObject (readonly)

Returns the value of attribute storage_location_service


11
12
13
# File 'app/models/labware.rb', line 11

def storage_location_service
  @storage_location_service
end

Class Method Details

.find_by_barcode(source_barcode) ⇒ Object Also known as: find_from_barcode


229
230
231
# File 'app/models/labware.rb', line 229

def find_by_barcode(source_barcode)
  with_barcode(source_barcode).first
end

.find_from_any_barcode(source_barcode) ⇒ Object


219
220
221
222
223
224
225
226
227
# File 'app/models/labware.rb', line 219

def find_from_any_barcode(source_barcode)
  if source_barcode.blank?
    nil
  elsif /\A[0-9]{1,7}\z/.match?(source_barcode) # Just a number
    joins(:barcodes).where('barcodes.barcode LIKE "__?_"', source_barcode).first # rubocop:disable Rails/FindBy
  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


199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'app/models/labware.rb', line 199

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({}) do |info, obj|
    obj[info.barcode] = info.location.location_info
  end

  unless labware_barcodes.count == barcodes_to_parentage.count
    labware_barcodes.each do |barcode|
      # add missing barcodes to the hash, with an empty string for location, for ones that Labwhere didn't return
      barcodes_to_parentage[barcode] ||= ''
    end
  end
  barcodes_to_parentage
end

Instance Method Details

#ancestor_of_purpose(ancestor_purpose_id) ⇒ Object


137
138
139
140
141
# File 'app/models/labware.rb', line 137

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


143
144
145
146
147
# File 'app/models/labware.rb', line 143

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

#childObject


239
240
241
# File 'app/models/labware.rb', line 239

def child
  children.last
end

#display_nameObject


172
173
174
# File 'app/models/labware.rb', line 172

def display_name
  name.presence || "#{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


168
169
170
# File 'app/models/labware.rb', line 168

def generate_name(new_name)
  self.name = new_name
end

#human_barcodeObject


149
150
151
# File 'app/models/labware.rb', line 149

def human_barcode
  'UNKNOWN'
end

#labwareObject

Labware reflects the physical piece of plastic corresponding to an asset


181
182
183
# File 'app/models/labware.rb', line 181

def labware
  self
end

#labwhere_locationObject


176
177
178
# File 'app/models/labware.rb', line 176

def labwhere_location
  @labwhere_location ||= lookup_labwhere_location
end

#parentObject


235
236
237
# File 'app/models/labware.rb', line 235

def parent
  parents.first
end

#roleObject


153
154
155
# File 'app/models/labware.rb', line 153

def role
  (requests_as_source.first || in_progress_requests.first)&.role
end

#scanned_in_dateObject


189
190
191
# File 'app/models/labware.rb', line 189

def scanned_in_date
  scanned_into_lab_event.try(:content) || ''
end

#source_plateObject


157
158
159
# File 'app/models/labware.rb', line 157

def source_plate
  @source_plate ||= purpose&.source_plate(self)
end

#source_platesObject


161
162
163
# File 'app/models/labware.rb', line 161

def source_plates
  @source_plates ||= purpose&.source_plates(self)
end

#storage_locationObject


185
186
187
# File 'app/models/labware.rb', line 185

def storage_location
  @storage_location ||= obtain_storage_location
end