oddb2xml 2.7.1 → 2.7.2

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.standard.yml +2 -0
  4. data/Gemfile +3 -3
  5. data/History.txt +8 -0
  6. data/README.md +1 -1
  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.rb +1 -1
  12. data/lib/oddb2xml/builder.rb +1070 -1038
  13. data/lib/oddb2xml/calc.rb +232 -233
  14. data/lib/oddb2xml/chapter_70_hack.rb +38 -32
  15. data/lib/oddb2xml/cli.rb +252 -236
  16. data/lib/oddb2xml/compare.rb +70 -59
  17. data/lib/oddb2xml/compositions_syntax.rb +448 -430
  18. data/lib/oddb2xml/compressor.rb +20 -20
  19. data/lib/oddb2xml/downloader.rb +153 -127
  20. data/lib/oddb2xml/extractor.rb +302 -289
  21. data/lib/oddb2xml/options.rb +34 -35
  22. data/lib/oddb2xml/parslet_compositions.rb +263 -269
  23. data/lib/oddb2xml/semantic_check.rb +39 -33
  24. data/lib/oddb2xml/util.rb +163 -163
  25. data/lib/oddb2xml/version.rb +1 -1
  26. data/lib/oddb2xml/xml_definitions.rb +32 -33
  27. data/oddb2xml.gemspec +31 -32
  28. data/spec/artikelstamm_spec.rb +111 -110
  29. data/spec/builder_spec.rb +489 -505
  30. data/spec/calc_spec.rb +552 -593
  31. data/spec/check_artikelstamm_spec.rb +26 -26
  32. data/spec/cli_spec.rb +173 -174
  33. data/spec/compare_spec.rb +9 -11
  34. data/spec/composition_syntax_spec.rb +390 -409
  35. data/spec/compressor_spec.rb +48 -48
  36. data/spec/data/transfer.dat +1 -0
  37. data/spec/data_helper.rb +47 -49
  38. data/spec/downloader_spec.rb +247 -260
  39. data/spec/extractor_spec.rb +171 -159
  40. data/spec/galenic_spec.rb +233 -256
  41. data/spec/options_spec.rb +116 -119
  42. data/spec/parslet_spec.rb +833 -861
  43. data/spec/spec_helper.rb +154 -153
  44. data/test_options.rb +39 -42
  45. data/tools/win_fetch_cacerts.rb +2 -3
  46. metadata +19 -3
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,86 @@ 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='1']").size).to eq 1
560
550
  end
561
551
 
562
552
  ean_with_drug_index = 7680555610041
563
553
  it "should have a correct drug information for #{ean_with_drug_index}" do
564
- doc = REXML::Document.new IO.read(checkAndGetArticleXmlName)
554
+ REXML::Document.new IO.read(checkAndGetArticleXmlName)
565
555
  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'
556
+ expect(REXML::XPath.match(@rexml, "//ART//DRUG_INDEX").size).to eq 1
557
+ expect(REXML::XPath.match(@rexml, "//ART//DRUG_INDEX").first.text).to eq "d"
568
558
  found = false
