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.lims.adapters.widgetvisibility import SenaiteATWidgetVisibility |
22
|
|
|
from bika.lims.interfaces import IBatch |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
class PatientFieldsVisibility(SenaiteATWidgetVisibility): |
26
|
|
|
""" |
27
|
|
|
Handles "Batch", "Patient" and "ClientPatientID" fields visibility. |
28
|
|
|
They are not editable, regardless of the current state of the Sample, except |
29
|
|
|
when displayed in AR Add view. The reason is that all these fields, together |
30
|
|
|
with Client field, are strongly related. |
31
|
|
|
""" |
32
|
|
|
def __init__(self, context): |
33
|
|
|
super(PatientFieldsVisibility, self).__init__( |
34
|
|
|
context=context, sort=10, |
35
|
|
|
field_names=["Batch", "Patient", "ClientPatientID", ]) |
36
|
|
|
|
37
|
|
|
def isVisible(self, field, mode="view", default="visible"): |
38
|
|
|
if mode == "edit": |
39
|
|
|
return "invisible" |
40
|
|
|
|
41
|
|
|
elif mode == "add": |
42
|
|
|
container = self.context.aq_parent |
43
|
|
|
|
44
|
|
|
# Do not display the Patient field if the Sample is being created |
45
|
|
|
# inside a Batch and the latter has a Patient assigned. In such |
46
|
|
|
# case, the patient assigned to the Batch will be used: |
47
|
|
|
# See: adapters.addsample.PatientDefaultFieldValue |
48
|
|
|
if IBatch.providedBy(container): |
49
|
|
|
patient = container.getField("Patient").get(container) |
50
|
|
|
if patient: |
51
|
|
|
return "hidden" |
52
|
|
|
|
53
|
|
|
return default |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
class DoctorFieldVisibility(SenaiteATWidgetVisibility): |
57
|
|
|
"""Handles Doctor field visibility in Sample add form and view |
58
|
|
|
""" |
59
|
|
|
|
60
|
|
|
def __init__(self, context): |
61
|
|
|
super(DoctorFieldVisibility, self).__init__( |
62
|
|
|
context=context, sort=10, field_names=["Doctor"]) |
63
|
|
|
|
64
|
|
|
def isVisible(self, field, mode="view", default="visible"): |
65
|
|
|
if mode == "add": |
66
|
|
|
container = self.context.aq_parent |
67
|
|
|
|
68
|
|
|
# Do not display the doctor field if the Sample is being created |
69
|
|
|
# inside a Batch and the latter has a Doctor assigned. In such |
70
|
|
|
# case, the batch assigned to the Batch will be used: |
71
|
|
|
# See: adapters.addsample.DoctorDefaultFieldValue |
72
|
|
|
if IBatch.providedBy(container): |
73
|
|
|
doctor = container.getField("Doctor").get(container) |
74
|
|
|
if doctor: |
75
|
|
|
return "hidden" |
76
|
|
|
|
77
|
|
|
return default |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
|