ramaze.ch.oddb.org 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (286) hide show
  1. data/History.txt +6 -0
  2. data/LICENSE +339 -0
  3. data/Manifest.txt +285 -0
  4. data/README.txt +45 -0
  5. data/Rakefile +28 -0
  6. data/bin/admin +69 -0
  7. data/bin/exportd +63 -0
  8. data/bin/migrate +461 -0
  9. data/bin/oddbd +62 -0
  10. data/data/fulltext/data/dicts/french/fulltext.aff +1057 -0
  11. data/data/fulltext/data/dicts/french/fulltext.dict +91189 -0
  12. data/data/fulltext/data/dicts/french/fulltext.stop +135 -0
  13. data/data/fulltext/data/dicts/german/fulltext.aff +1233 -0
  14. data/data/fulltext/data/dicts/german/fulltext.dict +287574 -0
  15. data/data/fulltext/data/dicts/german/fulltext.stop +133 -0
  16. data/data/fulltext/data/german_compound/README +15 -0
  17. data/data/fulltext/data/german_compound/compound.pl +63 -0
  18. data/data/fulltext/data/german_compound/german.stop +20 -0
  19. data/data/fulltext/data/ispell-german-compound.tar.gz +0 -0
  20. data/data/fulltext/redist/dict_french/Makefile +12 -0
  21. data/data/fulltext/redist/dict_french/README.french +1 -0
  22. data/data/fulltext/redist/dict_french/dict_french.sql.in +7 -0
  23. data/data/fulltext/redist/dict_french/dict_snowball.c +56 -0
  24. data/data/fulltext/redist/dict_french/french_stem.c +1222 -0
  25. data/data/fulltext/redist/dict_french/french_stem.h +16 -0
  26. data/data/fulltext/redist/dict_french/subinclude.h +2 -0
  27. data/data/fulltext/redist/dict_german/Makefile +12 -0
  28. data/data/fulltext/redist/dict_german/README.german +1 -0
  29. data/data/fulltext/redist/dict_german/dict_german.sql.in +7 -0
  30. data/data/fulltext/redist/dict_german/dict_snowball.c +56 -0
  31. data/data/fulltext/redist/dict_german/german_stem.c +527 -0
  32. data/data/fulltext/redist/dict_german/german_stem.h +16 -0
  33. data/data/fulltext/redist/dict_german/subinclude.h +1 -0
  34. data/data/fulltext/redist/french_stem.c +1222 -0
  35. data/data/fulltext/redist/french_stem.h +16 -0
  36. data/data/fulltext/redist/german_stem.c +527 -0
  37. data/data/fulltext/redist/german_stem.h +16 -0
  38. data/lib/fixes/ruby19.rb +21 -0
  39. data/lib/fixes/selenium.rb +20 -0
  40. data/lib/fixes/singular.rb +8 -0
  41. data/lib/fixes/yaml.rb +13 -0
  42. data/lib/oddb.rb +11 -0
  43. data/lib/oddb/business/company.rb +18 -0
  44. data/lib/oddb/business/invoice.rb +75 -0
  45. data/lib/oddb/business/price.rb +60 -0
  46. data/lib/oddb/config.rb +73 -0
  47. data/lib/oddb/drugs.rb +16 -0
  48. data/lib/oddb/drugs/active_agent.rb +37 -0
  49. data/lib/oddb/drugs/atc.rb +53 -0
  50. data/lib/oddb/drugs/composition.rb +41 -0
  51. data/lib/oddb/drugs/ddd.rb +24 -0
  52. data/lib/oddb/drugs/dose.rb +107 -0
  53. data/lib/oddb/drugs/galenic_form.rb +21 -0
  54. data/lib/oddb/drugs/galenic_group.rb +17 -0
  55. data/lib/oddb/drugs/package.rb +87 -0
  56. data/lib/oddb/drugs/part.rb +56 -0
  57. data/lib/oddb/drugs/product.rb +25 -0
  58. data/lib/oddb/drugs/sequence.rb +61 -0
  59. data/lib/oddb/drugs/substance.rb +31 -0
  60. data/lib/oddb/drugs/substance_group.rb +13 -0
  61. data/lib/oddb/drugs/unit.rb +12 -0
  62. data/lib/oddb/export.rb +4 -0
  63. data/lib/oddb/export/csv.rb +89 -0
  64. data/lib/oddb/export/l10n_sessions.rb +30 -0
  65. data/lib/oddb/export/rss.rb +44 -0
  66. data/lib/oddb/export/server.rb +58 -0
  67. data/lib/oddb/export/xls.rb +119 -0
  68. data/lib/oddb/export/yaml.rb +123 -0
  69. data/lib/oddb/html/state/drugs/admin/package.rb +189 -0
  70. data/lib/oddb/html/state/drugs/admin/product.rb +56 -0
  71. data/lib/oddb/html/state/drugs/admin/sequence.rb +259 -0
  72. data/lib/oddb/html/state/drugs/ajax/explain_ddd_price.rb +19 -0
  73. data/lib/oddb/html/state/drugs/ajax/explain_price.rb +19 -0
  74. data/lib/oddb/html/state/drugs/ajax/global.rb +18 -0
  75. data/lib/oddb/html/state/drugs/ajax/package_infos.rb +19 -0
  76. data/lib/oddb/html/state/drugs/ajax/remote_infos.rb +19 -0
  77. data/lib/oddb/html/state/drugs/atc_browser.rb +39 -0
  78. data/lib/oddb/html/state/drugs/atc_guidelines.rb +21 -0
  79. data/lib/oddb/html/state/drugs/compare.rb +52 -0
  80. data/lib/oddb/html/state/drugs/download_export.rb +18 -0
  81. data/lib/oddb/html/state/drugs/fachinfo.rb +21 -0
  82. data/lib/oddb/html/state/drugs/feedback.rb +94 -0
  83. data/lib/oddb/html/state/drugs/global.rb +266 -0
  84. data/lib/oddb/html/state/drugs/init.rb +18 -0
  85. data/lib/oddb/html/state/drugs/login.rb +17 -0
  86. data/lib/oddb/html/state/drugs/package.rb +32 -0
  87. data/lib/oddb/html/state/drugs/patinfo.rb +21 -0
  88. data/lib/oddb/html/state/drugs/products.rb +51 -0
  89. data/lib/oddb/html/state/drugs/result.rb +125 -0
  90. data/lib/oddb/html/state/global.rb +165 -0
  91. data/lib/oddb/html/state/global_predefine.rb +17 -0
  92. data/lib/oddb/html/state/limit.rb +17 -0
  93. data/lib/oddb/html/state/login.rb +56 -0
  94. data/lib/oddb/html/state/paypal/checkout.rb +130 -0
  95. data/lib/oddb/html/state/paypal/collect.rb +46 -0
  96. data/lib/oddb/html/state/paypal/redirect.rb +18 -0
  97. data/lib/oddb/html/state/register_export.rb +38 -0
  98. data/lib/oddb/html/state/register_poweruser.rb +17 -0
  99. data/lib/oddb/html/state/viral/admin.rb +76 -0
  100. data/lib/oddb/html/state/viral/poweruser.rb +16 -0
  101. data/lib/oddb/html/util/annotated_list.rb +39 -0
  102. data/lib/oddb/html/util/know_it_all.rb +28 -0
  103. data/lib/oddb/html/util/known_user.rb +55 -0
  104. data/lib/oddb/html/util/lookandfeel.rb +554 -0
  105. data/lib/oddb/html/util/need_all_input.rb +29 -0
  106. data/lib/oddb/html/util/session.rb +88 -0
  107. data/lib/oddb/html/util/sort.rb +72 -0
  108. data/lib/oddb/html/util/unsaved_helper.rb +20 -0
  109. data/lib/oddb/html/util/validator.rb +54 -0
  110. data/lib/oddb/html/view/ajax/json.rb +22 -0
  111. data/lib/oddb/html/view/alpha_header.rb +28 -0
  112. data/lib/oddb/html/view/document.rb +126 -0
  113. data/lib/oddb/html/view/drugs/admin/package.rb +237 -0
  114. data/lib/oddb/html/view/drugs/admin/product.rb +104 -0
  115. data/lib/oddb/html/view/drugs/admin/sequence.rb +312 -0
  116. data/lib/oddb/html/view/drugs/ajax/explain_ddd_price.rb +87 -0
  117. data/lib/oddb/html/view/drugs/ajax/explain_price.rb +61 -0
  118. data/lib/oddb/html/view/drugs/ajax/package_infos.rb +105 -0
  119. data/lib/oddb/html/view/drugs/ajax/remote_infos.rb +44 -0
  120. data/lib/oddb/html/view/drugs/atc_browser.rb +68 -0
  121. data/lib/oddb/html/view/drugs/atc_guidelines.rb +94 -0
  122. data/lib/oddb/html/view/drugs/compare.rb +95 -0
  123. data/lib/oddb/html/view/drugs/download_export.rb +28 -0
  124. data/lib/oddb/html/view/drugs/fachinfo.rb +46 -0
  125. data/lib/oddb/html/view/drugs/feedback.rb +231 -0
  126. data/lib/oddb/html/view/drugs/init.rb +51 -0
  127. data/lib/oddb/html/view/drugs/legend.rb +24 -0
  128. data/lib/oddb/html/view/drugs/package.rb +398 -0
  129. data/lib/oddb/html/view/drugs/patinfo.rb +46 -0
  130. data/lib/oddb/html/view/drugs/products.rb +97 -0
  131. data/lib/oddb/html/view/drugs/result.rb +296 -0
  132. data/lib/oddb/html/view/drugs/search.rb +33 -0
  133. data/lib/oddb/html/view/drugs/template.rb +15 -0
  134. data/lib/oddb/html/view/foot.rb +52 -0
  135. data/lib/oddb/html/view/google.rb +23 -0
  136. data/lib/oddb/html/view/google_ads.rb +40 -0
  137. data/lib/oddb/html/view/head.rb +78 -0
  138. data/lib/oddb/html/view/limit.rb +109 -0
  139. data/lib/oddb/html/view/list.rb +59 -0
  140. data/lib/oddb/html/view/login.rb +38 -0
  141. data/lib/oddb/html/view/navigation.rb +67 -0
  142. data/lib/oddb/html/view/offset_header.rb +35 -0
  143. data/lib/oddb/html/view/paypal/collect.rb +84 -0
  144. data/lib/oddb/html/view/paypal/redirect.rb +51 -0
  145. data/lib/oddb/html/view/paypal/register_form.rb +106 -0
  146. data/lib/oddb/html/view/register_export.rb +29 -0
  147. data/lib/oddb/html/view/register_poweruser.rb +29 -0
  148. data/lib/oddb/html/view/rss/feedback.rb +64 -0
  149. data/lib/oddb/html/view/rss_preview.rb +54 -0
  150. data/lib/oddb/html/view/search.rb +104 -0
  151. data/lib/oddb/html/view/snapback.rb +24 -0
  152. data/lib/oddb/html/view/template.rb +56 -0
  153. data/lib/oddb/import/excel.rb +45 -0
  154. data/lib/oddb/import/import.rb +39 -0
  155. data/lib/oddb/import/rtf.rb +410 -0
  156. data/lib/oddb/import/whocc.rb +173 -0
  157. data/lib/oddb/import/xml.rb +15 -0
  158. data/lib/oddb/model.rb +179 -0
  159. data/lib/oddb/persistence/odba.rb +33 -0
  160. data/lib/oddb/persistence/odba/business/company.rb +13 -0
  161. data/lib/oddb/persistence/odba/business/invoice.rb +15 -0
  162. data/lib/oddb/persistence/odba/drugs/atc.rb +15 -0
  163. data/lib/oddb/persistence/odba/drugs/galenic_form.rb +18 -0
  164. data/lib/oddb/persistence/odba/drugs/galenic_group.rb +13 -0
  165. data/lib/oddb/persistence/odba/drugs/package.rb +25 -0
  166. data/lib/oddb/persistence/odba/drugs/product.rb +13 -0
  167. data/lib/oddb/persistence/odba/drugs/sequence.rb +21 -0
  168. data/lib/oddb/persistence/odba/drugs/substance.rb +21 -0
  169. data/lib/oddb/persistence/odba/drugs/substance_group.rb +13 -0
  170. data/lib/oddb/persistence/odba/drugs/unit.rb +13 -0
  171. data/lib/oddb/persistence/odba/export.rb +26 -0
  172. data/lib/oddb/persistence/odba/model.rb +68 -0
  173. data/lib/oddb/persistence/odba/regulatory/authority.rb +13 -0
  174. data/lib/oddb/persistence/odba/regulatory/registration.rb +13 -0
  175. data/lib/oddb/persistence/odba/text/document.rb +11 -0
  176. data/lib/oddb/persistence/odba/util/code.rb +11 -0
  177. data/lib/oddb/persistence/odba/util/m10l_document.rb +13 -0
  178. data/lib/oddb/persistence/og.rb +16 -0
  179. data/lib/oddb/persistence/og/drugs/composition.rb +14 -0
  180. data/lib/oddb/persistence/og/drugs/product.rb +14 -0
  181. data/lib/oddb/persistence/og/drugs/sequence.rb +15 -0
  182. data/lib/oddb/persistence/og/model.rb +25 -0
  183. data/lib/oddb/persistence/og/util/multilingual.rb +13 -0
  184. data/lib/oddb/redist/rtf_tools/reader.rb +139 -0
  185. data/lib/oddb/regulatory/authority.rb +14 -0
  186. data/lib/oddb/regulatory/registration.rb +15 -0
  187. data/lib/oddb/remote/business/company.rb +23 -0
  188. data/lib/oddb/remote/drugs/active_agent.rb +27 -0
  189. data/lib/oddb/remote/drugs/atc.rb +32 -0
  190. data/lib/oddb/remote/drugs/dose.rb +8 -0
  191. data/lib/oddb/remote/drugs/galenic_form.rb +25 -0
  192. data/lib/oddb/remote/drugs/package.rb +126 -0
  193. data/lib/oddb/remote/drugs/part.rb +30 -0
  194. data/lib/oddb/remote/drugs/product.rb +19 -0
  195. data/lib/oddb/remote/drugs/sequence.rb +46 -0
  196. data/lib/oddb/remote/drugs/substance.rb +20 -0
  197. data/lib/oddb/remote/drugs/unit.rb +19 -0
  198. data/lib/oddb/remote/object.rb +36 -0
  199. data/lib/oddb/remote/text/document.rb +20 -0
  200. data/lib/oddb/remote/util/m10l_document.rb +22 -0
  201. data/lib/oddb/text/chapter.rb +27 -0
  202. data/lib/oddb/text/document.rb +43 -0
  203. data/lib/oddb/text/format.rb +37 -0
  204. data/lib/oddb/text/paragraph.rb +58 -0
  205. data/lib/oddb/text/picture.rb +93 -0
  206. data/lib/oddb/text/table.rb +68 -0
  207. data/lib/oddb/util.rb +8 -0
  208. data/lib/oddb/util/annotated_list.rb +37 -0
  209. data/lib/oddb/util/code.rb +69 -0
  210. data/lib/oddb/util/comparison.rb +36 -0
  211. data/lib/oddb/util/exporter.rb +8 -0
  212. data/lib/oddb/util/feedback.rb +23 -0
  213. data/lib/oddb/util/ipn.rb +48 -0
  214. data/lib/oddb/util/m10l_document.rb +38 -0
  215. data/lib/oddb/util/mail.rb +73 -0
  216. data/lib/oddb/util/money.rb +60 -0
  217. data/lib/oddb/util/multilingual.rb +70 -0
  218. data/lib/oddb/util/quanty.rb +4 -0
  219. data/lib/oddb/util/quanty/fact.rb +229 -0
  220. data/lib/oddb/util/quanty/main.rb +160 -0
  221. data/lib/oddb/util/quanty/parse.rb +853 -0
  222. data/lib/oddb/util/quanty/units.dump +0 -0
  223. data/lib/oddb/util/server.rb +117 -0
  224. data/lib/oddb/util/updater.rb +41 -0
  225. data/lib/oddb/util/ydim.rb +110 -0
  226. data/lib/oddb/util/yus.rb +46 -0
  227. data/test/business/test_company.rb +29 -0
  228. data/test/business/test_price.rb +46 -0
  229. data/test/drugs/test_active_agent.rb +53 -0
  230. data/test/drugs/test_atc.rb +54 -0
  231. data/test/drugs/test_composition.rb +88 -0
  232. data/test/drugs/test_ddd.rb +22 -0
  233. data/test/drugs/test_dose.rb +190 -0
  234. data/test/drugs/test_galenic_form.rb +41 -0
  235. data/test/drugs/test_package.rb +173 -0
  236. data/test/drugs/test_part.rb +32 -0
  237. data/test/drugs/test_product.rb +31 -0
  238. data/test/drugs/test_sequence.rb +140 -0
  239. data/test/drugs/test_substance.rb +51 -0
  240. data/test/drugs/test_substance_group.rb +27 -0
  241. data/test/export/test_rss.rb +94 -0
  242. data/test/export/test_server.rb +117 -0
  243. data/test/export/test_xls.rb +152 -0
  244. data/test/export/test_yaml.rb +120 -0
  245. data/test/import/data/html/whocc/A.html +56 -0
  246. data/test/import/data/html/whocc/A03.html +48 -0
  247. data/test/import/data/html/whocc/A03AB.html +48 -0
  248. data/test/import/data/html/whocc/A06AA.html +47 -0
  249. data/test/import/data/html/whocc/C03.html +47 -0
  250. data/test/import/data/html/whocc/login.html +77 -0
  251. data/test/import/data/xml/ATC_2006.xml +47 -0
  252. data/test/import/data/xml/ATC_2006_ddd.xml +35 -0
  253. data/test/import/test_excel.rb +34 -0
  254. data/test/import/test_rtf.rb +40 -0
  255. data/test/import/test_whocc.rb +315 -0
  256. data/test/remote/drugs/test_active_agent.rb +36 -0
  257. data/test/selenium/selenium-server.jar +0 -0
  258. data/test/selenium/test_atc_browser.rb +122 -0
  259. data/test/selenium/test_atc_guidelines.rb +96 -0
  260. data/test/selenium/test_collect.rb +138 -0
  261. data/test/selenium/test_compare.rb +206 -0
  262. data/test/selenium/test_fachinfo.rb +130 -0
  263. data/test/selenium/test_feedback.rb +196 -0
  264. data/test/selenium/test_init.rb +52 -0
  265. data/test/selenium/test_limit.rb +305 -0
  266. data/test/selenium/test_login.rb +67 -0
  267. data/test/selenium/test_package.rb +512 -0
  268. data/test/selenium/test_patinfo.rb +131 -0
  269. data/test/selenium/test_product.rb +80 -0
  270. data/test/selenium/test_products.rb +142 -0
  271. data/test/selenium/test_search.rb +715 -0
  272. data/test/selenium/test_sequence.rb +543 -0
  273. data/test/selenium/unit.rb +185 -0
  274. data/test/stub/http_server.rb +169 -0
  275. data/test/stub/model.rb +173 -0
  276. data/test/suite.rb +15 -0
  277. data/test/test_model.rb +83 -0
  278. data/test/util/test_code.rb +74 -0
  279. data/test/util/test_ipn.rb +117 -0
  280. data/test/util/test_mail.rb +86 -0
  281. data/test/util/test_multilingual.rb +97 -0
  282. data/test/util/test_server.rb +48 -0
  283. data/test/util/test_updater.rb +353 -0
  284. data/test/util/test_ydim.rb +115 -0
  285. data/test/util/test_yus.rb +79 -0
  286. metadata +418 -0
