oddb.org 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. data/.gemtest +0 -0
  2. data/Guide.txt +23 -17
  3. data/{README → INSTALL_from_Source.txt} +64 -75
  4. data/Manifest.txt +110 -4
  5. data/README.txt +4 -2
  6. data/Rakefile +5 -0
  7. data/doc/favicon.ico +0 -0
  8. data/doc/index.rbx +15 -0
  9. data/doc/resources/anthroposophy/favicon.ico +0 -0
  10. data/doc/resources/anthroposophy/logo.png +0 -0
  11. data/doc/resources/atupri/logo.gif +0 -0
  12. data/doc/resources/desitin/logo.jpg +0 -0
  13. data/doc/resources/downloads/datadesc/analysis.csv.txt +57 -0
  14. data/doc/resources/downloads/datadesc/doctors.csv.txt +43 -0
  15. data/doc/resources/downloads/datadesc/doctors.yaml.txt +52 -0
  16. data/doc/resources/downloads/datadesc/fachinfo.yaml.txt +107 -0
  17. data/doc/resources/downloads/datadesc/generics.xls.txt +42 -0
  18. data/doc/resources/downloads/datadesc/index_therapeuticus.txt +38 -0
  19. data/doc/resources/downloads/datadesc/interactions.yaml.txt +78 -0
  20. data/doc/resources/downloads/datadesc/migel.csv.txt +84 -0
  21. data/doc/resources/downloads/datadesc/narcotics.csv.txt +49 -0
  22. data/doc/resources/downloads/datadesc/narcotics.yaml.txt +40 -0
  23. data/doc/resources/downloads/datadesc/oddb.csv.txt +98 -0
  24. data/doc/resources/downloads/datadesc/oddb.yaml.txt +255 -0
  25. data/doc/resources/downloads/datadesc/oddb2.csv.txt +94 -0
  26. data/doc/resources/downloads/datadesc/oddbdat.txt +228 -0
  27. data/doc/resources/downloads/datadesc/patents.xls.txt +29 -0
  28. data/doc/resources/downloads/datadesc/patinfo.yaml.txt +79 -0
  29. data/doc/resources/downloads/datadesc/price_history.csv.txt +43 -0
  30. data/doc/resources/downloads/datadesc/price_history.yaml.txt +55 -0
  31. data/doc/resources/downloads/datadesc/s31x.txt +40 -0
  32. data/doc/resources/downloads/datadesc/swissdrug-update.xls.txt +59 -0
  33. data/doc/resources/downloads/examples/Inderal.Preisvergleich.csv +19 -0
  34. data/doc/resources/downloads/examples/analysis.csv +35 -0
  35. data/doc/resources/downloads/examples/compendium_ch.oddb.org.firefox.epub +0 -0
  36. data/doc/resources/downloads/examples/compendium_ch.oddb.org.htc.prc +0 -0
  37. data/doc/resources/downloads/examples/compendium_ch.oddb.org.kindle.mobi +0 -0
  38. data/doc/resources/downloads/examples/compendium_ch.oddb.org.stanza.epub +0 -0
  39. data/doc/resources/downloads/examples/doctors.csv +13 -0
  40. data/doc/resources/downloads/examples/doctors.yaml +238 -0
  41. data/doc/resources/downloads/examples/fachinfo.yaml +1255 -0
  42. data/doc/resources/downloads/examples/fachinfos_de.pdf +51565 -0
  43. data/doc/resources/downloads/examples/fachinfos_fr.pdf +52072 -0
  44. data/doc/resources/downloads/examples/generics.xls +0 -0
  45. data/doc/resources/downloads/examples/index_therapeuticus.tar.gz +0 -0
  46. data/doc/resources/downloads/examples/interactions.yaml +161 -0
  47. data/doc/resources/downloads/examples/migel.csv +36 -0
  48. data/doc/resources/downloads/examples/narcotics.yaml +92 -0
  49. data/doc/resources/downloads/examples/oddb.csv +1378 -0
  50. data/doc/resources/downloads/examples/oddb.yaml +14976 -0
  51. data/doc/resources/downloads/examples/oddb2.csv +1566 -0
  52. data/doc/resources/downloads/examples/oddbdat.tar.gz +0 -0
  53. data/doc/resources/downloads/examples/patents.xls +0 -0
  54. data/doc/resources/downloads/examples/patinfo.yaml +2505 -0
  55. data/doc/resources/downloads/examples/price_history.csv +99 -0
  56. data/doc/resources/downloads/examples/price_history.yaml +431 -0
  57. data/doc/resources/downloads/examples/swissdrug-update.xls +0 -0
  58. data/doc/resources/errors/appdown.html +50 -0
  59. data/doc/resources/errors/logo.png +0 -0
  60. data/doc/resources/errors/logo_de.gif +0 -0
  61. data/doc/resources/gcc/banner.gif +0 -0
  62. data/doc/resources/gcc/logo.png +0 -0
  63. data/doc/resources/gcc/logo_de.gif +0 -0
  64. data/doc/resources/gcc/logo_doc.gif +0 -0
  65. data/doc/resources/gcc/logo_fr.gif +0 -0
  66. data/doc/resources/gcc/logo_rss.png +0 -0
  67. data/doc/resources/generika/favicon.ico +0 -0
  68. data/doc/resources/generika/logo.gif +0 -0
  69. data/doc/resources/generika/logo_de.gif +0 -0
  70. data/doc/resources/generika/logo_fr.gif +0 -0
  71. data/doc/resources/homeopathy/favicon.ico +0 -0
  72. data/doc/resources/homeopathy/logo.png +0 -0
  73. data/doc/resources/icon_twitter.gif +0 -0
  74. data/doc/resources/innova/logo.gif +0 -0
  75. data/doc/resources/innova/logo_de.gif +0 -0
  76. data/doc/resources/javascript/admin.js +14 -0
  77. data/doc/resources/javascript/autofill.js +21 -0
  78. data/doc/resources/javascript/bit.ly.js +29 -0
  79. data/doc/resources/javascript/company.js +22 -0
  80. data/doc/resources/javascript/dojo/Editor.js +219 -0
  81. data/doc/resources/javascript/dojo/HtmlEditorToolbar.html +163 -0
  82. data/doc/resources/javascript/dojo/sigma.gif +0 -0
  83. data/doc/resources/javascript/widget/SymbolPalette.js +162 -0
  84. data/doc/resources/javascript/widget/Tooltip.js +85 -0
  85. data/doc/resources/javascript/widget/__package__.js +2 -0
  86. data/doc/resources/livemarks16.png +0 -0
  87. data/doc/resources/mail.gif +0 -0
  88. data/doc/resources/mobile/logo.png +0 -0
  89. data/doc/resources/paypal_donate.gif +0 -0
  90. data/doc/resources/phyto-pharma/favicon.ico +0 -0
  91. data/doc/resources/phyto-pharma/logo.png +0 -0
  92. data/doc/resources/plugins/Generika.cc.gif +0 -0
  93. data/doc/resources/plugins/Generika.cc.html +34 -0
  94. data/doc/resources/plugins/Generika.cc.src +34 -0
  95. data/doc/resources/plugins/oddb.org.gif +0 -0
  96. data/doc/resources/plugins/oddb.org.html +34 -0
  97. data/doc/resources/plugins/oddb.org.src +34 -0
  98. data/doc/resources/print.css +33 -0
  99. data/doc/resources/provita/logo_de.gif +0 -0
  100. data/doc/resources/santesuisse/logo_de.gif +0 -0
  101. data/doc/resources/schoenenberger/logo_de.gif +0 -0
  102. data/doc/resources/swissmedic/logo.png +0 -0
  103. data/doc/resources/swissmedic/logo_de.gif +0 -0
  104. data/doc/resources/swissmedic/logo_doc.gif +0 -0
  105. data/doc/resources/swissmedic/logo_fr.gif +0 -0
  106. data/doc/resources/sympany/logo.gif +0 -0
  107. data/doc/robots.txt +29 -0
  108. data/ext/export/src/generics_xls.rb +29 -5
  109. data/ext/export/src/oddbdat.rb +1 -1
  110. data/ext/export/test/test_generics_xls.rb +216 -0
  111. data/ext/export/test/test_oddbdat.rb +880 -0
  112. data/lib/oddb.org.rb +1 -1
  113. data/src/model/package.rb +3 -2
  114. data/src/plugin/analysis.rb +2 -0
  115. data/src/plugin/bsv_xml.rb +1 -1
  116. data/src/plugin/hospitals.rb +1 -0
  117. data/src/plugin/oddbdat_export.rb +12 -2
  118. data/src/plugin/text_info.rb +16 -29
  119. data/src/util/exporter.rb +21 -1
  120. data/src/util/log.rb +3 -0
  121. data/src/util/oddbapp.rb +1 -1
  122. data/src/util/oddbconfig.rb +1 -1
  123. data/src/util/updater.rb +9 -1
  124. data/test/data/html/interaction/flockhart/prepared_table.asp +820 -0
  125. data/test/data/html/interaction/flockhart/table.asp +820 -0
  126. data/test/data/html/text_info/News.html +18 -93
  127. data/test/suite.rb +78 -4
  128. data/test/test_model/package.rb +38 -0
  129. data/test/test_plugin/bsv_xml.rb +4 -2
  130. data/test/test_plugin/flockhart.rb +1 -1
  131. data/test/test_plugin/oddbdat_export.rb +79 -658
  132. data/test/test_plugin/ouwerkerk.rb +2 -2
  133. data/test/test_plugin/suite.rb +8 -6
  134. data/test/test_plugin/text_info.rb +40 -52
  135. data/test/test_plugin/{doctors.rb → zdoctor.rb} +0 -0
  136. data/test/test_util/exporter.rb +500 -0
  137. data/test/test_util/suite.rb +8 -6
  138. data/test/test_util/{log.rb → zlog.rb} +19 -0
  139. data/test/test_view/{search.rb → asearch.rb} +0 -0
  140. data/test/test_view/suite.rb +8 -6
  141. metadata +143 -14
