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 AccessControl import ClassSecurityInfo |
9
|
|
|
|
10
|
|
|
from DateTime import DateTime |
11
|
|
|
from Products.Archetypes.public import * |
12
|
|
|
from Products.CMFCore.utils import getToolByName |
13
|
|
|
from bika.lims.config import PROJECTNAME, STD_TYPES |
14
|
|
|
from bika.lims.content.abstractanalysis import AbstractAnalysis |
15
|
|
|
from bika.lims.content.abstractanalysis import schema |
16
|
|
|
from bika.lims.content.analysisspec import ResultsRangeDict |
17
|
|
|
from bika.lims.interfaces import IReferenceAnalysis |
18
|
|
|
from bika.lims.subscribers import skip |
19
|
|
|
from bika.lims.workflow import doActionFor |
20
|
|
|
from plone.app.blob.field import BlobField |
21
|
|
|
from zope.interface import implements |
22
|
|
|
|
23
|
|
|
schema = schema.copy() + Schema(( |
|
|
|
|
24
|
|
|
StringField( |
|
|
|
|
25
|
|
|
'ReferenceType', |
26
|
|
|
vocabulary=STD_TYPES, |
27
|
|
|
), |
28
|
|
|
BlobField( |
29
|
|
|
'RetractedAnalysesPdfReport', |
30
|
|
|
), |
31
|
|
|
StringField( |
|
|
|
|
32
|
|
|
'ReferenceAnalysesGroupID', |
33
|
|
|
) |
34
|
|
|
)) |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
class ReferenceAnalysis(AbstractAnalysis): |
38
|
|
|
implements(IReferenceAnalysis) |
39
|
|
|
security = ClassSecurityInfo() |
40
|
|
|
displayContentsTab = False |
41
|
|
|
schema = schema |
42
|
|
|
|
43
|
|
|
@security.public |
44
|
|
|
def getSupplier(self): |
45
|
|
|
""" Returns the Supplier of the ReferenceSample this ReferenceAnalysis |
46
|
|
|
refers to |
47
|
|
|
""" |
48
|
|
|
sample = self.getSample() |
49
|
|
|
if sample: |
50
|
|
|
return sample.aq_parent |
51
|
|
|
|
52
|
|
|
@security.public |
53
|
|
|
def getSupplierUID(self): |
54
|
|
|
supplier = self.getSupplier() |
55
|
|
|
if supplier: |
56
|
|
|
return supplier.UID() |
57
|
|
|
|
58
|
|
|
@security.public |
59
|
|
|
def getSample(self): |
60
|
|
|
""" Returns the ReferenceSample this ReferenceAnalysis refers to |
61
|
|
|
Delegates to self.aq_parent |
62
|
|
|
""" |
63
|
|
|
return self.aq_parent |
64
|
|
|
|
65
|
|
|
@security.public |
66
|
|
|
def getDueDate(self): |
67
|
|
|
"""Used to populate getDueDate index and metadata. |
68
|
|
|
This very simply returns the expiry date of the parent reference sample. |
69
|
|
|
""" |
70
|
|
|
sample = self.getSample() |
71
|
|
|
if sample: |
72
|
|
|
return sample.getExpiryDate() |
73
|
|
|
|
74
|
|
|
@security.public |
75
|
|
|
def setResult(self, value): |
76
|
|
|
# Always update ResultCapture date when this field is modified |
77
|
|
|
self.setResultCaptureDate(DateTime()) |
78
|
|
|
# Ensure result integrity regards to None, empty and 0 values |
79
|
|
|
val = str('' if not value and value != 0 else value).strip() |
80
|
|
|
self.getField('Result').set(self, val) |
81
|
|
|
|
82
|
|
|
def getReferenceResults(self): |
83
|
|
|
""" |
84
|
|
|
It is used as metacolumn |
85
|
|
|
""" |
86
|
|
|
return self.getSample().getReferenceResults() |
87
|
|
|
|
88
|
|
|
@security.public |
89
|
|
|
def getResultsRange(self): |
90
|
|
|
"""Returns the valid result range for this reference analysis based on |
91
|
|
|
the results ranges defined in the Reference Sample from which this |
92
|
|
|
analysis has been created. |
93
|
|
|
|
94
|
|
|
A Reference Analysis (control or blank) will be considered out of range |
95
|
|
|
if its results does not match with the result defined on its parent |
96
|
|
|
Reference Sample, with the % error as the margin of error, that will be |
97
|
|
|
used to set the range's min and max values |
98
|
|
|
:return: A dictionary with the keys min and max |
99
|
|
|
:rtype: dict |
100
|
|
|
""" |
101
|
|
|
specs = ResultsRangeDict(result="") |
102
|
|
|
sample = self.getSample() |
103
|
|
|
if not sample: |
104
|
|
|
return specs |
105
|
|
|
|
106
|
|
|
service_uid = self.getServiceUID() |
107
|
|
|
sample_range = sample.getResultsRangeDict() |
108
|
|
|
return sample_range.get(service_uid, specs) |
109
|
|
|
|
110
|
|
|
def getInstrumentUID(self): |
111
|
|
|
""" |
112
|
|
|
It is a metacolumn. |
113
|
|
|
Returns the same value as the service. |
114
|
|
|
""" |
115
|
|
|
instrument = self.getInstrument() |
116
|
|
|
if not instrument: |
117
|
|
|
return None |
118
|
|
|
return instrument.UID() |
119
|
|
|
|
120
|
|
|
def getServiceDefaultInstrumentUID(self): |
121
|
|
|
""" |
122
|
|
|
It is used as a metacolumn. |
123
|
|
|
Returns the default service's instrument UID |
124
|
|
|
""" |
125
|
|
|
ins = self.getInstrument() |
126
|
|
|
if ins: |
127
|
|
|
return ins.UID() |
128
|
|
|
return '' |
129
|
|
|
|
130
|
|
|
def getServiceDefaultInstrumentTitle(self): |
131
|
|
|
""" |
132
|
|
|
It is used as a metacolumn. |
133
|
|
|
Returns the default service's instrument UID |
134
|
|
|
""" |
135
|
|
|
ins = self.getInstrument() |
136
|
|
|
if ins: |
137
|
|
|
return ins.Title() |
138
|
|
|
return '' |
139
|
|
|
|
140
|
|
|
def getServiceDefaultInstrumentURL(self): |
141
|
|
|
""" |
142
|
|
|
It is used as a metacolumn. |
143
|
|
|
Returns the default service's instrument UID |
144
|
|
|
""" |
145
|
|
|
ins = self.getInstrument() |
146
|
|
|
if ins: |
147
|
|
|
return ins.absolute_url_path() |
148
|
|
|
return '' |
149
|
|
|
|
150
|
|
|
def getDependencies(self, retracted=False): |
151
|
|
|
"""It doesn't make sense for a ReferenceAnalysis to use |
152
|
|
|
dependencies, since them are only used in calculations for |
153
|
|
|
routine analyses |
154
|
|
|
""" |
155
|
|
|
return [] |
156
|
|
|
|
157
|
|
|
def getDependents(self, retracted=False): |
158
|
|
|
"""It doesn't make sense for a ReferenceAnalysis to use |
159
|
|
|
dependents, since them are only used in calculations for |
160
|
|
|
routine analyses |
161
|
|
|
""" |
162
|
|
|
return [] |
163
|
|
|
|
164
|
|
|
def workflow_script_attach(self): |
165
|
|
|
if skip(self, "attach"): |
166
|
|
|
return |
167
|
|
|
workflow = getToolByName(self, 'portal_workflow') |
168
|
|
|
# If all analyses on the worksheet have been attached, |
169
|
|
|
# then attach the worksheet. |
170
|
|
|
ws = self.getWorksheet() |
171
|
|
|
ws_state = workflow.getInfoFor(ws, 'review_state') |
172
|
|
View Code Duplication |
if ws_state == 'attachment_due' and not skip(ws, "attach", peek=True): |
|
|
|
|
173
|
|
|
can_attach = True |
174
|
|
|
for a in ws.getAnalyses(): |
175
|
|
|
if workflow.getInfoFor(a, 'review_state') in \ |
176
|
|
|
('sample_due', 'sample_received', 'attachment_due', |
177
|
|
|
'assigned',): |
178
|
|
|
can_attach = False |
179
|
|
|
break |
180
|
|
|
if can_attach: |
181
|
|
|
workflow.doActionFor(ws, 'attach') |
182
|
|
|
self.reindexObject() |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
registerType(ReferenceAnalysis, PROJECTNAME) |
|
|
|
|
186
|
|
|
|