forked from bikalims/bika.lims
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathabstractroutineanalysis.py
271 lines (238 loc) · 7.83 KB
/
abstractroutineanalysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# -*- coding: utf-8 -*-
# This file is part of Bika LIMS
#
# Copyright 2011-2016 by it's authors.
# Some rights reserved. See LICENSE.txt, AUTHORS.txt.
from AccessControl import ClassSecurityInfo
from Products.Archetypes.Field import BooleanField, FixedPointField, \
StringField
from Products.Archetypes.Schema import Schema
from bika.lims import bikaMessageFactory as _, logger
from bika.lims.browser.fields import UIDReferenceField
from bika.lims.browser.widgets import DecimalWidget
from bika.lims.content.abstractanalysis import AbstractAnalysis
from bika.lims.content.abstractanalysis import schema
from bika.lims.interfaces import IAnalysis, IRoutineAnalysis, \
ISamplePrepWorkflow
from bika.lims.workflow import getTransitionDate
from plone.api.portal import get_tool
from zope.interface import implements
# The physical sample partition linked to the Analysis.
SamplePartition = UIDReferenceField(
'SamplePartition',
required=0,
allowed_types=('SamplePartition',)
)
# True if the analysis is created by a reflex rule
IsReflexAnalysis = BooleanField(
'IsReflexAnalysis',
default=False,
required=0
)
# This field contains the original analysis which was reflected
OriginalReflexedAnalysis = UIDReferenceField(
'OriginalReflexedAnalysis',
required=0,
allowed_types=('Analysis',)
)
# This field contains the analysis which has been reflected following
# a reflex rule
ReflexAnalysisOf = UIDReferenceField(
'ReflexAnalysisOf',
required=0,
allowed_types=('Analysis',)
)
# Which is the Reflex Rule action that has created this analysis
ReflexRuleAction = StringField(
'ReflexRuleAction',
required=0,
default=0
)
# Which is the 'local_id' inside the reflex rule
ReflexRuleLocalID = StringField(
'ReflexRuleLocalID',
required=0,
default=0
)
# Reflex rule triggered actions which the current analysis is responsible for.
# Separated by '|'
ReflexRuleActionsTriggered = StringField(
'ReflexRuleActionsTriggered',
required=0,
default=''
)
# The actual uncertainty for this analysis' result, populated when the result
# is submitted.
Uncertainty = FixedPointField(
'Uncertainty',
precision=10,
widget=DecimalWidget(
label=_("Uncertainty")
)
)
schema = schema.copy() + Schema((
IsReflexAnalysis,
OriginalReflexedAnalysis,
ReflexAnalysisOf,
ReflexRuleAction,
ReflexRuleActionsTriggered,
ReflexRuleLocalID,
SamplePartition,
Uncertainty,
))
class AbstractRoutineAnalysis(AbstractAnalysis):
implements(IAnalysis, IRoutineAnalysis, ISamplePrepWorkflow)
security = ClassSecurityInfo()
displayContentsTab = False
schema = schema
def getSample(self):
raise NotImplementedError("getSample is not implemented.")
@security.public
def getSampleUID(self):
"""Instances must implement getSample
"""
sample = self.getSample()
if sample:
return sample.UID()
@security.public
def getRequestID(self):
"""Used to populate catalog values.
Returns the ID of the parent analysis request.
"""
ar = self.aq_parent
if ar:
return ar.getId()
@security.public
def getClientTitle(self):
"""Used to populate catalog values.
Returns the Title of the client for this analysis' AR.
"""
client = self.aq_parent.getClient()
if client:
return client.Title()
@security.public
def getClientUID(self):
"""Used to populate catalog values.
Returns the UID of the client for this analysis' AR.
"""
client = self.aq_parent.getClient()
if client:
return client.UID()
@security.public
def getClientURL(self):
"""This method is used to populate catalog values
Returns the URL of the client for this analysis' AR.
"""
client = self.aq_parent.getClient()
if client:
return client.absolute_url_path()
@security.public
def getClientOrderNumber(self):
"""Used to populate catalog values.
Returns the ClientOrderNumber of the associated AR
"""
return self.aq_parent.getClientOrderNumber()
@security.public
def getDateReceived(self):
"""Used to populate catalog values.
Returns the date on which the "receive" transition was invoked on this
analysis' Sample.
"""
sample = self.getSample()
if sample:
getTransitionDate(self, 'receive')
@security.public
def getDateSampled(self):
"""Used to populate catalog values.
"""
sample = self.getSample()
if sample:
getTransitionDate(self, 'sample')
@security.public
def getSamplePartitionUID(self):
part = self.getSamplePartition()
if part:
return part.UID()
@security.public
def getSamplePointUID(self):
"""Used to populate catalog values.
"""
sample = self.getSample()
if sample:
samplepoint = sample.getSamplePoint()
if samplepoint:
return samplepoint.UID()
@security.public
def getSamplePartitionID(self):
"""Used to populate catalog values.
Returns the sample partition ID
"""
partition = self.getSamplePartition()
if partition:
return partition.getId()
return ''
@security.public
def getDueDate(self):
"""Used to populate getDueDate index and metadata.
This calculates the difference between the time that the sample
partition associated with this analysis was recieved, and the
maximum turnaround time.
"""
maxtime = self.getMaxTimeAllowed()
if not maxtime:
maxtime = get_tool('bika_setup').getDefaultTurnaroundTime()
max_days = float(maxtime.get('days', 0)) + (
(float(maxtime.get('hours', 0)) * 3600 +
float(maxtime.get('minutes', 0)) * 60)
/ 86400
)
part = self.getSamplePartition()
if part:
starttime = part.getDateReceived()
duetime = starttime + max_days if starttime else ''
return duetime
@security.public
def getAnalysisRequestTitle(self):
"""This is a catalog metadata column
"""
return self.aq_parent.Title()
@security.public
def getAnalysisRequestUID(self):
"""This method is used to populate catalog values
"""
return self.aq_parent.UID()
@security.public
def getAnalysisRequestURL(self):
"""This is a catalog metadata column
"""
return self.aq_parent.absolute_url_path()
@security.public
def getSampleTypeUID(self):
"""Used to populate catalog values.
"""
sample = self.getSample()
if sample:
sampletype = sample.getSampleType()
if sampletype:
return sampletype.UID()
@security.public
def setReflexAnalysisOf(self, analysis):
"""Sets the analysis that has been reflexed in order to create this
one, but if the analysis is the same as self, do nothing.
:param analysis: an analysis object or UID
"""
if not analysis or analysis.UID() == self.UID():
pass
else:
self.getField('ReflexAnalysisOf').set(self, analysis)
@security.public
def addReflexRuleActionsTriggered(self, text):
"""This function adds a new item to the string field
ReflexRuleActionsTriggered. From the field: Reflex rule triggered
actions from which the current analysis is responsible of. Separated
by '|'
:param text: is a str object with the format '<UID>.<rulename>' ->
'123354.1'
"""
old = self.getReflexRuleActionsTriggered()
self.setReflexRuleActionsTriggered(old + text + '|')