@@ -0,0 +1,45 @@
1
+ = ramaze.ch.oddb.org
2
+
3
+ * http://scm.ywesee.com/?p=ch.oddb.org/.git;a=summary
4
+
5
+ == DESCRIPTION:
6
+
7
+ * ch.oddb.org running on Ramaze
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * still a lot of missing Features from oddb.org
12
+
13
+ == REQUIREMENTS:
14
+
15
+ You need the following gems and Versions.
16
+
17
+ activesupport (2.3.2)
18
+ dbd-pg (0.3.9)
19
+ dbi (0.4.2)
20
+ deprecated (2.0.1)
21
+ facets (1.8.54)
22
+ gd2 (1.1.1)
23
+ haml (2.2.2)
24
+ innate (2010.07, 2009.10)
25
+ minitest (1.6.0)
26
+ pg (0.10.1, 0.8.0)
27
+ rack (1.2.1, 1.0.1)
28
+ ramaze (2009.10)
29
+ rdoc (2.5.9, 2.5.8)
30
+ rmagick (2.13.1)
31
+ turing (0.0.11)
32
+
33
+ == INSTALL:
34
+
35
+ * sudo gem install ramaze.ch.oddb.org
36
+
37
+ == DEVELOPERS:
38
+
39
+ * Zeno R.R. Davatz
40
+ * Masaomi Hatakeyama
41
+ * Hannes Wyss (upto Version 1.0)
42
+
43
+ == LICENSE:
44
+
45
+ * GPLv2.0
@@ -0,0 +1,28 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ # Hoe.plugin :compiler
7
+ # Hoe.plugin :cucumberfeatures
8
+ # Hoe.plugin :gem_prelude_sucks
9
+ # Hoe.plugin :inline
10
+ # Hoe.plugin :inline
11
+ # Hoe.plugin :manifest
12
+ # Hoe.plugin :newgem
13
+ # Hoe.plugin :racc
14
+ # Hoe.plugin :rubyforge
15
+ # Hoe.plugin :rubyforge
16
+ # Hoe.plugin :website
17
+
18
+ Hoe.spec 'ramaze.ch.oddb.org' do
19
+ # HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
20
+ # you'll never have to touch them again!
21
+ # (delete this comment too, of course)
22
+
23
+ developer('Masaomi Hatakeyama, Zeno R.R. Davatz', 'mhatakeyama@ywesee.com, zdavatz@ywesee.com')
24
+
25
+ # self.rubyforge_name = 'ramaze.ch.oddb.orgx' # if different than 'ramaze.ch.oddb.org'
26
+ end
27
+
28
+ # vim: syntax=ruby
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+ # Admin -- oddb -- 09.07.2003 -- hwyss@ywesee.com
3
+
4
+ $:.push(File.expand_path('../lib', File.dirname(__FILE__)))
5
+
6
+ $KCODE = 'u'
7
+
8
+ require 'drb'
9
+ require 'sbsm/drb'
10
+ require 'oddb'
11
+ require 'oddb/config'
12
+ require 'encoding/character/utf-8'
13
+ require 'readline'
14
+ include Readline
15
+
16
+ Kernel.trap('INT') {
17
+ if($current.respond_to?(:exit))
18
+ $current.exit
19
+ $current = nil
20
+ else
21
+ puts "<ctrl-c> is used to kill admin-threads."
22
+ puts "Type <quit> or <exit> to exit."
23
+ end
24
+ }
25
+
26
+ prompt = 'de.oddb> '
27
+ DRb.start_service('druby://localhost:0')
28
+ oddb = DRbObject.new(nil, ODDB.config.server_url)
29
+ last_error = nil
30
+ priority = -1
31
+ while(line = readline(prompt, true))
32
+ result = ''
33
+ result.extend(DRb::DRbUndumped)
34
+ line.strip!
35
+ $stdout.print "-> "
36
+ case line.downcase
37
+ when 'exit', 'quit'
38
+ $stdout.puts 'Goodbye'
39
+ break
40
+ when 'bt', 'backtrace'
41
+ if last_error.respond_to?(:backtrace)
42
+ $stdout.puts last_error.backtrace
43
+ else
44
+ $stdout.puts 'No Error'
45
+ end
46
+ when /^last_error/
47
+ begin
48
+ $stdout.puts eval(line)
49
+ rescue Exception => last_error
50
+ $stdout.puts last_error
51
+ end
52
+ when /sp\s+(-?\d+)/, /set_priority\s+(-?\d+)/
53
+ priority = $~[1].to_i
54
+ $stdout.puts "setting Priority to #{priority}"
55
+ else
56
+ begin
57
+ bgflag = line.slice!(/\s*\&\s*$/)
58
+ $current = oddb._admin(line, result, priority)
59
+ unless(bgflag)
60
+ last_error = $current.join
61
+ end
62
+ $stdout.puts result
63
+ rescue Exception => last_error
64
+ $stdout.puts last_error
65
+ end
66
+ end
67
+ $current = nil
68
+ $stdout.flush
69
+ end
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
4
+ $KCODE = 'u'
5
+
6
+ require 'drb'
7
+ require 'logger'
8
+ require 'oddb/config'
9
+ require 'oddb/drugs'
10
+ require 'oddb/util'
11
+ require 'oddb/export'
12
+ require 'encoding/character/utf-8'
13
+
14
+ module ODDB
15
+ require File.join('oddb', 'persistence', @config.persistence)
16
+ require File.join('oddb', 'persistence', @config.persistence, 'export')
17
+ persistence = nil
18
+ case @config.persistence
19
+ when 'odba'
20
+ DRb.install_id_conv ODBA::DRbIdConv.new
21
+ @persistence = ODDB::Persistence::ODBA
22
+ when 'og'
23
+ DRb.install_id_conv DRb::TimerIdConv.new
24
+ Og.setup({
25
+ :name => @config.db_name,
26
+ :user => @config.db_user,
27
+ :password => @config.db_auth,
28
+ :store => @config.db_backend,
29
+ :evolve_schema => true,
30
+ :evolve_schema_cautious => false,
31
+ })
32
+ @persistence = ODDB::Persistence::Og
33
+ end
34
+
35
+ log_file = @config.log_file_export
36
+ if(log_file.is_a?(String))
37
+ FileUtils.mkdir_p(File.dirname(log_file))
38
+ log_file = File.open(log_file, 'a')
39
+ at_exit { log_file.close }
40
+ end
41
+ logger = Logger.new(log_file)
42
+ logger.level = Logger.const_get(@config.log_level_export)
43
+ @logger = logger
44
+
45
+ Currency = DRbObject.new(nil, @config.currency_rates)
46
+
47
+ begin
48
+ server = ODDB::Export::Server
49
+ server.extend(DRbUndumped)
50
+ @server = server
51
+
52
+ url = @config.server_url_export
53
+ url.untaint
54
+ DRb.start_service(url, server)
55
+ $SAFE = 1
56
+ logger.info('start') {
57
+ sprintf("starting export-server on %s", url) }
58
+ DRb.thread.join
59
+ rescue Exception => error
60
+ logger.error('fatal') { error }
61
+ raise
62
+ end
63
+ end
@@ -0,0 +1,461 @@
1
+ #!/usr/bin/env ruby19
2
+
3
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
4
+
5
+ require 'drb'
6
+ require 'oddb/persistence/odba'
7
+ require 'odba/18_19_loading_compatibility'
8
+
9
+ $project_path, url, _ = ARGV
10
+ $project_path ||= '/var/www/oddb.org'
11
+ url ||= 'druby://localhost:10000'
12
+
13
+ count = ODBA.cache.count(ODDB::Business::Company)
14
+ unless count == 0
15
+ padding = " " * $0.length
16
+ puts <<-EOS
17
+ #$0 should only be used to migrate to an empty database,
18
+ #{padding} but I found #{count} instances of ODDB::Business::Company.
19
+ #{padding} Please reconfigure and retry.
20
+ EOS
21
+ exit -1
22
+ end
23
+
24
+ require 'oddb/business/price'
25
+ require 'oddb/drugs/active_agent'
26
+ require 'oddb/drugs/composition'
27
+ require 'oddb/drugs/ddd'
28
+ require 'oddb/drugs/part'
29
+ require 'oddb/remote/business/company'
30
+ require 'oddb/text/chapter'
31
+ require 'oddb/text/document'
32
+ require 'oddb/text/paragraph'
33
+ require 'oddb/text/picture'
34
+ require 'oddb/util/feedback'
35
+
36
+ module ODDB
37
+ ## PatinfoDocument needs to be defined, because it is not a Persistable
38
+ # in the legacy code
39
+ class PatinfoDocument
40
+ CHAPTERS = [ :amzv, :company, :galenic_form, :effects, :purpose,
41
+ :amendments, :contra_indications, :precautions, :pregnancy, :usage,
42
+ :unwanted_effects, :general_advice, :other_advice, :composition,
43
+ :packages, :distribution, :fabrication, :date ]
44
+ attr_accessor :__drbref, *CHAPTERS
45
+ attr_reader :descriptions, :name
46
+ def chapter_names
47
+ CHAPTERS
48
+ end
49
+ def empty?
50
+ false
51
+ end
52
+ end
53
+ class PatinfoDocument2001 < PatinfoDocument
54
+ end
55
+ module Text
56
+ class Section
57
+ attr_reader :subheading, :paragraphs
58
+ end
59
+ class ImageLink
60
+ attr_reader :src
61
+ end
62
+ class Cell < Paragraph
63
+ end
64
+ end
65
+ end
66
+
67
+ DRb.start_service 'druby://localhost:0'
68
+
69
+ server = DRb::DRbObject.new(nil, url)
70
+ begin
71
+ server.admin "self.class"
72
+ rescue DRb::DRbConnError
73
+ puts <<-EOS
74
+ #$0 tried to import data from ch.oddb.org at #{url} but could not connect.
75
+ Exiting.
76
+ EOS
77
+ exit -1
78
+ end
79
+
80
+ def longest_common_prefix names
81
+ if min = names.compact.collect do |name| name.length end.min
82
+ names.collect! do |name| name[0,min] end
83
+ first = names.first
84
+ until(names.all? do |name| name == first end) do
85
+ names.each do |name| name.chop! end
86
+ end
87
+ first
88
+ end
89
+ end
90
+ def migrate_active_agent composition, agent
91
+ substance = migrate_substance agent.substance
92
+ remote = agent.dose
93
+ dose = remote ? ODDB::Drugs::Dose.from_quanty(remote) : nil
94
+ created = ODDB::Drugs::ActiveAgent.new substance, dose
95
+ created.composition = composition
96
+ created.save
97
+ end
98
+ $atc_ptrn = %r{^[ABCDGHJLMNPRSV]([0-9]{2}([A-Z]([A-Z]([0-9]{2}))?)?)?$}
99
+ def migrate_atc atc, sequence=nil
100
+ ## reject code B6
101
+ if atc && (code = atc.code) && $atc_ptrn.match(code)
102
+ code.force_encoding 'UTF-8'
103
+ created = ODDB::Drugs::Atc.find_by_code(code)
104
+ unless created
105
+ created = ODDB::Drugs::Atc.new code
106
+ migrate_multilingual atc, created.name
107
+ [:guidelines, :ddd_guidelines].each do |key|
108
+ if guidelines = atc.send(key)
109
+ created.send(key).en = guidelines.en.to_s
110
+ created.send(key).en.force_encoding 'UTF-8'
111
+ end
112
+ end
113
+ created.save
114
+ atc.remote.ddds.each_value do |ddd|
115
+ if dose = ddd.dose
116
+ roa = ddd.administration_route
117
+ roa.force_encoding 'UTF-8'
118
+ cddd = ODDB::Drugs::Ddd.new roa
119
+ cddd.dose = ddd.dose
120
+ if comment = ddd.note
121
+ comment.force_encoding 'UTF-8'
122
+ cddd.comment = comment
123
+ end
124
+ cddd.atc = created
125
+ end
126
+ end
127
+ end
128
+ sequence.atc = created if sequence
129
+ end
130
+ rescue NoMethodError
131
+ puts atc.inspect
132
+ raise
133
+ end
134
+ def migrate_company company
135
+ created = ODDB::Business::Company.new
136
+ created.name.de = company.name.de
137
+ created.name.de.force_encoding 'UTF-8'
138
+ created.data_origins[:migration] = company.uid
139
+ created.save
140
+ company.products.each do |prod|
141
+ migrate_product prod, created
142
+ end
143
+ end
144
+ def migrate_composition sequence, composition
145
+ created = ODDB::Drugs::Composition.new
146
+ if galenic_form = composition.galenic_form
147
+ created.galenic_form = migrate_galenic_form galenic_form
148
+ end
149
+ composition.active_agents.each do |act|
150
+ migrate_active_agent created, act
151
+ end
152
+ created.sequence = sequence
153
+ created.save
154
+ nil ## prevent DRb::DRbConnError (too large packet)
155
+ end
156
+ def migrate_feedback item, feedback
157
+ created = ODDB::Util::Feedback.new
158
+ [:name, :email, :message, :time].each do |key|
159
+ value = feedback.send(key)
160
+ if value.is_a?(String)
161
+ value.force_encoding 'UTF-8'
162
+ end
163
+ created.send "#{key}=", value
164
+ end
165
+ created.email_public = feedback.show_email
166
+ created.item_good_experience = feedback.experience
167
+ created.item_recommended = feedback.recommend
168
+ created.item_good_impression = feedback.impression
169
+ created.item_helps = feedback.helps
170
+ created.item = item
171
+ created.save
172
+ nil ## prevent DRb::DRbConnError (too large packet)
173
+ rescue NoMethodError
174
+ puts feedback.inspect
175
+ end
176
+ def migrate_galenic_form galenic_form
177
+ created = nil
178
+ galenic_form.all_descriptions.any? do |description|
179
+ description.force_encoding 'UTF-8'
180
+ created = ODDB::Drugs::GalenicForm.find_by_description description
181
+ end
182
+ unless created
183
+ created = ODDB::Drugs::GalenicForm.new
184
+ migrate_multilingual galenic_form, created.description
185
+ created.save
186
+ end
187
+ created
188
+ end
189
+ def migrate_m10l_document from, to
190
+ %w{de fr it en lt}.each do |key|
191
+ if (remote = from.descriptions[key]) && !remote.empty?
192
+ doc = ODDB::Text::Document.find_by_source remote.uid
193
+ unless doc
194
+ doc = ODDB::Text::Document.new
195
+ namechap = ODDB::Text::Chapter.new('name')
196
+ paragraph = ODDB::Text::Paragraph.new remote.name
197
+ namechap.add_paragraph paragraph
198
+ doc.add_chapter namechap
199
+ remote.chapter_names.each do |name|
200
+ begin
201
+ if name != :name && (rchap = remote.send(name))
202
+ ## update some chapter names
203
+ name = {
204
+ :contra_indications => 'counterindications',
205
+ :packages => 'packaging',
206
+ :preclinic => 'preclinicals',
207
+ }.fetch name, name.to_s
208
+ chapter = ODDB::Text::Chapter.new(name)
209
+ heading = if rchap.respond_to?(:heading)
210
+ rchap.heading
211
+ else
212
+ rchap.instance_variable_get :@heading
213
+ end
214
+ paragraph = ODDB::Text::Paragraph.new
215
+ paragraph.set_format 'b'
216
+ heading.force_encoding 'UTF-8'
217
+ paragraph << heading
218
+ chapter.add_paragraph paragraph
219
+ chapter.paragraphs.concat migrate_sections(rchap)
220
+ doc.add_chapter chapter
221
+ end
222
+ rescue TypeError
223
+ puts rchap.inspect
224
+ puts chapter.inspect
225
+ puts heading.inspect
226
+ raise
227
+ end
228
+ end
229
+ doc.source = remote.uid
230
+ end
231
+ to.send "#{key}=", doc
232
+ to.send(key).save
233
+ to.save
234
+ end
235
+ end
236
+ nil ## prevent DRb::DRbConnError (too large packet)
237
+ rescue NoMethodError
238
+ puts from.inspect
239
+ puts from.descriptions.inspect
240
+ puts from.descriptions['de'].inspect
241
+ raise
242
+ end
243
+ def migrate_multilingual from, to
244
+ %w{de fr it en lt}.each do |key|
245
+ if desc = from.descriptions[key]
246
+ desc.force_encoding 'UTF-8'
247
+ to.send "#{key}=", desc
248
+ end
249
+ if to.respond_to?(:synonyms) && from.respond_to?(:synonyms)
250
+ to.synonyms.concat(from.synonyms.uniq - to.all)
251
+ to.synonyms.each do |syn| syn.force_encoding 'UTF-8' end
252
+ end
253
+ end
254
+ to
255
+ end
256
+ def migrate_package sequence, package
257
+ created = ODDB::Drugs::Package.new
258
+ created.name.de = sequence.name.de
259
+ created.add_code ODDB::Util::Code.new(:cid, package.ikskey, 'CH')
260
+ if pcode = package.pharmacode
261
+ created.add_code ODDB::Util::Code.new(:pharmacode, pcode, 'CH')
262
+ end
263
+ package.prices.each do |key, prices|
264
+ unless prices.empty?
265
+ price = ODDB::Business::Price.new key, 'CH'
266
+ prices.each do |remote|
267
+ price.value = remote.to_f, remote.valid_from
268
+ end
269
+ created.add_price price
270
+ end
271
+ end
272
+ package.parts.each_with_index do |part, idx|
273
+ migrate_part created, part, sequence, idx
274
+ end
275
+ package.feedbacks.each do |feedback|
276
+ migrate_feedback created, feedback
277
+ end
278
+ created.sequence = sequence
279
+ nil ## prevent DRb::DRbConnError (too large packet)
280
+ end
281
+ def migrate_paragraph par
282
+ sanitized = ODDB::Text::Paragraph.new
283
+ par.text.force_encoding 'UTF-8'
284
+ sanitized << par.text
285
+ par.formats.each do |fmt|
286
+ fmt.values.collect! do |val|
287
+ {
288
+ :bold => 'b',
289
+ :italic => 'i',
290
+ }.fetch val, val.to_s
291
+ end
292
+ end
293
+ sanitized.formats.replace par.formats
294
+ sanitized
295
+ end
296
+ def migrate_part package, part, sequence, idx
297
+ created = ODDB::Drugs::Part.new
298
+ created.multi = part.multi
299
+ created.size = part.size
300
+ created.quantity = part.measure
301
+ if remote = part.remote.commercial_form
302
+ unit = nil
303
+ remote.all_descriptions.any? do |name|
304
+ unit = ODDB::Drugs::Unit.find_by_name
305
+ end
306
+ unless unit
307
+ unit = ODDB::Drugs::Unit.new
308
+ migrate_multilingual remote, unit.name
309
+ end
310
+ created.unit = unit
311
+ end
312
+ created.composition = sequence.compositions[idx] || sequence.compositions.last
313
+ created.package = package
314
+ created.save
315
+ nil ## prevent DRb::DRbConnError (too large packet)
316
+ end
317
+ def migrate_product product, company
318
+ names = product.sequences.collect do |seq|
319
+ name = seq.name_base[/^(.(?!,?[ \-]\d))+(.|$)/] || seq.name_base.to_s
320
+ name.force_encoding 'UTF-8'
321
+ name
322
+ end
323
+ name = nil
324
+ created = nil
325
+ if prefix = longest_common_prefix(names)
326
+ postfix = company.name.de[/(.{4}[^ ]+)|(^.{1,4}$)/]
327
+ name = prefix.include?(postfix) ? prefix : sprintf("%s %s", prefix, postfix)
328
+ created = ODDB::Drugs::Product.find_by_name name
329
+ if created && created.company != company
330
+ warn sprintf("%s and %s both have a Product called '%s'",
331
+ company.name.de, created.company.name.de, name)
332
+ created = company.products.find do |prod| prod.name.de == name end
333
+ end
334
+ end
335
+ created ||= ODDB::Drugs::Product.new
336
+ if name
337
+ created.name.de = name
338
+ created.name.de.force_encoding 'UTF-8'
339
+ end
340
+ created.company = company
341
+ created.save
342
+ registration = ODDB::Regulatory::Registration.new
343
+ registration.code = product.iksnr
344
+ registration.registration_date = product.registration_date
345
+ registration.revision_date = product.revision_date
346
+ registration.expiration_date = product.expiration_date
347
+ registration.deactivation_date = product.inactive_date
348
+ swissmedic = ODDB::Regulatory::Authority.find_by_name('Swissmedic') or begin
349
+ swissmedic = ODDB::Regulatory::Authority.new
350
+ swissmedic.name.de = 'Swissmedic'
351
+ swissmedic.url = 'http://www.swissmedic.ch'
352
+ swissmedic.save
353
+ end
354
+ registration.authority = swissmedic
355
+ product.sequences.each do |seq|
356
+ migrate_sequence created, registration, seq
357
+ end
358
+ nil ## prevent DRb::DRbConnError (too large packet)
359
+ end
360
+ def migrate_sections chapter
361
+ sections = if chapter.respond_to?(:sections)
362
+ chapter.sections
363
+ else
364
+ chapter.instance_variable_get :@sections
365
+ end
366
+ paragraphs = []
367
+ sections.each do |section|
368
+ if (subh = section.subheading) && !subh.empty?
369
+ paragraph = ODDB::Text::Paragraph.new
370
+ paragraph.set_format 'i'
371
+ subh.force_encoding 'UTF-8'
372
+ paragraph << subh
373
+ paragraphs.push paragraph
374
+ end
375
+ section.paragraphs.each do |par|
376
+ case par
377
+ when ODDB::Text::ImageLink
378
+ path = File.join $project_path, 'doc', par.src
379
+ if File.exist?(path)
380
+ pic = ODDB::Text::Picture.new
381
+ data = File.open(path, 'rb') do |fh| fh.read end
382
+ pic.replace data.unpack('H*').first
383
+ img = pic.image
384
+ pic.height = img.rows
385
+ pic.width = img.columns
386
+ paragraphs.push pic
387
+ end
388
+ when ODDB::Text::Table
389
+ par.rows.each do |row|
390
+ row.collect! do |cell|
391
+ migrate_paragraph(cell)
392
+ end
393
+ end
394
+ paragraphs.push par
395
+ else
396
+ paragraphs.push migrate_paragraph(par)
397
+ end
398
+ end
399
+ end
400
+ paragraphs
401
+ rescue NoMethodError
402
+ puts chapter.inspect, sections.inspect
403
+ raise
404
+ end
405
+ def migrate_sequence product, registration, sequence
406
+ created = ODDB::Drugs::Sequence.new
407
+ basename = sequence.name_base
408
+ basename.force_encoding 'UTF-8'
409
+ created.name.de = basename
410
+ migrate_atc sequence.atc, created
411
+ sequence.compositions.each do |comp|
412
+ migrate_composition created, comp
413
+ end
414
+ sequence.packages.each do |pac|
415
+ migrate_package created, pac
416
+ end
417
+ [:fachinfo, :patinfo].each do |key|
418
+ if info = sequence.send(key)
419
+ migrate_m10l_document info, created.send(key)
420
+ end
421
+ end
422
+ created.product = product
423
+ created.save
424
+ nil ## prevent DRb::DRbConnError (too large packet)
425
+ rescue DRb::DRbConnError
426
+ puts sequence.inspect
427
+ puts sequence.compositions.inspect
428
+ end
429
+ def migrate_substance substance
430
+ created = nil
431
+ substance.all_descriptions.any? do |description|
432
+ description.force_encoding 'UTF-8'
433
+ created = ODDB::Drugs::Substance.find_by_name description
434
+ end
435
+ unless created
436
+ created = ODDB::Drugs::Substance.new
437
+ migrate_multilingual substance, created.name
438
+ created.save
439
+ end
440
+ created
441
+ end
442
+
443
+ total = server.company_count.to_f
444
+ count = 0
445
+ server.remote_each_atc_class do |atc|
446
+ unless atc.en.to_s.empty?
447
+ migrate_atc ODDB::Remote::Drugs::Atc.new url, atc
448
+ end
449
+ end
450
+ server.remote_each_company do |remote|
451
+ company = ODDB::Remote::Business::Company.new(url, remote)
452
+ unless company.products.empty?
453
+ migrate_company company
454
+ end
455
+ count += 1
456
+ print (" " * 8) \
457
+ << ("\b" * 8) \
458
+ << sprintf('%7.3f%%', count*100/total) \
459
+ << ("\b" * 8)
460
+ $stdout.flush
461
+ end