GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ReferentieShredder.shred_xml_file()   B
last analyzed

Complexity

Conditions 1

Size

Total Lines 225
Code Lines 196

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 42
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 196
nop 2
dl 0
loc 225
ccs 42
cts 42
cp 1
crap 1
rs 7
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
from lxml import etree
2
3
from kerapu.shredder.Shredder import Shredder
4 1
5
6 1
class ReferentieShredder(Shredder):
7
    """
8
    Klasse voor het schreden en opslaan in CSV-formaat van referentietabellen opgeslagen in XML-formaat.
9 1
    """
10
11
    # ------------------------------------------------------------------------------------------------------------------
12
    def shred_xml_file(self, filename: str) -> None:
13
        """
14
        Slaat de referentietabellen op in CSV-formaat.
15 1
16
        :param str filename: De filenaam van het XML bestand.
17
        """
18
        self._io.title('Shredder')
19
20
        doc = etree.parse(filename)
21 1
22
        xpath = '/soapenv:Envelope/soapenv:Body/InlezenReferenties/Referenties/'
23 1
        namespaces = {'soapenv': 'http://schemas.xmlsoap.org/soap/envelope/'}
24
25 1
        # Extract AfsluitReden.
26 1
        table = doc.xpath(xpath + 'AfsluitRedenen/AfsluitReden', namespaces=namespaces)
27
        fields = ['AfsluitRedenCode',
28
                  'AfsluitRedenOmschrijving',
29 1
                  'BeginDatum',
30 1
                  'EindDatum',
31
                  'VersieDatum']
32
        self.extract_table(table, 'AfsluitRedenen.csv', fields, fields)
33
34
        # Extract BehandelKlasse.
35 1
        table = doc.xpath(xpath + 'BehandelKlassen/BehandelKlasse', namespaces=namespaces)
36
        fields = ['ZorgProductGroepCode',
37
                  'ZorgActiviteitCode',
38 1
                  'BehandelKlasseCode',
39 1
                  'BehandelKlasseOmschrijving',
40
                  'BeginDatum',
41
                  'EindDatum',
42
                  'VersieDatum']
43
        self.extract_table(table, 'BehandelKlassen.csv', fields, fields)
44
45
        # Extract Diagnose.
46 1
        table = doc.xpath(xpath + 'Diagnosen/Diagnose', namespaces=namespaces)
47
        fields = ['SpecialismeCode',
48
                  'DiagnoseCode',
49 1
                  'DiagnoseOmschrijving',
50 1
                  'DiagnoseAttribuutCode',
51
                  'ICD10DiagnoseCode',
52
                  'DiagnoseCluster1',
53
                  'DiagnoseCluster2',
54
                  'DiagnoseCluster3',
55
                  'DiagnoseCluster4',
56
                  'DiagnoseCluster5',
57
                  'DiagnoseCluster6',
58
                  'BeginDatum',
59
                  'EindDatum',
60
                  'VersieDatum']
61
        xpaths = ['SpecialismeCode',
62
                  'DiagnoseCode',
63
                  'DiagnoseOmschrijving',
64 1
                  'DiagnoseAttribuutCode',
65
                  'ICD10DiagnoseCode',
66
                  "DiagnoseCluster/DiagnoseClusterItem[@Key='1']",
67
                  "DiagnoseCluster/DiagnoseClusterItem[@Key='2']",
68
                  "DiagnoseCluster/DiagnoseClusterItem[@Key='3']",
69
                  "DiagnoseCluster/DiagnoseClusterItem[@Key='4']",
70
                  "DiagnoseCluster/DiagnoseClusterItem[@Key='5']",
71
                  "DiagnoseCluster/DiagnoseClusterItem[@Key='6']",
72
                  'BeginDatum',
73
                  'EindDatum',
74
                  'VersieDatum']
75
        self.extract_table(table, 'Diagnosen.csv', fields, xpaths)
76
77
        # Extract Geslacht.
78 1
        table = doc.xpath(xpath + 'Geslachten/Geslacht', namespaces=namespaces)
79
        fields = ['GeslachtCodeNEN',
80
                  'GeslachtCodeHL7',
81 1
                  'GeslachtOmschrijving',
82 1
                  'BeginDatum',
83
                  'EindDatum',
84
                  'VersieDatum']