569
- XPath.match( @rexml, "//ART//CDBG").each{
570
- |flag|
571
- if flag.text.eql?('Y')
572
- found = true
573
- break
574
- end
559
+ REXML::XPath.match(@rexml, "//ART//CDBG").each { |flag|
560
+ if flag.text.eql?("Y")
561
+ found = true
562
+ break
563
+ end
575
564
  }
576
565
  expect(found)
577
566
  end
578
567
 
579
- it 'should generate ATC for 7680002770014' do
580
- oddb_product_xml = IO.read(File.join(Oddb2xml::WorkDir, 'oddb_product.xml'))
568
+ it "should generate ATC for 7680002770014" do
569
+ oddb_product_xml = IO.read(File.join(Oddb2xml::WORK_DIR, "oddb_product.xml"))
581
570
  text = %(<GTIN>7680002770014</GTIN>
582
571
  <PRODNO>0027701</PRODNO>
583
572
  <DSCRD>SEROCYTOL Herz-Gefässe Supp 3 Stk</DSCRD>
@@ -588,8 +577,8 @@ describe Oddb2xml::Builder do
588
577
  expect(oddb_product_xml.index(text)).to be >= 1
589
578
  end
590
579
 
591
- it 'should generate ATC for 7680002770021' do
592
- oddb_product_xml = IO.read(File.join(Oddb2xml::WorkDir, 'oddb_product.xml'))
580
+ it "should generate ATC for 7680002770021" do
581
+ oddb_product_xml = IO.read(File.join(Oddb2xml::WORK_DIR, "oddb_product.xml"))
593
582
  text2 = %( <GTIN>7680002770021</GTIN>
594
583
  <PRODNO>0027701</PRODNO>
595
584
  <DSCRD>Coeur-Vaisseaux Sérocytol, suppositoire</DSCRD>
@@ -600,401 +589,396 @@ describe Oddb2xml::Builder do
600
589
  expect(oddb_product_xml.index(text2)).to be >= 1
601
590
  end
602
591
 
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
592
+ it "should generate SALECD A for swissmedic packages" do
593
+ 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
594
  end
606
-
607
595
  end
608
596
 
609
- context 'when -o for fachinfo is given' do
597
+ context "when -o for fachinfo is given" do
610
598
  before(:all) do
611
599
  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'])
600
+ @oddb_fi_xml = File.expand_path(File.join(Oddb2xml::WORK_DIR, "oddb_fi.xml"))
601
+ @oddb_fi_product_xml = File.expand_path(File.join(Oddb2xml::WORK_DIR, "oddb_fi_product.xml"))
602
+ options = Oddb2xml::Options.parse(["-o", "--log"])
615
603
  # @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
616
604
  Oddb2xml::Cli.new(options).run
617
605
  end
618
606
 
619
- it 'should have a correct NBR_RECORD in oddb_fi_product.xml' do
620
- check_result( File.read('oddb_fi_product.xml'), 0)
607
+ it "should have a correct NBR_RECORD in oddb_fi_product.xml" do
608
+ check_result(File.read("oddb_fi_product.xml"), 0)
621
609
  end
622
610
 
623
- it 'should have a correct NBR_RECORD in oddb_fi.xml' do
624
- check_result( File.read('oddb_fi.xml'), 2)
611
+ it "should have a correct NBR_RECORD in oddb_fi.xml" do
612
+ check_result(File.read("oddb_fi.xml"), 2)
625
613
  end
626
614
 
627
- it 'should return produce a correct oddb_fi.xml' do
628
- expect(File.exists?(@oddb_fi_xml)).to eq true
615
+ it "should return produce a correct oddb_fi.xml" do
616
+ expect(File.exist?(@oddb_fi_xml)).to eq true
629
617
  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'
618
+ expect(/<KMP/.match(inhalt.to_s).to_s).to eq "<KMP"
619
+ expect(/<style><!\[CDATA\[p{margin-top/.match(inhalt.to_s).to_s).to eq "<style><![CDATA[p{margin-top"
632
620
  m = /<paragraph><!\[CDATA\[(.+)\n(.*)/.match(inhalt.to_s)
633
621
  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)
622
+ skip { m[2].should eq '<p class="s4" id="section1"><span class="s2"><span>Zyvoxid</span></span><sup class="s3"><span>®</span></sup></p>' }
623
+ expect(File.exist?(@oddb_fi_product_xml)).to eq true
624
+ IO.read(@oddb_fi_product_xml)
638
625
  end
639
626
 
640
- it 'should produce valid xml files' do
627
+ it "should produce valid xml files" do
641
628
  skip "Niklaus does not know how to create a valid oddb_fi_product.xml"
642
629
  # check_validation_via_xsd
643
630
  end
644
631
 
645
- it 'should generate a valid oddb_product.xml' do
632
+ it "should generate a valid oddb_product.xml" do
646
633
  expect(@res).to match(/products/) if @res
647
- checkProductXml(NrPackages)
634
+ checkProductXml(NR_PACKAGES)
648
635
  end
649
-
650
636
  end
651
637
 
652
- context 'when -f dat is given' do
638
+ context "when -f dat is given" do
653
639
  before(:all) do
654
640
  common_run_init
655
- options = Oddb2xml::Options.parse('-f dat --log')
656
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
641
+ options = Oddb2xml::Options.parse("-f dat --log")
642
+ @res = buildr_capture(:stdout) { Oddb2xml::Cli.new(options).run }
657
643
  # Oddb2xml::Cli.new(options).run # to debug
658
644
  end
659
645
 
660
- it 'should contain the correct values fo CMUT from transfer.dat' do
646
+ it "should contain the correct values fo CMUT from transfer.dat" do
661
647
  expect(@res).to match(/products/)
662
- dat_filename = File.join(Oddb2xml::WorkDir, 'oddb.dat')
663
- expect(File.exists?(dat_filename)).to eq true
648
+ dat_filename = File.join(Oddb2xml::WORK_DIR, "oddb.dat")
649
+ expect(File.exist?(dat_filename)).to eq true
664
650
  oddb_dat = IO.read(dat_filename)
665
651
  expect(oddb_dat).to match(/^..2/), "should have a record with '2' in CMUT field"
666
652
  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) }
653
+ expect(oddb_dat).to match(REG_EXP_DESITIN), "should have Desitin"
654
+ IO.readlines(dat_filename).each { |line| check_article_IGM_format(line, 0) }
669
655
  m = /.+KENDURAL Depottabl 30 Stk.*7680353660163.+/.match(oddb_dat)
670
656
  expect(m[0].size).to eq 97 # size of IGM 1 record
671
- expect(m[0][74]).to eq '3'
657
+ expect(m[0][74]).to eq "3"
672
658
  end
673
659
  end
674
660
 
675
- context 'when --append -f dat is given' do
661
+ context "when --append -f dat is given" do
676
662
  before(:all) do
677
663
  common_run_init
678
- options = Oddb2xml::Options.parse('--append -f dat')
679
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
664
+ options = Oddb2xml::Options.parse("--append -f dat")
665
+ @res = buildr_capture(:stdout) { Oddb2xml::Cli.new(options).run }
680
666
  end
681
667
 
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
668
+ it "should generate a valid oddb_with_migel.dat" do
669
+ dat_filename = File.join(Oddb2xml::WORK_DIR, "oddb_with_migel.dat")
670
+ expect(File.exist?(dat_filename)).to eq true
685
671
  oddb_dat = IO.read(dat_filename)
686
- expect(oddb_dat).to match(RegExpDesitin), "should have Desitin"
672
+ expect(oddb_dat).to match(REG_EXP_DESITIN), "should have Desitin"
687
673
  expect(@res).to match(/products/)
688
674
  end
689
675
 
690
676
  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
677
+ dat_filename = File.join(Oddb2xml::WORK_DIR, "oddb_with_migel.dat")
678
+ expect(File.exist?(dat_filename)).to eq true
693
679
  oddb_dat = IO.read(dat_filename)
694
680
  expect(oddb_dat).to match(/76806206900842/), "should match EAN of Desitin"
695
681
  end
696
682
  end
697
683
 
698
- context 'when --append -I 80 -e is given' do
684
+ context "when --append -I 80 -e is given" do
699
685
  before(:all) do
700
686
  common_run_init
701
- options = Oddb2xml::Options.parse('--append -I 80 -e')
687
+ options = Oddb2xml::Options.parse("--append -I 80 -e")
702
688
  Oddb2xml::Cli.new(options).run
703
689
  # @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
704
690
  end
705
691
 
706
- it "oddb_article with stuf from ZurRose", :skip => "ZurRose contains ERYTHROCIN i.v. Troc*esteekensub 1000 mg Amp [!]" do
692
+ it "oddb_article with stuf from ZurRose", skip: "ZurRose contains ERYTHROCIN i.v. Troc*esteekensub 1000 mg Amp [!]" do
707
693
  checkArticleXml
708
694
  end
709
695
 
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
696
+ # Zeno used oddb2xml -e -I 45 -c zip for oddb_arcticle for artikelstamm 7680172330414 3605520301605
697
+ it "should add GTIN 7680172330414 which is marked as inactive in transfer.dat" do
712
698
  @inhalt = IO.read(oddb_article_xml)
713
- expect(@inhalt.index('7680172330414')).not_to be nil
699
+ expect(@inhalt.index("7680172330414")).not_to be nil
714
700
  end
715
701
 
716
- it 'should add GTIN 3605520301605 Armani Attitude which is marked as inactive in transfer.dat' do
702
+ it "should add GTIN 3605520301605 Armani Attitude which is marked as inactive in transfer.dat" do
717
703
  @inhalt = IO.read(oddb_article_xml)
718
704
  # <SALECD>I</SALECD>
719
705
 
720
- expect(@inhalt.index('3605520301605')).not_to be nil
706
+ expect(@inhalt.index("3605520301605")).not_to be nil
721
707
  end
722
708
 
723
- context 'XSD' do
709
+ context "XSD" do
724
710
  check_attributes(oddb_article_xml, ARTICLE_ATTRIBUTE_TESTS)
725
711
  check_elements(oddb_article_xml, ARTICLE_COMMON_ELEMENTS)
726
712
  check_elements(oddb_article_xml, ARTICLE_ZURROSE_ELEMENTS)
727
- it 'should contain NAROPIN' do
713
+ it "should contain NAROPIN" do
728
714
  # This fails on Ruby < 2.4 as NAROPIN INJ LÖS 0.2 % 10 is wrongly encoded
729
715
  expect(File.read(oddb_article_xml).scan(ARTICLE_NAROPIN).size).to eq 1
730
716
  end
731
717
  end
732
718
 
733
- it 'should emit a correct oddb_article.xml' do
719
+ it "should emit a correct oddb_article.xml" do
734
720
  checkArticleXml(false)
735
721
  end
736
722
 
737
- it 'should generate a valid oddb_product.xml' do
738
- expect(@res).to match(/products/) if @res != nil
739
- checkProductXml(NrPackages)
723
+ it "should generate a valid oddb_product.xml" do
724
+ expect(@res).to match(/products/) unless @res.nil?
725
+ checkProductXml(NR_PACKAGES)
740
726
  end
741
727
 
742
- it 'should contain the correct (increased) prices' do
728
+ it "should contain the correct (increased) prices" do
743
729
  checkPrices(true)
744
730
  end
745
731
  end
746
732
 
747
- context 'when option -e is given' do
733
+ context "when option -e is given" do
748
734
  before(:all) do
749
735
  common_run_init
750
- options = Oddb2xml::Options.parse('-e')
736
+ options = Oddb2xml::Options.parse("-e")
751
737
  puts options
752
738
  @cli = Oddb2xml::Cli.new(options)
753
739
  if RUN_ALL
754
- @res = buildr_capture(:stdout){ @cli.run }
740
+ @res = buildr_capture(:stdout) { @cli.run }
755
741
  else
756
742
  @cli.run
757
743
  end
758
744
  end
759
745
 
760
- context 'XSD limitation' do
746
+ context "XSD limitation" do
761
747
  check_attributes(oddb_limitation_xml, LIMITATION_ATTRIBUTE_TESTS)
762
748
  check_elements(oddb_limitation_xml, LIMITATION_ELEMENT_TESTS)
763
749
  end
764
750
 
765
- context 'XSD code' do
751
+ context "XSD code" do
766
752
  check_attributes(oddb_code_xml, CODE_ATTRIBUTE_TESTS)
767
753
  check_elements(oddb_code_xml, CODE_ELEMENT_TESTS)
768
754
  end
769
755
 
770
- it 'should have a correct NBR_RECORD in oddb_code.xml' do
771
- check_result(File.read(oddb_code_xml), NrCodes)
756
+ it "should have a correct NBR_RECORD in oddb_code.xml" do
757
+ check_result(File.read(oddb_code_xml), NR_CODES)
772
758
  end
773
759
 
774
- context 'XSD interaction' do
760
+ context "XSD interaction" do
775
761
  check_attributes(oddb_interaction_xml, INTERACTION_ATTRIBUTE_TESTS)
776
762
  check_elements(oddb_interaction_xml, INTERACTION_ELEMENT_TESTS)
777
763
  end
778
764
 
779
- it 'should have a correct NBR_RECORD in oddb_interaction.xml' do
780
- check_result(File.read(oddb_interaction_xml), NrInteractions)
765
+ it "should have a correct NBR_RECORD in oddb_interaction.xml" do
766
+ check_result(File.read(oddb_interaction_xml), NR_INTERACTIONS)
781
767
  end
782
768
 
783
- context 'XSD substance' do
769
+ context "XSD substance" do
784
770
  check_attributes(oddb_substance_xml, SUBSTANCE_ATTRIBUTE_TESTS)
785
771
  check_elements(oddb_substance_xml, SUBSTANCE_ELEMENT_TESTS)
786
772
  end
787
773
 
788
- it 'should have a correct NBR_RECORD in oddb_substance.xml' do
789
- check_result(File.read('oddb_substance.xml'), NrSubstances)
774
+ it "should have a correct NBR_RECORD in oddb_substance.xml" do
775
+ check_result(File.read("oddb_substance.xml"), NR_SUBSTANCES)
790
776
  end
791
777
 
792
- it 'should emit a correct oddb_article.xml' do
778
+ it "should emit a correct oddb_article.xml" do
793
779
  checkArticleXml
794
780
  end
795
781
 
796
- it 'should produce a correct oddb_product.xml' do
797
- checkProductXml(NrPackages)
782
+ it "should produce a correct oddb_product.xml" do
783
+ checkProductXml(NR_PACKAGES)
798
784
  end
799
785
 
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
786
+ if RUN_ALL
787
+ it "should report correct output on stdout" do
788
+ expect(@res).to match(/\sPharma products: \d+/)
789
+ expect(@res).to match(/\sNonPharma products: \d+/)
790
+ end
791
+ end
804
792
 
805
- it 'should contain the correct (normal) prices' do
793
+ it "should contain the correct (normal) prices" do
806
794
  checkPrices(false)
807
795
  end
808
796
 
809
- it 'should generate the flag ORPH for orphan' do
797
+ it "should generate the flag ORPH for orphan" do
810
798
  doc = REXML::Document.new File.new(oddb_product_xml)
811
799
  orphan = checkAndGetProductWithGTIN(doc, Oddb2xml::ORPHAN_GTIN)
812
800
  expect(orphan).not_to eq nil
813
- expect(orphan.elements['ORPH'].text).to eq("true")
801
+ expect(orphan.elements["ORPH"].text).to eq("true")
814
802
  end
815
803
 
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
804
+ it "should generate the flag non-refdata" do
805
+ doc = REXML::Document.new File.new(checkAndGetArticleXmlName("non-refdata"))
806
+ expect(REXML::XPath.match(doc, "//REF_DATA").size).to eq NR_EXTENDED_ARTICLES
819
807
  end
820
808
 
821
- it 'should generate SALECD A for migel (NINCD 13)' do
809
+ it "should generate SALECD A for migel (NINCD 13)" do
822
810
  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')
811
+ article = REXML::XPath.match(doc, "//ART[DSCRD='ACTICOAT Flex 7 Wundverband 10x12.5cm 5 Stk']").first
812
+ expect(article.elements["SALECD"].text).to eq("A")
813
+ expect(article.elements["ARTINS/NINCD"].text).to eq("13")
826
814
  end
827
815
 
828
- it 'should pass validating via oddb2xml.xsd' do
816
+ it "should pass validating via oddb2xml.xsd" do
829
817
  check_validation_via_xsd
830
818
  end
831
819
 
832
- it 'should not contain veterinary iksnr 47066 CANIPHEDRIN' do
820
+ it "should not contain veterinary iksnr 47066 CANIPHEDRIN" do
833
821
  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)
822
+ REXML::XPath.match(doc, "//ART")
823
+ expect(REXML::XPath.match(doc, "//BC").count { |x| x.text.match("47066") }).to eq(0)
824
+ expect(REXML::XPath.match(doc, "//DSCRD").count { |x| x.text.match(/CANIPHEDRIN/) }).to eq(0)
837
825
  end
838
826
 
839
- it 'should handle not duplicate pharmacode 5366964' do
827
+ it "should handle not duplicate pharmacode 5366964" do
840
828
  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)
829
+ dscrds = REXML::XPath.match(doc, "//ART")
830
+ expect(REXML::XPath.match(doc, "//PHAR").count { |x| x.text.match("5366964") }).to eq(1)
831
+ expect(dscrds.size).to eq(NR_EXTENDED_ARTICLES)
832
+ expect(REXML::XPath.match(doc, "//PRODNO").count { |x| true }.size).to be >= 1
833
+ expect(REXML::XPath.match(doc, "//PRODNO").count { |x| x.text.match("0027701") }).to eq(1)
834
+ expect(REXML::XPath.match(doc, "//PRODNO").count { |x| x.text.match("6206901") }).to eq(1)
847
835
  end
848
836
 
849
- it 'should load correct number of nonpharma' do
837
+ it "should load correct number of nonpharma" do
850
838
  puts checkAndGetArticleXmlName
851
839
  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
840
+ dscrds = REXML::XPath.match(doc, "//ART")
841
+ expect(dscrds.size).to eq(NR_EXTENDED_ARTICLES)
842
+ expect(REXML::XPath.match(doc, "//PHAR").count { |x| x.text.match("0000000") }).to eq(0) # 0 is not a valid pharmacode
843
+ expect(REXML::XPath.match(doc, "//PHAR").count { |x| x.text.match(/\d+/) }).to eq 66
856
844
  end
857
845
 
858
- it 'should have a correct NBR_RECORD in oddb_limitation.xml' do
859
- check_result(File.read('oddb_limitation.xml'), NrLimitations)
846
+ it "should have a correct NBR_RECORD in oddb_limitation.xml" do
847
+ check_result(File.read("oddb_limitation.xml"), NR_LIMITATIONS)
860
848
  end
861
849
 
862
- it 'should emit a correct oddb_limitation.xml' do
850
+ it "should emit a correct oddb_limitation.xml" do
863
851
  # check limitations
864
- limitation_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_limitation.xml'))
865
- expect(File.exists?(limitation_filename)).to eq true
852
+ limitation_filename = File.expand_path(File.join(Oddb2xml::WORK_DIR, "oddb_limitation.xml"))
853
+ expect(File.exist?(limitation_filename)).to eq true
866
854
  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
855
+ limitations = REXML::XPath.match(doc, "//LIM")
856
+ expect(limitations.size).to eql NR_LIMITATIONS
857
+ expect(REXML::XPath.match(doc, "//SwissmedicNo5").count { |x| x.text.match("28486") }).to eq(1)
858
+ expect(REXML::XPath.match(doc, "//LIMNAMEBAG").count { |x| x.text.match("ZYVOXID") }).to eq(2)
859
+ expect(REXML::XPath.match(doc, "//LIMNAMEBAG").count { |x| x.text.match("070240") }).to be >= 1
860
+ expect(REXML::XPath.match(doc, "//DSCRD").count { |x| x.text.match(/^Gesamthaft zugelassen/) }).to be >= 1
861
+ expect(REXML::XPath.match(doc, "//DSCRD").count { |x| x.text.match(/^Behandlung nosokomialer Pneumonien/) }).to be >= 1
874
862
  end
875
863
 
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)
864
+ it "should emit a correct oddb_substance.xml" do
865
+ doc = REXML::Document.new File.new(File.join(Oddb2xml::WORK_DIR, "oddb_substance.xml"))
866
+ names = REXML::XPath.match(doc, "//NAML")
867
+ expect(names.size).to eq(NR_SUBSTANCES)
868
+ expect(names.count { |x| x.text.match("Lamivudinum") }).to eq(1)
881
869
  end
882
870
 
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" )
871
+ it "should emit a correct oddb_interaction.xml" do
872
+ doc = REXML::Document.new File.new(File.join(Oddb2xml::WORK_DIR, "oddb_interaction.xml"))
873
+ titles = REXML::XPath.match(doc, "//TITD")
886
874
  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)
875
+ expect(titles.count { |x| x.text.match("Keine Interaktion") }).to be >= 1
876
+ expect(titles.count { |x| x.text.match("Erhöhtes Risiko für Myopathie und Rhabdomyolyse") }).to eq(1)
889
877
  end
890
878
 
891
879
  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
880
+ article = REXML::XPath.match(doc, "//ART[ARTBAR/BC=#{ean13}]").first
881
+ name = article.elements["DSCRD"].text
882
+ salecd = article.elements["SALECD"].text
883
+ if $VERBOSE || (article.elements["SALECD"].text != expected.to_s)
896
884
  puts "checking doc for ean13 #{ean13} expected #{expected} == #{salecd}. #{name}"
897
885
  puts article.text
898
886
  end
899
- expect(article.elements['SALECD'].text).to eq(expected.to_s)
887
+ expect(article.elements["SALECD"].text).to eq(expected.to_s)
900
888
  end
901
889
 
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)
890
+ it "should generate the flag SALECD" do
891
+ expect(File.exist?(oddb_article_xml)).to eq true
892
+ FileUtils.cp(oddb_article_xml, File.join(Oddb2xml::WORK_DIR, "tst-SALECD.xml"))
906
893
  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
