| Conditions | 10 |
| Total Lines | 93 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 110 |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
Complex classes like kerapu.command.TestsetShredderCommand.TestShredderCommand.__shred_xml_bestand() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | import csv |
||
| 115 | def __shred_xml_bestand(self, filename: str) -> Dict: |
||
| 116 | """ |
||
| 117 | Leest de relevante data in een XML-bestand met een test case. |
||
| 118 | |||
| 119 | :param str filename: De filenaam van het XML bestand. |
||
| 120 | |||
| 121 | :rtype: dict |
||
| 122 | """ |
||
| 123 | doc = etree.parse(filename) |
||
| 124 | |||
| 125 | xpath = '/soapenv:Envelope/soapenv:Body/xmlns:FICR_IN900101NL04' |
||
| 126 | namespaces = {'soapenv': 'http://schemas.xmlsoap.org/soap/envelope/', |
||
| 127 | 'xmlns': 'urn:hl7-org:v3'} |
||
| 128 | |||
| 129 | # Lees declaratiecode. |
||
| 130 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'id') |
||
| 131 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 132 | declaratie_code = elements[0].get('extension') |
||
| 133 | |||
| 134 | # Lees specialismecode. |
||
| 135 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'derivedFrom', |
||
| 136 | 'zorgtraject', 'responsibleParty', 'assignedPerson', 'code') |
||
| 137 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 138 | specialisme_code = elements[0].get('code') |
||
| 139 | |||
| 140 | # Lees diagnosecode. |
||
| 141 | parts = ( |
||
| 142 | 'ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'pertinentInformation1', |
||
| 143 | 'typerendeDiagnose', 'value') |
||
| 144 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 145 | diagnose_code = elements[0].get('code') |
||
| 146 | |||
| 147 | # Lees zorgtypecode. |
||
| 148 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'code') |
||
| 149 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 150 | zorg_type_code = elements[0].get('code') if elements else None |
||
| 151 | |||
| 152 | # Lees zorgvraagcode. |
||
| 153 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'derivedFrom', |
||
| 154 | 'zorgtraject', 'reason', 'zorgvraag', 'value') |
||
| 155 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 156 | zorg_vraag_code = elements[0].get('code') if elements else None |
||
| 157 | |||
| 158 | # Lees begindatum. |
||
| 159 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'effectiveTime', 'low') |
||
| 160 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 161 | begin_datum = self.__convert_date(elements[0].get('value')) if elements else None |
||
| 162 | |||
| 163 | # Lees de geboortedatum van de patient. |
||
| 164 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'subject', 'patient', 'subjectOf', 'leeftijd', |
||
| 165 | 'value') |
||
| 166 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 167 | leeftijd = int(elements[0].get('value')) if elements else None |
||
| 168 | geboorte_datum = self.__leeftijd_geboorte_datum(begin_datum, leeftijd) |
||
| 169 | |||
| 170 | # Lees het geslacht van de patient. |
||
| 171 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'subject', 'patient', 'patientPerson', |
||
| 172 | 'administrativeGenderCode') |
||
| 173 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 174 | geslacht_code = elements[0].get('code') if elements else None |
||
| 175 | |||
| 176 | # Lees de AGB-code van de zorginstelling. |
||
| 177 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'author', 'assignedOrganization', 'id') |
||
| 178 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 179 | zorg_instelling_code = elements[0].get('extension') if elements else None |
||
| 180 | |||
| 181 | # Lees alle zorgactiviteiten. |
||
| 182 | zorg_activiteiten = list() |
||
| 183 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'debit', |
||
| 184 | 'zorgactiviteit') |
||
| 185 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 186 | for element in elements: |
||
| 187 | path = 'xmlns:code' |
||
| 188 | sub_elements = element.xpath(path, namespaces=namespaces) |
||
| 189 | zorg_activiteit_code = sub_elements[0].get('code') if sub_elements else None |
||
| 190 | |||
| 191 | path = 'xmlns:repeatNumber' |
||
| 192 | sub_elements = element.xpath(path, namespaces=namespaces) |
||
| 193 | aantal = int(sub_elements[0].get('value')) if sub_elements else None |
||
| 194 | |||
| 195 | zorg_activiteiten.append((zorg_activiteit_code, aantal)) |
||
| 196 | |||
| 197 | return {'subtraject_nummer': os.path.basename(filename), |
||
| 198 | 'declaratie_code': declaratie_code, |
||
| 199 | 'specialisme_code': specialisme_code, |
||
| 200 | 'diagnose_code': diagnose_code, |
||
| 201 | 'zorg_type_code': zorg_type_code, |
||
| 202 | 'zorg_vraag_code': zorg_vraag_code, |
||
| 203 | 'begin_datum': begin_datum, |
||
| 204 | 'geboorte_datum': geboorte_datum, |
||
| 205 | 'geslacht_code': geslacht_code, |
||
| 206 | 'zorg_instelling_code': zorg_instelling_code, |
||
| 207 | 'zorg_activiteiten': zorg_activiteiten} |
||
| 208 | |||
| 269 |