ajaxGetDoctorInfo.__call__()   B
last analyzed

Complexity

Conditions 6

Size

Total Lines 33
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 33
rs 8.2266
c 0
b 0
f 0
cc 6
nop 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 Products.ZCTextIndex.ParseTree import ParseError
22
from bika.lims.browser import BrowserView
23
from Products.CMFCore.utils import getToolByName
24
import plone
25
import json
26
27
28
class ajaxGetDoctorInfo(BrowserView):
29
    """ Grab details of newly created doctor
30
    """
31
    def __call__(self):
32
        plone.protect.CheckAuthenticator(self.request)
33
        Fullname = self.request.get('Fullname', '')
34
        uid = self.request.get('UID', '')
35
        ret = {'id': '',
36
               'DoctorID': '',
37
               'UID': '',
38
               'Fullname': ''}
39
40
        bpc = getToolByName(self.context, 'portal_catalog')
41
        proxies = None
42
        if uid:
43
            try:
44
                proxies = bpc(UID=uid)
45
            except ParseError:
46
                pass
47
        elif Fullname:
48
            try:
49
                proxies = bpc(Title=Fullname,
50
                              sort_on='created',
51
                              sort_order='reverse')
52
            except ParseError:
53
                pass
54
55
        if not proxies:
56
            return json.dumps(ret)
57
58
        doctor = proxies[0].getObject()
59
        ret = {'DoctorID': doctor.getDoctorID(),
60
               'id': doctor.id,
61
               'UID': doctor.UID(),
62
               'Fullname': doctor.Title()}
63
        return json.dumps(ret)
64