Class: CaTissue::SpecimenCollectionGroup

Inherits:
Object
  • Object
show all
Includes:
CaRuby::Resource::Unique, Resource
Defined in:
lib/catissue/domain/specimen_collection_group.rb,
lib/catissue/domain/uniquify.rb,
lib/catissue/migration/shims.rb

Overview

The SpecimenCollectionGroup domain class.

Note: the SpecimenCollectionGroup name attribute is auto-generated on create in caTissue 1.1 API and should not be set by API clients when creating a new SpecimenCollectionGroup in the database.

Constant Summary collapse

[:consent_tier_statuses]
@@diagnosis_cv_finder =
nil

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) ⇒ SpecimenCollectionGroup

caTissue alert - Bug #64: Initialize the SCG consent_tier_statuses to an empty set.



110
111
112
113
114
# File 'lib/catissue/domain/specimen_collection_group.rb', line 110

def initialize(params=nil)
  super
  # work around caTissue Bug #64
  self.consent_tier_statuses ||= 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

.diagnosis_controlled_value(value) ⇒ Object

Returns the diagnosis controlled value as follows:

  • If CV lookup is disabled, then this method returns value.

  • Otherwise, if the value is remapped via a configuration remap file, then this method returns the remapped CV.

  • Otherwise, if the value is a valid CV, then this method returns value.

  • Otherwise, this method returns nil.



21
22
23
# File 'lib/catissue/migration/shims.rb', line 21

def self.diagnosis_controlled_value(value)
  @@diagnosis_cv_finder.nil? ? value : @@diagnosis_cv_finder.controlled_value(value)
end

.diagnosis_cv_finder=(finder) ⇒ Object

Sets this SpecimenCollectionGroup diagnosis ControlledValueFinder.



11
12
13
# File 'lib/catissue/migration/shims.rb', line 11

def self.diagnosis_cv_finder=(finder)
  @@diagnosis_cv_finder = finder
end

Instance Method Details

#autogenerated?(operation) ⇒ Boolean

Relaxes the CaRuby::Persistable#saved_fetch_attributes condition for a SCG as follows:

  • If the SCG status was updated from Pending to Collected, then fetch the saved SCG event parameters.

Returns:

  • (Boolean)


275
276
277
# File 'lib/catissue/domain/specimen_collection_group.rb', line 275

def autogenerated?(operation)
  operation == :update && status_changed_to_complete? ? EVENT_PARAM_ATTRS : super
end

#collect(params) ⇒ Object

Collects and receives this SCG with the given params option => value hash. The SCG collection status is set to ‘Completed’.

Supported parameters are as follows:

  • receiver - the required User who received the specimens

  • received_date - the optional receival date (default is now)

  • collector - the optional User who collected the specimens (default is receiver)

  • collection_date - the optional collection date (default is received_date)

If there is at least a receiver, then no additional event parameters are added.

Raises ValidationError if this SCG has already been received.

Raises:

  • (ValidationError)


180
181
182
183
# File 'lib/catissue/domain/specimen_collection_group.rb', line 180

def collect(params)
  raise ValidationError.new("SCG is already collected") if received?
  specimen_event_parameters.merge!(extract_event_params(params))
end

#collected?Boolean

Returns whether this SCG has a collected event.

Returns:

  • (Boolean)


190
191
192
# File 'lib/catissue/domain/specimen_collection_group.rb', line 190

def collected?
  collection_event_parameters
end

#collection_event_parametersObject

Returns the CollectionEventParameters for this specimen group.



207
208
209
# File 'lib/catissue/domain/specimen_collection_group.rb', line 207

def collection_event_parameters
  event_parameters.detect { |ep| CaTissue::CollectionEventParameters === ep }
end

#collection_protocolCollectionProtocol

Returns the SCG CPE CP.

Returns:



117
118
119
# File 'lib/catissue/domain/specimen_collection_group.rb', line 117