894
+ expect(REXML::XPath.match(doc, "//REF_DATA").size).to be > 0
895
+ checkItemForSALECD(doc, Oddb2xml::FERRO_GRADUMET_GTIN, "A") # FERRO-GRADUMET Depottabl 30 Stk
896
+ checkItemForSALECD(doc, Oddb2xml::SOFRADEX_GTIN, "I") # SOFRADEX
910
897
  end
911
898
  end
912
- context 'testing -e -I 80 option' do
899
+ context "testing -e -I 80 option" do
913
900
  before(:all) do
914
901
  common_run_init
915
- options = Oddb2xml::Options.parse('-e -I 80 --log')
902
+ options = Oddb2xml::Options.parse("-e -I 80 --log")
916
903
  # @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
917
904
  @res = Oddb2xml::Cli.new(options).run
918
905
  end
919
906
 
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'))
907
+ it "should add 80 percent to zur_rose pubbprice" do
908
+ expect(File.exist?(oddb_article_xml)).to eq true
909
+ FileUtils.cp(oddb_article_xml, File.join(Oddb2xml::WORK_DIR, "tst-e80.xml"))
923
910
  checkArticleXml
924
911
  checkPrices(true)
925
912
  end
926
913
 
927
- it 'should generate an article for EPIMINERAL' do
928
- expect(File.exists?(oddb_article_xml)).to eq true
914
+ it "should generate an article for EPIMINERAL" do
915
+ expect(File.exist?(oddb_article_xml)).to eq true
929
916
  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
