bika.health.widgets.patientmenstrualstatuswidget   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 43
dl 0
loc 73
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A PatientMenstrualStatusWidget.jsondumps() 0 2 1
A PatientMenstrualStatusWidget.getPatientsGender() 0 3 1
A PatientMenstrualStatusWidget.process_form() 0 11 2
A PatientMenstrualStatusWidget.getMenstrualStatus() 0 11 1
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.HEALTH.
4
#
5
# SENAITE.HEALTH is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by the Free
7
# Software Foundation, version 2.
8
#
9
# This program is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
# details.
13
#
14
# You should have received a copy of the GNU General Public License along with
15
# this program; if not, write to the Free Software Foundation, Inc., 51
16
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
#
18
# Copyright 2018-2019 by it's authors.
19
# Some rights reserved, see README and LICENSE.
20
21
from AccessControl import ClassSecurityInfo
22
from Products.ATExtensions.widget import RecordsWidget as ATRecordsWidget
23
from Products.Archetypes.Registry import registerWidget
24
from Products.CMFCore.utils import getToolByName
25
import json
26
27
from bika.health.interfaces import IPatient
28
29
30
class PatientMenstrualStatusWidget(ATRecordsWidget):
31
    security = ClassSecurityInfo()
32
    _properties = ATRecordsWidget._properties.copy()
33
    _properties.update({
34
        'macro': "bika_health_widgets/patientmenstrualstatuswidget",
35
        'helper_js': ("bika_health_widgets/patientmenstrualstatuswidget.js",),
36
        'helper_css': ("bika_health_widgets/patientmenstrualstatuswidget.css",),
37
    })
38
39
    def process_form(self, instance, field, form, empty_marker=None,
40
                     emptyReturnsMarker=False):
41
        outvalues = []
42
        values = form.get(field.getName(), empty_marker)
43
        for value in values:
44
            outvalues.append({'Hysterectomy': bool(value.get('Hysterectomy', False)),
45
                              'HysterectomyYear': value.get('HysterectomyYear', ''),
46
                              'OvariesRemoved': bool(value.get('OvariesRemoved', False)),
47
                              'OvariesRemovedNum': int(value.get('OvariesRemovedNum', 0)),
48
                              'OvariesRemovedYear': value.get('OvariesRemovedYear', '')})
49
        return outvalues, {}
50
51
    def jsondumps(self, val):
52
        return json.dumps(val)
53
54
    def getPatientsGender(self):
55
        patient = self.aq_parent
56
        return IPatient.providedBy(patient) and patient.getGender() or "dk"
57
58
    def getMenstrualStatus(self):
59
60
        statuses = [{'Hysterectomy': False,
61
                     'HysterectomyYear': '',
62
                     'OvariesRemoved': False,
63
                     'OvariesRemovedNum': 0,
64
                     'OvariesRemovedYear': ''}]
65
66
        return len(self.aq_parent.getMenstrualStatus()) > 0 \
67
                    and self.aq_parent.getMenstrualStatus() \
68
                    or statuses
69
70
registerWidget(PatientMenstrualStatusWidget,
71
               title='PatientMenstrualStatusWidget',
72
               description='Menstrual status information',
73
               )
74