@@ -0,0 +1,29 @@
1
+ User-agent: Mediapartners-Google*
2
+ Disallow: /
3
+ User-agent:
4
+ Disallow: /
5
+ User-agent: *
6
+ Disallow: /de/atupri/
7
+ Disallow: /fr/atupri/
8
+ Disallow: /en/atupri/
9
+ Disallow: /de/just-medical/
10
+ Disallow: /fr/just-medical/
11
+ Disallow: /en/just-medical/
12
+ Disallow: /de/hirslanden/
13
+ Disallow: /fr/hirslanden/
14
+ Disallow: /en/hirslanden/
15
+ Disallow: /de/generika/
16
+ Disallow: /fr/generika/
17
+ Disallow: /en/generika/
18
+ Disallow: /de/innova/
19
+ Disallow: /fr/innova/
20
+ Disallow: /en/innova/
21
+ Disallow: /de/provita/
22
+ Disallow: /fr/provita/
23
+ Disallow: /en/provita/
24
+ Disallow: /de/santesuisse/
25
+ Disallow: /fr/santesuisse/
26
+ Disallow: /en/santesuisse/
27
+ Disallow: /de/schoenenberger/
28
+ Disallow: /fr/schoenenberger/
29
+ Disallow: /en/schoenenberger/
@@ -9,6 +9,7 @@ require 'spreadsheet/excel'
9
9
  module ODDB
10
10
  module OdbaExporter
11
11
  class GenericXls
