Class: CaTissue::CollectionProtocol
- Inherits:
-
Object
- Object
- CaTissue::CollectionProtocol
- Defined in:
- lib/catissue/domain/collection_protocol.rb,
lib/catissue/domain/uniquify.rb
Overview
The CollectionProtocol domain class.
Instance Method Summary collapse
-
#add_specimens(*specimens_and_params) ⇒ SpecimenCollectionGroup
Adds specimens to this protocol.
-
#consent_tiers ⇒ Java::JavaUtil::Set
caTissue alert - Bug #64: Some domain collection properties not initialized.
-
#default_site ⇒ CaTissue::Site?
Returns the default protocol site, determined as follows: * If there is exactly one authorized site for this protocol, then that is the default site.
-
#first_event ⇒ Object
Returns the event in this protocol with the earliest study calendar event point.
-
#initialize(params = nil) ⇒ CollectionProtocol
constructor
A new instance of CollectionProtocol.
-
#participants ⇒ Object
Returns all participants registered in this protocol.
-
#register(participant, ppi = nil) ⇒ Object
Returns a new CollectionProtocolRegistration for the specified participant in this CollectionProtocol with optional
protocol_participant_identifier
ppi. -
#registration(participant) ⇒ Object
Returns the CollectionProtocolRegistration for the specified participant in this CollectionProtocol,.
-
#specimens(participant = nil) ⇒ Object
Returns the specimens collected from the given participant for this CollectionProtocol, or all specimens in this protocol if participant is nil.
-
#uniquify ⇒ Object
Makes this CP’s short and long title unique.
Methods included from Resource
#database, included, #tolerant_match?
Methods included from Annotatable
#annotation_proxy, #create_proxy, #method_missing
Methods included from HashCode
Constructor Details
#initialize(params = nil) ⇒ CollectionProtocol
Returns a new instance of CollectionProtocol.
44 45 46 47 48 49 |
# File 'lib/catissue/domain/collection_protocol.rb', line 44 def initialize(params=nil) super respond_to?(:consent_tiers) # work around caTissue Bug #64 - consent tiers is nil rather than an empty set self. ||= Java::JavaUtil::LinkedHashSet.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class CaTissue::Annotatable
Instance Method Details
#add_specimens(*specimens_and_params) ⇒ SpecimenCollectionGroup
Adds specimens to this protocol. The following parameter options are supported:
-
:participant - the Participant from whom the specimen is collected
-
:biospecimens - the collected top-level underived specimens
-
additional SCG parameters as described in SpecimenCollectionGroup#merge.
If the options does not include a :collection_protocol_event, then the SCG is assigned to the first collection event in this protocol. If the options does not include a :specimen_collection_site, then the SCG is assigned to the participant’s collection site as determined by Participant#collection_site, if that can be uniquely determined.
This add_specimens method adds the following parameter options before calling the SpecimenCollectionGroup constructor:
-
:registration => a new CollectionProtocolRegistration for this protocol and the specified participant
If there is no :name parameter, then this method builds a new unique SCG name as this CollectionProtocol’s name followed by a unique suffix.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/catissue/domain/collection_protocol.rb', line 101 def add_specimens(*specimens_and_params) params = specimens_and_params.pop spcs = specimens_and_params # validate arguments unless params then raise ArgumentError.new("Collection parameters are missing when adding specimens to protocol #{self}") end # there must be a participant pnt = params.delete(:participant) unless pnt then raise ArgumentError.new("Participant missing from collection parameters: #{params.qp}") end # there must be a receiver unless params[:receiver] then raise ArgumentError.new("Receiver missing from collection parameters: #{params.qp}") end # the required registration params[:registration] ||= registration(pnt) || make_cpr(pnt) # the new SCG scg = SpecimenCollectionGroup.new(params) # set each Specimen SCG spcs.each { |spc| spc.specimen_collection_group = scg } scg end |
#consent_tiers ⇒ Java::JavaUtil::Set
caTissue alert - Bug #64: Some domain collection properties not initialized. Initialize consent_tiers if necessary.
16 17 18 |
# File 'lib/catissue/domain/collection_protocol.rb', line 16 def getConsentTierCollection or (self. = Java::JavaUtil::LinkedHashSet.new) end |
#default_site ⇒ CaTissue::Site?
Returns the default protocol site, determined as follows:
-
If there is exactly one authorized site for this protocol, then that is the default site.
-
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.
133 134 135 136 137 138 |
# File 'lib/catissue/domain/collection_protocol.rb', line 133 def default_site case sites.size when 1 then sites.first when 2 then sites.select { |site| site.name != CaTissue::Site.default_site.name } end end |
#first_event ⇒ Object
Returns the event in this protocol with the earliest study calendar event point.
68 69 70 |
# File 'lib/catissue/domain/collection_protocol.rb', line 68 def first_event events.sort_by { |event| event.event_point or CollectionProtocolEvent::DEFAULT_EVENT_POINT }.first end |
#participants ⇒ Object
Returns all participants registered in this protocol.
52 53 54 |
# File 'lib/catissue/domain/collection_protocol.rb', line 52 def participants registrations.nil? ? [] : registrations.map { |reg| reg.participant } end |
#register(participant, ppi = nil) ⇒ Object
Returns a new CollectionProtocolRegistration for the specified participant in this CollectionProtocol with optional protocol_participant_identifier
ppi.
58 59 60 |
# File 'lib/catissue/domain/collection_protocol.rb', line 58 def register(participant, ppi=nil) CollectionProtocolRegistration.new(:participant => participant, :protocol => self, :protocol_participant_identifier => ppi) end |
#registration(participant) ⇒ Object
Returns the CollectionProtocolRegistration for the specified participant in this CollectionProtocol,
63 64 65 |
# File 'lib/catissue/domain/collection_protocol.rb', line 63 def registration(participant) registrations.detect { |registration| registration.participant == participant } end |
#specimens(participant = nil) ⇒ Object
Returns the specimens collected from the given participant for this CollectionProtocol, or all specimens in this protocol if participant is nil.
74 75 76 77 78 |
# File 'lib/catissue/domain/collection_protocol.rb', line 74 def specimens(participant=nil) if participant.nil? then return registrations.map { |reg| reg.specimens }.flatten end reg = registration(participant) reg.nil? ? Array::EMPTY_ARRAY : reg.specimens end |
#uniquify ⇒ Object
Makes this CP’s short and long title unique.
8 9 10 11 |
# File 'lib/catissue/domain/uniquify.rb', line 8 def uniquify super self.title = short_title end |