Class: ODDB::OuwerkerkPlugin

Inherits:
Plugin show all
Defined in:
src/plugin/ouwerkerk.rb,
test/test_plugin/ouwerkerk.rb

Constant Summary

RECIPIENTS =
[
  'matthijs.ouwerkerk@just-medical.com',
  'Josef.Hunkeler@pue.admin.ch',
]
NUMERIC_FLAGS =
{
  :new             =>  1,
  :sl_entry_delete =>  2,
  :name_base       =>  3,
  :productname     =>  3,  #legacy
  :address         =>  4,
  :ikscat            =>  5,
  :composition     =>  6, 
  :indication        =>  7,
  :sequence          => 8, 
  :expirydate        =>  9,  #legacy
  :expiry_date     =>  9,
  :sl_entry          => 10,
  :price           => 11, #legacy
  :price_exfactory =>  11, #legacy
  :price_public      => 11, #legacy
  :comment         =>  12,
  :price_rise        =>  13,
  :delete            =>  14,
  :price_cut       => 15,
  :not_specified   => 16,
}
ARCHIVE_PATH =
File.expand_path('../data', File.dirname(__FILE__))

Constants inherited from Plugin

ARCHIVE_PATH, RECIPIENTS

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Plugin

#l10n_sessions, #recipients, #resolve_link, #update_rss_feeds

Methods included from HttpFile

#http_body, #http_file

Constructor Details

- (OuwerkerkPlugin) initialize(app, title = "med-drugs update")

A new instance of OuwerkerkPlugin



40
41
42
43
44
45
# File 'src/plugin/ouwerkerk.rb', line 40

def initialize(app, title = "med-drugs update")
  super(app)
  @title_base = title
  @file_name = @@today.strftime("med-drugs-%Y%m%d.xls")
  @file_path = File.expand_path("xls/#{@file_name}", self::class::ARCHIVE_PATH)
end

Instance Attribute Details

- (Object) bsv

Returns the value of attribute bsv



20
21
22
# File 'test/test_plugin/ouwerkerk.rb', line 20

def bsv
  @bsv
end

- (Object) file_path

Returns the value of attribute file_path



39
40
41
# File 'src/plugin/ouwerkerk.rb', line 39

def file_path
  @file_path
end

- (Object) smj

Returns the value of attribute smj



20
21
22
# File 'test/test_plugin/ouwerkerk.rb', line 20

def smj
  @smj
end

Instance Method Details

- (Object) export_package(pack, row, pac_flags)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'src/plugin/ouwerkerk.rb', line 46

def export_package(pack, row, pac_flags)
  if(flags = pac_flags[pack.pointer.to_s])
    row[0] += flags
  end
  row[2] = pack.ikscd
  row[10] = pack.ikscat
  row[13] = pack.size
  if(price = pack.price_exfactory)
    row[16] = price.to_f
  end
  if(price = pack.price_public)
    row[17] = price.to_f
  end
  row[23] = pack.pharmacode
  row[24] = (pack.sl_entry.nil?) ? 'keine' : 'SL'
  row
end

- (Object) export_registration(reg, row, pac_flags)



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'src/plugin/ouwerkerk.rb', line 63

def export_registration(reg, row, pac_flags)
  rows = []
  row[1] = reg.iksnr
  if(ind = reg.indication)
    row[6] = ind.de
  end
  row[7] = reg.export_flag ? 'Export' : ''
  if(company = reg.company)
    row[12] = reg.company.name
    row[19] = reg.company.powerlink
  end
  if(reg.sequences.empty?)
    rows.push(row)
  else
    reg.sequences.each_value { |seq|
      seqrow = row.dup
      rows += export_sequence(seq, seqrow, pac_flags)
    }
  end
  rows
end

- (Object) export_registrations



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'src/plugin/ouwerkerk.rb', line 84

def export_registrations
  if(lgrp = @app.log_group(:swissmedic))
    @smj = lgrp.latest
  end
  if(lgrp = @app.log_group(:bsv_sl))
    @bsv = lgrp.latest
  end
  registrations = @smj.nil? ? {} : @smj.change_flags
  packages = @bsv.nil? ? {} : @bsv.change_flags

  # Hash-Table lookups fail for p1 == p2, if p1.id != p2.id
  # we can work around that problem using the serialized form p1.to_s
  pointer_table = {}
  reg_flags = {}
  pac_flags = {}
  registrations.each { |pointer, flags| 
    key = pointer.to_s
    pointer_table.store(key, pointer)
    if(flags.empty?)
      flags.push(:not_specified)
    end
    reg_flags.store(key, flags)
  }
  packages.each { |pointer, flags|
    ptr = pointer.parent.parent
    key = ptr.to_s
    reg_flags[key] ||= []
    pointer_table.store(key, ptr)
    pac_flags.store(pointer.to_s, flags)
  }

  rows = []
  reg_flags.each { |ptr_str, flags|
    if(reg = pointer_table[ptr_str].resolve(@app))
      rows += export_registration(reg, [flags], pac_flags)
    end
  }
  rows.delete_if { |row| 
    row[0] = row[0].collect { |flg| 
      self::class::NUMERIC_FLAGS[flg] 
    }.compact.uniq.sort
    row.first.empty?
  }
  rows.sort_by { |row| 
    [ 
      row.first, 
      row.at(4).to_s, 
      row.at(1).to_i, 
      row.at(3).to_i, 
      row.at(2).to_i 
    ] 
  }.collect { |row|
    row[0] = row.first.join(',')
    row
  }
end

- (Object) export_sequence(seq, row, pac_flags)



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'src/plugin/ouwerkerk.rb', line 140

def export_sequence(seq, row, pac_flags)
  rows = []
  row[3,2] = [
    seq.seqnr,
    seq.name,
  ]
  ## Sequence#dose is obsolete - it's just a sum of all ActiveAgent's Doses
  if (dose = seq.dose) && dose.is_a?(Dose)
    row[8,2] = [
      dose.qty,
      dose.unit,
    ]
  end
  row[11] = seq.active_agents.size
  seq.galenic_forms.collect { |galform|
    row[14] = galform.de
  }.join(', ')
  row[15] = seq.composition_text
  if(atc = seq.atc_class)
    row[21] = atc.code
  end
  if(seq.packages.empty?)
    rows << row
  else
    seq.packages.each_value { |pack| 
      prow = row.dup
      rows << export_package(pack, prow, pac_flags)
    }
  end
  rows
end

- (Object) export_xls(opts = {})



171
# File 'src/plugin/ouwerkerk.rb', line 171

def export_xls opts={}

- (Object) log_info



217
218
219
220
221
222
223
224
# File 'src/plugin/ouwerkerk.rb', line 217

def log_info
  hash = super
  if @file_path
    hash.store(:files, { @file_path => "application/vnd.ms-excel"}) 
  end
  hash.store(:date_str, date_str)
  hash
end

- (Object) title Also known as: report



225
226
227
# File 'src/plugin/ouwerkerk.rb', line 225

def title
  @title ||= @title_base + " #{date_str}"
end