Class: Accessionable::Study

Inherits:
Base
  • Object
show all
Defined in:
app/models/accessionable/study.rb

Constant Summary

Constants inherited from Base

Base::InvalidData

Instance Attribute Summary collapse

Attributes inherited from Base

#accession_number, #date, #date_short, #name

Instance Method Summary collapse

Methods inherited from Base

#add_updated_event, #alias, #center_name, #extract_accession_number, #extract_array_express_accession_number, #file_name, #label_scope, #released?, #schema_type

Constructor Details

#initialize(study) ⇒ Study

Returns a new instance of Study


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/accessionable/study.rb', line 10

def initialize(study)
  @study = study
  data = {}

  study_title = study..study_study_title
  @name = study_title.blank? ? '' : study_title.gsub(/[^a-z\d]/i, '_')

  study_type = study..study_type.name
  @existing_study_type = study_type # the study type if validated is exactly the one submission need

  @study_title = @name
  @center_study_name = @study_title

  pid = study..study_project_id
  @study_id = pid.presence || '0'

  study_abstract = study..study_abstract
  @study_abstract = study_abstract unless study_abstract.blank?

  study_desc = study..study_description
  @description = study_desc unless study_desc.blank?

  @tags = []
  @tags << Tag.new(label_scope, 'ArrayExpress', nil) if study.for_array_express?
  super(study..study_ebi_accession_number)
end

Instance Attribute Details

#center_study_nameObject (readonly)

Returns the value of attribute center_study_name


9
10
11
# File 'app/models/accessionable/study.rb', line 9

def center_study_name
  @center_study_name
end

#descriptionObject (readonly)

Returns the value of attribute description


9
10
11
# File 'app/models/accessionable/study.rb', line 9

def description
  @description
end

#existing_study_typeObject (readonly)

Returns the value of attribute existing_study_type


9
10
11
# File 'app/models/accessionable/study.rb', line 9

def existing_study_type
  @existing_study_type
end

#study_abstractObject (readonly)

Returns the value of attribute study_abstract


9
10
11
# File 'app/models/accessionable/study.rb', line 9

def study_abstract
  @study_abstract
end

#study_titleObject (readonly)

Returns the value of attribute study_title


9
10
11
# File 'app/models/accessionable/study.rb', line 9

def study_title
  @study_title
end

#tagsObject (readonly)

Returns the value of attribute tags


9
10
11
# File 'app/models/accessionable/study.rb', line 9

def tags
  @tags
end

Instance Method Details

#accessionable_idObject


73
74
75
# File 'app/models/accessionable/study.rb', line 73

def accessionable_id
  @study.id
end

#errorsObject


37
38
39
# File 'app/models/accessionable/study.rb', line 37

def errors
  error_list = []
end

#protect?(service) ⇒ Boolean

Returns:

  • (Boolean)

77
78
79
# File 'app/models/accessionable/study.rb', line 77

def protect?(service)
  service.study_visibility(@study) == AccessionService::Protect
end

#update_accession_number!(user, accession_number) ⇒ Object


81
82
83
84
85
86
# File 'app/models/accessionable/study.rb', line 81

def update_accession_number!(user, accession_number)
  @accession_number = accession_number
  add_updated_event(user, "Study #{@study.id}", @study) if @accession_number
  @study..study_ebi_accession_number = accession_number
  @study.save!
end

#update_array_express_accession_number!(number) ⇒ Object


88
89
90
91
# File 'app/models/accessionable/study.rb', line 88

def update_array_express_accession_number!(number)
  @study..array_express_accession_number = number
  @study.save!
end

#xmlObject


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/accessionable/study.rb', line 41

def xml
  xml = Builder::XmlMarkup.new
  xml.instruct!
  xml.STUDY_SET('xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance') {
    xml.STUDY(alias: self.alias, accession: accession_number) {
      xml.DESCRIPTOR {
        xml.STUDY_TITLE         study_title
        xml.STUDY_DESCRIPTION   description
        xml.CENTER_PROJECT_NAME center_study_name
        xml.CENTER_NAME         center_name
        xml.STUDY_ABSTRACT      study_abstract

        xml.PROJECT_ID(accessionable_id || '0')
        study_type = existing_study_type
        if StudyType.include?(study_type)
          xml.STUDY_TYPE(existing_study_type: study_type)
        else
          xml.STUDY_TYPE(existing_study_type: ::Study::Other_type, new_study_type: study_type)
        end
      }
      xml.STUDY_ATTRIBUTES {
        tags.each do |tag|
          xml.STUDY_ATTRIBUTE {
            tag.build(xml)
          }
        end
      } unless tags.blank?
    }
  }
  xml.target!
end