917
+ article = REXML::XPath.match(doc, "//ART[PHAR=5822801]").first
918
+ expect(article.elements["DSCRD"].text).to match(/EPIMINERAL/i)
932
919
  end
933
920
 
934
- it 'should generate a correct number of packages in oddb_product.xml' do
935
- checkProductXml(NrPackages)
921
+ it "should generate a correct number of packages in oddb_product.xml" do
922
+ checkProductXml(NR_PACKAGES)
936
923
  end
937
924
 
938
- it 'should generate an article with the COOL (fridge) attribute' do
925
+ it "should generate an article with the COOL (fridge) attribute" do
939
926
  doc = REXML::Document.new File.new(oddb_article_xml)
940
927
  fridge_product = checkAndGetArticleWithGTIN(doc, Oddb2xml::FRIDGE_GTIN)
941
- expect(fridge_product.elements['COOL'].text).to eq('1')
928
+ expect(fridge_product.elements["COOL"].text).to eq("1")
942
929
  end
943
930
 
944
- it 'should generate a correct oddb_article.xml' do
931
+ it "should generate a correct oddb_article.xml" do
945
932
  checkArticleXml
946
933
  end
947
934
  end
948
935
 
949
- context 'when -f dat -p is given' do
936
+ context "when -f dat -p is given" do
950
937
  before(:all) do
