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