Passed
Push — 2.x ( 2af15a...bf1acf )
by Ramon
07:06
created

senaite.core.catalog.indexer.analysisspec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 17
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A sampletype_title() 0 11 2
A sampletype_uid() 0 11 2
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-2024 by it's authors.
19
# Some rights reserved, see README and LICENSE.
20
21
from bika.lims import api
22
from bika.lims.interfaces import IAnalysisSpec
23
from plone.indexer import indexer
24
from senaite.core.interfaces import ISetupCatalog
25
26
27
@indexer(IAnalysisSpec, ISetupCatalog)
28
def sampletype_title(instance):
29
    """Returns a list containing the title of the sample type assigned to this
30
    instance, as defined by the AnalysisSpec type. The function returns a list
31
    because the index used is a KeywordIndex, which supports searching for
32
    missing values in cases where the sample type is not a mandatory field.
33
    """
34
    sample_type = instance.getSampleType()
35
    if not sample_type:
36
        return [""]
37
    return [api.get_title(sample_type)]
38
39
40
@indexer(IAnalysisSpec, ISetupCatalog)
41
def sampletype_uid(instance):
42
    """Returns a list containing the UID of the sample type assigned to this
43
    instance, as defined by the AnalysisSpec type. The function returns a list
44
    because the index used is a KeywordIndex, which supports searching for
45
    missing values in cases where the sample type is not a mandatory field.
46
    """
47
    uid = instance.getRawSampleType()
48
    if not uid:
49
        return [""]
50
    return [uid]
51