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