Class: CaTissue::SpecimenRequirement

Inherits:
Object
  • Object
show all
Includes:
Resource
Defined in:
lib/catissue/domain/specimen_requirement.rb

Overview

The SpecimenRequirement domain class.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

#database, included, #tolerant_match?

Methods included from Annotatable

#annotation_proxy, #create_proxy, #method_missing

Constructor Details

#initialize(params = nil) ⇒ SpecimenRequirement

Returns a new instance of SpecimenRequirement.



71
72
73
74
75
76
# File 'lib/catissue/domain/specimen_requirement.rb', line 71

def initialize(params=nil)
  super
  respond_to?(:specimens)
  # work around caTissue Bug #64
  self.specimens ||= Java::JavaUtil::LinkedHashSet.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CaTissue::Annotatable

Class Method Details

.create_requirement(type, event, params = Hash::EMPTY_HASH) ⇒ Object

Creates a SpecimenRequirement of the given subclass type for the given CollectionProtocolEvent event. The type is a SpecimenRequirement subclass name without the SpecimenRequirement suffix, e.g. Tissue. Lower-case, underscore symbols are supported and preferred, e.g. the :tissue type creates a TissueSpecimenRequirement.

The optional params argument are attribute => value associations, e.g.

SpecimenRequirement.create_requirement(:tissue, event, :specimen_type => 'RNA')


97
98
99
100
101
102
103
104
105
106
# File 'lib/catissue/domain/specimen_requirement.rb', line 97

def self.create_requirement(type, event, params=Hash::EMPTY_HASH)
  # make the class name by joining the camel-cased type prefix to the subclass suffix
  class_name = type.to_s.classify + self.qp
  begin
    klass = CaTissue.const_get(class_name)
  rescue
    raise ArgumentError.new("Unsupported requirement type: #{type}; #{class_name} must be a subtype of #{self}")
  end
  klass.new(params.merge(:collection_protocol_event => event))
end

Instance Method Details

#collection_protocolObject

Returns the #collection_event protocol, if any.



109
110
111
# File 'lib/catissue/domain/specimen_requirement.rb', line 109

def collection_protocol
  collection_event.protocol if collection_event
end

#match_in_owner_scope(others) ⇒ Object

Returns the SpecimenRequirement in others which matches this SpecimenRequirement in the scope of an owner CollectionProtocolEvent. This method relaxes CaRuby::Resource#match_in_owner_scope for a SpecimenRequirement that matches any SpecimenRequirement in others with the same class, specimen type, pathological_status and characteristics.



47
48
49
50
51
52
# File 'lib/catissue/domain/specimen_requirement.rb', line 47

def match_in_owner_scope(others)
  others.detect do |other|
    self.class == other.class and specimen_type == other.specimen_type and pathological_status == other.pathological_status and
     characteristics and characteristics.match?(other.characteristics)
  end
end

#ownerObject

Overrides Resource#owner to return the parent_specimen, if it exists, or the collection_protocol_event otherwise.



40
41
42
# File 'lib/catissue/domain/specimen_requirement.rb', line 40

def owner
  parent_specimen or collection_protocol_event
end

#specimensJava::JavaUtil::Set

Returns the specimens.

Returns:

  • (Java::JavaUtil::Set)

    the specimens



13
14
15
# File 'lib/catissue/domain/specimen_requirement.rb', line 13

def specimens
  getSpecimenCollection or (self.specimens = Java::JavaUtil::LinkedHashSet.new)
end

#validateObject

Augments CaRuby::Resource#validate to verify that this SpecimenRequirement does not have multiple non-aliquot derivatives, which is disallowed by caTissue.

caTissue alert - multiple SpecimenRequirement non-aliquot derivatives is accepted by caTissue but results in obscure downstream errors (cf. Bug #151).

Raises ValidationError if this SpecimenRequirement has multiple non-aliquot derivatives.



85
86
87
88
# File 'lib/catissue/domain/specimen_requirement.rb', line 85

def validate
  super
  if multiple_derivatives? then raise ValidationError.new("Multiple derivatives not supported by caTissue") end
end