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,185 @@
1
+ #!/usr/bin/env ruby
2
+ # Selenium::TestCase -- de.oddb.org -- 21.11.2006 -- hwyss@ywesee.com
3
+
4
+ $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
+
6
+ ENV['LD_LIBRARY_PATH'] = '/usr/local/firefox'
7
+
8
+ $log_level = 0
9
+
10
+ if(pid = Kernel.fork)
11
+ at_exit {
12
+ Process.kill('HUP', pid)
13
+ $selenium.stop if($log_level == 0 && $selenium.respond_to?(:stop))
14
+ }
15
+ else
16
+ path = File.expand_path('selenium-server.jar', File.dirname(__FILE__))
17
+ command = $log_level > 0 ? "java -jar #{path}" : "java -jar #{path} &> /dev/null"
18
+ exec(command)
19
+ end
20
+
21
+ require "oddb/config"
22
+ require 'delegate'
23
+ require 'fixes/selenium'
24
+
25
+ $selenium = ::Selenium::Client::Driver.new :host => "localhost", :port => 4444,
26
+ :browser => "*chrome", :url => ODDB.config.http_server + ":10080"
27
+
28
+ start = Time.now
29
+ begin
30
+ $selenium.start
31
+ rescue Errno::ECONNREFUSED
32
+ sleep 1
33
+ if((Time.now - start) > 15)
34
+ raise
35
+ else
36
+ retry
37
+ end
38
+ end
39
+
40
+ require "oddb/util/server"
41
+ require 'flexmock'
42
+ require 'logger'
43
+ require 'stub/http_server'
44
+ require "test/unit"
45
+
46
+ module ODDB
47
+ module Selenium
48
+ module TestCase
49
+ include FlexMock::TestCase
50
+ include ::Selenium::Client::SeleniumHelper
51
+ def setup
52
+ Drugs::ActiveAgent.instances.clear
53
+ Drugs::Atc.instances.clear
54
+ Drugs::Composition.instances.clear
55
+ Drugs::Package.instances.clear
56
+ Drugs::Part.instances.clear
57
+ Drugs::Product.instances.clear
58
+ Drugs::Sequence.instances.clear
59
+ Drugs::Package.instances.clear
60
+ Business::Company.instances.clear
61
+ ODDB.logger = Logger.new($stdout)
62
+ ODDB.logger.level = Logger::DEBUG
63
+ @auth = flexmock('authenticator')
64
+ ODDB.auth = @auth
65
+ @persistence = flexmock('persistence')
66
+ ODDB.persistence = @persistence
67
+ @server = Util::Server.new(@persistence)
68
+ @server.extend(DRbUndumped)
69
+ drb_url = "druby://localhost:10081"
70
+ retriable = true
71
+ begin
72
+ @drb_server = DRb.start_service(drb_url, @server)
73
+ rescue Errno::EADDRINUSE
74
+ if retriable
75
+ retriable = false
76
+ sleep 1
77
+ retry
78
+ else
79
+ raise
80
+ end
81
+ end
82
+ @http_server = Stub.http_server(drb_url, $log_level)
83
+ @webrick = Thread.new { @http_server.start }
84
+ @webrick.abort_on_exception = true
85
+ @verification_errors = []
86
+ if $selenium
87
+ @selenium = $selenium
88
+ else
89
+ @selenium = ::Selenium::Client::Driver.new :host => "localhost",
90
+ :port => 4444, :browser => "*chrome",
91
+ :url => ODDB.config.http_server + ":10080"
92
+ @selenium.start
93
+ end
94
+ @selenium.set_context("info")
95
+ ODDB::Html::Util::Session.reset_query_limit
96
+ end
97
+ def teardown
98
+ @selenium.stop unless $selenium
99
+ @http_server.shutdown if @http_server
100
+ @drb_server.stop_service if @drb_server
101
+ assert_equal [], @verification_errors
102
+ super
103
+ end
104
+ def login(email, *permissions)
105
+ user = mock_user email, *permissions
106
+ @auth.should_receive(:login).and_return(user)
107
+ open "/de/drugs/login"
108
+ type "email", email
109
+ type "pass", "test"
110
+ click "//input[@name='login_']"
111
+ wait_for_page_to_load 30
112
+ user
113
+ end
114
+ def login_admin
115
+ login "test.admin@oddb.org", ['login', 'org.oddb.de.Admin']
116
+ end
117
+ def mock_user(email, *permissions)
118
+ user = flexmock(email)
119
+ user.should_receive(:allowed?).and_return { |*pair|
120
+ permissions.include?(pair)
121
+ }
122
+ user.should_receive(:name).and_return(email)
123
+ user.should_receive(:get_preference)
124
+ user.should_receive(:find_entity).and_return { |email|
125
+ (@yus_entities ||= {})[email]
126
+ }
127
+ user.should_receive(:last_login)
128
+ user.should_receive(:permissions).and_return(permissions)
129
+ user.should_ignore_missing
130
+ user
131
+ end
132
+ def setup_package(name="Amantadin by Producer", atccode='N04BB01')
133
+ product = Drugs::Product.new
134
+ company = Business::Company.new
135
+ company.name.de = 'Producer AG'
136
+ product.company = company
137
+ company.save
138
+ sequence = Drugs::Sequence.new
139
+ sequence.product = product
140
+ atc = Drugs::Atc.new(atccode)
141
+ atc.name.de = 'Amantadin'
142
+ ddd = Drugs::Ddd.new('O')
143
+ ddd.dose = Drugs::Dose.new(10, 'mg')
144
+ atc.add_ddd(ddd)
145
+ sequence.atc = atc
146
+ composition = Drugs::Composition.new
147
+ galform = Drugs::GalenicForm.new
148
+ galform.description.de = 'Tabletten'
149
+ composition.galenic_form = galform
150
+ grp = Drugs::GalenicGroup.new('Tabletten')
151
+ grp.administration = 'O'
152
+ galform.group = grp
153
+ sequence.add_composition(composition)
154
+ substance = Drugs::Substance.new
155
+ substance.name.de = 'Amantadin'
156
+ dose = Drugs::Dose.new(100, 'mg')
157
+ active_agent = Drugs::ActiveAgent.new(substance, dose)
158
+ composition.add_active_agent(active_agent)
159
+ package = Drugs::Package.new
160
+ code = Util::Code.new(:cid, '12345', 'DE')
161
+ package.add_code(code)
162
+ code = Util::Code.new(:festbetragsstufe, 3, 'DE')
163
+ package.add_code(code)
164
+ code = Util::Code.new(:festbetragsgruppe, 4, 'DE')
165
+ package.add_code(code)
166
+ code = Util::Code.new(:zuzahlungsbefreit, true, 'DE')
167
+ package.add_code(code)
168
+ part = Drugs::Part.new
169
+ part.package = package
170
+ part.size = 5
171
+ part.composition = composition
172
+ unit = Drugs::Unit.new
173
+ unit.name.de = 'Ampullen'
174
+ part.unit = unit
175
+ part.quantity = Drugs::Dose.new(20, 'ml')
176
+ package.name.de = name
177
+ package.sequence = sequence
178
+ package.add_price(Business::Price.new(:public, 'DE', 6))
179
+ package.add_price(Business::Price.new(:festbetrag, 'DE', 10))
180
+ package.save
181
+ package
182
+ end
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env ruby
2
+ # Stub.http_server -- de.oddb.org -- 21.11.2006 -- hwyss@ywesee.com
3
+
4
+ require 'sbsm/request'
5
+ require 'sbsm/trans_handler'
6
+ require 'webrick'
7
+
8
+ class Object
9
+ def meta_class; class << self; self; end; end
10
+ def meta_eval &blk; meta_class.instance_eval &blk; end
11
+ end
12
+
13
+ ## compatibility-brainfuck for integrating Apache-SBSM-Requests with WEBrick
14
+ module ODDB
15
+ module Stub
16
+ class Notes < Hash
17
+ alias :add :store
18
+ end
19
+ class Output < String
20
+ alias :write :<<
21
+ alias :print :<<
22
+ end
23
+ class HTTPServer < WEBrick::HTTPServer
24
+ attr_accessor :document_root, :redirected_output, :attachment
25
+ def method_missing(method, *args, &block)
26
+ @logger.warn "ignoring method: #{method}"
27
+ end
28
+ end
29
+ def Stub.http_server(drburi, log_level=0)
30
+ doc = File.expand_path('../../doc', File.dirname(__FILE__))
31
+ logger = WEBrick::Log.new
32
+ logger.level = log_level
33
+ config = { :Host => 'localhost', :Port => 10080,
34
+ :DocumentRoot => doc, :Logger => logger }
35
+ if(log_level == 0)
36
+ config.store(:AccessLog, [])
37
+ end
38
+ server = HTTPServer.new(config)
39
+ server.document_root = doc
40
+ application = Proc.new { |req, resp|
41
+ ## this works around a bug where some POST requests were left hanging
42
+ # due to an Errno::EAGAIN
43
+ # Resource temporarily unavailable - <STDIN>
44
+ # see also http://trac.ywesee.com/ticket/1#comment:19
45
+ # and subsequent comments
46
+ data = StringIO.new('')
47
+ data << req.request_line
48
+ req.raw_header.each do |line|
49
+ unless line == req.request_line
50
+ data << line
51
+ end
52
+ end
53
+ if body = req.body
54
+ data << "\n" << body << "\n"
55
+ end
56
+ data.rewind
57
+ $stdin = data
58
+ ##
59
+ begin
60
+ if(req.uri == '/favicon.ico')
61
+ resp.body = File.open(File.join(doc, req.uri))
62
+ else
63
+ ARGV.push('')
64
+ req.server = server
65
+ req.uri = CGI.unescape(req.uri)
66
+ SBSM::ZoneTransHandler.instance.translate_uri(req)
67
+ ## not Threadsafe!
68
+ SBSM::Apache.request = req
69
+ output = Output.new
70
+ ENV.store 'CONTENT_LENGTH', req['content-length'].to_i.to_s
71
+ sbsm = SBSM::Request.new(drburi)
72
+ sbsm.meta_eval { define_method(:handle_exception) { |e| raise e } }
73
+ sbsm.cgi.params.update(req.query)
74
+ sbsm.cgi.env_table['SERVER_NAME'] =
75
+ ODDB.config.http_server.gsub('http://', '') + ':10080'
76
+ sbsm.cgi.env_table['REQUEST_METHOD'] = req.request_method
77
+ sbsm.cgi.cookies['_session_id'] = 'test:preset-session-id'
78
+ sbsm.cgi.output = output
79
+ sbsm.process
80
+ if(/^location: http...localhost/i.match(output))
81
+ resp.status = 303
82
+ elsif(/^location:.*paypal/i.match(output))
83
+ req.server.redirected_output = output
84
+ elsif(!/content-disposition:\s*attachment/i.match(output))
85
+ req.server.attachment = output
86
+ end
87
+ resp.rawdata = true
88
+ resp.body = output
89
+ end
90
+ rescue StandardError, Exception => e
91
+ ODDB.logger.error e.class.to_s
92
+ ODDB.logger.error e.message
93
+ ODDB.logger.error e.backtrace.join("\n")
94
+ end
95
+ }
96
+ server.mount_proc('/', &application)
97
+ server.mount_proc('/de', &application)
98
+ server.mount_proc('/de/.*', &application)
99
+ server.mount('/resources', WEBrick::HTTPServlet::FileHandler,
100
+ File.join(doc, 'resources'), {})
101
+ server.mount('/captcha', WEBrick::HTTPServlet::FileHandler,
102
+ File.join(ODDB.config.var, 'captcha'), {})
103
+ server
104
+ end
105
+ end
106
+ end
107
+ module WEBrick
108
+ class HTTPRequest
109
+ attr_accessor :server, :uri, :notes
110
+ alias :__old_initialize__ :initialize
111
+ def initialize(*args)
112
+ __old_initialize__(*args)
113
+ @notes = ODDB::Stub::Notes.new
114
+ end
115
+ def headers_in
116
+ headers = {}
117
+ if(@header)
118
+ @header.each { |key, vals| headers.store(key, vals.join(';')) }
119
+ end
120
+ headers
121
+ end
122
+ def uri
123
+ @uri || unparsed_uri
124
+ end
125
+ end
126
+ class HTTPResponse
127
+ attr_accessor :rawdata
128
+ alias :__old_send_header__ :send_header
129
+ def send_header(socket)
130
+ if(@rawdata)
131
+ _write_data(socket, status_line)
132
+ else
133
+ __old_send_header__(socket)
134
+ end
135
+ end
136
+ alias :__old_setup_header__ :setup_header
137
+ def setup_header()
138
+ unless(@rawdata)
139
+ __old_setup_header__
140
+ end
141
+ end
142
+ end
143
+ end
144
+ module SBSM
145
+ class Request
146
+ def handle_exception(e)
147
+ raise e
148
+ end
149
+ def remote_host(*args)
150
+ "127.0.0.1"
151
+ end
152
+ end
153
+ module Apache
154
+ DECLINED = nil
155
+ def Apache.request=(request)
156
+ @request = request
157
+ end
158
+ def Apache.request
159
+ @request
160
+ end
161
+ end
162
+ end
163
+ class CGI
164
+ attr_accessor :output
165
+ def stdoutput
166
+ output
167
+ end
168
+ public :env_table
169
+ end
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/env ruby
2
+ # Model -- de.oddb.org -- 17.11.2006 -- hwyss@ywesee.com
3
+
4
+ require 'oddb/drugs'
5
+ require 'oddb/business/company'
6
+ require 'oddb/util/code'
7
+
8
+ class Object
9
+ def metaclass; class << self; self; end; end
10
+ def meta_eval &blk; metaclass.instance_eval &blk; end
11
+ end
12
+ module ODDB
13
+ class Model
14
+ class << self
15
+ def all(&block)
16
+ if(block)
17
+ instances.each(&block)
18
+ else
19
+ instances
20
+ end
21
+ end
22
+ def simulate_database(*names)
23
+ meta_eval {
24
+ define_method(:instances) {
25
+ @instances ||= []
26
+ }
27
+ define_method(:find_by_code) { |criteria|
28
+ thing = instances.find { |instance| instance.codes.any? { |code|
29
+ code == criteria } }
30
+ }
31
+ define_method(:search_by_code) { |criteria|
32
+ thing = instances.select { |instance| instance.codes.any? { |code|
33
+ code == criteria } }
34
+ }
35
+ names.each { |name|
36
+ define_method("find_by_#{name}") { |nme|
37
+ instances.find { |instance| instance.send(name) == nme }
38
+ }
39
+ define_method("search_by_#{name}") { |nme|
40
+ instances.select { |instance|
41
+ if(instance.respond_to?(name))
42
+ /^#{nme}/i.match(instance.send(name).to_s)
43
+ end
44
+ }
45
+ }
46
+ define_method("search_by_exact_#{name}") { |nme|
47
+ instances.select { |instance|
48
+ nme.downcase == instance.send(name).to_s.downcase
49
+ }
50
+ }
51
+ }
52
+ }
53
+ define_method(:save) {
54
+ @saved = true
55
+ self.class.instances.push(self).uniq!
56
+ self
57
+ }
58
+ define_method(:delete) {
59
+ self.class.instances.delete(self)
60
+ self.class.connections.each { |name|
61
+ method = "remove_#{self.class.singular}"
62
+ conn = instance_variable_get(name)
63
+ if conn.respond_to?(method)
64
+ conn.send(method, self)
65
+ end
66
+ }
67
+ checkout
68
+ super()
69
+ }
70
+ end
71
+ def find_by_uid(uid)
72
+ ObjectSpace._id2ref(uid.to_i)
73
+ end
74
+ def index_keys(name, *keys)
75
+ meta_eval {
76
+ define_method(name) { |*args| keys }
77
+ }
78
+ end
79
+ end
80
+ alias :uid :object_id
81
+ attr_accessor :saved
82
+ def checkout
83
+ end
84
+ def saved?
85
+ @saved
86
+ end
87
+ #unless(instance_methods.include?('__stub_to_yaml_properties__'))
88
+ # alias :__stub_to_yaml_properties__ :to_yaml_properties
89
+ def to_yaml_properties
90
+ super - [:@saved]
91
+ # __stub_to_yaml_properties__ - ['@saved']
92
+ end
93
+ #end
94
+ end
95
+ module Business
96
+ class Company < Model
97
+ simulate_database(:name)
98
+ end
99
+ class Invoice < Model
100
+ simulate_database(:yus_name, :id)
101
+ end
102
+ end
103
+ module Drugs
104
+ class ActiveAgent < Model
105
+ simulate_database
106
+ end
107
+ class Atc < Model
108
+ simulate_database(:name)
109
+ class << self
110
+ def find_by_code(code)
111
+ @instances.find { |inst| inst.code == code }
112
+ end
113
+ def search_by_level_and_code(level, code)
114
+ @instances.select { |inst|
115
+ inst.level == level && inst.code[0,code.length] == code }
116
+ end
117
+ end
118
+ end
119
+ class Composition < Model
120
+ simulate_database
121
+ def checkout
122
+ Sequence.all { |seq| seq.remove_composition self }
123
+ end
124
+ end
125
+ class GalenicForm < Model
126
+ simulate_database(:description)
127
+ end
128
+ class GalenicGroup < Model
129
+ simulate_database(:name)
130
+ end
131
+ class Package < Model
132
+ simulate_database(:name, :atc, :substance, :company, :product)
133
+ def self.count
134
+ instances.size
135
+ end
136
+ end
137
+ class Part < Model
138
+ simulate_database
139
+ def checkout
140
+ Package.all { |pac| pac.remove_part self }
141
+ end
142
+ end
143
+ class Product < Model
144
+ simulate_database(:name)
145
+ index_keys(:name_keys, 'a', '4')
146
+ end
147
+ class Sequence < Model
148
+ simulate_database(:product)
149
+ end
150
+ class Substance < Model
151
+ simulate_database(:name)
152
+ end
153
+ class SubstanceGroup < Model
154
+ simulate_database(:name)
155
+ end
156
+ class Unit < Model
157
+ simulate_database(:name)
158
+ end
159
+ end
160
+ module Util
161
+ class Feedback < Model
162
+ simulate_database
163
+ end
164
+ class M10lDocument < Model
165
+ end
166
+ end
167
+ module Text
168
+ class Document < Model
169
+ simulate_database(:source)
170
+ end
171
+ end
172
+ Currency = Object.new
173
+ end