Class: CaTissue::CollectionProtocol

Inherits:
Object
  • Object
show all
Includes:
HashCode, Jinx::Unique
Defined in:
lib/catissue/domain/collection_protocol.rb,
lib/catissue/migration/unique.rb

Overview

The CollectionProtocol domain class.

Instance Method Summary collapse

Methods included from HashCode

#==, #hash

Constructor Details

#initializeCollectionProtocol

Returns a new instance of CollectionProtocol.



50
51
52
53
54
55
# File 'lib/catissue/domain/collection_protocol.rb', line 50

def initialize
  super
  # @quirk JRuby consent_tiers property method is not accessible until respond_to? is called.
  respond_to?(:consent_tiers)
  self.consent_tiers ||= Java::JavaUtil::LinkedHashSet.new
end

Instance Method Details

#add_specimens(*args) ⇒ CaTissue::SpecimenCollectionGroup

Adds specimens to this protocol. The argumentes includes the specimens to add followed by a Hash with parameters and options. If the SCG registration parameter is not set, then a default registration is created which registers the given participant to this protocol.

Examples:

protocol.add_specimens(tumor, normal, :participant => pnt, :collector => srg) 
#=> a new SCG for the given participant with a matched pair of samples
#=> collected by the given surgeon.

Parameters:

  • args ((<Specimen>, {Symbol => Object}))

    the specimens to add followed by the parameters and options hash

Options Hash (*args):

Returns:

Raises:

  • (ArgumentError)

    if the options do not include either a participant or a registration



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/catissue/domain/collection_protocol.rb', line 84

def add_specimens(*args)
  hash = args.pop
  spcs = args
  # validate arguments
  unless Hash === hash then
    raise ArgumentError.new("Collection parameters are missing when adding specimens to protocol #{self}")
  end
  # Make the default registration, if necessary.
  unless hash.has_key?(:registration) || hash.has_key?(:collection_protocol_registration) then
    # the participant
    pnt = hash.delete(:participant)
    unless pnt then
      raise ArgumentError.new("Registration or participant missing from collection parameters: #{hash.qp}")
    end
    hash[:registration] = registration(pnt) || make_cpr(pnt)
  end
  # the new SCG
  scg = SpecimenCollectionGroup.new(hash)
  # set each Specimen SCG
  spcs.each { |spc| spc.specimen_collection_group = scg }
  scg
end

Returns the tiers.

Returns:

  • (Java::JavaUtil::Set)

    the tiers



20
21
22
# File 'lib/catissue/domain/collection_protocol.rb', line 20

def consent_tiers
  getConsentTierCollection or (self.consent_tiers = Java::JavaUtil::LinkedHashSet.new)
end

#default_siteCaTissue::Site?

Returns the default protocol site, determined as follows:

  • If there is exactly one coordinator with one site, then the coordinator’s site is the default.

  • Otherwise, if there is exactly one authorized site for this protocol, then that is the default site.

  • Otherwise, if there is exactly two authorized sites for this protocol, then the site other than the Site.default_site is returned.

  • Otherwise, this method returns nil.

Returns:



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/catissue/domain/collection_protocol.rb', line 115

def default_site
  coord = coordinators.first if coordinators.size == 1
  site = coord.sites.first if coord and coord.sites.size == 1
  return site if site
  # If this CP's identifier was set by the client but the CP was not fetched, then do so now
  # in order to enable lazy-loading the sites.
  find if sites.empty? and identifier and not fetched?
  case sites.size
  when 1 then sites.first
  when 2 then sites.select { |site| site.name != CaTissue::Site.default_site.name }
  end
end

#register(participant, ppi = nil) ⇒ Object

Returns a new CollectionProtocolRegistration for the specified participant in this CollectionProtocol with optional protocol_participant_identifier ppi.



59
60
61
# File 'lib/catissue/domain/collection_protocol.rb', line 59

def register(participant, ppi=nil)
  CollectionProtocolRegistration.new(:participant => participant, :protocol => self, :protocol_participant_identifier => ppi)
end

#sorted_eventsObject

Returns this protocol’s events sorted by study calendar event point.



64
65
66
# File 'lib/catissue/domain/collection_protocol.rb', line 64

def sorted_events
  events.sort_by { |ev| ev.event_point || CollectionProtocolEvent::DEFAULT_EVENT_POINT }
end

#uniquifyObject

Makes this CP’s short and long title unique.



12
13
14
15
# File 'lib/catissue/migration/unique.rb', line 12

def uniquify
  super
  self.short_title = title
end