| 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 | """ |
||
| 118 | def __shred_xml_bestand(self, filename: str) -> dict: |
||
| 119 | """ |
||
| 120 | Leest de relevante data in een XML-bestand met een test case. |
||
| 121 | |||
| 122 | :param str filename: De filenaam van het XML bestand. |
||
| 123 | |||
| 124 | :rtype: dict |
||
| 125 | """ |
||
| 126 | doc = etree.parse(filename) |
||
| 127 | |||
| 128 | xpath = '/soapenv:Envelope/soapenv:Body/xmlns:FICR_IN900101NL04' |
||
| 129 | namespaces = {'soapenv': 'http://schemas.xmlsoap.org/soap/envelope/', |
||
| 130 | 'xmlns': 'urn:hl7-org:v3'} |
||
| 131 | |||
| 132 | # Lees declaratiecode. |
||
| 133 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'id') |
||
| 134 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 135 | declaratie_code = elements[0].get('extension') |
||
| 136 | |||
| 137 | # Lees specialismecode. |
||
| 138 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'derivedFrom', |
||
| 139 | 'zorgtraject', 'responsibleParty', 'assignedPerson', 'code') |
||
| 140 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 141 | specialisme_code = elements[0].get('code') |
||
| 142 | |||
| 143 | # Lees diagnosecode. |
||
| 144 | parts = ( |
||
| 145 | 'ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'pertinentInformation1', |
||
| 146 | 'typerendeDiagnose', 'value') |
||
| 147 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 148 | diagnose_code = elements[0].get('code') |
||
| 149 | |||
| 150 | # Lees zorgtypecode. |
||
| 151 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'code') |
||
| 152 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 153 | zorg_type_code = elements[0].get('code') if elements else None |
||
| 154 | |||
| 155 | # Lees zorgvraagcode. |
||
| 156 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'derivedFrom', |
||
| 157 | 'zorgtraject', 'reason', 'zorgvraag', 'value') |
||
| 158 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 159 | zorg_vraag_code = elements[0].get('code') if elements else None |
||
| 160 | |||
| 161 | # Lees begindatum. |
||
| 162 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'effectiveTime', 'low') |
||
| 163 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 164 | begin_datum = self.__convert_date(elements[0].get('value')) if elements else None |
||
| 165 | |||
| 166 | # Lees de geboortedatum van de patient. |
||
| 167 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'subject', 'patient', 'subjectOf', 'leeftijd', |
||
| 168 | 'value') |
||
| 169 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 170 | leeftijd = int(elements[0].get('value')) if elements else None |
||
| 171 | geboorte_datum = self.__leeftijd_geboorte_datum(begin_datum, leeftijd) |
||
| 172 | |||
| 173 | # Lees het geslacht van de patient. |
||
| 174 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'subject', 'patient', 'patientPerson', |
||
| 175 | 'administrativeGenderCode') |
||
| 176 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 177 | geslacht_code = elements[0].get('code') if elements else None |
||
| 178 | |||
| 179 | # Lees de AGB-code van de zorginstelling. |
||
| 180 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'author', 'assignedOrganization', 'id') |
||
| 181 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 182 | zorg_instelling_code = elements[0].get('extension') if elements else None |
||
| 183 | |||
| 184 | # Lees alle zorgactiviteiten. |
||
| 185 | zorg_activiteiten = list() |
||
| 186 | parts = ('ControlActProcess', 'subject', 'Declaratiedataset', 'component', 'subtraject', 'debit', |
||
| 187 | 'zorgactiviteit') |
||
| 188 | elements = doc.xpath(xpath + '/' + self.__maak_xpath(parts), namespaces=namespaces) |
||
| 189 | for element in elements: |
||
| 190 | path = 'xmlns:code' |
||
| 191 | sub_elements = element.xpath(path, namespaces=namespaces) |
||
| 192 | zorg_activiteit_code = sub_elements[0].get('code') if sub_elements else None |
||
| 193 | |||
| 194 | path = 'xmlns:repeatNumber' |
||
| 195 | sub_elements = element.xpath(path, namespaces=namespaces) |
||
| 196 | aantal = int(sub_elements[0].get('value')) if sub_elements else None |
||
| 197 | |||
| 198 | zorg_activiteiten.append((zorg_activiteit_code, aantal)) |
||
| 199 | |||
| 200 | return {'subtraject_nummer': os.path.basename(filename), |
||
| 201 | 'declaratie_code': declaratie_code, |
||
| 202 | 'specialisme_code': specialisme_code, |
||
| 203 | 'diagnose_code': diagnose_code, |
||
| 204 | 'zorg_type_code': zorg_type_code, |
||
| 205 | 'zorg_vraag_code': zorg_vraag_code, |
||
| 206 | 'begin_datum': begin_datum, |
||
| 207 | 'geboorte_datum': geboorte_datum, |
||
| 208 | 'geslacht_code': geslacht_code, |
||
| 209 | 'zorg_instelling_code': zorg_instelling_code, |
||
| 210 | 'zorg_activiteiten': zorg_activiteiten} |
||
| 211 | |||
| 272 |