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 bika.health.interfaces import IPatient |
22
|
|
|
from bika.lims.adapters.widgetvisibility import SenaiteATWidgetVisibility |
23
|
|
|
from bika.lims.interfaces import IClient |
24
|
|
|
|
25
|
|
|
|
26
|
|
View Code Duplication |
class ClientFieldVisibility(SenaiteATWidgetVisibility): |
|
|
|
|
27
|
|
|
"""Handles the Client field visibility in Batch context |
28
|
|
|
""" |
29
|
|
|
|
30
|
|
|
def __init__(self, context): |
31
|
|
|
super(ClientFieldVisibility, self).__init__( |
32
|
|
|
context=context, field_names=["Client"]) |
33
|
|
|
|
34
|
|
|
def isVisible(self, field, mode="view", default="visible"): |
35
|
|
|
"""Renders the Client field as hidden if the current mode is "edit" and |
36
|
|
|
the container is either a Patient or a Client |
37
|
|
|
""" |
38
|
|
|
if mode == "edit": |
39
|
|
|
container = self.context.aq_parent |
40
|
|
|
|
41
|
|
|
# If the Batch is created or edited inside either Client or Patient, |
42
|
|
|
# make Client field to be rendered, but hidden to prevent the error |
43
|
|
|
# message "Patient is required, please correct". |
44
|
|
|
if IPatient.providedBy(container): |
45
|
|
|
return "readonly" |
46
|
|
|
|
47
|
|
|
elif IClient.providedBy(container): |
48
|
|
|
return "readonly" |
49
|
|
|
|
50
|
|
|
return default |
51
|
|
|
|
52
|
|
|
|
53
|
|
View Code Duplication |
class PatientFieldsVisibility(SenaiteATWidgetVisibility): |
|
|
|
|
54
|
|
|
"""Handles the visibility of Patient and ClientPatientID fields |
55
|
|
|
""" |
56
|
|
|
|
57
|
|
|
def __init__(self, context): |
58
|
|
|
super(PatientFieldsVisibility, self).__init__( |
59
|
|
|
context=context, sort=10, field_names=["Patient", "ClientPatientID"]) |
60
|
|
|
|
61
|
|
|
def isVisible(self, field, mode="view", default="visible"): |
62
|
|
|
"""Renders Patient and ClientPatientID fields as hidden if the current |
63
|
|
|
mode is "edit" and the the container is a Patient or if the Batch has |
64
|
|
|
a Patient already assigned (do not allow the modification of Patient) |
65
|
|
|
""" |
66
|
|
|
if mode == "edit": |
67
|
|
|
container = self.context.aq_parent |
68
|
|
|
if IPatient.providedBy(container): |
69
|
|
|
return "readonly" |
70
|
|
|
|
71
|
|
|
# Do not allow the edition of Patient if assigned already |
72
|
|
|
patient = self.context.getField("Patient").get(self.context) |
73
|
|
|
if patient: |
74
|
|
|
return "readonly" |
75
|
|
|
|
76
|
|
|
return default |
77
|
|
|
|