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.


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/qc_result_factory.rb', line 58

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.


52
53
54
# File 'app/models/qc_result_factory.rb', line 52

def assay_type
  @assay_type
end

#assay_versionObject

Returns the value of attribute assay_version.


52
53
54
# File 'app/models/qc_result_factory.rb', line 52

def assay_version
  @assay_version
end

#assetObject (readonly)

Returns the value of attribute asset.


54
55
56
# File 'app/models/qc_result_factory.rb', line 54

def asset
  @asset
end

#asset_identifierObject (readonly)

Returns the value of attribute asset_identifier.


54
55
56
# File 'app/models/qc_result_factory.rb', line 54

def asset_identifier
  @asset_identifier
end

#barcodeObject

Returns the value of attribute barcode.


54
55
56
# File 'app/models/qc_result_factory.rb', line 54

def barcode
  @barcode
end

#cvObject

Returns the value of attribute cv.


52
53
54
# File 'app/models/qc_result_factory.rb', line 52

def cv
  @cv
end

#keyObject

Returns the value of attribute key.


52
53
54
# File 'app/models/qc_result_factory.rb', line 52

def key
  @key
end

#plateObject (readonly)

Returns the value of attribute plate.


54
55
56
# File 'app/models/qc_result_factory.rb', line 54

def plate
  @plate
end

#qc_assayObject

Returns the value of attribute qc_assay.


52
53
54
# File 'app/models/qc_result_factory.rb', line 52

def qc_assay
  @qc_assay
end

#qc_resultObject (readonly)

Returns the value of attribute qc_result.


54
55
56
# File 'app/models/qc_result_factory.rb', line 54

def qc_result
  @qc_result
end

#unitsObject

Returns the value of attribute units.


52
53
54
# File 'app/models/qc_result_factory.rb', line 52

def units
  @units
end

#uuidObject

Returns the value of attribute uuid.


54
55
56
# File 'app/models/qc_result_factory.rb', line 54

def uuid
  @uuid
end

#valueObject

Returns the value of attribute value.


52
53
54
# File 'app/models/qc_result_factory.rb', line 52

def value
  @value
end

#well_locationObject

Returns the value of attribute well_location.


52
53
54
# File 'app/models/qc_result_factory.rb', line 52

def well_location
  @well_location
end

Instance Method Details

#blank_well?Boolean

Returns:

  • (Boolean)

143
144
145
# File 'app/models/qc_result_factory.rb', line 143

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.


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

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)

130
131
132
# File 'app/models/qc_result_factory.rb', line 130

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

#concentration?Boolean

Returns:

  • (Boolean)

126
127
128
# File 'app/models/qc_result_factory.rb', line 126

def concentration?
  key == 'concentration'
end

#message_idObject


75
76
77
# File 'app/models/qc_result_factory.rb', line 75

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

#parent_plateObject


79
80
81
# File 'app/models/qc_result_factory.rb', line 79

def parent_plate
  @parent_plate ||= plate.parent
end

#saveObject


115
116
117
118
119
120
# File 'app/models/qc_result_factory.rb', line 115

def save
  return false unless valid?

  update_parent_well
  qc_result.save
end

#update_parent_wellObject


134
135
136
137
138
139
140
141
# File 'app/models/qc_result_factory.rb', line 134

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)

122
123
124
# File 'app/models/qc_result_factory.rb', line 122

def working_dilution?
  plate.instance_of? WorkingDilutionPlate
end