|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# |
|
3
|
|
|
# This file is part of SENAITE.CORE |
|
4
|
|
|
# |
|
5
|
|
|
# Copyright 2018 by it's authors. |
|
6
|
|
|
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst. |
|
7
|
|
|
|
|
8
|
|
|
from bika.lims import api |
|
9
|
|
|
from bika.lims.browser import BrowserView |
|
10
|
|
|
from bika.lims.browser.header_table import HeaderTableView |
|
11
|
|
|
from bika.lims.permissions import EditFieldResults |
|
12
|
|
|
from bika.lims.permissions import EditResults |
|
13
|
|
|
from bika.lims.utils import check_permission |
|
14
|
|
|
from bika.lims.workflow import wasTransitionPerformed |
|
15
|
|
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
|
16
|
|
|
from resultsinterpretation import ARResultsInterpretationView |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
class AnalysisRequestViewView(BrowserView): |
|
20
|
|
|
"""Main AR View |
|
21
|
|
|
""" |
|
22
|
|
|
template = ViewPageTemplateFile("templates/analysisrequest_view.pt") |
|
23
|
|
|
|
|
24
|
|
|
def __init__(self, context, request): |
|
25
|
|
|
self.init__ = super( |
|
26
|
|
|
AnalysisRequestViewView, self).__init__(context, request) |
|
27
|
|
|
self.icon = "{}/{}".format( |
|
28
|
|
|
self.portal_url, |
|
29
|
|
|
"/++resource++bika.lims.images/analysisrequest_big.png", |
|
30
|
|
|
) |
|
31
|
|
|
|
|
32
|
|
|
def __call__(self): |
|
33
|
|
|
# If the analysis request has been received and hasn't been yet |
|
34
|
|
|
# verified yet, redirect the user to manage_results view, but only if |
|
35
|
|
|
# the user has privileges to Edit(Field)Results, cause otherwise she/he |
|
36
|
|
|
# will receive an InsufficientPrivileges error! |
|
37
|
|
|
if (self.request.PATH_TRANSLATED.endswith(self.context.id) and |
|
38
|
|
|
self.can_edit_results() and self.can_edit_field_results() and |
|
39
|
|
|
self.is_received() and not self.is_verified()): |
|
40
|
|
|
|
|
41
|
|
|
# Redirect to manage results view if not cancelled |
|
42
|
|
|
if not self.is_cancelled(): |
|
43
|
|
|
manage_results_url = "{}/{}".format( |
|
44
|
|
|
self.context.absolute_url(), "manage_results") |
|
45
|
|
|
return self.request.response.redirect(manage_results_url) |
|
46
|
|
|
|
|
47
|
|
|
# render header table |
|
48
|
|
|
self.header_table = HeaderTableView(self.context, self.request)() |
|
49
|
|
|
|
|
50
|
|
|
# Create the ResultsInterpretation by department view |
|
51
|
|
|
self.riview = ARResultsInterpretationView(self.context, self.request) |
|
52
|
|
|
|
|
53
|
|
|
return self.template() |
|
54
|
|
|
|
|
55
|
|
|
def render_analyses_table(self, table="lab"): |
|
56
|
|
|
"""Render Analyses Table |
|
57
|
|
|
""" |
|
58
|
|
|
if table not in ["lab", "field", "qc"]: |
|
59
|
|
|
raise KeyError("Table '{}' does not exist".format(table)) |
|
60
|
|
|
view_name = "table_{}_analyses".format(table) |
|
61
|
|
|
view = api.get_view( |
|
62
|
|
|
view_name, context=self.context, request=self.request) |
|
63
|
|
|
# Call listing hooks |
|
64
|
|
|
view.update() |
|
65
|
|
|
view.before_render() |
|
66
|
|
|
return view.ajax_contents_table() |
|
67
|
|
|
|
|
68
|
|
|
def has_lab_analyses(self): |
|
69
|
|
|
"""Check if the AR contains lab analyses |
|
70
|
|
|
""" |
|
71
|
|
|
# Negative performance impact - add a Metadata column |
|
72
|
|
|
analyses = self.context.getAnalyses(getPointOfCapture="lab") |
|
73
|
|
|
return len(analyses) > 0 |
|
74
|
|
|
|
|
75
|
|
|
def has_field_analyses(self): |
|
76
|
|
|
"""Check if the AR contains field analyses |
|
77
|
|
|
""" |
|
78
|
|
|
# Negative performance impact - add a Metadata column |
|
79
|
|
|
analyses = self.context.getAnalyses(getPointOfCapture="field") |
|
80
|
|
|
return len(analyses) > 0 |
|
81
|
|
|
|
|
82
|
|
|
def has_qc_analyses(self): |
|
83
|
|
|
"""Check if the AR contains field analyses |
|
84
|
|
|
""" |
|
85
|
|
|
# Negative performance impact - add a Metadata column |
|
86
|
|
|
analyses = self.context.getQCAnalyses() |
|
87
|
|
|
return len(analyses) > 0 |
|
88
|
|
|
|
|
89
|
|
|
def can_edit_results(self): |
|
90
|
|
|
"""Checks if the current user has the permission "EditResults" |
|
91
|
|
|
""" |
|
92
|
|
|
return check_permission(EditResults, self.context) |
|
93
|
|
|
|
|
94
|
|
|
def can_edit_field_results(self): |
|
95
|
|
|
"""Checks if the current user has the permission "EditFieldResults" |
|
96
|
|
|
""" |
|
97
|
|
|
return check_permission(EditFieldResults, self.context) |
|
98
|
|
|
|
|
99
|
|
|
def is_received(self): |
|
100
|
|
|
"""Checks if the AR is received |
|
101
|
|
|
""" |
|
102
|
|
|
return wasTransitionPerformed(self.context, "receive") |
|
103
|
|
|
|
|
104
|
|
|
def is_verified(self): |
|
105
|
|
|
"""Checks if the AR is verified |
|
106
|
|
|
""" |
|
107
|
|
|
return wasTransitionPerformed(self.context, "verify") |
|
108
|
|
|
|
|
109
|
|
|
def is_cancelled(self): |
|
110
|
|
|
"""Checks if the AR is cancelled |
|
111
|
|
|
""" |
|
112
|
|
|
return api.get_cancellation_status(self.context) == "cancelled" |
|
113
|
|
|
|
|
114
|
|
|
def is_hazardous(self): |
|
115
|
|
|
"""Checks if the AR is hazardous |
|
116
|
|
|
""" |
|
117
|
|
|
sample = self.context.getSample() |
|
118
|
|
|
sample_type = sample.getSampleType() |
|
119
|
|
|
return sample_type.getHazardous() |
|
120
|
|
|
|
|
121
|
|
|
def is_retest(self): |
|
122
|
|
|
"""Checks if the AR is a retest |
|
123
|
|
|
""" |
|
124
|
|
|
return self.context.getRetest() |
|
125
|
|
|
|
|
126
|
|
|
def exclude_invoice(self): |
|
127
|
|
|
"""True if the invoice should be excluded |
|
128
|
|
|
""" |
|
129
|
|
|
|
|
130
|
|
|
def show_categories(self): |
|
131
|
|
|
"""Check the setup if analysis services should be categorized |
|
132
|
|
|
""" |
|
133
|
|
|
setup = api.get_setup() |
|
134
|
|
|
return setup.getCategoriseAnalysisServices() |
|
135
|
|
|
|
|
136
|
|
|
|