951
938
  common_run_init
952
- options = Oddb2xml::Options.parse('-f dat -p')
953
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
939
+ options = Oddb2xml::Options.parse("-f dat -p")
940
+ @res = buildr_capture(:stdout) { Oddb2xml::Cli.new(options).run }
954
941
  end
955
942
 
956
- it 'should report correct number of items' do
943
+ it "should report correct number of items" do
957
944
  expect(@res).to match(/products/)
958
945
  end
959
946
 
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
947
+ it "should contain the correct values fo CMUT from transfer.dat" do
948
+ dat_filename = File.join(Oddb2xml::WORK_DIR, "oddb.dat")
949
+ expect(File.exist?(dat_filename)).to eq true
963
950
  oddb_dat = IO.read(dat_filename)
964
951
  expect(oddb_dat).to match(/^..2/), "should have a record with '2' in CMUT field"
965
952
  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) }
953
+ expect(oddb_dat).to match(REG_EXP_DESITIN), "should have Desitin"
954
+ IO.readlines(dat_filename).each { |line| check_article_IGM_format(line, 0) }
968
955
  # oddb_dat.should match(/^..1/), "should have a record with '1' in CMUT field" # we have no
969
956
  end
970
957
  end
971
958
 
972
- context 'when -f dat -I 80 is given' do
959
+ context "when -f dat -I 80 is given" do
973
960
  before(:all) do
