| Conditions | 11 |
| Total Lines | 51 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| 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 bika.health.widgets.casesymptomswidget.CaseSymptomsWidget.getSymptoms() 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 | # -*- coding: utf-8 -*- |
||
| 61 | def getSymptoms(self, gender=None): |
||
| 62 | """ Returns the symptoms from the instance merged with those symptoms |
||
| 63 | active from bika setup, with severity values assigned to default 0 |
||
| 64 | """ |
||
| 65 | outsymptoms = {} |
||
| 66 | field = self.aq_parent.Schema()['Symptoms'] |
||
| 67 | value = field.get(self.aq_parent) |
||
| 68 | casesymptoms = value and value or [] |
||
| 69 | |||
| 70 | if not gender: |
||
| 71 | patient = self.aq_parent.Schema()['Patient'].get(self.aq_parent) |
||
| 72 | gender = patient and patient.getGender() or 'dk' |
||
| 73 | |||
| 74 | symptoms = self.bika_setup_catalog(portal_type='Symptom', |
||
| 75 | is_active=True) |
||
| 76 | for symptom in symptoms: |
||
| 77 | symptom = symptom.getObject() |
||
| 78 | s_gender = symptom.getGender() |
||
| 79 | outsymptoms[symptom.UID()] = { |
||
| 80 | 'UID': symptom.UID(), |
||
| 81 | 'Title': symptom.Title(), |
||
| 82 | 'Description':symptom.Description(), |
||
| 83 | 'SeverityAllowed':symptom.getSeverityAllowed() and 1 or 0, |
||
| 84 | 'Severity':'0', |
||
| 85 | 'Assigned':0, |
||
| 86 | 'Gender':symptom.getGender(), |
||
| 87 | 'Visible':symptom.getGender()=='dk' or symptom.getGender()==gender} |
||
| 88 | |||
| 89 | for symptom in casesymptoms: |
||
| 90 | if 'UID' in symptom: |
||
| 91 | if symptom['UID'] in outsymptoms \ |
||
| 92 | and ('Severity' in symptom \ |
||
| 93 | and symptom['Severity'] is not None \ |
||
| 94 | and symptom['Severity'] != '0'): |
||
| 95 | sym = outsymptoms[symptom['UID']] |
||
| 96 | sym['Severity'] = symptom['Severity'] |
||
| 97 | sym['Assigned'] = 1 |
||
| 98 | else: |
||
| 99 | outsymptoms[symptom['UID']] = {'UID': symptom['UID'], |
||
| 100 | 'Title': symptom.get('Title',''), |
||
| 101 | 'Description': symptom.get('Description',''), |
||
| 102 | 'SeverityAllowed': 'SeverityAllowed' in symptom and symptom['SeverityAllowed'] or 0, |
||
| 103 | 'Severity': symptom.get('Severity','0'), |
||
| 104 | 'Assigned': 1, |
||
| 105 | 'Gender':symptom.get('Gender', 'dk'), |
||
| 106 | 'Visible':symptom.get('Gender', 'dk')=='dk' or symptom.get('Gender', 'dk')==gender} |
||
| 107 | items=[] |
||
| 108 | for symptom in outsymptoms.values(): |
||
| 109 | items.append(symptom) |
||
| 110 | items.sort(lambda x, y: cmp(x['Title'].lower(), y['Title'].lower())) |
||
|
|
|||
| 111 | return items |
||
| 112 | |||
| 117 |