Passed
Push — master ( 9e6aa2...b9e514 )
by Ramon
07:36 queued 02:57
created

ReferenceAnalysis.getInstrumentUID()   A

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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