oddb2xml 2.7.1 → 2.7.5

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -2
  3. data/.standard.yml +2 -0
  4. data/Gemfile +3 -3
  5. data/History.txt +24 -0
  6. data/README.md +3 -3
  7. data/Rakefile +24 -23
  8. data/bin/check_artikelstamm +11 -11
  9. data/bin/compare_v5 +23 -23
  10. data/bin/oddb2xml +14 -13
  11. data/lib/oddb2xml/builder.rb +1070 -1038
  12. data/lib/oddb2xml/calc.rb +232 -233
  13. data/lib/oddb2xml/chapter_70_hack.rb +38 -32
  14. data/lib/oddb2xml/cli.rb +252 -236
  15. data/lib/oddb2xml/compare.rb +70 -59
  16. data/lib/oddb2xml/compositions_syntax.rb +451 -430
  17. data/lib/oddb2xml/compressor.rb +20 -20
  18. data/lib/oddb2xml/downloader.rb +157 -129
  19. data/lib/oddb2xml/extractor.rb +295 -295
  20. data/lib/oddb2xml/options.rb +34 -35
  21. data/lib/oddb2xml/parslet_compositions.rb +265 -269
  22. data/lib/oddb2xml/semantic_check.rb +39 -33
  23. data/lib/oddb2xml/util.rb +163 -163
  24. data/lib/oddb2xml/version.rb +1 -1
  25. data/lib/oddb2xml/xml_definitions.rb +32 -33
  26. data/lib/oddb2xml.rb +1 -1
  27. data/oddb2xml.gemspec +34 -34
  28. data/shell.nix +17 -0
  29. data/spec/artikelstamm_spec.rb +111 -110
  30. data/spec/builder_spec.rb +490 -505
  31. data/spec/calc_spec.rb +552 -593
  32. data/spec/check_artikelstamm_spec.rb +26 -26
  33. data/spec/cli_spec.rb +173 -174
  34. data/spec/compare_spec.rb +9 -11
  35. data/spec/composition_syntax_spec.rb +390 -409
  36. data/spec/compressor_spec.rb +48 -48
  37. data/spec/data/transfer.dat +1 -0
  38. data/spec/data_helper.rb +47 -49
  39. data/spec/downloader_spec.rb +251 -260
  40. data/spec/extractor_spec.rb +171 -159
  41. data/spec/fixtures/vcr_cassettes/oddb2xml.json +1 -1
  42. data/spec/galenic_spec.rb +233 -256
  43. data/spec/options_spec.rb +116 -119
  44. data/spec/parslet_spec.rb +896 -863
  45. data/spec/spec_helper.rb +153 -153
  46. data/test_options.rb +39 -42
  47. data/tools/win_fetch_cacerts.rb +2 -3
  48. metadata +42 -12
data/spec/builder_spec.rb CHANGED
@@ -1,41 +1,38 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
1
+ require "spec_helper"
4
2
  require "rexml/document"
5
- require 'webmock/rspec'
6
- include REXML
3
+ require "webmock/rspec"
7
4
  RUN_ALL = true
8
5
 
9
6
  # TODO: Add articles which contain these values
10
7
  # not done, because it was easy to verify this by running on the command line grep 'LIMPTS' oddb_article.xml | sort | uniq