def collection_protocol
  collection_protocol_event.collection_protocol if collection_protocol_event
end

#collection_status=(value) ⇒ Object

Sets the collection status for this SCG. If the SCG status is set to Complete, then the status of each of the SCG Specimens with status Pending is reset to Collected.

Parameters:

  • value (String)

    a permissible SCG status



27
28
29
30
31
32
# File 'lib/catissue/domain/specimen_collection_group.rb', line 27

def collection_status=(value)
  if value == 'Complete' then
    specimens.each { |spc| spc.collection_status = 'Collected' if spc.pending? }
  end
  setCollectionStatus(value)
end

#collection_timestampDate

Returns the date this SCG was donated by the participant.

Returns:

  • (Date)

    the date this SCG was donated by the participant.



201
202
203
204
# File 'lib/catissue/domain/specimen_collection_group.rb', line 201

def collection_timestamp
  ep = collection_event_parameters
  ep.timestamp if ep
end

#collectorObject

Returns the User who collected this SCG.



195
196
197
198
# File 'lib/catissue/domain/specimen_collection_group.rb', line 195

def collector
  ep = collection_event_parameters
  ep.user if ep
end

caTissue alert - Bug #64: Some domain collection properties not initialized. Initialize consent_tier_statuses if necessary.

Returns:

  • (Java::JavaUtil::Set)

    the statuses



18
19
20
# File 'lib/catissue/domain/specimen_collection_group.rb', line 18

def consent_tier_statuses
  getConsentTierStatusCollection or (self.consent_tier_statuses = Java::JavaUtil::LinkedHashSet.new)
end

#deleteObject

Removes associations to this registration.



142
143
144
# File 'lib/catissue/domain/specimen_collection_group.rb', line 142

def delete
  registration.specimen_collection_groups.delete(self) if registration
end

#direct_dependents(attribute) ⇒ Object

Overrides CaRuby::Resource#direct_dependents in the case of the specimens attribute to select only top-level Specimens not derived from another Specimen.



236
237
238
239
240
241
242
# File 'lib/catissue/domain/specimen_collection_group.rb', line 236

def direct_dependents(attribute)
  if attribute == :specimens then
    super.reject { |spc| spc.parent }
  else
    super
  end
end

#event_pointDouble?

Returns the SCG CPE event point.

Returns:

  • (Double, nil)

    the SCG CPE event point



122
123
124
# File 'lib/catissue/domain/specimen_collection_group.rb', line 122

def event_point
  collection_protocol_event and collection_protocol_event.study_calendar_event_point
end

#mandatory_attributesObject



246
247
248
249
250
251
252
253
# File 'lib/catissue/domain/specimen_collection_group.rb', line 246

def mandatory_attributes
  attrs = super
  if registration and not registration.consent_tier_responses.empty? then
    attrs + CONSENT_TIER_STATUS_ATTRS
  else
    attrs
  end
end

#merge_attributes(other, attributes = nil) ⇒ Object

Merges the other object into this SpecimenCollectionGroup. This method overrides the standard CaRuby::Resource#merge_attributes method as follows:

  • Builds the SpecimenEventParameter objects from atomic parameters, e.g.:

    SpecimenCollectionGroup.create(:name = > name, ..., :collector => collector, :receiver => receiver)
    

    The supported event parameters are described in #collect.

  • Adds the transitive closure of each non-derived Specimen in other.



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/catissue/domain/specimen_collection_group.rb', line 152

def merge_attributes(other, attributes=nil)
  if Hash === other then
    # extract the event parameters
    other[:specimen_event_parameters] = extract_event_params(other)
    # take the transitive closure of the specimens
    spcs = other.delete(:specimens)
    if spcs then
      spcs = [spcs] if CaTissue::Specimen === spcs
      # take the transitive closure of the root specimens in the hierarchy
      other[:specimens] = spcs.select { |spc| spc.parent.nil? }.transitive_closure(:children)
    end
  end
  # delegate to super for standard attribute value merge
  super