974
961
  common_run_init
975
- options = Oddb2xml::Options.parse('-f dat -I 80')
976
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
962
+ options = Oddb2xml::Options.parse("-f dat -I 80")
963
+ @res = buildr_capture(:stdout) { Oddb2xml::Cli.new(options).run }
977
964
  end
978
965
 
979
- it 'should report correct number of items' do
966
+ it "should report correct number of items" do
980
967
  expect(@res).to match(/products/)
981
968
  end
982
969
 
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) }
970
+ it "should contain the corect prices" do
971
+ dat_filename = File.join(Oddb2xml::WORK_DIR, "oddb.dat")
972
+ expect(File.exist?(dat_filename)).to eq true
973
+ IO.readlines(dat_filename).each { |line| check_article_IGM_format(line, 892, true) }
989
974
  end
990
975
  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'))
976
+ context "when utf-8 to iso-8859 fails" do
977
+ it "should return a correct 8859 line" do
978
+ lines = IO.readlines(File.join(Oddb2xml::SpecData, "problems.txt"))
994
979
  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>'
980
+ expect(out.encoding.to_s).to eq "ISO-8859-1"
981
+ expect(out.chomp).to eq "<NAME_DE>SENSURA Mio 1t Uro 10-33 midi con lig so op 10 Stk</NAME_DE>"
997
982
  end
998
983
  end
999
-
1000
984
  end