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
|
|
|
from Products.Archetypes.interfaces import IBaseObject |
21
|
|
|
from plone.indexer import indexer |
22
|
|
|
|
23
|
|
|
from bika.lims import api |
24
|
|
|
from bika.lims.catalog.bikasetup_catalog import SETUP_CATALOG |
25
|
|
|
from bika.lims.catalog.indexers import generic_listing_searchable_text |
26
|
|
|
from bika.lims.interfaces import IAnalysisService |
27
|
|
|
from bika.lims.interfaces import IBikaSetupCatalog |
28
|
|
|
from bika.lims.interfaces import IHaveAnalysisCategory |
29
|
|
|
from bika.lims.interfaces import IHaveDepartment |
30
|
|
|
from bika.lims.interfaces import IHaveInstrument |
31
|
|
|
from bika.lims.interfaces import IHavePrice |
32
|
|
|
from bika.lims.interfaces import IInstrument |
33
|
|
|
from bika.lims.interfaces import ISampleTypeAwareMixin |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
@indexer(ISampleTypeAwareMixin, IBikaSetupCatalog) |
37
|
|
|
def sampletype_uid(instance): |
38
|
|
|
"""Returns the list of SampleType UIDs the instance is assigned to |
39
|
|
|
|
40
|
|
|
This is a KeywordIndex, so it will be indexed as a list, even if only one |
41
|
|
|
SampleType can be assigned to the instance. Moreover, if the instance has no |
42
|
|
|
SampleType assigned, it returns a tuple with a None value. This allows |
43
|
|
|
searches for `MissingValue` entries too. |
44
|
|
|
""" |
45
|
|
|
sample_type = instance.getSampleType() |
46
|
|
|
return to_keywords_list(sample_type, api.get_uid) |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
@indexer(ISampleTypeAwareMixin, IBikaSetupCatalog) |
50
|
|
|
def sampletype_title(instance): |
51
|
|
|
"""Returns a list of titles from SampleType the instance is assigned to |
52
|
|
|
|
53
|
|
|
If the instance has no sample type assigned, it returns a tuple with |
54
|
|
|
a None value. This allows searches for `MissingValue` entries too. |
55
|
|
|
""" |
56
|
|
|
sample_type = instance.getSampleType() |
57
|
|
|
return to_keywords_list(sample_type, api.get_title) |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
@indexer(IAnalysisService, IBikaSetupCatalog) |
61
|
|
|
def method_available_uid(instance): |
62
|
|
|
"""Returns a list of Method UIDs that are available for this instance |
63
|
|
|
|
64
|
|
|
If the instance (AnalysisService) has InstrumentEntryOfResults set to True, |
65
|
|
|
it returns the methods available from the instruments capable to perform the |
66
|
|
|
service, as well as the methods set manually to the analysis. Otherwise, it |
67
|
|
|
returns the methods assigned manually only. |
68
|
|
|
|
69
|
|
|
If the instance has no available method assigned, it returns a tuple with |
70
|
|
|
a None value. This allows searches for `MissingValue` entries too. |
71
|
|
|
""" |
72
|
|
|
return instance.getAvailableMethodUIDs() or (None, ) |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
@indexer(IHaveInstrument, IBikaSetupCatalog) |
76
|
|
|
def instrument_title(instance): |
77
|
|
|
"""Returns a list of titles from Instrument the instance is assigned to |
78
|
|
|
|
79
|
|
|
If the instance has no instrument assigned, it returns a tuple with |
80
|
|
|
a None value. This allows searches for `MissingValue` entries too. |
81
|
|
|
""" |
82
|
|
|
instrument = instance.getInstrument() |
83
|
|
|
return to_keywords_list(instrument, api.get_title) |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
@indexer(IHavePrice, IBikaSetupCatalog) |
87
|
|
|
def price(instance): |
88
|
|
|
"""Returns the price of the instance |
89
|
|
|
""" |
90
|
|
|
return instance.getPrice() |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
@indexer(IHavePrice, IBikaSetupCatalog) |
94
|
|
|
def price_total(instance): |
95
|
|
|
"""Returns the total price of the instance |
96
|
|
|
""" |
97
|
|
|
return instance.getTotalPrice() |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
@indexer(IInstrument, IBikaSetupCatalog) |
101
|
|
|
def instrumenttype_title(instance): |
102
|
|
|
"""Returns a list of Instrument Type titles the instance is assigned to |
103
|
|
|
""" |
104
|
|
|
instrument_type = instance.getInstrumentType() |
105
|
|
|
return to_keywords_list(instrument_type, api.get_title) |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
@indexer(IHaveDepartment, IBikaSetupCatalog) |
109
|
|
|
def department_uid(instance): |
110
|
|
|
"""Returns a list of Department UIDs the instance is assigned to |
111
|
|
|
""" |
112
|
|
|
department = instance.getDepartment() |
113
|
|
|
return to_keywords_list(department, api.get_uid) |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
@indexer(IHaveDepartment, IBikaSetupCatalog) |
117
|
|
|
def department_title(instance): |
118
|
|
|
"""Returns the title of the Department the instance is assigned to |
119
|
|
|
""" |
120
|
|
|
department = instance.getDepartment() |
121
|
|
|
return to_keywords_list(department, api.get_title) |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
@indexer(IAnalysisService, IBikaSetupCatalog) |
125
|
|
|
def point_of_capture(instance): |
126
|
|
|
"""Returns the point of capture of the instance |
127
|
|
|
""" |
128
|
|
|
return instance.getPointOfCapture() |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
@indexer(IBaseObject, IBikaSetupCatalog) |
132
|
|
|
def listing_searchable_text(instance): |
133
|
|
|
""" Retrieves all the values of metadata columns in the catalog for |
134
|
|
|
wildcard searches |
135
|
|
|
:return: all metadata values joined in a string |
136
|
|
|
""" |
137
|
|
|
exclude = ["getObjPositionInParent", ] |
138
|
|
|
|
139
|
|
|
# Additional non-metadata fields to include in the index |
140
|
|
|
include = ["getCalculation" |
141
|
|
|
"getDepartment", |
142
|
|
|
"getInstrument", |
143
|
|
|
"getInstrumentType", |
144
|
|
|
"getSamplePoint" |
145
|
|
|
"getSampleType", |
146
|
|
|
"getSupplier", |
147
|
|
|
"getManufacturer", ] |
148
|
|
|
|
149
|
|
|
return generic_listing_searchable_text(instance, SETUP_CATALOG, |
150
|
|
|
exclude_field_names=exclude, |
151
|
|
|
include_field_names=include) |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
@indexer(IHaveAnalysisCategory, IBikaSetupCatalog) |
155
|
|
|
def category_uid(instance): |
156
|
|
|
"""Returns a list of Category UIDs the instance is assigned to |
157
|
|
|
""" |
158
|
|
|
category = instance.getCategory() |
159
|
|
|
return to_keywords_list(category, api.get_uid) |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
def to_keywords_list(obj, func): |
163
|
|
|
if isinstance(obj, (list, tuple)): |
164
|
|
|
return map(func, obj) |
165
|
|
|
elif obj: |
166
|
|
|
return [func(obj)] |
167
|
|
|
return [None] |
168
|
|
|
|