Module: FieldOccurrence::DwcExtensions

Extended by:
ActiveSupport::Concern
Includes:
Shared::Dwc::CollectingEventExtensions, Shared::Dwc::TaxonDeterminationExtensions, Shared::IsDwcOccurrence
Included in:
FieldOccurrence, BiologicalFieldOccurrence
Defined in:
app/models/field_occurrence/dwc_extensions.rb

Constant Summary

Constants included from Shared::IsDwcOccurrence

Shared::IsDwcOccurrence::DWC_DELIMITER, Shared::IsDwcOccurrence::VIEW_EXCLUSIONS

Instance Method Summary collapse

Methods included from Shared::IsDwcOccurrence

#dwc_occurrence_attribute_values, #dwc_occurrence_attributes, #dwc_occurrence_id, #get_dwc_occurrence, #set_dwc_occurrence

Instance Method Details

TODO: likeley a helper



145
146
147
148
149
150
151
152
153
154
# File 'app/models/field_occurrence/dwc_extensions.rb', line 145

def api_image_link(image)
  s = ENV['SERVER_NAME']
  if s.nil?
    s ||= 'http://127.0.0.1:3000'
  else
    s = 'https://' + s
  end

  s = s + '/api/v1/images/' + image.image_file_fingerprint # An experiment, use md5 as a proxy for id (also unique id)
end

#dwc_associated_mediaObject



135
136
137
# File 'app/models/field_occurrence/dwc_extensions.rb', line 135

def dwc_associated_media
  images.collect{|i| api_image_link(i) }.join(FieldOccurrence::DWC_DELIMITER).presence
end

#dwc_associated_taxaObject



140
141
142
# File 'app/models/field_occurrence/dwc_extensions.rb', line 140

def dwc_associated_taxa
  dwc_internal_attribute_for(:collection_object, :associatedTaxa)
end

#dwc_casteObject



201
202
203
204
# File 'app/models/field_occurrence/dwc_extensions.rb', line 201

def dwc_caste
  biocuration_classes.tagged_with_uri(::DWC_ATTRIBUTE_URIS[:caste])
    .pluck(:name)&.join(', ').presence
end

#dwc_classObject



245
246
247
# File 'app/models/field_occurrence/dwc_extensions.rb', line 245

def dwc_class
  taxonomy['class']
end

#dwc_date_identifiedObject

ISO 8601:2004(E).



225
226
227
# File 'app/models/field_occurrence/dwc_extensions.rb', line 225

def dwc_date_identified
  current_taxon_determination&.date.presence
end

#dwc_familyObject



259
260
261
# File 'app/models/field_occurrence/dwc_extensions.rb', line 259

def dwc_family
  taxonomy['family']
end

#dwc_genusObject



279
280
281
# File 'app/models/field_occurrence/dwc_extensions.rb', line 279

def dwc_genus
  taxonomy['genus'] && taxonomy['genus'].compact.join(' ').presence
end

#dwc_higher_classificationObject



229
230
231
232
233
234
235
# File 'app/models/field_occurrence/dwc_extensions.rb', line 229

def dwc_higher_classification
  v = taxonomy.values.collect{|a| a.kind_of?(Array) ? a.second : a}
  v.shift
  v.pop
  v.compact
  v.join(FieldOccurrence::DWC_DELIMITER)
end

#dwc_identification_remarksObject



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

def dwc_identification_remarks
  current_taxon_determination&.notes&.collect { |n| n.text }&.join(FieldOccurrence::DWC_DELIMITER)
end

#dwc_individual_countObject

TODO: handle ranged lots



309
310
311
# File 'app/models/field_occurrence/dwc_extensions.rb', line 309

def dwc_individual_count
  total
end

#dwc_infraspecific_epithetObject



206
207
208
209
210
211
# File 'app/models/field_occurrence/dwc_extensions.rb', line 206

def dwc_infraspecific_epithet
  %w{variety form subspecies}.each do |n| # add more as observed
    return taxonomy[n].last if taxonomy[n]
  end
  nil
end

#dwc_institution_codeObject



296
297
298
# File 'app/models/field_occurrence/dwc_extensions.rb', line 296

def dwc_institution_code
  repository.try(:acronym)
end

#dwc_internal_attribute_for(target = :collection_object, dwc_term_name) ⇒ Object

TODO: normalize



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'app/models/field_occurrence/dwc_extensions.rb', line 169

def dwc_internal_attribute_for(target = :collection_object, dwc_term_name)
  return nil if dwc_term_name.nil?

  case target
  when  :collecting_event
    return nil unless collecting_event
    collecting_event.internal_attributes.includes(:predicate)
      .where(
        controlled_vocabulary_terms: {uri: ::DWC_ATTRIBUTE_URIS[dwc_term_name.to_sym] })
      .pluck(:value)&.join(', ').presence
  when :collection_object
    internal_attributes.includes(:predicate)
      .where(
        controlled_vocabulary_terms: {uri: ::DWC_ATTRIBUTE_URIS[dwc_term_name.to_sym] })
      .pluck(:value)&.join(', ').presence
  else
    nil
  end
end

#dwc_kingdomObject



237
238
239
# File 'app/models/field_occurrence/dwc_extensions.rb', line 237