85
        self.extract_table(table, 'Geslachten.csv', fields, fields)
86
87
        # Extract LimitatieMachtiging.
88 1
        table = doc.xpath(xpath + 'LimitatieMachtigingen/LimitatieMachtiging', namespaces=namespaces)
89
        fields = ['SpecialismeCode',
90
                  'DiagnoseCode',
91 1
                  'DiagnoseOmschrijving',
92 1
                  'ZorgActiviteitCode',
93
                  'ZorgActiviteitOmschrijving',
94
                  'BeginDatum',
95
                  'EindDatum',
96
                  'VersieDatum']
97
        self.extract_table(table, 'LimitatieMachtigingen.csv', fields, fields)
98
99
        # Extract Specialisme.
100 1
        table = doc.xpath(xpath + 'Specialismen/Specialisme', namespaces=namespaces)
101
        fields = ['SpecialismeCode',
102
                  'SpecialismeOmschrijving',
103 1
                  'SpecialismeIndicatie',
104 1
                  'SpecialismeOID',
105
                  'SpecialismeCluster1',
106
                  'SpecialismeCluster2',
107
                  'IndicatieAanspraakbeperking',
108
                  'BeginDatum',
109
                  'EindDatum',
110
                  'VersieDatum']
111
        xpaths = ['SpecialismeCode',
112
                  'SpecialismeOmschrijving',
113
                  'SpecialismeIndicatie',
114 1
                  'SpecialismeOID',
115
                  'SpecialismeCluster/SpecialismeClusterItem[(@Key=1)]',
116
                  'SpecialismeCluster/SpecialismeClusterItem[(@Key=2)]',
117
                  'IndicatieAanspraakbeperking',
118
                  'BeginDatum',
119
                  'EindDatum',
120
                  'VersieDatum']
121
        self.extract_table(table, 'Specialismen.csv', fields, xpaths)
122
123
        # Extract VertaalZorgActiviteit.
124 1
        table = doc.xpath(xpath + 'VertaalZorgActiviteiten/VertaalZorgActiviteit', namespaces=namespaces)
125
        fields = ['ZorgActiviteitCode',
126
                  'ZorgActiviteitOmschrijving',
127 1
                  'ZorgActiviteitCodeOud',
128 1
                  'ZorgActiviteitOmschrijvingOud',
129
                  'BeginDatum',
130
                  'EindDatum',
131
                  'VersieDatum']
132
        self.extract_table(table, 'VertaalZorgActiviteiten.csv', fields, fields)
133
134
        # Extract ZorgActiviteit.
135 1
        table = doc.xpath(xpath + 'ZorgActiviteiten/ZorgActiviteit', namespaces=namespaces)
136
        fields = ['ZorgActiviteitCode',
137
                  'ZorgActiviteitOmschrijving',
138 1
                  'ZorgActiviteitCluster01',
139 1
                  'ZorgActiviteitCluster02',
140
                  'ZorgActiviteitCluster03',
141
                  'ZorgActiviteitCluster04',
142
                  'ZorgActiviteitCluster05',
143
                  'ZorgActiviteitCluster06',
144
                  'ZorgActiviteitCluster07',
145
                  'ZorgActiviteitCluster08',
146
                  'ZorgActiviteitCluster09',
147
                  'ZorgActiviteitCluster10',
148
                  'ZorgActiviteitWeegFactor1',
149
                  'ZorgActiviteitWeegFactor2',
150
                  'WBMVCode',
151
                  'InnovatieCode',
152
                  'AanspraakCode',
153
                  'TariefType',
154
                  'Zorgprofielklassecode',
155
                  'OpNota',
156
                  'BeginDatum',
157
                  'EindDatum',
158
                  'VersieDatum']
