bika.health.content.doctors   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 52
dl 0
loc 87
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Doctors.getContacts() 0 20 5
B Doctors.getCCs() 0 18 6
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
import json
22
23
from Products.ATContentTypes.content import schemata
24
from Products.Archetypes.public import registerType
25
from Products.Archetypes.utils import DisplayList
26
from Products.CMFCore.utils import getToolByName
27
from bika.health.config import PROJECTNAME
28
from bika.health.interfaces import IDoctors
29
from bika.lims import api
30
from bika.lims.interfaces import IHaveNoBreadCrumbs
31
from plone.app.folder.folder import ATFolder, ATFolderSchema
32
from zope.interface.declarations import implements
33
34
schema = ATFolderSchema.copy()
35
36
37
class Doctors(ATFolder):
38
    """Root folder for Doctors
39
    """
40
    implements(IDoctors, IHaveNoBreadCrumbs)
41
    displayContentsTab = False
42
    schema = schema
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable schema does not seem to be defined.
Loading history...
43
44
    def getContacts(self, dl=True):
45
        pc = getToolByName(self, 'portal_catalog')
46
        bsc = getToolByName(self, 'bika_setup_catalog')
47
        pairs = []
48
        objects = []
49
        # All Doctors
50
        for contact in pc(portal_type='Doctor',
51
                          is_active=True,
52
                          sort_on='sortable_title'):
53
            pairs.append((contact.UID, contact.Title))
54
            if not dl:
55
                objects.append(contact.getObject())
56
        # All LabContacts
57
        for contact in bsc(portal_type='LabContact',
58
                           is_active=True,
59
                           sort_on='sortable_title'):
60
            pairs.append((contact.UID, contact.Title))
61
            if not dl:
62
                objects.append(contact.getObject())
63
        return dl and DisplayList(pairs) or objects
64
65
    def getCCs(self):
66
        """Return a JSON value, containing all Contacts and their default CCs.
67
           This function is used to set form values for javascript.
68
        """
69
        items = []
70
        for contact in self.getContacts(dl=False):
71
            item = {'uid': contact.UID(), 'title': contact.Title()}
72
            ccs = []
73
            if hasattr(contact, 'getCCContact'):
74
                for cc in contact.getCCContact():
75
                    if api.is_active(cc):
76
                        ccs.append({'title': cc.Title(),
77
                                    'uid': cc.UID(), })
78
            item['ccs_json'] = json.dumps(ccs)
79
            item['ccs'] = ccs
80
            items.append(item)
81
        items.sort(lambda x, y: cmp(x['title'].lower(), y['title'].lower()))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable cmp does not seem to be defined.
Loading history...
82
        return items
83
84
schemata.finalizeATCTSchema(schema, folderish=True, moveDiscussion=False)
85
86
registerType(Doctors, PROJECTNAME)
87