Class: QcResultFactory::Resource

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/qc_result_factory.rb

Overview

QcResultFactory::Resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Resource

Returns a new instance of Resource


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

def initialize(attributes = {})
  super(attributes)

  @asset = build_asset
  @qc_result = QcResult.new(asset: asset, key: key, value: value, units: units, cv: cv, assay_type: assay_type, assay_version: assay_version, qc_assay: qc_assay)
end

Instance Attribute Details

#assay_typeObject

Returns the value of attribute assay_type


56
57
58
# File 'app/models/qc_result_factory.rb', line 56

def assay_type
  @assay_type
end

#assay_versionObject

Returns the value of attribute assay_version


56
57
58
# File 'app/models/qc_result_factory.rb', line 56

def assay_version
  @assay_version
end

#assetObject (readonly)

Returns the value of attribute asset


58
59
60
# File 'app/models/qc_result_factory.rb', line 58

def asset
  @asset
end

#asset_identifierObject (readonly)

Returns the value of attribute asset_identifier


58
59
60
# File 'app/models/qc_result_factory.rb', line 58

def asset_identifier
  @asset_identifier
end

#barcodeObject

Returns the value of attribute barcode


58
59
60
# File 'app/models/qc_result_factory.rb', line 58

def barcode
  @barcode
end

#cvObject

Returns the value of attribute cv


56
57
58
# File 'app/models/qc_result_factory.rb', line 56

def cv
  @cv
end

#keyObject

Returns the value of attribute key


56
57
58
# File 'app/models/qc_result_factory.rb', line 56

def key
  @key
end

#plateObject (readonly)

Returns the value of attribute plate


58
59
60
# File 'app/models/qc_result_factory.rb', line 58

def plate
  @plate
end

#qc_assayObject

Returns the value of attribute qc_assay


56
57
58
# File 'app/models/qc_result_factory.rb', line 56

def qc_assay
  @qc_assay
end

#qc_resultObject (readonly)

Returns the value of attribute qc_result


58
59
60
# File 'app/models/qc_result_factory.rb', line 58

def qc_result
  @qc_result
end

#unitsObject

Returns the value of attribute units


56
57
58
# File 'app/models/qc_result_factory.rb', line 56

def units
  @units
end

#uuidObject

Returns the value of attribute uuid


58
59
60
# File 'app/models/qc_result_factory.rb', line 58

def uuid
  @uuid
end

#valueObject

Returns the value of attribute value


56
57
58
# File 'app/models/qc_result_factory.rb', line 56

def value
  @value
end

#well_locationObject

Returns the value of attribute well_location


56
57
58
# File 'app/models/qc_result_factory.rb', line 56

def well_location
  @well_location
end

Instance Method Details

#blank_well?Boolean

Returns:

  • (Boolean)

140
141
142
# File 'app/models/qc_result_factory.rb', line 140

def blank_well?
  asset.blank? && well_location.present?
end

#build_assetObject

This is where the complexity is. First we need to find the uuid object. Then we need to return the asset it relates to. If the object is a sample we need to return it's primary receptacle which will be a well. If the object is a tube then do nothing just return the asset. If a well location is passed then assume it is a plate so we need to return the associated well.


104
105
106
107
108
109
110
111
# File 'app/models/qc_result_factory.rb', line 104

def build_asset
  asset = uuid || barcode
  return if asset.blank?
  return asset if well_location.blank?

  @plate = Plate.find(asset.id)
  plate.find_well_by_map_description(well_location)
end

#can_update_parent_well?Boolean

Returns:

  • (Boolean)

128
129
130
# File 'app/models/qc_result_factory.rb', line 128

def can_update_parent_well?
  working_dilution? && concentration? && well_location.present? && plate.dilution_factor.present?
end

#concentration?Boolean

Returns:

  • (Boolean)

124
125
126
# File 'app/models/qc_result_factory.rb', line 124

def concentration?
  key == 'concentration'
end

#message_idObject


69
70
71
# File 'app/models/qc_result_factory.rb', line 69

def message_id
  "Asset identifier - #{(asset_identifier || 'blank')}"
end

#parent_plateObject


73
74
75
# File 'app/models/qc_result_factory.rb', line 73

def parent_plate
  @parent_plate ||= plate.parent
end

#saveObject


113
114
115
116
117
118
# File 'app/models/qc_result_factory.rb', line 113

def save
  return false unless valid?

  update_parent_well
  qc_result.save
end

#update_parent_wellObject


132
133
134
135
136
137
138
# File 'app/models/qc_result_factory.rb', line 132

def update_parent_well
  return unless can_update_parent_well?

  well = parent_plate.find_well_by_map_description(well_location)
  parent_qc_result = QcResult.new(qc_result.attributes.merge(asset: well, value: value.to_f * plate.dilution_factor))
  parent_qc_result.save!
end

#working_dilution?Boolean

Returns:

  • (Boolean)

120
121
122
# File 'app/models/qc_result_factory.rb', line 120

def working_dilution?
  plate.instance_of? WorkingDilutionPlate
end