end

#migrate_clinical_diagnosis(value, row) ⇒ Object

Returns the #diagnosis_controlled_value.



26
27
28
# File 'lib/catissue/migration/shims.rb', line 26

def migrate_clinical_diagnosis(value, row)
  SpecimenCollectionGroup.diagnosis_controlled_value(value)
end

#minimal_match?(other) ⇒ Boolean

Returns whether this SCG is the same as the other SCG in the scope of an existing parent CPR. This method returns whether the other SCG status is Pending and the event point is the same as the other event point.

Returns:

  • (Boolean)


230
231
232
# File 'lib/catissue/domain/specimen_collection_group.rb', line 230

def minimal_match?(other)
  super and event_point == other.event_point
end

#pending?Boolean

Returns whether this SCG collection status is one of the Pending statuses.

Returns:

  • (Boolean)

    whether this SCG collection status is one of the Pending statuses.



132
133
134
# File 'lib/catissue/domain/specimen_collection_group.rb', line 132

def pending?
  collection_status =~ /^Pending/
end

#protocolObject



185
186
187
# File 'lib/catissue/domain/specimen_collection_group.rb', line 185

def protocol
  collection_event.protocol if collection_event
end

#received?Boolean

Returns whether this SCG has a received event.

Returns:

  • (Boolean)


212
213
214
# File 'lib/catissue/domain/specimen_collection_group.rb', line 212

def received?
  received_event_parameters
end

#received_event_parametersObject

Returns the ReceivedEventParameters for this specimen group.



223
224
225
# File 'lib/catissue/domain/specimen_collection_group.rb', line 223

def received_event_parameters
  event_parameters.detect { |ep| CaTissue::ReceivedEventParameters === ep }
end

#receiverObject

Returns the User who received this specimen group.



217
218
219
220
# File 'lib/catissue/domain/specimen_collection_group.rb', line 217

def receiver
  ep = received_event_parameters
  ep.user if ep
end

#requirements<SpecimenRequirement>

Returns the SCG CPE requirements.

Returns:



127
128
129
# File 'lib/catissue/domain/specimen_collection_group.rb', line 127

def requirements
  collection_protocol_event.nil? ? Array::EMPTY_ARRAY : collection_protocol_event.requirements
end

#saved_fetch_attributes(operation) ⇒ Object

Relaxes the CaRuby::Persistable#saved_fetch_attributes condition for a SCG as follows:

  • If the SCG status was updated from Pending to Collected, then fetch the saved SCG event parameters.



266
267
268
# File 'lib/catissue/domain/specimen_collection_group.rb', line 266

def saved_fetch_attributes(operation)
  operation == :update && status_changed_to_complete? ? EVENT_PARAM_ATTRS : super
end

#sizeObject

Returns the number of specimens in this SpecimenCollectionGroup.



137
138
139
# File 'lib/catissue/domain/specimen_collection_group.rb', line 137

def size
  specimens.size
end

#surgical_pathology_number=(value) ⇒ Object

Converts an Integer SPN value to a String.

Parameters:

  • value (Numeric, String)

    the SPN value



37
38
39
40
# File 'lib/catissue/domain/specimen_collection_group.rb', line 37

def surgical_pathology_number=(value)
  value = value.to_s if Numeric === value
  setSurgicalPathologyNumber(value)
end

#uniquifyObject

Makes this SCG’s SPN unique.



44
45
46
47
48
49
50
# File 'lib/catissue/domain/uniquify.rb', line 44

def uniquify
  super
  oldval = surgical_pathology_number || return
  newval = uniquify_value(oldval)
  self.surgical_pathology_number = newval
  logger.debug { "Reset #{qp} SPN from #{oldval} to unique value #{newval}." }
end

#validateObject



255
256
257
258
259
# File 'lib/catissue/domain/specimen_collection_group.rb', line 255

def validate
  super
  validate_consent
  validate_event_parameters
end