Class: ReportBuilder::FulltextReport

Inherits:
Object
  • Object
show all
Defined in:
lib/report_builder/fulltext_report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sr, app) ⇒ FulltextReport

Returns a new instance of FulltextReport



33
34
35
36
37
38
39
40
# File 'lib/report_builder/fulltext_report.rb', line 33

def initialize(sr,app)
  @sr=sr
  @app=app
  @ars=AnalysisSystematicReview.new(sr)
  @cd_h=CanonicalDocument.where(:id=>@sr.cd_id_by_stage(:report)).to_hash
  @analysis_rs=@sr.analysis_cd
  @fields=@sr.fields.to_hash(:name)
end

Instance Attribute Details

#analysis_rsObject (readonly)

Returns the value of attribute analysis_rs



32
33
34
# File 'lib/report_builder/fulltext_report.rb', line 32

def analysis_rs
  @analysis_rs
end

#appObject (readonly)

Returns the value of attribute app



32
33
34
# File 'lib/report_builder/fulltext_report.rb', line 32

def app
  @app
end

#arsObject (readonly)

Returns the value of attribute ars



32
33
34
# File 'lib/report_builder/fulltext_report.rb', line 32

def ars
  @ars
end

#cd_hObject (readonly)

Returns the value of attribute cd_h



32
33
34
# File 'lib/report_builder/fulltext_report.rb', line 32

def cd_h
  @cd_h
end

#fieldsObject (readonly)

Returns the value of attribute fields



32
33
34
# File 'lib/report_builder/fulltext_report.rb', line 32

def fields
  @fields
end

#srObject (readonly)

Returns the value of attribute sr



32
33
34
# File 'lib/report_builder/fulltext_report.rb', line 32

def sr
  @sr
end

Instance Method Details

#get_inline_codesObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/report_builder/fulltext_report.rb', line 97

def get_inline_codes
  cd_ids = @cd_h.keys
  codes=@fields.keys.inject({}) {|ac,v| ac[v]={}; ac}
  @analysis_rs.where(:canonical_document_id => cd_ids).each do |an|
    @fields.keys.each do |field|
      codes_an=an[field.to_sym].to_s.scan(/\[(.+?)\]/)
      if codes_an.length>0
        codes_an.uniq.each {|code|
          # Busquemos el párrafo donde está el text
          uses=an[field.to_sym].scan(/^.+#{code[0]}.+$/)
          codes[field][code[0]]||=[]
          codes[field][code[0]].push({cd_id:an[:canonical_document_id], uses:uses})
        }
      end

    end
  end
  codes
end

#html_field(field_name, user_id) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/report_builder/fulltext_report.rb', line 47

def html_field(field_name,user_id)
  type=@fields[field_name].type
  if type=='select'
    html_field_select(field_name,user_id)
  elsif type=='multiple'
    html_field_multiple(field_name,user_id)

  else
    raise 'not implemented'
  end
end

#html_field_multiple(field_name, user_id) ⇒ Object



92
93
94
95
# File 'lib/report_builder/fulltext_report.rb', line 92

def html_field_multiple(field_name,user_id)
  info=multiple_info(field_name, user_id)
  app.partial("reports/fulltext_table_multiple", :locals=>{info:info, cd_h:@cd_h, options_h:@fields[field_name].options_as_hash})
end

#html_field_select(field_name, user_id) ⇒ Object



88
89
90
91
# File 'lib/report_builder/fulltext_report.rb', line 88

def html_field_select(field_name, user_id)
  info=select_info(field_name, user_id)
  app.partial("reports/fulltext_table_select", :locals=>{info:info, cd_h:@cd_h})
end

#multiple_info(field_name, user_id) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/report_builder/fulltext_report.rb', line 74

def multiple_info(field_name,user_id)
  field_sym=field_name.to_sym
  values=@analysis_rs.select(:canonical_document_id, field_sym).where(user_id:user_id, :canonical_document_id=>@cd_h.keys)
  options_h=@fields[field_name].options_as_hash
  values.inject({}) {|ac,v|
    values_included=v[field_sym].nil? ? [] : v[field_sym].split(",")
    ac[v[:canonical_document_id]]=options_h.keys.sort.inject({}) {|ac2,key_opt|
      ac2[key_opt]=values_included.include? key_opt
      ac2
    }
    ac
  }

end

#output(format) ⇒ Object



42
43
44
# File 'lib/report_builder/fulltext_report.rb', line 42

def output(format)
  send("output_#{format}".to_sym)
end

#select_info(field_name, user_id) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/report_builder/fulltext_report.rb', line 59

def select_info(field_name,user_id)
  field_sym=field_name.to_sym
  values=@analysis_rs.select(:canonical_document_id, field_sym).where(user_id:user_id, :canonical_document_id=>@cd_h.keys).to_hash_groups(field_sym)
  options_h=@fields[field_name].options_as_hash
  #$log.info(options_h)

  values.inject({}) {|ac,v|
    ac[v[0]]={ key:v[0],
               text:options_h[v[0]],
               canonical_documents_id:v[1].map {|vv|  vv[:canonical_document_id]}
              }
    ac
  }

end