|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# |
|
3
|
|
|
# This file is part of SENAITE.CORE. |
|
4
|
|
|
# |
|
5
|
|
|
# SENAITE.CORE is free software: you can redistribute it and/or modify it under |
|
6
|
|
|
# the terms of the GNU General Public License as published by the Free Software |
|
7
|
|
|
# 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 collections import OrderedDict |
|
22
|
|
|
|
|
23
|
|
|
from bika.lims import api |
|
24
|
|
|
from bika.lims import bikaMessageFactory as _ |
|
25
|
|
|
from bika.lims.browser.analyses.view import AnalysesView |
|
26
|
|
|
from bika.lims.config import QCANALYSIS_TYPES |
|
27
|
|
|
from bika.lims.interfaces import IDuplicateAnalysis |
|
28
|
|
|
from bika.lims.utils import get_image |
|
29
|
|
|
from bika.lims.utils import get_link |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
class QCAnalysesView(AnalysesView): |
|
33
|
|
|
"""Renders the table of QC Analyses performed related to an AR. |
|
34
|
|
|
|
|
35
|
|
|
Different AR analyses can be achieved inside different worksheets, and each |
|
36
|
|
|
one of these can have different QC Analyses. This table only lists the QC |
|
37
|
|
|
Analyses performed in those worksheets in which the current AR has, at |
|
38
|
|
|
least, one analysis assigned and if the QC analysis services match with |
|
39
|
|
|
those from the current AR. |
|
40
|
|
|
""" |
|
41
|
|
|
|
|
42
|
|
|
def __init__(self, context, request, **kwargs): |
|
43
|
|
|
super(QCAnalysesView, self).__init__(context, request, **kwargs) |
|
44
|
|
|
|
|
45
|
|
|
icon_path = "/++resource++bika.lims.images/referencesample.png" |
|
46
|
|
|
self.icon = "{}{}".format(self.portal_url, icon_path) |
|
47
|
|
|
|
|
48
|
|
|
# Add Worksheet and QC Sample ID columns |
|
49
|
|
|
new_columns = OrderedDict(( |
|
50
|
|
|
("Worksheet", { |
|
51
|
|
|
"title": _("Worksheet"), |
|
52
|
|
|
"sortable": True, |
|
53
|
|
|
}), |
|
54
|
|
|
("getReferenceAnalysesGroupID", { |
|
55
|
|
|
"title": _('QC Sample ID'), |
|
56
|
|
|
"sortable": False, |
|
57
|
|
|
}), |
|
58
|
|
|
("Parent", { |
|
59
|
|
|
"title": _("Source"), |
|
60
|
|
|
"sortable": False, |
|
61
|
|
|
}) |
|
62
|
|
|
)) |
|
63
|
|
|
self.columns.update(new_columns) |
|
64
|
|
|
|
|
65
|
|
|
# Remove unnecessary columns |
|
66
|
|
|
if "Hidden" in self.columns: |
|
67
|
|
|
del(self.columns["Hidden"]) |
|
68
|
|
|
|
|
69
|
|
|
# Remove filters (Valid, Invalid, All) |
|
70
|
|
|
self.review_states = [self.review_states[0]] |
|
71
|
|
|
|
|
72
|
|
|
# Apply the columns to all review_states |
|
73
|
|
|
for review_state in self.review_states: |
|
74
|
|
|
review_state.update({"columns": self.columns.keys()}) |
|
75
|
|
|
|
|
76
|
|
|
def update(self): |
|
77
|
|
|
"""Update hook |
|
78
|
|
|
""" |
|
79
|
|
|
super(AnalysesView, self).update() |
|
80
|
|
|
# Update the query with the QC Analyses uids |
|
81
|
|
|
qc_uids = map(api.get_uid, self.context.getQCAnalyses()) |
|
82
|
|
|
self.contentFilter.update({ |
|
83
|
|
|
"UID": qc_uids, |
|
84
|
|
|
"portal_type": ["DuplicateAnalysis", "ReferenceAnalysis"], |
|
85
|
|
|
"sort_on": "sortable_title" |
|
86
|
|
|
}) |
|
87
|
|
|
|
|
88
|
|
|
def is_analysis_edition_allowed(self, analysis_brain): |
|
89
|
|
|
"""Overwrite this method to ensure the table is recognized as readonly |
|
90
|
|
|
|
|
91
|
|
|
XXX: why is the super method not recognizing `self.allow_edit`? |
|
92
|
|
|
""" |
|
93
|
|
|
return False |
|
94
|
|
|
|
|
95
|
|
|
def folderitem(self, obj, item, index): |
|
96
|
|
|
item = super(QCAnalysesView, self).folderitem(obj, item, index) |
|
97
|
|
|
|
|
98
|
|
|
obj = self.get_object(obj) |
|
99
|
|
|
|
|
100
|
|
|
# Fill Worksheet cell |
|
101
|
|
|
worksheet = obj.getWorksheet() |
|
102
|
|
|
if not worksheet: |
|
103
|
|
|
return item |
|
104
|
|
|
|
|
105
|
|
|
# Fill the Worksheet cell |
|
106
|
|
|
ws_id = api.get_id(worksheet) |
|
107
|
|
|
ws_url = api.get_url(worksheet) |
|
108
|
|
|
item["replace"]["Worksheet"] = get_link(ws_url, value=ws_id) |
|
109
|
|
|
|
|
110
|
|
|
if IDuplicateAnalysis.providedBy(obj): |
|
111
|
|
|
an_type = "d" |
|
112
|
|
|
img_name = "duplicate.png" |
|
113
|
|
|
parent = obj.getRequest() |
|
114
|
|
|
else: |
|
115
|
|
|
an_type = obj.getReferenceType() |
|
116
|
|
|
img_name = an_type == "c" and "control.png" or "blank.png" |
|
117
|
|
|
parent = obj.aq_parent |
|
118
|
|
|
|
|
119
|
|
|
# Render the image |
|
120
|
|
|
an_type = QCANALYSIS_TYPES.getValue(an_type) |
|
121
|
|
|
item['before']['Service'] = get_image(img_name, title=an_type) |
|
122
|
|
|
|
|
123
|
|
|
# Fill the Parent cell |
|
124
|
|
|
parent_url = api.get_url(parent) |
|
125
|
|
|
parent_id = api.get_id(parent) |
|
126
|
|
|
item["replace"]["Parent"] = get_link(parent_url, value=parent_id) |
|
127
|
|
|
|
|
128
|
|
|
return item |
|
129
|
|
|
|