159
        xpaths = ['ZorgActiviteitCode',
160
                  'ZorgActiviteitOmschrijving',
161
                  'ZorgActiviteitCluster/ZorgActiviteitClusterItem[@Key=1]',
162 1
                  'ZorgActiviteitCluster/ZorgActiviteitClusterItem[@Key=2]',
163
                  'ZorgActiviteitCluster/ZorgActiviteitClusterItem[@Key=3]',
164
                  'ZorgActiviteitCluster/ZorgActiviteitClusterItem[@Key=4]',
165
                  'ZorgActiviteitCluster/ZorgActiviteitClusterItem[@Key=5]',
166
                  'ZorgActiviteitCluster/ZorgActiviteitClusterItem[@Key=6]',
167
                  'ZorgActiviteitCluster/ZorgActiviteitClusterItem[@Key=7]',
168
                  'ZorgActiviteitCluster/ZorgActiviteitClusterItem[@Key=8]',
169
                  'ZorgActiviteitCluster/ZorgActiviteitClusterItem[@Key=9]',
170
                  'ZorgActiviteitCluster/ZorgActiviteitClusterItem[@Key=10]',
171
                  'ZorgActiviteitWeegFactor/ZorgActiviteitWeegFactorItem[@Key=1]',
172
                  'ZorgActiviteitWeegFactor/ZorgActiviteitWeegFactorItem[@Key=2]',
173
                  'WBMVCode',
174
                  'InnovatieCode',
175
                  'AanspraakCode',
176
                  'TariefType',
177
                  'Zorgprofielklassecode',
178
                  'OpNota',
179
                  'BeginDatum',
180
                  'EindDatum',
181
                  'VersieDatum']
182
        self.extract_table(table, 'ZorgActiviteiten.csv', fields, xpaths)
183
184
        # Extract ZorgProductGroep.
185 1
        table = doc.xpath(xpath + 'ZorgProductGroepen/ZorgProductGroep', namespaces=namespaces)
186
        fields = ['ZorgProductGroepCode',
187
                  'ZorgProductGroepOmschrijving',
188 1
                  'BeslisRegelStart',
189 1
                  'BeginDatum',
190
                  'EindDatum',
191
                  'VersieDatum']
192
        self.extract_table(table, 'ZorgProductGroepen.csv', fields, fields)
193
194
        # Extract ZorgType.
195 1
        table = doc.xpath(xpath + 'ZorgTypen/ZorgType', namespaces=namespaces)
196
        fields = ['SpecialismeCode',
197
                  'ZorgTypeCode',
198 1
                  'ZorgTypeOmschrijving',
199 1
                  'ZorgTypeAttribuutCode',
200
                  'ZorgTypeCluster1',
201
                  'ZorgTypeCluster2',
202
                  'BeginDatum',
203
                  'EindDatum',
204
                  'VersieDatum']
205
        xpaths = ['SpecialismeCode',
206
                  'ZorgTypeCode',
207
                  'ZorgTypeOmschrijving',
208 1
                  'ZorgTypeAttribuutCode',
209
                  'ZorgTypeCluster/ZorgTypeClusterItem[(@Key=1)]',
210
                  'ZorgTypeCluster/ZorgTypeClusterItem[(@Key=2)]',
211
                  'BeginDatum',
212
                  'EindDatum',
213
                  'VersieDatum']
214
        self.extract_table(table, 'ZorgTypen.csv', fields, xpaths)
215
216
        # Extract ZorgVraag.
217 1
        table = doc.xpath(xpath + 'ZorgVragen/ZorgVraag', namespaces=namespaces)
218
        fields = ['SpecialismeCode',
219
                  'ZorgVraagCode',
220 1
                  'ZorgVraagOmschrijving',
221 1
                  'ZorgVraagAttribuutCode',
222
                  'ZorgVraagCluster1',
223
                  'ZorgVraagCluster2',
224
                  'BeginDatum',
225
                  'EindDatum',
226
                  'VersieDatum']
227
        xpaths = ['SpecialismeCode',
228
                  'ZorgVraagCode',
229
                  'ZorgVraagOmschrijving',
230 1
                  'ZorgVraagAttribuutCode',
231
                  'ZorgVraagCluster/ZorgVraagClusterItem[(@Key=1)]',
232
                  'ZorgVraagCluster/ZorgVraagClusterItem[(@Key=2)]',
233
                  'BeginDatum',
234
                  'EindDatum',
235
                  'VersieDatum']
236
        self.extract_table(table, 'ZorgVragen.csv', fields, xpaths)
237
238
# ----------------------------------------------------------------------------------------------------------------------
239