11
- ARTICLE_ATTRIBUTE_TESTS = [
12
- ['ARTICLE', 'CREATION_DATETIME', Oddb2xml::DATE_REGEXP],
13
- ['ARTICLE', 'PROD_DATE', Oddb2xml::DATE_REGEXP],
14
- ['ARTICLE', 'VALID_DATE', Oddb2xml::DATE_REGEXP],
15
- ['ARTICLE/ART', 'SHA256', /[a-f0-9]{32}/],
16
- ['ARTICLE/ART', 'DT', /\d{4}-\d{2}-\d{2}/],
8
+ ARTICLE_ATTRIBUTE_TESTS = [
9
+ ["ARTICLE", "CREATION_DATETIME", Oddb2xml::DATE_REGEXP],
10
+ ["ARTICLE", "PROD_DATE", Oddb2xml::DATE_REGEXP],
11
+ ["ARTICLE", "VALID_DATE", Oddb2xml::DATE_REGEXP],
12
+ ["ARTICLE/ART", "SHA256", /[a-f0-9]{32}/],
13
+ ["ARTICLE/ART", "DT", /\d{4}-\d{2}-\d{2}/]
17
14
  ]
18
15
 
19
- ARTICLE_MISSING_ELEMENTS = [
20
- ['ARTICLE/ART/LIMPTS', '10'],
21
- ['ARTICLE/ART/LIMPTS', '30'],
22
- ['ARTICLE/ART/LIMPTS', '40'],
23
- ['ARTICLE/ART/LIMPTS', '50'],
24
- ['ARTICLE/ART/LIMPTS', '60'],
25
- ['ARTICLE/ART/LIMPTS', '80'],
26
- ['ARTICLE/ART/LIMPTS', '100'],
27
- ['ARTICLE/ART/SLOPLUS', '1'],
16
+ ARTICLE_MISSING_ELEMENTS = [
17
+ ["ARTICLE/ART/LIMPTS", "10"],
18
+ ["ARTICLE/ART/LIMPTS", "30"],
19
+ ["ARTICLE/ART/LIMPTS", "40"],
20
+ ["ARTICLE/ART/LIMPTS", "50"],
21
+ ["ARTICLE/ART/LIMPTS", "60"],
22
+ ["ARTICLE/ART/LIMPTS", "80"],
23
+ ["ARTICLE/ART/LIMPTS", "100"],
24
+ ["ARTICLE/ART/SLOPLUS", "1"]
28
25
  ]
29
26
 
30
- ARTICLE_ZURROSE_ELEMENTS = [
31
- ['ARTICLE/ART/REF_DATA', '0'],
32
- ['ARTICLE/ART/ARTCOMP/COMPNO', '7601001000896'],
33
- ['ARTICLE/ART/ARTPRI/PTYP', 'PEXF'],
34
- ['ARTICLE/ART/ARTPRI/PTYP', 'PPUB'],
35
- ['ARTICLE/ART/ARTPRI/PTYP', 'ZURROSE'],
36
- ['ARTICLE/ART/ARTPRI/PTYP', 'ZURROSEPUB'],
37
- ['ARTICLE/ART/ARTINS/NINCD', '13'],
38
- ['ARTICLE/ART/ARTINS/NINCD', '20'],
27
+ ARTICLE_ZURROSE_ELEMENTS = [
28
+ ["ARTICLE/ART/REF_DATA", "0"],
29
+ ["ARTICLE/ART/ARTCOMP/COMPNO", "7601001000896"],
30
+ ["ARTICLE/ART/ARTPRI/PTYP", "PEXF"],
31
+ ["ARTICLE/ART/ARTPRI/PTYP", "PPUB"],
32
+ ["ARTICLE/ART/ARTPRI/PTYP", "ZURROSE"],
33
+ ["ARTICLE/ART/ARTPRI/PTYP", "ZURROSEPUB"],
34
+ ["ARTICLE/ART/ARTINS/NINCD", "13"],
35
+ ["ARTICLE/ART/ARTINS/NINCD", "20"]
39
36
  ]
40
37
 
41
38
  ARTICLE_NAROPIN = %(<REF_DATA>1</REF_DATA>
@@ -59,275 +56,268 @@ ARTICLE_NAROPIN = %(<REF_DATA>1</REF_DATA>
59
56
  </ARTBAR>
60
57
  </ART>)
61
58
 
62
- ARTICLE_COMMON_ELEMENTS = [
63
- ['ARTICLE/ART/REF_DATA', '1'],
64
- ['ARTICLE/ART/SMCAT', 'A'],
65
- ['ARTICLE/ART/SMCAT', 'B'],
66
- ['ARTICLE/ART/SMCAT', 'C'],
67
- ['ARTICLE/ART/SMCAT', 'D'],
68
- ['ARTICLE/ART/GEN_PRODUCTION', 'X'],
69
- ['ARTICLE/ART/DRUG_INDEX', 'd'],
70
- ['ARTICLE/ART/INSULIN_CATEGORY', 'Insulinanalog: schnell wirkend'],
71
- ['ARTICLE/ART/SMNO', '16105058'],
72
- ['ARTICLE/ART/PRODNO', '1610501'],
73
- ['ARTICLE/ART/VAT', '2'],
74
- ['ARTICLE/ART/SALECD', 'A'],
75
- ['ARTICLE/ART/SALECD', 'I'],
76
- ['ARTICLE/ART/COOL', '1'],
77
- ['ARTICLE/ART/LIMPTS', '20'],
78
- ['ARTICLE/ART/CDBG', 'Y'],
79
- ['ARTICLE/ART/CDBG', 'N'],
80
- ['ARTICLE/ART/BG', 'Y'],
81
- ['ARTICLE/ART/BG', 'N'],
82
- ['ARTICLE/ART/ARTBAR/BC', Oddb2xml::ORPHAN_GTIN.to_s],
83
- ['ARTICLE/ART/ARTBAR/BC', Oddb2xml::FRIDGE_GTIN.to_s],
84
- ['ARTICLE/ART/SYN1D', 'Hirudoid'],
85
- ['ARTICLE/ART/SYN1F', 'Hirudoid'],
86
- ['ARTICLE/ART/SLOPLUS', '2'],
87
- ['ARTICLE/ART/ARTINS/NINCD', '10'],
59
+ ARTICLE_COMMON_ELEMENTS = [
60
+ ["ARTICLE/ART/REF_DATA", "1"],
61
+ ["ARTICLE/ART/SMCAT", "A"],
62
+ ["ARTICLE/ART/SMCAT", "B"],
63
+ ["ARTICLE/ART/SMCAT", "C"],
64
+ ["ARTICLE/ART/SMCAT", "D"],
65
+ ["ARTICLE/ART/GEN_PRODUCTION", "X"],
66
+ ["ARTICLE/ART/DRUG_INDEX", "d"],
67
+ ["ARTICLE/ART/INSULIN_CATEGORY", "Insulinanalog: schnell wirkend"],
68
+ ["ARTICLE/ART/SMNO", "16105058"],
69
+ ["ARTICLE/ART/PRODNO", "1610501"],
70
+ ["ARTICLE/ART/VAT", "2"],
71
+ ["ARTICLE/ART/SALECD", "A"],
72
+ ["ARTICLE/ART/SALECD", "I"],
73
+ ["ARTICLE/ART/COOL", "1"],
74
+ ["ARTICLE/ART/LIMPTS", "20"],
75
+ ["ARTICLE/ART/CDBG", "Y"],
76
+ ["ARTICLE/ART/CDBG", "N"],
77
+ ["ARTICLE/ART/BG", "Y"],
78
+ ["ARTICLE/ART/BG", "N"],
79
+ ["ARTICLE/ART/ARTBAR/BC", Oddb2xml::ORPHAN_GTIN.to_s],
80
+ ["ARTICLE/ART/ARTBAR/BC", Oddb2xml::FRIDGE_GTIN.to_s],
81
+ ["ARTICLE/ART/SYN1D", "Hirudoid"],
82
+ ["ARTICLE/ART/SYN1F", "Hirudoid"],
83
+ ["ARTICLE/ART/SLOPLUS", "2"],
84
+ ["ARTICLE/ART/ARTINS/NINCD", "10"]
88
85
  ]
89
86
 
90
- CODE_ATTRIBUTE_TESTS = [
91
- ['CODE', 'CREATION_DATETIME', Oddb2xml::DATE_REGEXP],
92
- ['CODE', 'PROD_DATE', Oddb2xml::DATE_REGEXP],
93
- ['CODE', 'VALID_DATE', Oddb2xml::DATE_REGEXP],
94
- ['CODE/CD', 'DT', ''],
87
+ CODE_ATTRIBUTE_TESTS = [
88
+ ["CODE", "CREATION_DATETIME", Oddb2xml::DATE_REGEXP],
89
+ ["CODE", "PROD_DATE", Oddb2xml::DATE_REGEXP],
90
+ ["CODE", "VALID_DATE", Oddb2xml::DATE_REGEXP],
91
+ ["CODE/CD", "DT", ""]
95
92
  ]
96
93
 
97
- CODE_MISSING_ELEMENT_TESTS = [
98
- ]
94
+ CODE_MISSING_ELEMENT_TESTS = []
99
95
 
100
96
  CODE_ELEMENT_TESTS = [
101
- ['CODE/CD/CDTYP', '11'],
102
- ['CODE/CD/CDTYP', '13'],
103
- ['CODE/CD/CDTYP', '14'],
104
- ['CODE/CD/CDTYP', '15'],
105
- ['CODE/CD/CDTYP', '16'],
106
- ['CODE/CD/CDVAL', 'A'],
107
- ['CODE/CD/CDVAL', 'B'],
108
- ['CODE/CD/CDVAL', 'C'],
109
- ['CODE/CD/CDVAL', 'D'],
110
- ['CODE/CD/CDVAL', 'X'],
111
- ['CODE/CD/DSCRSD', 'Kontraindiziert'],
112
- ['CODE/CD/DSCRSD', 'Kombination meiden'],
113
- ['CODE/CD/DSCRSD', 'Monitorisieren'],
114
- ['CODE/CD/DSCRSD', 'Vorsichtsmassnahmen'],
115
- ['CODE/CD/DSCRSD', 'keine Massnahmen'],
116
- ['CODE/CD/DEL', 'false'],
97
+ ["CODE/CD/CDTYP", "11"],
98
+ ["CODE/CD/CDTYP", "13"],
99
+ ["CODE/CD/CDTYP", "14"],
100
+ ["CODE/CD/CDTYP", "15"],
101
+ ["CODE/CD/CDTYP", "16"],
102
+ ["CODE/CD/CDVAL", "A"],
103
+ ["CODE/CD/CDVAL", "B"],
104
+ ["CODE/CD/CDVAL", "C"],
105
+ ["CODE/CD/CDVAL", "D"],
106
+ ["CODE/CD/CDVAL", "X"],
107
+ ["CODE/CD/DSCRSD", "Kontraindiziert"],
108
+ ["CODE/CD/DSCRSD", "Kombination meiden"],
109
+ ["CODE/CD/DSCRSD", "Monitorisieren"],
110
+ ["CODE/CD/DSCRSD", "Vorsichtsmassnahmen"],
111
+ ["CODE/CD/DSCRSD", "keine Massnahmen"],
112
+ ["CODE/CD/DEL", "false"]
117
113
  ]
118
114
 
119
- INTERACTION_ATTRIBUTE_TESTS = [
120
- ['INTERACTION', 'CREATION_DATETIME', Oddb2xml::DATE_REGEXP],
121
- ['INTERACTION', 'PROD_DATE', Oddb2xml::DATE_REGEXP],
122
- ['INTERACTION', 'VALID_DATE', Oddb2xml::DATE_REGEXP],
123
- ['INTERACTION/IX', 'SHA256', /[a-f0-9]{32}/],
124
- ['INTERACTION/IX', 'DT', ''],
115
+ INTERACTION_ATTRIBUTE_TESTS = [
116
+ ["INTERACTION", "CREATION_DATETIME", Oddb2xml::DATE_REGEXP],
117
+ ["INTERACTION", "PROD_DATE", Oddb2xml::DATE_REGEXP],
118
+ ["INTERACTION", "VALID_DATE", Oddb2xml::DATE_REGEXP],
119
+ ["INTERACTION/IX", "SHA256", /[a-f0-9]{32}/],
120
+ ["INTERACTION/IX", "DT", ""]
125
121
  ]
126
122
 
127
123
  INTERACTION_MISSING_ELEMENT_TESTS = [
128
- ['INTERACTION/IX/EFFD', 'Kombination meiden'],
129
- ['INTERACTION/IX/EFFD', 'Kontraindiziert'],
130
- ['INTERACTION/IX/EFFD', 'Monitorisieren'],
131
- ['INTERACTION/IX/EFFD', 'Vorsichtsmassnahmen'],
132
- ['INTERACTION/IX/DEL', 'true'], # Never found???
124
+ ["INTERACTION/IX/EFFD", "Kombination meiden"],
125
+ ["INTERACTION/IX/EFFD", "Kontraindiziert"],
126
+ ["INTERACTION/IX/EFFD", "Monitorisieren"],
127
+ ["INTERACTION/IX/EFFD", "Vorsichtsmassnahmen"],
128
+ ["INTERACTION/IX/DEL", "true"] # Never found???
133
129
  ]
134
130
 
135
131
  INTERACTION_ELEMENT_TESTS = [
136
- ['INTERACTION/IX/IXNO', '2'],
137
- ['INTERACTION/IX/TITD', 'Keine Interaktion'],
138
- ['INTERACTION/IX/GRP1D', 'N06AB06'],
139
- ['INTERACTION/IX/GRP2D', 'M03BX02'],
140
- ['INTERACTION/IX/EFFD', 'Keine Interaktion.'],
141
- ['INTERACTION/IX/MECHD', /Tizanidin wird über CYP1A2 metabolisiert/],
142
- ['INTERACTION/IX/MEASD', /Die Kombination aus Sertralin und Tizanidin/],
143
- ['INTERACTION/IX/DEL', 'false'],
144
- ]
145
-
146
- LIMITATION_ATTRIBUTE_TESTS = [
147
- ['LIMITATION', 'CREATION_DATETIME', Oddb2xml::DATE_REGEXP],
148
- ['LIMITATION', 'PROD_DATE', Oddb2xml::DATE_REGEXP],
149
- ['LIMITATION', 'VALID_DATE', Oddb2xml::DATE_REGEXP],
150
- ['LIMITATION/LIM', 'SHA256', /[a-f0-9]{32}/],
151
- ['LIMITATION/LIM', 'DT', ''],
132
+ ["INTERACTION/IX/IXNO", "2"],
133
+ ["INTERACTION/IX/TITD", "Keine Interaktion"],
134
+ ["INTERACTION/IX/GRP1D", "N06AB06"],
135
+ ["INTERACTION/IX/GRP2D", "M03BX02"],
136
+ ["INTERACTION/IX/EFFD", "Keine Interaktion."],
137
+ ["INTERACTION/IX/MECHD", /Tizanidin wird über CYP1A2 metabolisiert/],
138
+ ["INTERACTION/IX/MEASD", /Die Kombination aus Sertralin und Tizanidin/],
139
+ ["INTERACTION/IX/DEL", "false"]
140
+ ]
141
+
142
+ LIMITATION_ATTRIBUTE_TESTS = [
143
+ ["LIMITATION", "CREATION_DATETIME", Oddb2xml::DATE_REGEXP],
144
+ ["LIMITATION", "PROD_DATE", Oddb2xml::DATE_REGEXP],
145
+ ["LIMITATION", "VALID_DATE", Oddb2xml::DATE_REGEXP],
146
+ ["LIMITATION/LIM", "SHA256", /[a-f0-9]{32}/],
147
+ ["LIMITATION/LIM", "DT", ""]
152
148
  ]
153
149
 
154
150
  # Found by grep LIMTYP oddb_limitation.xml | sort | uniq
155
151
  LIMITATION_MISSING_ELEMENT_TESTS = [
156
- ['LIMITATION/LIM/SwissmedicNo8', '62089002'],
157
- ['LIMITATION/LIM/Pharmacode', '0'],
158
- ['LIMITATION/LIM/LIMTYP', 'AUD'],
159
- ['LIMITATION/LIM/LIMTYP', 'KOM'],
160
- ['LIMITATION/LIM/LIMTYP', 'ZEI'],
152
+ ["LIMITATION/LIM/SwissmedicNo8", "62089002"],
153
+ ["LIMITATION/LIM/Pharmacode", "0"],
154
+ ["LIMITATION/LIM/LIMTYP", "AUD"],
155
+ ["LIMITATION/LIM/LIMTYP", "KOM"],
156
+ ["LIMITATION/LIM/LIMTYP", "ZEI"]
161
157
  ]
162
158
 
163
159
  LIMITATION_ELEMENT_TESTS = [
164
- ['LIMITATION/LIM/LIMVAL', '10'],
165
- ['LIMITATION/LIM/LIMVAL', '20'],
166
- ['LIMITATION/LIM/LIMVAL', '30'],
167
- ['LIMITATION/LIM/LIMVAL', '40'],
168
- ['LIMITATION/LIM/LIMVAL', '50'],
169
- ['LIMITATION/LIM/LIMVAL', '60'],
170
- ['LIMITATION/LIM/LIMVAL', '80'],
171
- ['LIMITATION/LIM/LIMVAL', '100'],
172
- ['LIMITATION/LIM/IT', '07.02.40.'],
173
- ['LIMITATION/LIM/LIMTYP', 'DIA'],
174
- ['LIMITATION/LIM/LIMTYP', 'PKT'],
175
- ['LIMITATION/LIM/LIMNAMEBAG', '070240'],
176
- ['LIMITATION/LIM/LIMNIV', 'IP'],
177
- ['LIMITATION/LIM/VDAT', /\d{2}\.\d{2}\.\d{4}/],
178
- ['LIMITATION/LIM/DSCRD', /Therapiedauer/],
179
- ['LIMITATION/LIM/DSCRF', /Traitement de la pneumonie/],
180
- ['LIMITATION/LIM/SwissmedicNo5', '28486'],
181
- ]
182
-
183
- SUBSTANCE_ATTRIBUTE_TESTS = [
184
- ['SUBSTANCE', 'CREATION_DATETIME', Oddb2xml::DATE_REGEXP],
185
- ['SUBSTANCE', 'PROD_DATE', Oddb2xml::DATE_REGEXP],
186
- ['SUBSTANCE', 'VALID_DATE', Oddb2xml::DATE_REGEXP],
187
- ['SUBSTANCE/SB', 'SHA256', /[a-f0-9]{32}/],
188
- ['SUBSTANCE/SB', 'DT', ''],
160
+ ["LIMITATION/LIM/LIMVAL", "10"],
161
+ ["LIMITATION/LIM/LIMVAL", "20"],
162
+ ["LIMITATION/LIM/LIMVAL", "30"],
163
+ ["LIMITATION/LIM/LIMVAL", "40"],
164
+ ["LIMITATION/LIM/LIMVAL", "50"],
165
+ ["LIMITATION/LIM/LIMVAL", "60"],
166
+ ["LIMITATION/LIM/LIMVAL", "80"],
167
+ ["LIMITATION/LIM/LIMVAL", "100"],
168
+ ["LIMITATION/LIM/IT", "07.02.40."],
169
+ ["LIMITATION/LIM/LIMTYP", "DIA"],
170
+ ["LIMITATION/LIM/LIMTYP", "PKT"],
171
+ ["LIMITATION/LIM/LIMNAMEBAG", "070240"],
172
+ ["LIMITATION/LIM/LIMNIV", "IP"],
173
+ ["LIMITATION/LIM/VDAT", /\d{2}\.\d{2}\.\d{4}/],
174
+ ["LIMITATION/LIM/DSCRD", /Therapiedauer/],
175
+ ["LIMITATION/LIM/DSCRF", /Traitement de la pneumonie/],
176
+ ["LIMITATION/LIM/SwissmedicNo5", "28486"]
189
177
  ]
190
178
 
191
- SUBSTANCE_MISSING_ELEMENT_TESTS = [
179
+ SUBSTANCE_ATTRIBUTE_TESTS = [
180
+ ["SUBSTANCE", "CREATION_DATETIME", Oddb2xml::DATE_REGEXP],
181
+ ["SUBSTANCE", "PROD_DATE", Oddb2xml::DATE_REGEXP],
182
+ ["SUBSTANCE", "VALID_DATE", Oddb2xml::DATE_REGEXP],
183
+ ["SUBSTANCE/SB", "SHA256", /[a-f0-9]{32}/],
184
+ ["SUBSTANCE/SB", "DT", ""]
192
185
  ]
193
186
 
187
+ SUBSTANCE_MISSING_ELEMENT_TESTS = []
188
+
194
189
  SUBSTANCE_ELEMENT_TESTS = [
195
- ['SUBSTANCE/SB/SUBNO', '1'],
196
- ['SUBSTANCE/SB/NAML', 'Linezolidum'],
190
+ ["SUBSTANCE/SB/SUBNO", "1"],
191
+ ["SUBSTANCE/SB/NAML", "Linezolidum"]
197
192
  ]
198
193
 
199
194
  # Betriebe and Medizinalpersonen don't work at the moment
200
- BETRIEB_ATTRIBUTE_TESTS = [
201
- ['Betriebe', 'CREATION_DATETIME', Oddb2xml::DATE_REGEXP],
202
- ['Betriebe', 'PROD_DATE', Oddb2xml::DATE_REGEXP],
203
- ['Betriebe', 'VALID_DATE', Oddb2xml::DATE_REGEXP],
204
- ['Betriebe/Betrieb', 'DT', ''],
195
+ BETRIEB_ATTRIBUTE_TESTS = [
196
+ ["Betriebe", "CREATION_DATETIME", Oddb2xml::DATE_REGEXP],
197
+ ["Betriebe", "PROD_DATE", Oddb2xml::DATE_REGEXP],
198
+ ["Betriebe", "VALID_DATE", Oddb2xml::DATE_REGEXP],
199
+ ["Betriebe/Betrieb", "DT", ""]
205
200
  ]
206
201
 
207
- BETRIEB_MISSING_ELEMENT_TESTS = [
208
- ]
202
+ BETRIEB_MISSING_ELEMENT_TESTS = []
209
203
 
210
204
  BETRIEB_ELEMENT_TESTS = [
211
- ['Betriebe/Betrieb/GLN_Betrieb', '974633'],
212
- ['Betriebe/Betrieb/Betriebsname_1', 'Betriebsname_1'],
213
- ['Betriebe/Betrieb/Betriebsname_2', 'Betriebsname_2'],
214
- ['Betriebe/Betrieb/Strasse', 'Strasse'],
215
- ['Betriebe/Betrieb/Nummer', 'Nummer'],
216
- ['Betriebe/Betrieb/PLZ', 'PLZ'],
217
- ['Betriebe/Betrieb/Ort', 'Ort'],
218
- ['Betriebe/Betrieb/Bewilligungskanton', 'Bewilligungskanton'],
219
- ['Betriebe/Betrieb/Land', 'Land'],
220
- ['Betriebe/Betrieb/Betriebstyp', 'Betriebstyp'],
221
- ['Betriebe/Betrieb/BTM_Berechtigung', 'BTM_Berechtigung'],
205
+ ["Betriebe/Betrieb/GLN_Betrieb", "974633"],
206
+ ["Betriebe/Betrieb/Betriebsname_1", "Betriebsname_1"],
207
+ ["Betriebe/Betrieb/Betriebsname_2", "Betriebsname_2"],
208
+ ["Betriebe/Betrieb/Strasse", "Strasse"],
209
+ ["Betriebe/Betrieb/Nummer", "Nummer"],
210
+ ["Betriebe/Betrieb/PLZ", "PLZ"],
211
+ ["Betriebe/Betrieb/Ort", "Ort"],
212
+ ["Betriebe/Betrieb/Bewilligungskanton", "Bewilligungskanton"],
213
+ ["Betriebe/Betrieb/Land", "Land"],
214
+ ["Betriebe/Betrieb/Betriebstyp", "Betriebstyp"],
215
+ ["Betriebe/Betrieb/BTM_Berechtigung", "BTM_Berechtigung"]
222
216
  ]
223
217
 
224
- MEDIZINALPERSON_ATTRIBUTE_TESTS = [
225
- ['Personen', 'CREATION_DATETIME', Oddb2xml::DATE_REGEXP],
226
- ['Personen', 'PROD_DATE', Oddb2xml::DATE_REGEXP],
227
- ['Personen', 'VALID_DATE', Oddb2xml::DATE_REGEXP],
228
- ['Personen/Person', 'DT', ''],
218
+ MEDIZINALPERSON_ATTRIBUTE_TESTS = [
219
+ ["Personen", "CREATION_DATETIME", Oddb2xml::DATE_REGEXP],
220
+ ["Personen", "PROD_DATE", Oddb2xml::DATE_REGEXP],
221
+ ["Personen", "VALID_DATE", Oddb2xml::DATE_REGEXP],
222
+ ["Personen/Person", "DT", ""]
229
223
  ]
230
224
 
231
- MEDIZINALPERSON_MISSING_ELEMENT_TESTS = [
232
- ]
225
+ MEDIZINALPERSON_MISSING_ELEMENT_TESTS = []
233
226
 
234
227
  MEDIZINALPERSON_ELEMENT_TESTS = [
235
- ['Personen/Person/GLN_Person', '56459'],
236
- ['Personen/Person/Name', 'Name'],
237
- ['Personen/Person/Vorname', 'Vorname'],
238
- ['Personen/Person/PLZ', 'PLZ'],
239
- ['Personen/Person/Ort', 'Ort'],
240
- ['Personen/Person/Bewilligungskanton', 'Bewilligungskanton'],
241
- ['Personen/Person/Land', 'Land'],
242
- ['Personen/Person/Bewilligung_Selbstdispensation', 'Bewilligung_Selbstdispensation'],
243
- ['Personen/Person/Diplom', 'Diplom'],
244
- ['Personen/Person/BTM_Berechtigung', 'BTM_Berechtigung'],
228
+ ["Personen/Person/GLN_Person", "56459"],
229
+ ["Personen/Person/Name", "Name"],
230
+ ["Personen/Person/Vorname", "Vorname"],
231
+ ["Personen/Person/PLZ", "PLZ"],
232
+ ["Personen/Person/Ort", "Ort"],
233
+ ["Personen/Person/Bewilligungskanton", "Bewilligungskanton"],
234
+ ["Personen/Person/Land", "Land"],
235
+ ["Personen/Person/Bewilligung_Selbstdispensation", "Bewilligung_Selbstdispensation"],
236
+ ["Personen/Person/Diplom", "Diplom"],
237
+ ["Personen/Person/BTM_Berechtigung", "BTM_Berechtigung"]
245
238
  ]
246
239
 
247
240
  def check_result(inhalt, nbr_record)
248
- [ "<NBR_RECORD>",
241
+ ["<NBR_RECORD>",
249
242
  "<OK_ERROR>",
250
- '<OK_ERROR>OK</OK_ERROR>',
251
- ].each do |what|
243
+ "<OK_ERROR>OK</OK_ERROR>"].each do |what|
252
244
  expect(inhalt.scan(what).size).to eq 1
253
245
  end
254
- expect(inhalt.index('<OK_ERROR>OK</OK_ERROR>')).to be > 0
255
- expect(inhalt.index('<ERROR_CODE/>')).to be > 0
246
+ expect(inhalt.index("<OK_ERROR>OK</OK_ERROR>")).to be > 0
247
+ expect(inhalt.index("<ERROR_CODE/>")).to be > 0
256
248
  m = /<NBR_RECORD>(\d+)<\/NBR_RECORD>/.match(inhalt)
257
249
  expect(m).not_to be nil
258
- expect(m[1].to_i).to eq nbr_record
250
+ expect(m[1].to_i).to eq nbr_record
259
251
  end
260
252
 
261
- ['article', 'betrieb', 'code', 'interaction', 'limitation', 'medizinalperson', 'product', 'substance'].each do |cat|
253
+ ["article", "betrieb", "code", "interaction", "limitation", "medizinalperson", "product", "substance"].each do |cat|
262
254
  eval "
263
255
  def oddb_#{cat}_xml
264
- File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_#{cat}.xml'))
256
+ File.expand_path(File.join(Oddb2xml::WORK_DIR, 'oddb_#{cat}.xml'))
265
257
  end
266
258
  "
267
259
  end
268
260
 
269
- def check_article_IGM_format(line, price_kendural=825, add_80_percents=false)
270
- typ = line[0..1]
271
- name = line[10..59]
272
- ckzl = line[72]
273
- ciks = line[75]
274
- price_exf = line[60..65].to_i
261
+ def check_article_IGM_format(line, price_kendural = 825, add_80_percents = false)
262
+ typ = line[0..1]
263
+ name = line[10..59]
264
+ ckzl = line[72]
265
+ ciks = line[75]
266
+ price_exf = line[60..65].to_i
275
267
  price_reseller = line[66..71].to_i
276
- price_public = line[66..71].to_i
277
- expect(typ).to eq '11'
268
+ price_public = line[66..71].to_i
269
+ expect(typ).to eq "11"
278
270
  puts "check_article_IGM_format: #{price_exf} #{price_public} CKZL is #{ckzl} CIKS is #{ciks} name #{name} " if $VERBOSE
279
- found_SL = false
280
- found_non_SL = false
271
+ found_sl = false
272
+ found_non_sl = false
281
273
 
282
- if /7680353660163\d$/.match(line) # KENDURAL Depottabl 30 Stk
283
- puts "found_SL for #{line}" if $VERBOSE
284
- found_SL = true
285
- expect(line[60..65]).to eq '000496'
274
+ if /7680353660163\d$/.match?(line) # KENDURAL Depottabl 30 Stk
275
+ puts "found_sl for #{line}" if $VERBOSE
276
+ found_sl = true
277
+ expect(line[60..65]).to eq "000496"
286
278
  expect(price_exf).to eq 496
287
- expect(ckzl).to eq '1'
288
- expect(price_public).to eq price_kendural # this is a SL-product. Therefore we may not have a price increase
289
- expect(line[66..71]).to eq '000'+sprintf('%03d', price_kendural) # the dat format requires leading zeroes and not point
279
+ expect(ckzl).to eq "1"
280
+ expect(price_public).to eq price_kendural # this is a SL-product. Therefore we may not have a price increase
281
+ expect(line[66..71]).to eq "000" + sprintf("%03d", price_kendural) # the dat format requires leading zeroes and not point
290
282
  end
291
283
 
292
- if /7680403330459\d$/.match(line) # CARBADERM
293
- found_non_SL = true
294
- puts "found_non_SL for #{line}" if $VERBOSE
295
- expect(ckzl).to eq '3'
284
+ if /7680403330459\d$/.match?(line) # CARBADERM
285
+ found_non_sl = true
286
+ puts "found_non_sl for #{line}" if $VERBOSE
287
+ expect(ckzl).to eq "3"
296
288
  if add_80_percents
297
- expect(price_reseller).to eq 2919 # = 1545*1.8 this is a non SL-product. Therefore we must increase its price as requsted
298
- expect(line[66..71]).to eq '002919' # dat format requires leading zeroes and not poin
289
+ expect(price_reseller).to eq 2919 # = 1545*1.8 this is a non SL-product. Therefore we must increase its price as requsted
290
+ expect(line[66..71]).to eq "002919" # dat format requires leading zeroes and not poin
299
291
  else
300
- expect(price_reseller).to eq 2770 # this is a non SL-product, but no price increase was requested
301
- expect(line[66..71]).to eq '002770' # the dat format requires leading zeroes and not point
292
+ expect(price_reseller).to eq 2770 # this is a non SL-product, but no price increase was requested
293
+ expect(line[66..71]).to eq "002770" # the dat format requires leading zeroes and not point
302
294
  end
303
- expect(line[60..65]).to eq '001622' # the dat format requires leading zeroes and not point
304
- expect(price_exf).to eq 1622 # this is a non SL-product, but no price increase was requested
295
+ expect(line[60..65]).to eq "001622" # the dat format requires leading zeroes and not point
296
+ expect(price_exf).to eq 1622 # this is a non SL-product, but no price increase was requested
305
297
  end
306
- return [found_SL, found_non_SL]
298
+ [found_sl, found_non_sl]
307
299
  end
308
300
 
309
301
  def validate_via_xsd(xsd_file, xml_file)
310
- xsd =open(xsd_file).read
302
+ xsd = File.open(xsd_file).read
311
303
  xsd_rtikelstamm_xml = Nokogiri::XML::Schema(xsd)
312
304
  doc = Nokogiri::XML(File.read(xml_file))
313
- xsd_rtikelstamm_xml.validate(doc).each do
314
- |error|
315
- if error.message
316
- puts "Failed validating #{xml_file} with #{File.size(xml_file)} bytes using XSD from #{xsd_file}"
317
- puts "CMD: xmllint --noout --schema #{xsd_file} #{xml_file}"
318
- end
319
- msg = "expected #{error.message} to be nil\nfor #{xml_file}"
320
- puts msg
321
- expect(error.message).to be_nil, msg
305
+ xsd_rtikelstamm_xml.validate(doc).each do |error|
306
+ if error.message
307
+ puts "Failed validating #{xml_file} with #{File.size(xml_file)} bytes using XSD from #{xsd_file}"
308
+ puts "CMD: xmllint --noout --schema #{xsd_file} #{xml_file}"
309
+ end
310
+ msg = "expected #{error.message} to be nil\nfor #{xml_file}"
311
+ puts msg
312
+ expect(error.message).to be_nil, msg
322
313
  end
323
314
  end
324
315
 
325
316
  def check_validation_via_xsd
326
- files = Dir.glob('*.xml')
327
- files.each{
328
- |file|
329
- next if /#{Time.now.year}/.match(file)
330
- xsd2use = /oddb_calc/.match(file) ? @oddb_calc_xsd : @oddb2xml_xsd
317
+ files = Dir.glob("*.xml")
318
+ files.each { |file|
319
+ next if /#{Time.now.year}/.match?(file)
320
+ xsd2use = /oddb_calc/.match?(file) ? @oddb_calc_xsd : @oddb2xml_xsd
331
321
  validate_via_xsd(xsd2use, File.expand_path(file))
332
322
  }
333
323
  end
@@ -358,33 +348,33 @@ def checkPrices(increased = false)
358
348
  end
359
349
  end
360
350
 
361
- def checkAndGetArticleXmlName(tst=nil)
362
- article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
363
- expect(File.exists?(article_xml)).to eq true
364
- FileUtils.cp(article_xml, File.join(Oddb2xml::WorkDir, "tst-#{tst}.xml")) if tst
351
+ def checkAndGetArticleXmlName(tst = nil)
352
+ article_xml = File.expand_path(File.join(Oddb2xml::WORK_DIR, "oddb_article.xml"))
353
+ expect(File.exist?(article_xml)).to eq true
354
+ FileUtils.cp(article_xml, File.join(Oddb2xml::WORK_DIR, "tst-#{tst}.xml")) if tst
365
355
  article_xml
366
356
  end
367
357
 
368
358
  def checkAndGetProductWithGTIN(doc, gtin)
369
- products = XPath.match( doc, "//PRD[GTIN=#{gtin.to_s}]")
370
- gtins = XPath.match( doc, "//PRD[GTIN=#{gtin.to_s}]/GTIN")
359
+ products = REXML::XPath.match(doc, "//PRD[GTIN=#{gtin}]")
360
+ gtins = REXML::XPath.match(doc, "//PRD[GTIN=#{gtin}]/GTIN")
371
361
  expect(gtins.size).to eq 1
372
362
  expect(gtins.first.text).to eq gtin.to_s
373
363
  # return product
374
- return products.size == 1 ? products.first : nil
364
+ products.size == 1 ? products.first : nil
375
365
  end
376
366
 
377
367
  def checkAndGetArticleWithGTIN(doc, gtin)
378
- articles = XPath.match( doc, "//ART[ARTBAR/BC=#{gtin}]")
379
- gtins = XPath.match( doc, "//ART[ARTBAR/BC=#{gtin}]/ARTBAR/BC")
368
+ articles = REXML::XPath.match(doc, "//ART[ARTBAR/BC=#{gtin}]")
369
+ gtins = REXML::XPath.match(doc, "//ART[ARTBAR/BC=#{gtin}]/ARTBAR/BC")
380
370
  expect(gtins.size).to eq 1
381
371
  expect(gtins.first.text).to eq gtin.to_s
382
372
  gtins.first
383
373
  # return article
384
- return articles.size == 1 ? articles.first : nil
374
+ articles.size == 1 ? articles.first : nil
385
375
  end
386
376
 
387
- def checkArticleXml(checkERYTHROCIN = true)
377
+ def checkArticleXml(check_erythrocin = true)
388
378
  article_filename = checkAndGetArticleXmlName
389
379
 
390
380
  # check articles
@@ -394,101 +384,101 @@ def checkArticleXml(checkERYTHROCIN = true)
394
384
  desitin = checkAndGetArticleWithGTIN(doc, Oddb2xml::LEVETIRACETAM_GTIN)
395
385
  expect(desitin).not_to eq nil
396
386
  # TODO: why is this now nil? desitin.elements['ATC'].text.should == 'N03AX14'
397
- expect(desitin.elements['DSCRD'].text).to eq("LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk")
398
- expect(desitin.elements['DSCRF'].text).to eq('LEVETIRACETAM DESITIN mini cpr pel 250 mg 30 pce')
399
- expect(desitin.elements['REF_DATA'].text).to eq('1')
400
- expect(desitin.elements['PHAR'].text).to eq('5819012')
401
- expect(desitin.elements['SMCAT'].text).to eq('B')
402
- expect(desitin.elements['SMNO'].text).to eq('62069008')
403
- expect(desitin.elements['VAT'].text).to eq('2')
404
- expect(desitin.elements['PRODNO'].text).to eq('6206901')
405
- expect(desitin.elements['SALECD'].text).to eq('A')
406
- expect(desitin.elements['CDBG'].text).to eq('N')
407
- expect(desitin.elements['BG'].text).to eq('N')
408
-
409
- erythrocin_gtin = '7680202580475' # picked up from zur rose
387
+ expect(desitin.elements["DSCRD"].text).to eq("LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk")
388
+ expect(desitin.elements["DSCRF"].text).to eq("LEVETIRACETAM DESITIN mini cpr pel 250 mg 30 pce")
389
+ expect(desitin.elements["REF_DATA"].text).to eq("1")
390
+ expect(desitin.elements["PHAR"].text).to eq("5819012")
391
+ expect(desitin.elements["SMCAT"].text).to eq("B")
392
+ expect(desitin.elements["SMNO"].text).to eq("62069008")
393
+ expect(desitin.elements["VAT"].text).to eq("2")
394
+ expect(desitin.elements["PRODNO"].text).to eq("6206901")
395
+ expect(desitin.elements["SALECD"].text).to eq("A")
396
+ expect(desitin.elements["CDBG"].text).to eq("N")
397
+ expect(desitin.elements["BG"].text).to eq("N")
398
+
399
+ erythrocin_gtin = "7680202580475" # picked up from zur rose
410
400
  erythrocin = checkAndGetArticleWithGTIN(doc, erythrocin_gtin)
411
- expect(erythrocin.elements['DSCRD'].text).to eq("ERYTHROCIN i.v. Trockensub 1000 mg Amp") if checkERYTHROCIN
401
+ expect(erythrocin.elements["DSCRD"].text).to eq("ERYTHROCIN i.v. Trockensub 1000 mg Amp") if check_erythrocin
412
402
 
413
403
  lansoyl = checkAndGetArticleWithGTIN(doc, Oddb2xml::LANSOYL_GTIN)
414
- expect(lansoyl.elements['DSCRD'].text).to eq 'LANSOYL Gel 225 g'
415
- expect(lansoyl.elements['REF_DATA'].text).to eq '1'
416
- expect(lansoyl.elements['SMNO'].text).to eq '32475019'
417
- expect(lansoyl.elements['PHAR'].text).to eq '0023722'
418
- expect(lansoyl.elements['ARTCOMP/COMPNO'].text).to eq('7601001002012')
404
+ expect(lansoyl.elements["DSCRD"].text).to eq "LANSOYL Gel 225 g"
405
+ expect(lansoyl.elements["REF_DATA"].text).to eq "1"
406
+ expect(lansoyl.elements["SMNO"].text).to eq "32475019"
407
+ expect(lansoyl.elements["PHAR"].text).to eq "0023722"
408
+ expect(lansoyl.elements["ARTCOMP/COMPNO"].text).to eq("7601001002012")
419
409
 
420
410
  zyvoxid = checkAndGetArticleWithGTIN(doc, Oddb2xml::ZYVOXID_GTIN)
421
- expect(zyvoxid.elements['DSCRD'].text).to eq 'ZYVOXID Filmtabl 600 mg 10 Stk'
411
+ expect(zyvoxid.elements["DSCRD"].text).to eq "ZYVOXID Filmtabl 600 mg 10 Stk"
422
412
 
423
- expect(XPath.match( doc, "//LIMPTS" ).size).to be >= 1
413
+ expect(REXML::XPath.match(doc, "//LIMPTS").size).to be >= 1
424
414
  # TODO: desitin.elements['QTY'].text.should eq '250 mg'
425
415
  end
426
416
 
427
417
  def checkProductXml(nbr_record = -1)
428
- product_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_product.xml'))
429
- expect(File.exists?(product_filename)).to eq true
418
+ product_filename = File.expand_path(File.join(Oddb2xml::WORK_DIR, "oddb_product.xml"))
419
+ expect(File.exist?(product_filename)).to eq true
430
420
 
431
421
  # check products
432
422
  content = IO.read(product_filename)
433
423
  doc = REXML::Document.new content
434
424
  check_result(content, nbr_record)
435
- expect(nbr_record).to eq content.scan(/<PRD/).size if nbr_record != -1
425
+ expect(nbr_record).to eq content.scan(/<PRD/).size if nbr_record != -1
436
426
 
437
427
  desitin = checkAndGetProductWithGTIN(doc, Oddb2xml::LEVETIRACETAM_GTIN)
438
- expect(desitin.elements['ATC'].text).to eq('N03AX14')
439
- expect(desitin.elements['DSCRD'].text).to eq("LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk")
440
- expect(desitin.elements['DSCRF'].text).to eq('LEVETIRACETAM DESITIN mini cpr pel 250 mg 30 pce')
441
- expect(desitin.elements['PRODNO'].text).to eq '6206901'
442
- expect(desitin.elements['IT'].text).to eq '01.07.1.'
443
- expect(desitin.elements['PackGrSwissmedic'].text).to eq '30'
444
- expect(desitin.elements['EinheitSwissmedic'].text).to eq 'Tablette(n)'
445
- expect(desitin.elements['SubstanceSwissmedic'].text).to eq 'levetiracetamum'
446
- expect(desitin.elements['CompositionSwissmedic'].text).to eq 'levetiracetamum 250 mg, excipiens pro compressi obducti pro charta.'
447
- expect(desitin.elements['CPT/CPTCMP/LINE'].text).to eq '0'
448
- expect(desitin.elements['CPT/CPTCMP/SUBNO'].text).to eq '13'
449
- expect(desitin.elements['CPT/CPTCMP/QTY'].text).to eq '250'
450
- expect(desitin.elements['CPT/CPTCMP/QTYU'].text).to eq 'mg'
428
+ expect(desitin.elements["ATC"].text).to eq("N03AX14")
429
+ expect(desitin.elements["DSCRD"].text).to eq("LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk")
430
+ expect(desitin.elements["DSCRF"].text).to eq("LEVETIRACETAM DESITIN mini cpr pel 250 mg 30 pce")
431
+ expect(desitin.elements["PRODNO"].text).to eq "6206901"
432
+ expect(desitin.elements["IT"].text).to eq "01.07.1."
433
+ expect(desitin.elements["PackGrSwissmedic"].text).to eq "30"
434
+ expect(desitin.elements["EinheitSwissmedic"].text).to eq "Tablette(n)"
435
+ expect(desitin.elements["SubstanceSwissmedic"].text).to eq "levetiracetamum"
436
+ expect(desitin.elements["CompositionSwissmedic"].text).to eq "levetiracetamum 250 mg, excipiens pro compressi obducti pro charta."
437
+ expect(desitin.elements["CPT/CPTCMP/LINE"].text).to eq "0"
438
+ expect(desitin.elements["CPT/CPTCMP/SUBNO"].text).to eq "13"
439
+ expect(desitin.elements["CPT/CPTCMP/QTY"].text).to eq "250"
440
+ expect(desitin.elements["CPT/CPTCMP/QTYU"].text).to eq "mg"
451
441
 
452
442
  checkAndGetProductWithGTIN(doc, Oddb2xml::THREE_TC_GTIN)
453
443
  checkAndGetProductWithGTIN(doc, Oddb2xml::ZYVOXID_GTIN)
454
444
  if $VERBOSE
455
445
  puts "checkProductXml #{product_filename} #{File.size(product_filename)} #{File.mtime(product_filename)}"
456
- puts "checkProductXml has #{XPath.match( doc, "//PRD" ).find_all{|x| true}.size} packages"
457
- puts "checkProductXml has #{XPath.match( doc, "//GTIN" ).find_all{|x| true}.size} GTIN"
458
- puts "checkProductXml has #{XPath.match( doc, "//PRODNO" ).find_all{|x| true}.size} PRODNO"
446
+ puts "checkProductXml has #{REXML::XPath.match(doc, "//PRD").count { |x| true }} packages"
447
+ puts "checkProductXml has #{REXML::XPath.match(doc, "//GTIN").count { |x| true }} GTIN"
448
+ puts "checkProductXml has #{REXML::XPath.match(doc, "//PRODNO").count { |x| true }} PRODNO"
459
449
  end
460
450
  hirudoid = checkAndGetProductWithGTIN(doc, Oddb2xml::HIRUDOID_GTIN)
461
- expect(hirudoid.elements['ATC'].text).to eq('C05BA01') # modified by atc.csv!
451
+ expect(hirudoid.elements["ATC"].text).to eq("C05BA01") # modified by atc.csv!
462
452
  end
463
453
 
454
+ NR_EXTENDED_ARTICLES = 80
455
+ NR_SUBSTANCES = 28
456
+ NR_LIMITATIONS = 15
457
+
458
+ NR_INTERACTIONS = 2
459
+ NR_CODES = 5
460
+ NR_PRODNO = 31
461
+ NR_PACKAGES = 46
462
+ NR_PRODUCTS = 40
463
+ REG_EXP_DESITIN = /1120000000LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk/
464
464
  describe Oddb2xml::Builder do
465
- NrExtendedArticles = 80
466
- NrSubstances = 28
467
- NrLimitations = 15
468
-
469
- NrInteractions = 2
470
- NrCodes = 5
471
- NrProdno = 31
472
- NrPackages = 46
473
- NrProducts = 40
474
- RegExpDesitin = /1120000000LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk/
475
465
  include ServerMockHelper
476
466
  def common_run_init(options = {})
477
- @savedDir = Dir.pwd
478
- @oddb2xml_xsd = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb2xml.xsd'))
479
- @oddb_calc_xsd = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_calc.xsd'))
467
+ @saved_dir = Dir.pwd
468
+ @oddb2xml_xsd = File.expand_path(File.join(File.dirname(__FILE__), "..", "oddb2xml.xsd"))
469
+ @oddb_calc_xsd = File.expand_path(File.join(File.dirname(__FILE__), "..", "oddb_calc.xsd"))
480
470
  expect(File.exist?(@oddb2xml_xsd)).to eq true
481
471
  expect(File.exist?(@oddb_calc_xsd)).to eq true
482
472
  cleanup_directories_before_run
483
- FileUtils.makedirs(Oddb2xml::WorkDir)
484
- Dir.chdir(Oddb2xml::WorkDir)
473
+ FileUtils.makedirs(Oddb2xml::WORK_DIR)
474
+ Dir.chdir(Oddb2xml::WORK_DIR)
485
475
  mock_downloads
486
476
  end
487
477
 
488
478
  after(:all) do
489
- Dir.chdir @savedDir if @savedDir and File.directory?(@savedDir)
479
+ Dir.chdir @saved_dir if @saved_dir && File.directory?(@saved_dir)
490
480
  end
491
- context 'when default options are given' do
481
+ context "when default options are given" do
492
482
  before(:all) do
493
483
  common_run_init
494
484
  Oddb2xml::Cli.new({}).run # to debug
@@ -497,87 +487,87 @@ describe Oddb2xml::Builder do
497
487
  @rexml = REXML::Document.new File.read(oddb_article_xml)
498
488
  end
499
489
 
500
- it 'should produce a oddb_article.xml' do
501
- expect(File.exists?(oddb_article_xml)).to eq true
490
+ it "should produce a oddb_article.xml" do
491
+ expect(File.exist?(oddb_article_xml)).to eq true
502
492
  end
503
493
 
504
- it 'should have a correct NBR_RECORD in oddb_article.xml' do
505
- check_result(@inhalt, NrProducts)
494
+ it "should have a correct NBR_RECORD in oddb_article.xml" do
495
+ check_result(@inhalt, NR_PRODUCTS)
506
496
  end
507
497
 
508
- it 'should have a correct NBR_RECORD in oddb_products.xml' do
509
- oddb_product_xml = oddb_article_xml.sub('oddb_article.xml', 'oddb_product.xml')
498
+ it "should have a correct NBR_RECORD in oddb_products.xml" do
499
+ oddb_product_xml = oddb_article_xml.sub("oddb_article.xml", "oddb_product.xml")
510
500
  check_result(File.read(oddb_product_xml), 46)
511
501
  end
512
502
 
513
- it 'oddb_article.xml should contain a SHA256' do
514
- expect(XPath.match(@rexml, "//ART" ).first.attributes['SHA256'].size).to eq 64
515
- expect(XPath.match(@rexml, "//ART" ).size).to eq XPath.match(@rexml, "//ART" ).size
503
+ it "oddb_article.xml should contain a SHA256" do
504
+ expect(REXML::XPath.match(@rexml, "//ART").first.attributes["SHA256"].size).to eq 64
505
+ expect(REXML::XPath.match(@rexml, "//ART").size).to eq REXML::XPath.match(@rexml, "//ART").size
516
506
  end
517
507
 
518
- it 'should be possible to verify the oddb_article.xml' do
508
+ it "should be possible to verify the oddb_article.xml" do
519
509
  result = Oddb2xml.verify_sha256(oddb_article_xml)
520
510
  expect(result)
521
511
  end
522
512
 
523
- it 'should be possible to verify all xml files against our XSD' do
513
+ it "should be possible to verify all xml files against our XSD" do
524
514
  check_validation_via_xsd
525
515
  end
526
516
 
527
517
  check_attributes(oddb_article_xml, ARTICLE_ATTRIBUTE_TESTS)
528
518
  check_elements(oddb_article_xml, ARTICLE_COMMON_ELEMENTS)
529
519
 
530
- it 'should validate XSD article' do
520
+ it "should validate XSD article" do
531
521
  @inhalt = File.read(oddb_article_xml)
532
522
  # This fails on Ruby < 2.4 as NAROPIN INJ LÖS 0.2 % 10 is wrongly encoded
533
523
  expect(File.read(oddb_article_xml).scan(ARTICLE_NAROPIN).size).to eq 1
534
524
  end
535
525
 
536
- context 'XSD betrieb' do
537
- skip 'At the moment downloading and extractiong the medreg is broken!'
526
+ context "XSD betrieb" do
527
+ skip "At the moment downloading and extractiong the medreg is broken!"
538
528
  # check_attributes(oddb_betrieb_xml, BETRIEB_ATTRIBUTE_TESTS)
539
529
  # check_elements(oddb_betrieb_xml, BETRIEB_COMMON_ELEMENTS)
540
530
  end
541
531
 
542
- context 'XSD medizinalperson' do
543
- skip 'At the moment downloading and extractiong the medreg is broken!'
532
+ context "XSD medizinalperson" do
533
+ skip "At the moment downloading and extractiong the medreg is broken!"
544
534
  # check_attributes(oddb_medizinalperson_xml, MEDIZINAPERSON_ATTRIBUTE_TESTS)
545
535
  # check_elements(oddb_medizinalperson_xml, MEDIZINAPERSON_COMMON_ELEMENTS)
546
536
  end
547
537
 
548
- it 'should have a correct insulin (gentechnik) for 7680532900196' do
538
+ it "should have a correct insulin (gentechnik) for 7680532900196" do
549
539
  expect(@inhalt.match(/.*<BC>7680532900196<\/BC>.*/).class).to be MatchData
550
- expect(XPath.match( @rexml, "//ART//GEN_PRODUCTION").size).to be >= 1
551
- expect(XPath.match( @rexml, "//ART//GEN_PRODUCTION").first.text).to eq 'X'
552
- expect(XPath.match( @rexml, "//ART//INSULIN_CATEGORY").size).to eq 1
553
- expect(XPath.match( @rexml, "//ART//INSULIN_CATEGORY").first.text).to eq 'Insulinanalog: schnell wirkend'
540
+ expect(REXML::XPath.match(@rexml, "//ART//GEN_PRODUCTION").size).to be >= 1
541
+ expect(REXML::XPath.match(@rexml, "//ART//GEN_PRODUCTION").first.text).to eq "X"
542
+ expect(REXML::XPath.match(@rexml, "//ART//INSULIN_CATEGORY").size).to eq 1
543
+ expect(REXML::XPath.match(@rexml, "//ART//INSULIN_CATEGORY").first.text).to eq "Insulinanalog: schnell wirkend"
554
544
  end
555
545
 
556
- it 'should flag fridge drugs correctly' do
546
+ it "should flag fridge drugs correctly" do
557
547
  doc = REXML::Document.new IO.read(checkAndGetArticleXmlName)
558
548
  checkAndGetArticleWithGTIN(doc, Oddb2xml::FRIDGE_GTIN)
559
- expect(XPath.match( doc, "//COOL='1']").size).to eq 1
549
+ expect(REXML::XPath.match(doc, "//COOL=").size).to eq 1
550
+ expect(REXML::XPath.match(doc, "//COOL").first.text).to eq "1"
560
551
  end
561
552
 
562
553
  ean_with_drug_index = 7680555610041
563
554
  it "should have a correct drug information for #{ean_with_drug_index}" do
564
- doc = REXML::Document.new IO.read(checkAndGetArticleXmlName)
555
+ REXML::Document.new IO.read(checkAndGetArticleXmlName)
565
556
  expect(@inhalt.match(/.*<BC>#{ean_with_drug_index}<\/BC>.*/).class).to be MatchData
566
- expect(XPath.match( @rexml, "//ART//DRUG_INDEX").size).to eq 1
567
- expect(XPath.match( @rexml, "//ART//DRUG_INDEX").first.text).to eq 'd'
557
+ expect(REXML::XPath.match(@rexml, "//ART//DRUG_INDEX").size).to eq 1
558
+ expect(REXML::XPath.match(@rexml, "//ART//DRUG_INDEX").first.text).to eq "d"
568
559
  found = false
569
- XPath.match( @rexml, "//ART//CDBG").each{
570
- |flag|
571
- if flag.text.eql?('Y')
572
- found = true
573
- break
574
- end
560
+ REXML::XPath.match(@rexml, "//ART//CDBG").each { |flag|
561
+ if flag.text.eql?("Y")
562
+ found = true
563
+ break
564
+ end
575
565
  }
576
566
  expect(found)
577
567
  end
578
568
 
579
- it 'should generate ATC for 7680002770014' do
580
- oddb_product_xml = IO.read(File.join(Oddb2xml::WorkDir, 'oddb_product.xml'))
569
+ it "should generate ATC for 7680002770014" do
570
+ oddb_product_xml = IO.read(File.join(Oddb2xml::WORK_DIR, "oddb_product.xml"))
581
571
  text = %(<GTIN>7680002770014</GTIN>
582
572
  <PRODNO>0027701</PRODNO>
583
573
  <DSCRD>SEROCYTOL Herz-Gefässe Supp 3 Stk</DSCRD>
@@ -588,8 +578,8 @@ describe Oddb2xml::Builder do
588
578
  expect(oddb_product_xml.index(text)).to be >= 1
589
579
  end
590
580
 
591
- it 'should generate ATC for 7680002770021' do
592
- oddb_product_xml = IO.read(File.join(Oddb2xml::WorkDir, 'oddb_product.xml'))
581
+ it "should generate ATC for 7680002770021" do
582
+ oddb_product_xml = IO.read(File.join(Oddb2xml::WORK_DIR, "oddb_product.xml"))
593
583
  text2 = %( <GTIN>7680002770021</GTIN>
594
584
  <PRODNO>0027701</PRODNO>
595
585
  <DSCRD>Coeur-Vaisseaux Sérocytol, suppositoire</DSCRD>
@@ -600,401 +590,396 @@ describe Oddb2xml::Builder do
600
590
  expect(oddb_product_xml.index(text2)).to be >= 1
601
591
  end
602
592
 
603
- it 'should generate SALECD A for swissmedic packages' do
604
- expect(IO.read(oddb_article_xml).index('<SALECD>A<!--Overriding status I nincd 10 for 7680658560014 as in refdata_pharma--></SALECD>')).to be >= 1
593
+ it "should generate SALECD A for swissmedic packages" do
594
+ expect(IO.read(oddb_article_xml).index("<SALECD>A<!--Overriding status I nincd 10 for 7680658560014 as in refdata_pharma--></SALECD>")).to be >= 1
605
595
  end
606
-
607
596
  end
608
597
 
609
- context 'when -o for fachinfo is given' do
598
+ context "when -o for fachinfo is given" do
610
599
  before(:all) do
611
600
  common_run_init
612
- @oddb_fi_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_fi.xml'))
613
- @oddb_fi_product_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_fi_product.xml'))
614
- options = Oddb2xml::Options.parse(['-o', '--log'])
601
+ @oddb_fi_xml = File.expand_path(File.join(Oddb2xml::WORK_DIR, "oddb_fi.xml"))
602
+ @oddb_fi_product_xml = File.expand_path(File.join(Oddb2xml::WORK_DIR, "oddb_fi_product.xml"))
603
+ options = Oddb2xml::Options.parse(["-o", "--log"])
615
604
  # @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
616
605
  Oddb2xml::Cli.new(options).run
617
606
  end
618
607
 
619
- it 'should have a correct NBR_RECORD in oddb_fi_product.xml' do
620
- check_result( File.read('oddb_fi_product.xml'), 0)
608
+ it "should have a correct NBR_RECORD in oddb_fi_product.xml" do
609
+ check_result(File.read("oddb_fi_product.xml"), 0)
621
610
  end
622
611
 
623
- it 'should have a correct NBR_RECORD in oddb_fi.xml' do
624
- check_result( File.read('oddb_fi.xml'), 2)
612
+ it "should have a correct NBR_RECORD in oddb_fi.xml" do
613
+ check_result(File.read("oddb_fi.xml"), 2)
625
614
  end
626
615
 
627
- it 'should return produce a correct oddb_fi.xml' do
628
- expect(File.exists?(@oddb_fi_xml)).to eq true
616
+ it "should return produce a correct oddb_fi.xml" do
617
+ expect(File.exist?(@oddb_fi_xml)).to eq true
629
618
  inhalt = IO.read(@oddb_fi_xml)
630
- expect(/<KMP/.match(inhalt.to_s).to_s).to eq '<KMP'
631
- expect(/<style><!\[CDATA\[p{margin-top/.match(inhalt.to_s).to_s).to eq '<style><![CDATA[p{margin-top'
619
+ expect(/<KMP/.match(inhalt.to_s).to_s).to eq "<KMP"
620
+ expect(/<style><!\[CDATA\[p{margin-top/.match(inhalt.to_s).to_s).to eq "<style><![CDATA[p{margin-top"
632
621
  m = /<paragraph><!\[CDATA\[(.+)\n(.*)/.match(inhalt.to_s)
633
622
  expect(m[1]).to eq '<?xml version="1.0" encoding="utf-8"?><div xmlns="http://www.w3.org/1999/xhtml">'
634
- expected = '<p class="s2"> </p>'
635
- skip { m[2].should eq '<p class="s4" id="section1"><span class="s2"><span>Zyvoxid</span></span><sup class="s3"><span>®</span></sup></p>' }
636
- expect(File.exists?(@oddb_fi_product_xml)).to eq true
637
- inhalt = IO.read(@oddb_fi_product_xml)
623
+ skip { m[2].should eq '<p class="s4" id="section1"><span class="s2"><span>Zyvoxid</span></span><sup class="s3"><span>®</span></sup></p>' }
624
+ expect(File.exist?(@oddb_fi_product_xml)).to eq true
625
+ IO.read(@oddb_fi_product_xml)
638
626
  end
639
627
 
640
- it 'should produce valid xml files' do
628
+ it "should produce valid xml files" do
641
629
  skip "Niklaus does not know how to create a valid oddb_fi_product.xml"
642
630
  # check_validation_via_xsd
643
631
  end
644
632
 
645
- it 'should generate a valid oddb_product.xml' do
633
+ it "should generate a valid oddb_product.xml" do
646
634
  expect(@res).to match(/products/) if @res
647
- checkProductXml(NrPackages)
635
+ checkProductXml(NR_PACKAGES)
648
636
  end
649
-
650
637
  end
651
638
 
652
- context 'when -f dat is given' do
639
+ context "when -f dat is given" do
653
640
  before(:all) do
654
641
  common_run_init
655
- options = Oddb2xml::Options.parse('-f dat --log')
656
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
642
+ options = Oddb2xml::Options.parse("-f dat --log")
643
+ @res = buildr_capture(:stdout) { Oddb2xml::Cli.new(options).run }
657
644
  # Oddb2xml::Cli.new(options).run # to debug
658
645
  end
659
646
 
660
- it 'should contain the correct values fo CMUT from transfer.dat' do
647
+ it "should contain the correct values fo CMUT from transfer.dat" do
661
648
  expect(@res).to match(/products/)
662
- dat_filename = File.join(Oddb2xml::WorkDir, 'oddb.dat')
663
- expect(File.exists?(dat_filename)).to eq true
649
+ dat_filename = File.join(Oddb2xml::WORK_DIR, "oddb.dat")
650
+ expect(File.exist?(dat_filename)).to eq true
664
651
  oddb_dat = IO.read(dat_filename)
665
652
  expect(oddb_dat).to match(/^..2/), "should have a record with '2' in CMUT field"
666
653
  expect(oddb_dat).to match(/^..3/), "should have a record with '3' in CMUT field"
667
- expect(oddb_dat).to match(RegExpDesitin), "should have Desitin"
668
- IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line, 0) }
654
+ expect(oddb_dat).to match(REG_EXP_DESITIN), "should have Desitin"
655
+ IO.readlines(dat_filename).each { |line| check_article_IGM_format(line, 0) }
669
656
  m = /.+KENDURAL Depottabl 30 Stk.*7680353660163.+/.match(oddb_dat)
670
657
  expect(m[0].size).to eq 97 # size of IGM 1 record
671
- expect(m[0][74]).to eq '3'
658
+ expect(m[0][74]).to eq "3"
672
659
  end
673
660
  end
674
661
 
675
- context 'when --append -f dat is given' do
662
+ context "when --append -f dat is given" do
676
663
  before(:all) do
677
664
  common_run_init
678
- options = Oddb2xml::Options.parse('--append -f dat')
679
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
665
+ options = Oddb2xml::Options.parse("--append -f dat")
666
+ @res = buildr_capture(:stdout) { Oddb2xml::Cli.new(options).run }
680
667
  end
681
668
 
682
- it 'should generate a valid oddb_with_migel.dat' do
683
- dat_filename = File.join(Oddb2xml::WorkDir, 'oddb_with_migel.dat')
684
- expect(File.exists?(dat_filename)).to eq true
669
+ it "should generate a valid oddb_with_migel.dat" do
670
+ dat_filename = File.join(Oddb2xml::WORK_DIR, "oddb_with_migel.dat")
671
+ expect(File.exist?(dat_filename)).to eq true
685
672
  oddb_dat = IO.read(dat_filename)
686
- expect(oddb_dat).to match(RegExpDesitin), "should have Desitin"
673
+ expect(oddb_dat).to match(REG_EXP_DESITIN), "should have Desitin"
687
674
  expect(@res).to match(/products/)
688
675
  end
689
676
 
690
677
  it "should match EAN 76806206900842 of Desitin" do
691
- dat_filename = File.join(Oddb2xml::WorkDir, 'oddb_with_migel.dat')
692
- expect(File.exists?(dat_filename)).to eq true
678
+ dat_filename = File.join(Oddb2xml::WORK_DIR, "oddb_with_migel.dat")
679
+ expect(File.exist?(dat_filename)).to eq true
693
680
  oddb_dat = IO.read(dat_filename)
694
681
  expect(oddb_dat).to match(/76806206900842/), "should match EAN of Desitin"
695
682
  end
696
683
  end
697
684
 
698
- context 'when --append -I 80 -e is given' do
685
+ context "when --append -I 80 -e is given" do
699
686
  before(:all) do
700
687
  common_run_init
701
- options = Oddb2xml::Options.parse('--append -I 80 -e')
688
+ options = Oddb2xml::Options.parse("--append -I 80 -e")
702
689
  Oddb2xml::Cli.new(options).run
703
690
  # @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
704
691
  end
705
692
 
706
- it "oddb_article with stuf from ZurRose", :skip => "ZurRose contains ERYTHROCIN i.v. Troc*esteekensub 1000 mg Amp [!]" do
693
+ it "oddb_article with stuf from ZurRose", skip: "ZurRose contains ERYTHROCIN i.v. Troc*esteekensub 1000 mg Amp [!]" do
707
694
  checkArticleXml
708
695
  end
709
696
 
710
- # Zeno used oddb2xml -e -I 45 -c zip for oddb_arcticle for artikelstamm 7680172330414 3605520301605
711
- it 'should add GTIN 7680172330414 which is marked as inactive in transfer.dat' do
697
+ # Zeno used oddb2xml -e -I 45 -c zip for oddb_arcticle for artikelstamm 7680172330414 3605520301605
698
+ it "should add GTIN 7680172330414 which is marked as inactive in transfer.dat" do
712
699
  @inhalt = IO.read(oddb_article_xml)
713
- expect(@inhalt.index('7680172330414')).not_to be nil
700
+ expect(@inhalt.index("7680172330414")).not_to be nil
714
701
  end
715
702
 
716
- it 'should add GTIN 3605520301605 Armani Attitude which is marked as inactive in transfer.dat' do
703
+ it "should add GTIN 3605520301605 Armani Attitude which is marked as inactive in transfer.dat" do
717
704
  @inhalt = IO.read(oddb_article_xml)
718
705
  # <SALECD>I</SALECD>
719
706
 
720
- expect(@inhalt.index('3605520301605')).not_to be nil
707
+ expect(@inhalt.index("3605520301605")).not_to be nil
721
708
  end
722
709
 
723
- context 'XSD' do
710
+ context "XSD" do
724
711
  check_attributes(oddb_article_xml, ARTICLE_ATTRIBUTE_TESTS)
725
712
  check_elements(oddb_article_xml, ARTICLE_COMMON_ELEMENTS)
726
713
  check_elements(oddb_article_xml, ARTICLE_ZURROSE_ELEMENTS)
727
- it 'should contain NAROPIN' do
714
+ it "should contain NAROPIN" do
728
715
  # This fails on Ruby < 2.4 as NAROPIN INJ LÖS 0.2 % 10 is wrongly encoded
729
716
  expect(File.read(oddb_article_xml).scan(ARTICLE_NAROPIN).size).to eq 1
730
717
  end
731
718
  end
732
719
 
733
- it 'should emit a correct oddb_article.xml' do
720
+ it "should emit a correct oddb_article.xml" do
734
721
  checkArticleXml(false)
735
722
  end
736
723
 
737
- it 'should generate a valid oddb_product.xml' do
738
- expect(@res).to match(/products/) if @res != nil
739
- checkProductXml(NrPackages)
724
+ it "should generate a valid oddb_product.xml" do
725
+ expect(@res).to match(/products/) unless @res.nil?
726
+ checkProductXml(NR_PACKAGES)
740
727
  end
741
728
 
742
- it 'should contain the correct (increased) prices' do
729
+ it "should contain the correct (increased) prices" do
743
730
  checkPrices(true)
744
731
  end
745
732
  end
746
733
 
747
- context 'when option -e is given' do
734
+ context "when option -e is given" do
748
735
  before(:all) do
749
736
  common_run_init
750
- options = Oddb2xml::Options.parse('-e')
737
+ options = Oddb2xml::Options.parse("-e")
751
738
  puts options
752
739
  @cli = Oddb2xml::Cli.new(options)
753
740
  if RUN_ALL
754
- @res = buildr_capture(:stdout){ @cli.run }
741
+ @res = buildr_capture(:stdout) { @cli.run }
755
742
  else
756
743
  @cli.run
757
744
  end
758
745
  end
759
746
 
760
- context 'XSD limitation' do
747
+ context "XSD limitation" do
761
748
  check_attributes(oddb_limitation_xml, LIMITATION_ATTRIBUTE_TESTS)
762
749
  check_elements(oddb_limitation_xml, LIMITATION_ELEMENT_TESTS)
763
750
  end
764
751
 
765
- context 'XSD code' do
752
+ context "XSD code" do
766
753
  check_attributes(oddb_code_xml, CODE_ATTRIBUTE_TESTS)
767
754
  check_elements(oddb_code_xml, CODE_ELEMENT_TESTS)
768
755
  end
769
756
 
770
- it 'should have a correct NBR_RECORD in oddb_code.xml' do
771
- check_result(File.read(oddb_code_xml), NrCodes)
757
+ it "should have a correct NBR_RECORD in oddb_code.xml" do
758
+ check_result(File.read(oddb_code_xml), NR_CODES)
772
759
  end
773
760
 
774
- context 'XSD interaction' do
761
+ context "XSD interaction" do
775
762
  check_attributes(oddb_interaction_xml, INTERACTION_ATTRIBUTE_TESTS)
776
763
  check_elements(oddb_interaction_xml, INTERACTION_ELEMENT_TESTS)
777
764
  end
778
765
 
779
- it 'should have a correct NBR_RECORD in oddb_interaction.xml' do
780
- check_result(File.read(oddb_interaction_xml), NrInteractions)
766
+ it "should have a correct NBR_RECORD in oddb_interaction.xml" do
767
+ check_result(File.read(oddb_interaction_xml), NR_INTERACTIONS)
781
768
  end
782
769
 
783
- context 'XSD substance' do
770
+ context "XSD substance" do
784
771
  check_attributes(oddb_substance_xml, SUBSTANCE_ATTRIBUTE_TESTS)
785
772
  check_elements(oddb_substance_xml, SUBSTANCE_ELEMENT_TESTS)
786
773
  end
787
774
 
788
- it 'should have a correct NBR_RECORD in oddb_substance.xml' do
789
- check_result(File.read('oddb_substance.xml'), NrSubstances)
775
+ it "should have a correct NBR_RECORD in oddb_substance.xml" do
776
+ check_result(File.read("oddb_substance.xml"), NR_SUBSTANCES)
790
777
  end
791
778
 
792
- it 'should emit a correct oddb_article.xml' do
779
+ it "should emit a correct oddb_article.xml" do
793
780
  checkArticleXml
794
781
  end
795
782
 
796
- it 'should produce a correct oddb_product.xml' do
797
- checkProductXml(NrPackages)
783
+ it "should produce a correct oddb_product.xml" do
784
+ checkProductXml(NR_PACKAGES)
798
785
  end
799
786
 
800
- it 'should report correct output on stdout' do
801
- expect(@res).to match(/\sPharma products: \d+/)
802
- expect(@res).to match(/\sNonPharma products: \d+/)
803
- end if RUN_ALL
787
+ if RUN_ALL
788
+ it "should report correct output on stdout" do
789
+ expect(@res).to match(/\sPharma products: \d+/)
790
+ expect(@res).to match(/\sNonPharma products: \d+/)
791
+ end
792
+ end
804
793
 
805
- it 'should contain the correct (normal) prices' do
794
+ it "should contain the correct (normal) prices" do
806
795
  checkPrices(false)
807
796
  end
808
797
 
809
- it 'should generate the flag ORPH for orphan' do
798
+ it "should generate the flag ORPH for orphan" do
810
799
  doc = REXML::Document.new File.new(oddb_product_xml)
811
800
  orphan = checkAndGetProductWithGTIN(doc, Oddb2xml::ORPHAN_GTIN)
812
801
  expect(orphan).not_to eq nil
813
- expect(orphan.elements['ORPH'].text).to eq("true")
802
+ expect(orphan.elements["ORPH"].text).to eq("true")
814
803
  end
815
804
 
816
- it 'should generate the flag non-refdata' do
817
- doc = REXML::Document.new File.new(checkAndGetArticleXmlName('non-refdata'))
818
- expect(XPath.match( doc, "//REF_DATA" ).size).to eq NrExtendedArticles
805
+ it "should generate the flag non-refdata" do
806
+ doc = REXML::Document.new File.new(checkAndGetArticleXmlName("non-refdata"))
807
+ expect(REXML::XPath.match(doc, "//REF_DATA").size).to eq NR_EXTENDED_ARTICLES
819
808
  end
820
809
 
821
- it 'should generate SALECD A for migel (NINCD 13)' do
810
+ it "should generate SALECD A for migel (NINCD 13)" do
822
811
  doc = REXML::Document.new File.new(checkAndGetArticleXmlName)
823
- article = XPath.match( doc, "//ART[DSCRD='ACTICOAT Flex 7 Wundverband 10x12.5cm 5 Stk']").first
824
- expect(article.elements['SALECD'].text).to eq('A')
825
- expect(article.elements['ARTINS/NINCD'].text).to eq('13')
812
+ article = REXML::XPath.match(doc, "//ART[DSCRD='ACTICOAT Flex 7 Wundverband 10x12.5cm 5 Stk']").first
813
+ expect(article.elements["SALECD"].text).to eq("A")
814
+ expect(article.elements["ARTINS/NINCD"].text).to eq("13")
826
815
  end
827
816
 
828
- it 'should pass validating via oddb2xml.xsd' do
817
+ it "should pass validating via oddb2xml.xsd" do
829
818
  check_validation_via_xsd
830
819
  end
831
820
 
832
- it 'should not contain veterinary iksnr 47066 CANIPHEDRIN' do
821
+ it "should not contain veterinary iksnr 47066 CANIPHEDRIN" do
833
822
  doc = REXML::Document.new File.new(checkAndGetArticleXmlName)
834
- dscrds = XPath.match( doc, "//ART" )
835
- expect(XPath.match( doc, "//BC" ).find_all{|x| x.text.match('47066') }.size).to eq(0)
836
- expect(XPath.match( doc, "//DSCRD" ).find_all{|x| x.text.match(/CANIPHEDRIN/) }.size).to eq(0)
823
+ REXML::XPath.match(doc, "//ART")
824
+ expect(REXML::XPath.match(doc, "//BC").count { |x| x.text.match("47066") }).to eq(0)
825
+ expect(REXML::XPath.match(doc, "//DSCRD").count { |x| x.text.match(/CANIPHEDRIN/) }).to eq(0)
837
826
  end
838
827
 
839
- it 'should handle not duplicate pharmacode 5366964' do
828
+ it "should handle not duplicate pharmacode 5366964" do
840
829
  doc = REXML::Document.new File.new(checkAndGetArticleXmlName)
841
- dscrds = XPath.match( doc, "//ART" )
842
- expect(XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('5366964') }.size).to eq(1)
843
- expect(dscrds.size).to eq(NrExtendedArticles)
844
- expect(XPath.match( doc, "//PRODNO" ).find_all{|x| true}.size).to be >= 1
845
- expect(XPath.match( doc, "//PRODNO" ).find_all{|x| x.text.match('0027701') }.size).to eq(1)
846
- expect(XPath.match( doc, "//PRODNO" ).find_all{|x| x.text.match('6206901') }.size).to eq(1)
830
+ dscrds = REXML::XPath.match(doc, "//ART")
831
+ expect(REXML::XPath.match(doc, "//PHAR").count { |x| x.text.match("5366964") }).to eq(1)
832
+ expect(dscrds.size).to eq(NR_EXTENDED_ARTICLES)
833
+ expect(REXML::XPath.match(doc, "//PRODNO").count { |x| true }.size).to be >= 1
834
+ expect(REXML::XPath.match(doc, "//PRODNO").count { |x| x.text.match("0027701") }).to eq(1)
835
+ expect(REXML::XPath.match(doc, "//PRODNO").count { |x| x.text.match("6206901") }).to eq(1)
847
836
  end
848
837
 
849
- it 'should load correct number of nonpharma' do
838
+ it "should load correct number of nonpharma" do
850
839
  puts checkAndGetArticleXmlName
851
840
  doc = REXML::Document.new File.new(checkAndGetArticleXmlName)
852
- dscrds = XPath.match( doc, "//ART" )
853
- expect(dscrds.size).to eq(NrExtendedArticles)
854
- expect(XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('0000000') }.size).to eq(0) # 0 is not a valid pharmacode
855
- expect(XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match(/\d+/)}.size).to eq 65
841
+ dscrds = REXML::XPath.match(doc, "//ART")
842
+ expect(dscrds.size).to eq(NR_EXTENDED_ARTICLES)
843
+ expect(REXML::XPath.match(doc, "//PHAR").count { |x| x.text.match("0000000") }).to eq(0) # 0 is not a valid pharmacode
844
+ expect(REXML::XPath.match(doc, "//PHAR").count { |x| x.text.match(/\d+/) }).to eq 66
856
845
  end
857
846
 
858
- it 'should have a correct NBR_RECORD in oddb_limitation.xml' do
859
- check_result(File.read('oddb_limitation.xml'), NrLimitations)
847
+ it "should have a correct NBR_RECORD in oddb_limitation.xml" do
848
+ check_result(File.read("oddb_limitation.xml"), NR_LIMITATIONS)
860
849
  end
861
850
 
862
- it 'should emit a correct oddb_limitation.xml' do
851
+ it "should emit a correct oddb_limitation.xml" do
863
852
  # check limitations
864
- limitation_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_limitation.xml'))
865
- expect(File.exists?(limitation_filename)).to eq true
853
+ limitation_filename = File.expand_path(File.join(Oddb2xml::WORK_DIR, "oddb_limitation.xml"))
854
+ expect(File.exist?(limitation_filename)).to eq true
866
855
  doc = REXML::Document.new File.new(limitation_filename)
867
- limitations = XPath.match( doc, "//LIM" )
868
- expect(limitations.size).to eql NrLimitations
869
- expect(XPath.match( doc, "//SwissmedicNo5" ).find_all{|x| x.text.match('28486') }.size).to eq(1)
870
- expect(XPath.match( doc, "//LIMNAMEBAG" ).find_all{|x| x.text.match('ZYVOXID') }.size).to eq(2)
871
- expect(XPath.match( doc, "//LIMNAMEBAG" ).find_all{|x| x.text.match('070240') }.size).to be >= 1
872
- expect(XPath.match( doc, "//DSCRD" ).find_all{|x| x.text.match(/^Gesamthaft zugelassen/) }.size).to be >= 1
873
- expect(XPath.match( doc, "//DSCRD" ).find_all{|x| x.text.match(/^Behandlung nosokomialer Pneumonien/) }.size).to be >= 1
856
+ limitations = REXML::XPath.match(doc, "//LIM")
857
+ expect(limitations.size).to eql NR_LIMITATIONS
858
+ expect(REXML::XPath.match(doc, "//SwissmedicNo5").count { |x| x.text.match("28486") }).to eq(1)
859
+ expect(REXML::XPath.match(doc, "//LIMNAMEBAG").count { |x| x.text.match("ZYVOXID") }).to eq(2)
860
+ expect(REXML::XPath.match(doc, "//LIMNAMEBAG").count { |x| x.text.match("070240") }).to be >= 1
861
+ expect(REXML::XPath.match(doc, "//DSCRD").count { |x| x.text.match(/^Gesamthaft zugelassen/) }).to be >= 1
862
+ expect(REXML::XPath.match(doc, "//DSCRD").count { |x| x.text.match(/^Behandlung nosokomialer Pneumonien/) }).to be >= 1
874
863
  end
875
864
 
876
- it 'should emit a correct oddb_substance.xml' do
877
- doc = REXML::Document.new File.new(File.join(Oddb2xml::WorkDir, 'oddb_substance.xml'))
878
- names = XPath.match( doc, "//NAML" )
879
- expect(names.size).to eq(NrSubstances)
880
- expect(names.find_all{|x| x.text.match('Lamivudinum') }.size).to eq(1)
865
+ it "should emit a correct oddb_substance.xml" do
866
+ doc = REXML::Document.new File.new(File.join(Oddb2xml::WORK_DIR, "oddb_substance.xml"))
867
+ names = REXML::XPath.match(doc, "//NAML")
868
+ expect(names.size).to eq(NR_SUBSTANCES)
869
+ expect(names.count { |x| x.text.match("Lamivudinum") }).to eq(1)
881
870
  end
882
871
 
883
- it 'should emit a correct oddb_interaction.xml' do
884
- doc = REXML::Document.new File.new(File.join(Oddb2xml::WorkDir, 'oddb_interaction.xml'))
885
- titles = XPath.match( doc, "//TITD" )
872
+ it "should emit a correct oddb_interaction.xml" do
873
+ doc = REXML::Document.new File.new(File.join(Oddb2xml::WORK_DIR, "oddb_interaction.xml"))
874
+ titles = REXML::XPath.match(doc, "//TITD")
886
875
  expect(titles.size).to eq 2
887
- expect(titles.find_all{|x| x.text.match('Keine Interaktion') }.size).to be >= 1
888
- expect(titles.find_all{|x| x.text.match('Erhöhtes Risiko für Myopathie und Rhabdomyolyse') }.size).to eq(1)
876
+ expect(titles.count { |x| x.text.match("Keine Interaktion") }).to be >= 1
877
+ expect(titles.count { |x| x.text.match("Erhöhtes Risiko für Myopathie und Rhabdomyolyse") }).to eq(1)
889
878
  end
890
879
 
891
880
  def checkItemForSALECD(doc, ean13, expected)
892
- article = XPath.match( doc, "//ART[ARTBAR/BC=#{ean13.to_s}]").first
893
- name = article.elements['DSCRD'].text
894
- salecd = article.elements['SALECD'].text
895
- if $VERBOSE or article.elements['SALECD'].text != expected.to_s
881
+ article = REXML::XPath.match(doc, "//ART[ARTBAR/BC=#{ean13}]").first
882
+ name = article.elements["DSCRD"].text
883
+ salecd = article.elements["SALECD"].text
884
+ if $VERBOSE || (article.elements["SALECD"].text != expected.to_s)
896
885
  puts "checking doc for ean13 #{ean13} expected #{expected} == #{salecd}. #{name}"
897
886
  puts article.text
898
887
  end
899
- expect(article.elements['SALECD'].text).to eq(expected.to_s)
888
+ expect(article.elements["SALECD"].text).to eq(expected.to_s)
900
889
  end
901
890
 
902
- it 'should generate the flag SALECD' do
903
- expect(File.exists?(oddb_article_xml)).to eq true
904
- FileUtils.cp(oddb_article_xml, File.join(Oddb2xml::WorkDir, 'tst-SALECD.xml'))
905
- article_xml = IO.read(oddb_article_xml)
891
+ it "should generate the flag SALECD" do
892
+ expect(File.exist?(oddb_article_xml)).to eq true
893
+ FileUtils.cp(oddb_article_xml, File.join(Oddb2xml::WORK_DIR, "tst-SALECD.xml"))
906
894
  doc = REXML::Document.new File.new(oddb_article_xml)
907
- expect(XPath.match( doc, "//REF_DATA" ).size).to be > 0
908
- checkItemForSALECD(doc, Oddb2xml::FERRO_GRADUMET_GTIN, 'A') # FERRO-GRADUMET Depottabl 30 Stk
909
- checkItemForSALECD(doc, Oddb2xml::SOFRADEX_GTIN, 'I') # SOFRADEX
895
+ expect(REXML::XPath.match(doc, "//REF_DATA").size).to be > 0
896
+ checkItemForSALECD(doc, Oddb2xml::FERRO_GRADUMET_GTIN, "A") # FERRO-GRADUMET Depottabl 30 Stk
897
+ checkItemForSALECD(doc, Oddb2xml::SOFRADEX_GTIN, "I") # SOFRADEX
910
898
  end
911
899
  end
912
- context 'testing -e -I 80 option' do
900
+ context "testing -e -I 80 option" do
913
901
  before(:all) do
914
902
  common_run_init
915
- options = Oddb2xml::Options.parse('-e -I 80 --log')
903
+ options = Oddb2xml::Options.parse("-e -I 80 --log")
916
904
  # @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
917
905
  @res = Oddb2xml::Cli.new(options).run
918
906
  end
919
907
 
920
- it 'should add 80 percent to zur_rose pubbprice' do
921
- expect(File.exists?(oddb_article_xml)).to eq true
922
- FileUtils.cp(oddb_article_xml, File.join(Oddb2xml::WorkDir, 'tst-e80.xml'))
908
+ it "should add 80 percent to zur_rose pubbprice" do
909
+ expect(File.exist?(oddb_article_xml)).to eq true
910
+ FileUtils.cp(oddb_article_xml, File.join(Oddb2xml::WORK_DIR, "tst-e80.xml"))
923
911
  checkArticleXml
924
912
  checkPrices(true)
925
913
  end
926
914
 
927
- it 'should generate an article for EPIMINERAL' do
928
- expect(File.exists?(oddb_article_xml)).to eq true
915
+ it "should generate an article for EPIMINERAL" do
916
+ expect(File.exist?(oddb_article_xml)).to eq true
929
917
  doc = REXML::Document.new IO.read(oddb_article_xml)
930
- article = XPath.match( doc, "//ART[PHAR=5822801]").first
931
- expect(article.elements['DSCRD'].text).to match /EPIMINERAL/i
918
+ article = REXML::XPath.match(doc, "//ART[PHAR=5822801]").first
919
+ expect(article.elements["DSCRD"].text).to match(/EPIMINERAL/i)
932
920
  end
933
921
 
934
- it 'should generate a correct number of packages in oddb_product.xml' do
935
- checkProductXml(NrPackages)
922
+ it "should generate a correct number of packages in oddb_product.xml" do
923
+ checkProductXml(NR_PACKAGES)
936
924
  end
937
925
 
938
- it 'should generate an article with the COOL (fridge) attribute' do
926
+ it "should generate an article with the COOL (fridge) attribute" do
939
927
  doc = REXML::Document.new File.new(oddb_article_xml)
940
928
  fridge_product = checkAndGetArticleWithGTIN(doc, Oddb2xml::FRIDGE_GTIN)
941
- expect(fridge_product.elements['COOL'].text).to eq('1')
929
+ expect(fridge_product.elements["COOL"].text).to eq("1")
942
930
  end
943
931
 
944
- it 'should generate a correct oddb_article.xml' do
932
+ it "should generate a correct oddb_article.xml" do
945
933
  checkArticleXml
946
934
  end
947
935
  end
948
936
 
949
- context 'when -f dat -p is given' do
937
+ context "when -f dat -p is given" do
950
938
  before(:all) do
951
939
  common_run_init
952
- options = Oddb2xml::Options.parse('-f dat -p')
953
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
940
+ options = Oddb2xml::Options.parse("-f dat -p")
941
+ @res = buildr_capture(:stdout) { Oddb2xml::Cli.new(options).run }
954
942
  end
955
943
 
956
- it 'should report correct number of items' do
944
+ it "should report correct number of items" do
957
945
  expect(@res).to match(/products/)
958
946
  end
959
947
 
960
- it 'should contain the correct values fo CMUT from transfer.dat' do
961
- dat_filename = File.join(Oddb2xml::WorkDir, 'oddb.dat')
962
- expect(File.exists?(dat_filename)).to eq true
948
+ it "should contain the correct values fo CMUT from transfer.dat" do
949
+ dat_filename = File.join(Oddb2xml::WORK_DIR, "oddb.dat")
950
+ expect(File.exist?(dat_filename)).to eq true
963
951
  oddb_dat = IO.read(dat_filename)
964
952
  expect(oddb_dat).to match(/^..2/), "should have a record with '2' in CMUT field"
965
953
  expect(oddb_dat).to match(/^..3/), "should have a record with '3' in CMUT field"
966
- expect(oddb_dat).to match(RegExpDesitin), "should have Desitin"
967
- IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line, 0) }
954
+ expect(oddb_dat).to match(REG_EXP_DESITIN), "should have Desitin"
955
+ IO.readlines(dat_filename).each { |line| check_article_IGM_format(line, 0) }
968
956
  # oddb_dat.should match(/^..1/), "should have a record with '1' in CMUT field" # we have no
969
957
  end
970
958
  end
971
959
 
972
- context 'when -f dat -I 80 is given' do
960
+ context "when -f dat -I 80 is given" do
973
961
  before(:all) do
974
962
  common_run_init
975
- options = Oddb2xml::Options.parse('-f dat -I 80')
976
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
963
+ options = Oddb2xml::Options.parse("-f dat -I 80")
964
+ @res = buildr_capture(:stdout) { Oddb2xml::Cli.new(options).run }
977
965
  end
978
966
 
979
- it 'should report correct number of items' do
967
+ it "should report correct number of items" do
980
968
  expect(@res).to match(/products/)
981
969
  end
982
970
 
983
- it 'should contain the corect prices' do
984
- dat_filename = File.join(Oddb2xml::WorkDir, 'oddb.dat')
985
- expect(File.exists?(dat_filename)).to eq true
986
- oddb_dat = IO.read(dat_filename)
987
- oddb_dat_lines = IO.readlines(dat_filename)
988
- IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line, 892, true) }
971
+ it "should contain the corect prices" do
972
+ dat_filename = File.join(Oddb2xml::WORK_DIR, "oddb.dat")
973
+ expect(File.exist?(dat_filename)).to eq true
974
+ IO.readlines(dat_filename).each { |line| check_article_IGM_format(line, 892, true) }
989
975
  end
990
976
  end
991
- context 'when utf-8 to iso-8859 fails' do
992
- it 'should return a correct 8859 line' do
993
- lines = IO.readlines(File.join(Oddb2xml::SpecData, 'problems.txt'))
977
+ context "when utf-8 to iso-8859 fails" do
978
+ it "should return a correct 8859 line" do
979
+ lines = IO.readlines(File.join(Oddb2xml::SpecData, "problems.txt"))
994
980
  out = Oddb2xml.convert_to_8859_1(lines.first)
995
- expect(out.encoding.to_s).to eq 'ISO-8859-1'
996
- expect(out.chomp).to eq '<NAME_DE>SENSURA Mio 1t Uro 10-33 midi con lig so op 10 Stk</NAME_DE>'
981
+ expect(out.encoding.to_s).to eq "ISO-8859-1"
982
+ expect(out.chomp).to eq "<NAME_DE>SENSURA Mio 1t Uro 10-33 midi con lig so op 10 Stk</NAME_DE>"
997
983
  end
998
984
  end
999
-
1000
985
  end