def dwc_kingdom
  taxonomy['kingdom']
end

#dwc_life_stageObject

TODO: consider CVT attributes with Predicates linked to URIs



190
191
192
193
# File 'app/models/field_occurrence/dwc_extensions.rb', line 190

def dwc_life_stage
  biocuration_classes.tagged_with_uri(::DWC_ATTRIBUTE_URIS[:lifeStage])
    .pluck(:name)&.join(', ').presence # `.presence` is a Rails extension
end

#dwc_nomenclatural_codeObject



313
314
315
# File 'app/models/field_occurrence/dwc_extensions.rb', line 313

def dwc_nomenclatural_code
  current_otu.try(:taxon_name).try(:nomenclatural_code)
end

#dwc_occurrence_remarksObject



125
126
127
# File 'app/models/field_occurrence/dwc_extensions.rb', line 125

def dwc_occurrence_remarks
  notes.collect{|n| n.text}&.join(FieldOccurrence::DWC_DELIMITER)
end

#dwc_occurrence_statusObject



120
121
122
# File 'app/models/field_occurrence/dwc_extensions.rb', line 120

def dwc_occurrence_status
  is_absent == true ? 'absent' : 'present'
end

#dwc_orderObject



249
250
251
# File 'app/models/field_occurrence/dwc_extensions.rb', line 249

def dwc_order
  taxonomy['order']
end

#dwc_other_catalog_numbersObject



156
157
158
159
160
# File 'app/models/field_occurrence/dwc_extensions.rb', line 156

def dwc_other_catalog_numbers
  i = identifiers.where.not('type ilike ?', 'Identifier::Global::Uuid%').order(:position).to_a
  i.shift
  i.map(&:cached).join(FieldOccurrence::DWC_DELIMITER).presence
end

#dwc_phylumObject



241
242
243
# File 'app/models/field_occurrence/dwc_extensions.rb', line 241

def dwc_phylum
  taxonomy['phylum']
end

#dwc_previous_identificationsObject



162
163
164
165
166
# File 'app/models/field_occurrence/dwc_extensions.rb', line 162

def dwc_previous_identifications
  a = taxon_determinations.order(:position).to_a
  a.shift
  a.collect{|d| ApplicationController.helpers.label_for_taxon_determination(d)}.join(FieldOccurrence::DWC_DELIMITER).presence
end

#dwc_scientific_nameObject



288
289
290
# File 'app/models/field_occurrence/dwc_extensions.rb', line 288

def dwc_scientific_name
  current_taxon_name.try(:cached_name_and_author_year)
end

#dwc_sexObject

TODO: consider CVT attributes with Predicates linked to URIs



196
197
198
199
# File 'app/models/field_occurrence/dwc_extensions.rb', line 196

def dwc_sex
  biocuration_classes.tagged_with_uri(::DWC_ATTRIBUTE_URIS[:sex])
    .pluck(:name)&.join(', ').presence
end

#dwc_specific_epithetObject



284
285
286
# File 'app/models/field_occurrence/dwc_extensions.rb', line 284

def dwc_specific_epithet
  taxonomy['species'] && taxonomy['species'].compact.join(' ').presence
end

#dwc_subfamilyObject



264
265
266
# File 'app/models/field_occurrence/dwc_extensions.rb', line 264

def dwc_subfamily
  taxonomy['subfamily']
end

#dwc_subtribeObject



274
275
276
# File 'app/models/field_occurrence/dwc_extensions.rb', line 274

def dwc_subtribe
  taxonomy['subtribe']
end

#dwc_superfamilyObject



254
255
256
# File 'app/models/field_occurrence/dwc_extensions.rb', line 254

def dwc_superfamily
  taxonomy['superfamily']
end

#dwc_taxon_name_authorshipObject



292
293
294
# File 'app/models/field_occurrence/dwc_extensions.rb', line 292

def dwc_taxon_name_authorship
  current_taxon_name.try(:cached_author_year)
end

#dwc_taxon_rankObject



213
214
215
# File 'app/models/field_occurrence/dwc_extensions.rb', line 213

def dwc_taxon_rank
  current_taxon_name&.rank
end

#dwc_tribeObject



269
270
271
# File 'app/models/field_occurrence/dwc_extensions.rb', line 269

def dwc_tribe
  taxonomy['tribe']
end

#dwc_type_statusObject

holotype of Ctenomys sociabilis. Pearson O. P., and M. I. Christie. 1985. Historia Natural, 5(37):388, holotype of Pinus abies | holotype of Picea abies



218
219
220
221
222
# File 'app/models/field_occurrence/dwc_extensions.rb', line 218

def dwc_type_status
  type_materials.all.collect{|t|
    ApplicationController.helpers.label_for_type_material(t)
  }.join(FieldOccurrence::DWC_DELIMITER).presence
end

#dwc_verbatim_labelObject



116
117
118
# File 'app/models/field_occurrence/dwc_extensions.rb', line 116

def dwc_verbatim_label
  collecting_event&.verbatim_label.presence
end

#is_fossil?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'app/models/field_occurrence/dwc_extensions.rb', line 112

def is_fossil?
  biocuration_classes.where(uri: DWC_FOSSIL_URI).any?
end