12
+ RECIPIENTS = [ 'mhatakeyama@ywesee.com', 'zdavatz@ywesee.com' ]
12
13
  FLAGS = {
13
14
  :address => 'neue Herstelleradresse',
14
15
  :comment => 'neue Bemerkung',
@@ -90,7 +91,7 @@ module ODDB
90
91
  generics = []
91
92
  comparables = []
92
93
  @app.each_package { |pac|
93
- if(pac.public? && pac.registration.active? && !pac.basename.nil? && pac.comparables.select{|pack| pack.basename.nil?}.empty?)
94
+ if(pac.public? && pac.registration.active?)
94
95
  if(pac.registration.original? && (comps = pac.comparables) \
95
96
  && !comps.empty?)
96
97
  originals.push(pac)
@@ -102,11 +103,28 @@ module ODDB
102
103
  }
103
104
  # Check Packages
104
105
  # Some packages cannot be compared if package basename is nil
105
- nilpackages = originals.select{|pac| pac.basename.nil?}.map{|pac| [pac.company_name, pac.barcode]}
106
+ nilpackages = originals.select{|pac| pac.basename.nil?} + generics.select{|pac| pac.basename.nil?}
106
107
  unless nilpackages.empty?
107
- error_message = "Package basename is nil. The package is not comparable.\n\n"
108
- error_message << "Package (company, EAN code): " << nilpackages.join(", ") << "\n"
109
- raise StandardError, error_message
108
+ message = "Package name may have a number in it and therefore basename becomes nil.\n"
109
+ message << "The following packages are skipped during export_generics, since the packages are not comparable.\n\n"
110
+ link = "http://#{SERVER_NAME}/de/gcc/search/zone/drugs/search_query/"
111
+ message << "Package (company, EAN code, link):\n"
112
+ message << nilpackages.map{|pac| [pac.company_name, pac.barcode, link + pac.barcode].join(", ")}.join("\n")
113
+ message << "\n"
114
+ log = Log.new(@@today)
115
+ log.report = [
116
+ "Class: #{self.class}",
117
+ "Method: export_generics",
118
+ "Message: #{message}",
119
+ "Backtrace:",
120
+ caller(0).join("\n"),
121
+ ].join("\n")
122
+ log.recipients = RECIPIENTS.dup
123
+ log.notify("Warning: Nil basename packages")
124
+
125
+ # Remove the packages that basename is nil
126
+ originals -= nilpackages
127
+ generics -= nilpackages
110
128
  end
111
129
 
112
130
  originals.sort.each { |pac| export_comparables(pac) }
@@ -176,3 +194,9 @@ module ODDB
176
194
  end
177
195
  end
178
196
  end
197
+
198
+ begin
199
+ require 'testenvironment2'
200
+ rescue LoadError
201
+ end
202
+
@@ -420,7 +420,7 @@ module ODDB
420
420
  11 => galform,
421
421
  12 => conc,
422
422
  13 => unit,
423
- 16 => @package.parts.first.multi,
423
+ 16 => @package.parts.first ? @package.parts.first.multi : '',
424
424
  17 => comform,
425
425
  18 => qty,
426
426
  19 => qty_unit,
@@ -0,0 +1,216 @@
1
+ #!/usr/bin/env ruby
2
+ # Odba::Exporter::TestGenericsXls -- oddb -- 22.12.2010 -- mhatakeyama@ywesee.com
3
+
4
+ $: << File.expand_path('../src', File.dirname(__FILE__))
5
+ $: << File.expand_path('../../../src', File.dirname(__FILE__))
6
+ $: << File.expand_path('../../..', File.dirname(__FILE__))
7
+
8
+ require 'test/unit'
9
+ require 'flexmock'
10
+ require 'spreadsheet'
11
+ require 'generics_xls'
12
+ require 'date'
13
+
14
+ module ODDB
15
+ module OdbaExporter
16
+ class TestGenericXls < Test::Unit::TestCase
17
+ include FlexMock::TestCase
18
+ def setup
19
+ @loggroup_swiss = LogGroup.new(:swissmedic_journal)
20
+ @loggroup_swiss.create_log(Date.today)
21
+ @loggroup_swiss.latest.change_flags = {123 => [:new]}
22
+ @loggroup_bsv = LogGroup.new(:bsv_sl)
23
+ @loggroup_bsv.create_log(Date.today)
24
+ @loggroup_bsv.latest.change_flags = {123 => [:price_cut]}
25
+
26
+ flexstub(ODBA.cache) do |cacheobj|
27
+ cacheobj.should_receive(:fetch_named).and_return do
28
+ flexmock do |appobj|
29
+ appobj.should_receive(:log_group).with(:swissmedic_journal).and_return(@loggroup_swiss)
30
+ appobj.should_receive(:log_group).with(:bsv_sl).and_return(@loggroup_bsv)
31
+ end
32
+ end
33
+ end
34
+
35
+ @pac = flexmock('Package') do |pack|
36
+ pack.should_receive(:basename).and_return("basename")
37
+ pack.should_receive(:dose).and_return("dose")
38
+ pack.should_receive(:comparable_size).and_return(111)
39
+ pack.should_receive(:barcode).and_return("222")
40
+ pack.should_receive(:pharmacode).and_return(333)
41
+ pack.should_receive(:name).and_return("name")
42
+ pack.should_receive(:price_exfactory).and_return(444.444)
43
+ pack.should_receive(:price_public).and_return(555.555)
44
+ pack.should_receive(:company_name).and_return("company_name")
45
+ pack.should_receive(:ikscat).and_return(666)
46
+ pack.should_receive(:sl_entry).and_return(777)
47
+ pack.should_receive(:registration_date).and_return(Date.new(2010,12,31))
48
+ pack.should_receive(:"registration.pointer").and_return(123)
49
+ pack.should_receive(:pointer).and_return(123)
50
+ pack.should_receive(:comparables).and_return([@pac])
51
+ pack.should_receive(:"registration.generic?").and_return(true)
52
+ pack.should_receive(:public?).and_return(true)
53
+ end
54
+
55
+ @generics_xls = GenericXls.new(".")
56
+ end
57
+ def test__remarks1
58
+ pac = flexstub(Package) do |pack|
59
+ pack.should_receive(:"registration.pointer").and_return(999)
60
+ pack.should_receive(:pointer).and_return(999)
61
+ end
62
+ assert_nil(@generics_xls._remarks(pac, 'Generikum'))
63
+ end
64
+ def test__remarks2
65
+ expect = "Generikum: neue Registration, Preissenkung"
66
+ assert_equal(expect, @generics_xls._remarks(@pac, 'Generikum'))
67
+ end
68
+ def test_remarks
69
+ expect = "Original: neue Registration, Preissenkung Generikum: neue Registration, Preissenkung"
70
+ assert_equal(expect, @generics_xls.remarks(@pac, @pac))
71
+ end
72
+ def test_format_price
73
+ price = nil
74
+ assert_nil(@generics_xls.format_price(price))
75
+ price = 12.349
76
+ assert_equal("12.35", @generics_xls.format_price(price))
77
+ end
78
+ def test_preprocess_fields
79
+ fields = [1,2,3,Date.new(2010, 12, 31)]
80
+ assert_equal(["1","2","3","31.12.2010"], @generics_xls.preprocess_fields(fields))
81
+ end
82
+ def test_format_original
83
+ expect = ["basename", "basename dose/111", "222", "333", "name", "dose", "111",
84
+ "444.44", "555.55", "company_name", "666", "SL", "31.12.2010"]
85
+ assert_equal(expect, @generics_xls.format_original(@pac))
86
+ end
87
+ def test_format_generic
88
+ pac = flexstub(@pac) do |pack|
89
+ pack.should_receive(:sl_entry).and_return(nil)
90
+ end
91
+ expect = ["222", "333", "name", "dose", "111", "444.44", "555.55", "company_name",
92
+ "666", "", "31.12.2010"]
93
+ assert_equal(expect, @generics_xls.format_generic(pac))
94
+ end
95
+ def test_format_row
96
+ expect = ["basename", "basename dose/111", "222", "333", "name", "dose", "111",
97
+ "444.44", "555.55", "company_name", "666", "SL", "31.12.2010", "222",
98
+ "333", "name", "dose", "111", "444.44", "555.55", "company_name",
99
+ "666", "SL", "31.12.2010",
100
+ "Original: neue Registration, Preissenkung Generikum: neue Registration, Preissenkung"]
101
+ assert_equal(expect, @generics_xls.format_row(@pac, @pac))
102
+ end
103
+ def assert_row(row)
104
+ flexstub(Spreadsheet::Excel) do |klass|
105
+ klass.should_receive(:new).and_return(flexmock{|book|
106
+ book.should_receive(:add_worksheet).and_return(flexmock{|sheet|
107
+ sheet.should_receive(:format_column)
108
+ sheet.should_receive(:write).with(0,0,Array, Spreadsheet::Format)
109
+ sheet.should_receive(:write).with(1,0,row) # This is the check point
110
+ })
111
+ })
112
+ end
113
+ end
114
+ def test_export_generic
115
+ expect_row = ["", "", "", "", "", "", "", "", "", "", "", "", "",
116
+ "222", "333", "name", "dose", "111", "444.44", "555.55",
117
+ "company_name", "666", "SL", "31.12.2010",
118
+ "Generikum: neue Registration, Preissenkung"]
119
+ assert_row(expect_row)
120
+ generics_xls = GenericXls.new(".")
121
+ assert_equal(2, generics_xls.export_generic(@pac))
122
+ end
123
+ def test_export_comparable
124
+ expect_row = ["basename", "basename dose/111", "222", "333", "name",
125
+ "dose", "111", "444.44", "555.55", "company_name", "666",
126
+ "SL", "31.12.2010", "222", "333", "name", "dose", "111",
127
+ "444.44", "555.55", "company_name", "666", "SL", "31.12.2010",
128
+ "Original: neue Registration, Preissenkung Generikum: neue Registration, Preissenkung"]
129
+ assert_row(expect_row)
130
+ generics_xls = GenericXls.new(".")
131
+ assert_equal(2, generics_xls.export_comparable(@pac, @pac))
132
+ end
133
+ def test_export_comparables
134
+ expect_row = ["basename", "basename dose/111", "222", "333", "name",
135
+ "dose", "111", "444.44", "555.55", "company_name", "666",
136
+ "SL", "31.12.2010", "222", "333", "name", "dose", "111",
137
+ "444.44", "555.55", "company_name", "666", "SL", "31.12.2010",
138
+ "Original: neue Registration, Preissenkung Generikum: neue Registration, Preissenkung"]
139
+ assert_row(expect_row)
140
+ generics_xls = GenericXls.new(".")
141
+ assert_equal(2, generics_xls.export_comparable(@pac, @pac))
142
+
143
+ end
144
+ def redefine_ODBA(package)
145
+ # This is a trick code, a little bit different from the flexstub in setup method
146
+ # That is why I can re-define the ODBA stub.
147
+ flexstub(ODBA) do |odba|
148
+ odba.should_receive(:cache).and_return(flexmock{|cache|
149
+ cache.should_receive(:fetch_named).and_return(flexmock{|app|
150
+ app.should_receive(:log_group).with(:swissmedic_journal).and_return(@loggroup_swiss)
151
+ app.should_receive(:log_group).with(:bsv_sl).and_return(@loggroup_bsv)
152
+ app.should_receive(:each_package).and_yield(package)
153
+ })
154
+ })
155
+ end
156
+ end
157
+ def test_export_generics__case_no_output
158
+ # Note:
159
+ # if the return value of comparables is not empty (point.1), or
160
+ # if the return value of registration.generics? is not false (ture) (point.2),
161
+ # then you have to define the other method in the flexstub(Package),
162
+ # since export_comparables or export_generic will be called.
163
+ pac = flexstub(@pac) do |pack|
164
+ pack.should_receive(:"registration.active?").and_return(true)
165
+ pack.should_receive(:"registration.original?").and_return(true)
166
+ pack.should_receive(:comparables).and_return([]) # point.1
167
+ pack.should_receive(:"registration.generic?").and_return(false) # point.2
168
+ end
169
+
170
+ redefine_ODBA(pac)
171
+
172
+ generics_xls = GenericXls.new(".")
173
+ assert_equal(2, generics_xls.export_generics)
174
+ end
175
+ def test_export_generics__case_warning
176
+ pac = flexstub(@pac) do |pack|
177
+ pack.should_receive(:"registration.active?").and_return(true)
178
+ pack.should_receive(:"registration.original?").and_return(true)
179
+ pack.should_receive(:basename).and_return(nil) # This is the point
180
+ end
181
+
182
+ redefine_ODBA(pac)
183
+
184
+ # Note:
185
+ # if the following flexstub is not defined,
186
+ # an actual email will be sent.
187
+ flexstub(Log) do |log|
188
+ log.should_receive(:new)
189
+ end
190
+
191
+ generics_xls = GenericXls.new(".")
192
+ assert_raise(NoMethodError) do # This means the report process runs if this assert passes
193
+ generics_xls.export_generics
194
+ end
195
+ end
196
+ def test_export_generics__case_export
197
+ pac = flexstub(@pac) do |pack|
198
+ pack.should_receive(:"registration.active?").and_return(true)
199
+ pack.should_receive(:"registration.original?").and_return(true)
200
+ pack.should_receive(:comparables).and_return([])
201
+ pack.should_receive(:basename).and_return("basename") # This is the point
202
+ pack.should_receive(:"registration.generic?").and_return(true) # This is the point
203
+ pack.should_receive(:"registration.pointer").and_return(123)
204
+ end
205
+
206
+ redefine_ODBA(pac)
207
+
208
+ # Note:
209
+ # The actual row value (data) is not checked here,
210
+ # since it is tested in test_export_generic.
211
+ generics_xls = GenericXls.new(".")
212
+ assert_equal(3, generics_xls.export_generics)
213
+ end
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,880 @@
1
+ #!/usr/bin/env ruby
2
+ # ODDB::OdbaExporter::TestTable, TestLine -- oddb -- 03.02.2011 -- mhatakeyama@ywesee.com
3
+
4
+ $: << File.expand_path('../src', File.dirname(__FILE__))
5
+ $: << File.expand_path('../../../src', File.dirname(__FILE__))
6
+ $: << File.expand_path('../../..', File.dirname(__FILE__))
7
+ $: << File.expand_path('../../../test', File.dirname(__FILE__))
8
+
9
+ require 'stub/odba'
10
+ require 'test/unit'
11
+ require 'flexmock'
12
+ require 'oddbdat'
13
+ require 'model/package'
14
+ require 'model/text'
15
+ require 'date'
16
+
17
+
18
+ # This definition is called in TestMCMTable
19
+ class String
20
+ def src
21
+ self + ".src"
22
+ end
23
+ end
24
+
25
+ module ODDB
26
+ module OdbaExporter
27
+ DATE = Date.today.strftime("%Y%m%d%H%M%S")
28
+ # Tests for *Line classes
29
+ class TestLine < Test::Unit::TestCase
30
+ Line::LENGTH = 3
31
+ def setup
32
+ @line = Line.new
33
+ end
34
+ def test_content
35
+ assert_equal([], @line.content(nil))
36
+ structure = {1=>"1", 2=>"2", 3=>"3"}
37
+ assert_equal(["1", "2", "3"], @line.content(structure))
38
+ end
39
+ def test_empty?
40
+ assert_equal(true, @line.empty?)
41
+ end
42
+ def test_structure
43
+ assert_equal(nil, @line.structure)
44
+ end
45
+ def test_to_s
46
+ assert_equal('', @line.to_s)
47
+ end
48
+ end
49
+ class TestAcLine < Test::Unit::TestCase
50
+ include FlexMock::TestCase
51
+ def setup
52
+ @package = ODDB::Package.new('12')
53
+ @registration = flexmock('registration') do |mock|
54
+ mock.should_receive(:generic_type).and_return(:generic)
55
+ #mock.should_receive(:registration_date).and_return(Date.today)
56
+ mock.should_receive(:registration_date).and_return(Date.new(2011,2,3))
57
+ end
58
+ @package.sequence = flexmock('sequence') do |seq|
59
+ seq.should_receive(:registration).and_return @registration
60
+ seq.should_receive(:iksnr).and_return('12345')
61
+ end
62
+ @package.create_sl_entry
63
+ @package.sl_entry.limitation = 'limitation'
64
+ @package.sl_entry.limitation_points = 5
65
+ flexstub(@package).should_receive(:oid).and_return(123)
66
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
67
+ @acline = AcLine.new(@package)
68
+ end
69
+ def test_generic_code
70
+ assert_equal('Y', @acline.generic_code(@registration))
71
+ end
72
+ def test_iks_date
73
+ expected = '20110203'
74
+ assert_equal(expected, @acline.iks_date(@registration))
75
+ end
76
+ def test_ikskey
77
+ assert_equal('12345012', @acline.ikskey)
78
+ end
79
+ def test_inscode
80
+ assert_equal('1', @acline.inscode)
81
+ end
82
+ def test_limitation
83
+ assert_equal('Y', @acline.limitation)
84
+ end
85
+ def test_limitation_points
86
+ assert_equal(5, @acline.limitation_points)
87
+ end
88
+ def test_structure
89
+ expected = {
90
+ 1 =>"01",
91
+ 2 =>"20110203000000",
92
+ 3 =>"1",
93
+ 4 =>123,
94
+ 5 =>"4",
95
+ 7 =>"12345012",
96
+ 14=>nil,
97
+ 20=>"Y",
98
+ 22=>"20110203",
99
+ 29=>"3",
100
+ 32=>nil,
101
+ 39=>"1",
102
+ 40=>"Y",
103
+ 41=>5,
104
+ 47=>nil,
105
+ }
106
+
107
+ # test
108
+ assert_equal(expected.sort, @acline.structure.sort)
109
+ end
110
+ end
111
+ class TestAccompLine < Test::Unit::TestCase
112
+ include FlexMock::TestCase
113
+ def test_structure
114
+ package = ODDB::Package.new('12')
115
+ flexstub(package).should_receive(:oid).and_return(123)
116
+ registration = flexmock('registration') do |mock|
117
+ mock.should_receive(:company).and_return(flexmock('compay') do |comp|
118
+ comp.should_receive(:oid).and_return(111)
119
+ end)
120
+ end
121
+ package.sequence = flexmock('sequence') do |seq|
122
+ seq.should_receive(:registration).and_return registration
123
+ seq.should_receive(:iksnr).and_return('12345')
124
+ end
125
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
126
+ @accompline = AccompLine.new(package)
127
+ expected = {
128
+ 1=>"19",
129
+ 2=>"20110203000000",
130
+ 3=>123,
131
+ 4=>111,
132
+ 5=>"H",
133
+ 6=>"4",
134
+ }
135
+ assert_equal(expected.sort, @accompline.structure.sort)
136
+ end
137
+ end
138
+ class TestAcLimLine < Test::Unit::TestCase
139
+ include FlexMock::TestCase
140
+ def test_structure
141
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
142
+ @aclimline = AcLimLine.new(111, 222, 333)
143
+ expected = {
144
+ 1=>"09",
145
+ 2=>"20110203000000",
146
+ 3=>111,
147
+ 4=>333,
148
+ 5=>222,
149
+ 6=>"4",
150
+ }
151
+ assert_equal(expected.sort, @aclimline.structure.sort)
152
+ end
153
+ end
154
+ class TestAcnamLine < Test::Unit::TestCase
155
+ include FlexMock::TestCase
156
+ def setup
157
+ @package = ODDB::Package.new('12')
158
+ @package.sequence = flexmock('sequence') do |seq|
159
+ seq.should_receive(:galenic_forms).and_return(['galenic_forms'])
160
+ seq.should_receive(:dose).and_return(flexmock('dose') do |dose|
161
+ dose.should_receive(:is_a?).and_return(true)
162
+ dose.should_receive(:qty).and_return('qty')
163
+ dose.should_receive(:unit).and_return('unit')
164
+ end)
165
+ seq.should_receive(:name).and_return('name')
166
+ seq.should_receive(:name_base).and_return('name_base')
167
+ seq.should_receive(:name_descr).and_return('name_descr')
168
+ end
169
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
170
+ end
171
+ def test_structure__package_parts_nil_case
172
+ flexstub(@package) do |pack|
173
+ pack.should_receive(:oid).and_return(123)
174
+ pack.should_receive(:commercial_forms).and_return(['commercial_forms'])
175
+ pack.should_receive(:"comparable_size.qty").and_return('comparable_size.qty')
176
+ pack.should_receive(:parts).and_return([])
177
+ end
178
+
179
+ @acnamline = AcnamLine.new(@package)
180
+ expected = {
181
+ 1=>"03",
182
+ 2=>"20110203000000",
183
+ 3=>"1",
184
+ 4=>123,
185
+ 5=>"D",
186
+ 6=>"4",
187
+ 7=>"name",
188
+ 8=>"name_base",
189
+ 9=>"name_descr",
190
+ 11=>"galenic_forms",
191
+ 12=>"qty",
192
+ 13=>"unit",
193
+ 16=>"",
194
+ 17=>"commercial_forms",
195
+ 18=>"comparable_size.qty",
196
+ 19=>"commercial_forms",
197
+ }
198
+ assert_equal(expected.sort, @acnamline.structure.sort)
199
+ end
200
+ def test_structure__package_parts_not_nil_case
201
+ count = 0
202
+ part = flexmock('part') do |mock|
203
+ mock.should_receive(:measure).and_return(count+=1)
204
+ mock.should_receive(:multi).and_return('multi')
205
+ end
206
+ parts = [part, part, part]
207
+ flexstub(@package) do |pack|
208
+ pack.should_receive(:oid).and_return(123)
209
+ pack.should_receive(:commercial_forms).and_return(['commercial_forms'])
210
+ pack.should_receive(:"comparable_size.qty").and_return('comparable_size.qty')
211
+ pack.should_receive(:parts).and_return(parts)
212
+ end
213
+
214
+ @acnamline = AcnamLine.new(@package)
215
+ expected = {
216
+ 1=>"03",
217
+ 2=>"20110203000000",
218
+ 3=>"1",
219
+ 4=>123,
220
+ 5=>"D",
221
+ 6=>"4",
222
+ 7=>"name",
223
+ 8=>"name_base",
224
+ 9=>"name_descr",
225
+ 11=>"galenic_forms",
226
+ 12=>"qty",
227
+ 13=>"unit",
228
+ 16=>"multi",
229
+ 17=>"commercial_forms",
230
+ 18=>"comparable_size.qty",
231
+ 19=>"commercial_forms",
232
+ }
233
+ assert_equal(expected.sort, @acnamline.structure.sort)
234
+ end
235
+ end
236
+ class TestAcmedLine < Test::Unit::TestCase
237
+ include FlexMock::TestCase
238
+ def test_structure
239
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
240
+ package = ODDB::Package.new('12')
241
+ flexstub(package) do |pack|
242
+ pack.should_receive(:oid).and_return(123)
243
+ pack.should_receive(:fachinfo).and_return(flexmock('fachinfo') do |fach|
244
+ fach.should_receive(:oid).and_return('fachinfo.oid')
245
+ end)
246
+ end
247
+ package.sequence = flexmock('sequence') do |seq|
248
+ seq.should_receive(:atc_class).and_return(flexmock('atc_class') do |atc|
249
+ atc.should_receive(:code).and_return('atc.code')
250
+ end)
251
+ seq.should_receive(:galenic_forms).and_return(flexmock('galenic_forms') do |gal|
252
+ gal.should_receive(:first).and_return(flexmock('galform') do |form|
253
+ form.should_receive(:oid).and_return('galform.oid')
254
+ end)
255
+ end)
256
+ end
257
+
258
+ @acmedline = AcmedLine.new(package)
259
+ expected = {
260
+ 1=>"02",
261
+ 2=>"20110203000000",
262
+ 3=>"1",
263
+ 4=>123,
264
+ 5=>"4",
265
+ 7=>"fachinfo.oid",
266
+ 10=>"atc.code",
267
+ 12=>"galform.oid",
268
+ }
269
+ assert_equal(expected.sort, @acmedline.structure.sort)
270
+ end
271
+ end
272
+ class TestAcOddbLine < Test::Unit::TestCase
273
+ include FlexMock::TestCase
274
+ def test_structure
275
+ package = ODDB::Package.new('12')
276
+ flexstub(package).should_receive(:oid).and_return(123)
277
+ package.pharmacode = 223
278
+ @acoddbline = AcOddbLine.new(package)
279
+ expected = {
280
+ 1 => 123,
281
+ 2 => "223"
282
+ }
283
+ assert_equal(expected.sort, @acoddbline.structure.sort)
284
+ end
285
+ end
286
+ class TestAcpricealgPublicLine < Test::Unit::TestCase
287
+ include FlexMock::TestCase
288
+ def setup
289
+ @package = ODDB::Package.new('12')
290
+ @package.price_public = 123.45
291
+ flexstub(@package).should_receive(:oid).and_return(123)
292
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
293
+ @acpriceline = AcpricealgPublicLine.new(@package)
294
+ end
295
+ def test_price_public_type
296
+ assert_equal('PPUB', @acpriceline.price_public_type)
297
+ @package.create_sl_entry
298
+ assert_equal('PSL2', @acpriceline.price_public_type)
299
+ end
300
+ def test_structure
301
+ expected = {
302
+ 1=>"07",
303
+ 2=>"20110203000000",
304
+ 3=>123,
305
+ 4=>"PPUB",
306
+ 5=>"4",
307
+ 6=>"123.45",
308
+ }
309
+ assert_equal(expected.sort, @acpriceline.structure.sort)
310
+ end
311
+ end
312
+ class TestAcpricealgExfactoryLine < Test::Unit::TestCase
313
+ include FlexMock::TestCase
314
+ def test_structure
315
+ package = ODDB::Package.new('12')
316
+ flexstub(package).should_receive(:oid).and_return(123)
317
+ package.price_exfactory = 123.45
318
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
319
+ @acpriceline = AcpricealgExfactoryLine.new(package)
320
+ expected = {
321
+ 1=>"07",
322
+ 2=>"20110203000000",
323
+ 3=>123,
324
+ 4=>"PSL1",
325
+ 5=>"4",
326
+ 6=>"123.45",
327
+ }
328
+ assert_equal(expected.sort, @acpriceline.structure.sort)
329
+ end
330
+ end
331
+ class TestAcscLine < Test::Unit::TestCase
332
+ include FlexMock::TestCase
333
+ def test_structure
334
+ # test nil case
335
+ package = ODDB::Package.new('12')
336
+ @acscline = AcscLine.new(package, nil, 'count')
337
+ assert_equal(nil, @acscline.structure)
338
+
339
+ # test not nil case
340
+ flexstub(package).should_receive(:oid).and_return(123)
341
+ active_agent = flexmock('active_agent') do |act|
342
+ act.should_receive(:dose).and_return(flexmock('dose') do |dose|
343
+ dose.should_receive(:is_a?).and_return(true)
344
+ dose.should_receive(:qty).and_return('qty')
345
+ dose.should_receive(:unit).and_return('unit')
346
+ end)
347
+ act.should_receive(:substance).and_return(flexmock('oid') do |oid|
348
+ oid.should_receive(:oid).and_return('oid')
349
+ end)
350
+ end
351
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
352
+ @acscline =AcscLine.new(package, active_agent, 223)
353
+
354
+ expected = {
355
+ 1=>"41",
356
+ 2=>"20110203000000",
357
+ 3=>123,
358
+ 4=>223,
359
+ 5=>"4",
360
+ 6=>"oid",
361
+ 7=>"qty",
362
+ 8=>"unit",
363
+ 9=>"W",
364
+ }
365
+ assert_equal(expected.sort, @acscline.structure.sort)
366
+ end
367
+ end
368
+ class TestAtcLine < Test::Unit::TestCase
369
+ include FlexMock::TestCase
370
+ def test_structure
371
+ # test nil case
372
+ @atcline = AtcLine.new(nil)
373
+ assert_equal(nil, @atcline.structure)
374
+
375
+ # test not nil case
376
+ atcclass = flexmock('atcclass') do |atc|
377
+ atc.should_receive(:code).and_return('code')
378
+ atc.should_receive(:description).and_return('description')
379
+ end
380
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
381
+ @atcline = AtcLine.new(atcclass)
382
+ expected = {
383
+ 1=>"11",
384
+ 2=>"20110203000000",
385
+ 3=>"8",
386
+ 4=>"code",
387
+ 5=>"D",
388
+ 6=>"4",
389
+ 7=>"description",
390
+ }
391
+ assert_equal(expected, @atcline.structure)
392
+ end
393
+ end
394
+ class TestCompLine < Test::Unit::TestCase
395
+ include FlexMock::TestCase
396
+ def test_structure
397
+ company = flexmock('company') do |comp|
398
+ comp.should_receive(:oid).and_return('oid')
399
+ comp.should_receive(:ean13).and_return('ean13')
400
+ comp.should_receive(:name).and_return('name')
401
+ comp.should_receive(:address_email).and_return('address_email')
402
+ comp.should_receive(:url).and_return('url')
403
+ comp.should_receive(:address).and_return(flexmock('addr') do |addr|
404
+ addr.should_receive(:address).and_return('address')
405
+ addr.should_receive(:plz).and_return('plz')
406
+ addr.should_receive(:city).and_return('city')
407
+ addr.should_receive(:"fon.first").and_return('fon.first')
408
+ addr.should_receive(:"fax.first").and_return('fax.first')
409
+ end)
410
+ end
411
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
412
+ @compline = CompLine.new(company)
413
+ expected = {
414
+ 1=>"12",
415
+ 2=>"20110203000000",
416
+ 3=>"oid",
417
+ 4=>"4",
418
+ 5=>"ean13",
419
+ 7=>"name",
420
+ 8=>"address",
421
+ 9=>"CH",
422
+ 10=>"plz",
423
+ 11=>"city",
424
+ 13=>"fon.first",
425
+ 15=>"fax.first",
426
+ 16=>"address_email",
427
+ 17=>"url",
428
+ }
429
+ assert_equal(expected.sort, @compline.structure.sort)
430
+ end
431
+ end
432
+ class TestEanLine < Test::Unit::TestCase
433
+ include FlexMock::TestCase
434
+ def setup
435
+ packclass = flexmock('package') do |pack|
436
+ pack.should_receive(:new).and_return(flexmock do |mock|
437
+ mock.should_receive(:oid).and_return('oid')
438
+ mock.should_receive(:barcode).and_return('barcode')
439
+ end)
440
+ end
441
+ @package = packclass.new
442
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
443
+ end
444
+ def test_barcode
445
+ @eanline = EanLine.new(@package)
446
+ assert_equal('barcode', @eanline.barcode)
447
+ end
448
+ def test_structure
449
+ @eanline = EanLine.new(@package)
450
+ expected = {
451
+ 1=>"06",
452
+ 2=>"20110203000000",
453
+ 3=>"oid",
454
+ 4=>"E13",
455
+ 5=>"barcode",
456
+ 6=>"4",
457
+ }
458
+ assert_equal(expected, @eanline.structure)
459
+ end
460
+ end
461
+ class TestGalenicFormLine < Test::Unit::TestCase
462
+ include FlexMock::TestCase
463
+ def test_structure
464
+ galenic_form = flexmock('galenic_form') do |gal|
465
+ gal.should_receive(:oid).and_return('oid')
466
+ gal.should_receive(:to_s).and_return('to_s')
467
+ end
468
+ @galenicline = GalenicFormLine.new(galenic_form)
469
+ expected = {
470
+ 1=>"11",
471
+ 2=>DATE,
472
+ 3=>"5",
473
+ 4=>"oid",
474
+ 5=>"D",
475
+ 6=>"4",
476
+ 7=>"to_s",
477
+ }
478
+ assert_equal(expected.sort, @galenicline.structure.sort)
479
+ end
480
+ end
481
+ class TestScLine < Test::Unit::TestCase
482
+ include FlexMock::TestCase
483
+ def test_structure
484
+ package = ODDB::Package.new('12')
485
+ substance = flexmock('substance') do |sub|
486
+ sub.should_receive(:oid).and_return('oid')
487
+ end
488
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
489
+ @scline = ScLine.new(package, substance)
490
+ expected = {
491
+ 1=>"40",
492
+ 2=>"20110203000000",
493
+ 3=>"oid",
494
+ 4=>"L",
495
+ 5=>"4",
496
+ 6=>substance,
497
+ }
498
+ assert_equal(expected.sort, @scline.structure.sort)
499
+ end
500
+ end
501
+ class TestLimitationLine < Test::Unit::TestCase
502
+ include FlexMock::TestCase
503
+ def test_structure
504
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
505
+ @limitationline = LimitationLine.new('lim_oid')
506
+ expected = {
507
+ 1=>"16",
508
+ 2=>"20110203000000",
509
+ 3=>"lim_oid",
510
+ 5=>"4",
511
+ 6=>"COM",
512
+ }
513
+ assert_equal(expected.sort, @limitationline.structure.sort)
514
+ end
515
+ end
516
+ class TestLimTxtLine < Test::Unit::TestCase
517
+ include FlexMock::TestCase
518
+ def test_structure
519
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
520
+ @limtxtline = LimTxtLine.new('lim_oid', 'language', 'txt')
521
+ expected = {
522
+ 1=>"10",
523
+ 2=>"20110203000000",
524
+ 3=>"lim_oid",
525
+ 4=>"language",
526
+ 5=>"4",
527
+ 6=>"txt",
528
+ }
529
+ assert_equal(expected.sort, @limtxtline.structure.sort)
530
+ end
531
+ end
532
+ class TestMCMLine < Test::Unit::TestCase
533
+ include FlexMock::TestCase
534
+ def test_structure
535
+ flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000')
536
+ @mcmline = MCMLine.new('fi_oid', 'line_nr', 'language', 'text')
537
+ expected = {
538
+ 1=>"31",
539
+ 7=>"text",
540
+ 2=>"20110203000000",
541
+ 3=>"fi_oid",
542
+ 4=>"L",
543
+ 5=>"line_nr",
544
+ 6=>"4",
545
+ }
546
+ assert_equal(expected.sort, @mcmline.structure.sort)
547
+ end
548
+ end
549
+
550
+ # Tests for *Table classes
551
+ class TestTable < Test::Unit::TestCase
552
+ Table::FILENAME = 'table'
553
+ def test_filename
554
+ table = Table.new
555
+ assert_equal('table', table.filename)
556
+ end
557
+ end
558
+ class TestAcTable < Test::Unit::TestCase
559
+ include FlexMock::TestCase
560
+ def test_lines
561
+ flexstub(AcLine).should_receive(:new).and_return('acline')
562
+ @actable = AcTable.new
563
+ assert_equal(['acline'], @actable.lines('package'))
564
+ end
565
+ end
566
+ class TestAccompTable < Test::Unit::TestCase
567
+ include FlexMock::TestCase
568
+ def test_lines
569
+ flexstub(AccompLine).should_receive(:new).and_return('accompline')
570
+ @accomptable = AccompTable.new
571
+ assert_equal(['accompline'], @accomptable.lines('package'))
572
+ end
573
+ end
574
+ class TestAcLimTable < Test::Unit::TestCase
575
+ include FlexMock::TestCase
576
+ def test_lines
577
+ # test package.sl_entry == nil calse
578
+ package = ODDB::Package.new('12')
579
+ @aclimtable = AcLimTable.new
580
+ assert_equal([], @aclimtable.lines(package))
581
+
582
+ # test not nil case
583
+ ## preparation
584
+ package.create_sl_entry
585
+ package.sl_entry.create_limitation_text
586
+ paragraphs = [1,2]
587
+ chap = flexmock('chap') do |chap|
588
+ chap.should_receive(:paragraphs).and_return(flexmock('paragraphs') do |para|
589
+ para.should_receive(:each_with_index).and_yield(paragraphs)
590
+ end)
591
+ end
592
+ package.sl_entry.limitation_text.descriptions[0] = chap
593
+ ## test
594
+ flexstub(AcLimLine).should_receive(:new).with(1,2,1002).and_return('aclimline')
595
+ assert_equal(['aclimline'], @aclimtable.lines(package))
596
+ end
597
+ end
598
+ class TestAcmedTable < Test::Unit::TestCase
599
+ include FlexMock::TestCase
600
+ def test_lines
601
+ flexstub(AcmedLine).should_receive(:new).and_return('acmedline')
602
+ @acmedtable = AcmedTable.new
603
+ assert_equal(['acmedline'], @acmedtable.lines('package'))
604
+ end
605
+ end
606
+ class TestAcnamTable < Test::Unit::TestCase
607
+ include FlexMock::TestCase
608
+ def test_lines
609
+ flexstub(AcnamLine).should_receive(:new).and_return('acnamline')
610
+ @acnamtable = AcnamTable.new
611
+ assert_equal(['acnamline'], @acnamtable.lines('package'))
612
+ end
613
+ end
614
+ class TestAcOddbTable < Test::Unit::TestCase
615
+ include FlexMock::TestCase
616
+ def test_lines
617
+ # test package.pharmacode nil case
618
+ package = ODDB::Package.new('12')
619
+ @acoddbtable = AcOddbTable.new
620
+ assert_equal([], @acoddbtable.lines(package))
621
+
622
+ # test not nil case
623
+ package.pharmacode = 123
624
+ flexstub(AcOddbLine).should_receive(:new).and_return('acoddbline')
625
+ assert_equal(['acoddbline'], @acoddbtable.lines(package))
626
+ end
627
+ end
628
+ class TestAcpricealgTable < Test::Unit::TestCase
629
+ include FlexMock::TestCase
630
+ def test_lines
631
+ flexstub(AcpricealgPublicLine).should_receive(:new).and_return('acpricepublic')
632
+ flexstub(AcpricealgExfactoryLine).should_receive(:new).and_return('acpriceexfactory')
633
+ @acpricetable = AcpricealgTable.new
634
+ assert_equal(["acpricepublic", "acpriceexfactory"], @acpricetable.lines('package'))
635
+ end
636
+ end
637
+ class TestAcscTable < Test::Unit::TestCase
638
+ include FlexMock::TestCase
639
+ def test_lines
640
+ active_agents = ['act']
641
+ package = flexmock('package') do |pack|
642
+ pack.should_receive(:active_agents).and_return(active_agents)
643
+ end
644
+
645
+ # test
646
+ flexstub(AcscLine).should_receive(:new).with(package, 'act', 0).and_return('acscline')
647
+ @acsctable = AcscTable.new
648
+ assert_equal(['acscline'], @acsctable.lines(package))
649
+ end
650
+ end
651
+ class TestLimitationTable < Test::Unit::TestCase
652
+ include FlexMock::TestCase
653
+ def test_lines
654
+ # test package.sl_entry nil case
655
+ package = ODDB::Package.new('12')
656
+ @limitationtable = LimitationTable.new
657
+ assert_equal([], @limitationtable.lines(package))
658
+
659
+ # test not nil case
660
+ package.create_sl_entry
661
+ package.sl_entry.create_limitation_text
662
+ paragraphs = ['par']
663
+ chap = flexmock('chap') do |cha|
664
+ cha.should_receive(:paragraphs).and_return(paragraphs)
665
+ end
666
+ package.sl_entry.limitation_text.descriptions[0] = chap
667
+ flexstub(package).should_receive(:oid).and_return(123)
668
+
669
+ # test
670
+ flexstub(LimitationLine).should_receive(:new).with(123000).and_return('limitationline')
671
+ assert_equal(['limitationline'], @limitationtable.lines(package))
672
+ end
673
+ end
674
+ class TestLimTxtTable < Test::Unit::TestCase
675
+ include FlexMock::TestCase
676
+ def test_lines
677
+ # test package.sl_entry nil case
678
+ package = ODDB::Package.new('12')
679
+ @limtxttable = LimTxtTable.new
680
+ assert_equal([], @limtxttable.lines(package))
681
+
682
+ # test not nil case
683
+ package.create_sl_entry
684
+ package.sl_entry.create_limitation_text
685
+ flexstub(package).should_receive(:oid).and_return(123)
686
+ paragraph = flexmock('par') do |par|
687
+ par.should_receive(:text).and_return('text')
688
+ end
689
+ paragraphs = [paragraph]
690
+ chap = flexmock('chap') do |cha|
691
+ cha.should_receive(:paragraphs).and_return(paragraphs)
692
+ end
693
+ package.sl_entry.limitation_text.descriptions['lang'] = chap
694
+
695
+ # test
696
+ flexstub(LimTxtLine).should_receive(:new).with(123000, 'L', 'text').and_return('limtxtline')
697
+ assert_equal(['limtxtline'], @limtxttable.lines(package))
698
+ end
699
+ end
700
+ class TestEanTable < Test::Unit::TestCase
701
+ include FlexMock::TestCase
702
+ def test_lines
703
+ flexstub(EanLine).should_receive(:new).and_return('eanline')
704
+ @eantable = EanTable.new
705
+ assert_equal(['eanline'], @eantable.lines('package'))
706
+ end
707
+ end
708
+ # The following constants are necessary for TestMCMTable
709
+ ODDB::Text::ImageLink = 'imagelink'
710
+ ODDB::Text::Table = 'table'
711
+ SERVER_NAME = 'server_name/'
712
+ class TestMCMTable < Test::Unit::TestCase
713
+ include FlexMock::TestCase
714
+ def setup
715
+ @mcmtable = MCMTable.new
716
+ end
717
+ def test_lines
718
+ # test fi.description empty case
719
+ fi = flexmock('fi') do |f|
720
+ f.should_receive(:descriptions).and_return([])
721
+ end
722
+ assert_equal([], @mcmtable.lines(fi))
723
+
724
+ # test not empty case
725
+ flexstub(MCMLine).should_receive(:new).and_return('mcmline')
726
+ chapter = flexmock('chapter') do |chap|
727
+ chap.should_receive(:heading).and_return('')
728
+ chap.should_receive(:sections).and_return([])
729
+ end
730
+ doc = flexmock('doc') do |d|
731
+ d.should_receive(:each_chapter).and_yield(chapter)
732
+ end
733
+ fi = flexmock('fi') do |f|
734
+ f.should_receive(:descriptions).and_return({'lang', doc})
735
+ f.should_receive(:oid).and_return('oid')
736
+ end
737
+ assert_equal(['mcmline'], @mcmtable.lines(fi))
738
+ end
739
+ def test_format_lines__sections_empty
740
+ chapter = flexmock('chapter') do |chap|
741
+ chap.should_receive(:heading).and_return('')
742
+ chap.should_receive(:sections).and_return([])
743
+ end
744
+
745
+ assert_equal('', @mcmtable.format_line(chapter))
746
+ end
747
+ def test_format_lines__sections_not_empty
748
+ format = flexmock('format') do |form|
749
+ form.should_receive(:italic?).and_return(true)
750
+ form.should_receive(:range).and_return(0..7)
751
+ end
752
+ paragraph = flexmock('paragraph') do |par|
753
+ par.should_receive(:text).and_return('par.text')
754
+ par.should_receive(:formats).and_return([format])
755
+ par.should_receive(:preformatted?).and_return(true)
756
+ end
757
+ section = flexmock('section') do |sec|
758
+ sec.should_receive(:subheading).and_return('subhead')
759
+ sec.should_receive(:paragraphs).and_return([paragraph])
760
+ end
761
+ chapter = flexmock('chapter') do |chap|
762
+ chap.should_receive(:heading).and_return('head')
763
+ chap.should_receive(:sections).and_return([section])
764
+ end
765
+
766
+ # test
767
+ expected = "<BI>head<E><P><I>subhead<E><I>par.text<E><P>"
768
+ assert_equal(expected, @mcmtable.format_line(chapter))
769
+ end
770
+ def test_format_lines__ImageLink
771
+ section = flexmock('section') do |sec|
772
+ sec.should_receive(:subheading).and_return('subhead')
773
+ sec.should_receive(:paragraphs).and_return([ODDB::Text::ImageLink])
774
+ end
775
+ chapter = flexmock('chapter') do |chap|
776
+ chap.should_receive(:heading).and_return('head')
777
+ chap.should_receive(:sections).and_return([section])
778
+ end
779
+
780
+ # test
781
+ expected = "<BI>head<E><P><I>subhead<E><IMG src='http://server_name/imagelink.src'/>"
782
+ assert_equal(expected, @mcmtable.format_line(chapter))
783
+ end
784
+ def test_format_lines__Table
785
+ section = flexmock('section') do |sec|
786
+ sec.should_receive(:subheading).and_return('subhead')
787
+ sec.should_receive(:paragraphs).and_return([ODDB::Text::Table])
788
+ end
789
+ chapter = flexmock('chapter') do |chap|
790
+ chap.should_receive(:heading).and_return('head')
791
+ chap.should_receive(:sections).and_return([section])
792
+ end
793
+
794
+ # test
795
+ expected = "<BI>head<E><P><I>subhead<E><N>table<E>"
796
+ assert_equal(expected, @mcmtable.format_line(chapter))
797
+ end
798
+ end
799
+ # the followings are necessary for TestCodesTable
800
+ AtcClass = 'atcclass'
801
+ GalenicForm = 'galenicform'
802
+ class TestCodesTable < Test::Unit::TestCase
803
+ include FlexMock::TestCase
804
+ def setup
805
+ flexstub(AtcLine).should_receive(:new).and_return('atcline')
806
+ flexstub(GalenicFormLine).should_receive(:new).and_return('galenicformline')
807
+ @codestable = CodesTable.new
808
+ end
809
+ def test_atclines
810
+ assert_equal(['atcline'], @codestable.atclines('atcclass'))
811
+ end
812
+ def test_gallines
813
+ assert_equal(['galenicformline'], @codestable.gallines('galform'))
814
+ end
815
+ def test_lines
816
+ assert_equal(['atcline'], @codestable.lines(AtcClass))
817
+ assert_equal(['galenicformline'], @codestable.lines(GalenicForm))
818
+ end
819
+ end
820
+ class TestScTable < Test::Unit::TestCase
821
+ include FlexMock::TestCase
822
+ def test_lines
823
+ flexstub(ScLine).should_receive(:new).and_return('scline')
824
+ @sctable = ScTable.new
825
+ assert_equal(['scline'], @sctable.lines('substance'))
826
+ end
827
+ end
828
+ class TestCompTable < Test::Unit::TestCase
829
+ include FlexMock::TestCase
830
+ def test_lines
831
+ flexstub(CompLine).should_receive(:new).and_return('compline')
832
+ @comptable = CompTable.new
833
+ assert_equal(['compline'], @comptable.lines('company'))
834
+ end
835
+ end
836
+ class TestReadme < Test::Unit::TestCase
837
+ def test_lines
838
+ expected = <<-EOS
839
+ oddbdat.tar.gz und oddbdat.zip enthalten die täglich aktualisierten Artikelstammdaten der ODDB. Die Daten werden von ywesee in das OddbDat-Format umgewandelt und allen gewünschten Systemlieferanten von Schweizer Spitälern zur Verfügung gestellt.
840
+
841
+ Feedback bitte an zdavatz@ywesee.com
842
+
843
+ -AC (Tabelle 1) - ODDB-Code
844
+ -ACMED (Tabelle 2) - Weitere Produktinformationen
845
+ -ACNAM (Tabelle 3) - Sprachen
846
+ -ACBARCODE (Tabelle 6) - EAN-Artikelcode
847
+ -ACPRICEALG (Tabelle 7) - Preise
848
+ -ACLIM (Tabelle 9) - Limitationen
849
+ -LIMTXT (Tabelle 10) - Limitationstexte
850
+ -CODES (Tabelle 11) - Codebeschreibungen (ATC-Beschreibung, Galenische Form)
851
+ -COMP (Tabelle 12) - Hersteller
852
+ -LIMITATION (Tabelle 16) - Limitationen der SL
853
+ -ACCOMP (Tabelle 19) - Verbindungstabelle zwischen AC und COMP
854
+ -SC (Tabelle 40) - Substanzen
855
+ -ACSC (Tabelle 41) - Verbindungstabelle zwischen AC und SC
856
+ -ACODDB (Tabelle 99) - Verbindungstabelle zwischen ODDB-ID und Pharmacode
857
+
858
+ Folgende Tabelle mit den Fachinformationen steht wegen ihrer Grösse separat als tar.gz- oder zip-Download zur Verfügung.
859
+
860
+ -MCM (Tabelle 31) - Fachinformationen
861
+
862
+ Die Daten werden als oddbdat.tar.gz und oddbdat.zip auf unserem Server bereitgestellt - Vorzugsweise benutzen Sie einen der folgenden direkten Links.
863
+
864
+ Ganze Packages (ohne Fachinformationen):
865
+ http://www.oddb.org/resources/downloads/oddbdat.tar.gz
866
+ http://www.oddb.org/resources/downloads/oddbdat.zip
867
+
868
+ Nur Fachinformationen (sehr grosse Dateien):
869
+ http://www.oddb.org/resources/downloads/s31x.tar.gz
870
+ http://www.oddb.org/resources/downloads/s31x.zip
871
+
872
+
873
+ EOS
874
+ assert_equal(expected, Readme.new.lines)
875
+ end
876
+ end
877
+
878
+ end
879
+ end
880
+