Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to enable/disable analysis categories for samples #2140

Merged
merged 9 commits into from
Sep 24, 2022
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
2.3.0 (unreleased)
------------------

- #2140 Allow to enable/disable analysis categories for samples
- #2137 Dynamic Workflow Menu
- #2139 Fix LabClerk cannot create partitions from received samples
- #2130 Catalog mapping for Samples and Analyses
Expand Down
13 changes: 13 additions & 0 deletions src/bika/lims/browser/analyses/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def __init__(self, context, request, **kwargs):
self.dmk = context.bika_setup.getResultsDecimalMark()
self.scinot = context.bika_setup.getScientificNotationResults()
self.categories = []
self.expand_all_categories = True

# each editable item needs it's own allow_edit
# which is a list of field names.
Expand Down Expand Up @@ -239,6 +240,8 @@ def update(self):
super(AnalysesView, self).update()
self.load_analysis_categories()
self.append_partition_filters()
if self.analysis_categories_enabled():
self.show_categories = True

def before_render(self):
"""Before render hook
Expand Down Expand Up @@ -269,6 +272,16 @@ def analysis_remarks_enabled(self):
"""
return self.context.bika_setup.getEnableAnalysisRemarks()

@viewcache.memoize
def analysis_categories_enabled(self):
"""Check if analyses should be grouped by category
"""
# setting applies only for samples
if not IAnalysisRequest.providedBy(self.context):
return False
setup = api.get_senaite_setup()
return setup.getCategorizeSampleAnalyses()

@viewcache.memoize
def has_permission(self, permission, obj=None):
"""Returns if the current user has rights for the permission passed in
Expand Down
28 changes: 28 additions & 0 deletions src/bika/lims/content/bikasetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,17 @@ def getCounterTypes(self, instance=None):
description=_("Group analysis services by category in the LIMS tables, helpful when the list is long")
),
),
BooleanField(
"CategorizeSampleAnalyses",
schemata="Analyses",
default=False,
widget=BooleanWidget(
label=_("label_bikasetup_categorizesampleanalyses",
default="Categorize sample analyses"),
description=_("description_bikasetup_categorizesampleanalyses",
"Group analyses by category for samples")
),
),
BooleanField(
'EnableARSpecs',
schemata="Analyses",
Expand Down Expand Up @@ -1065,5 +1076,22 @@ def setImmediateResultsEntry(self, value):
if setup:
setup.setImmediateResultsEntry(value)

def getCategorizeSampleAnalyses(self):
"""Get the value from the senaite setup
"""
setup = api.get_senaite_setup()
# setup is `None` during initial site content structure installation
if setup:
return setup.getCategorizeSampleAnalyses()
return False

def setCategorizeSampleAnalyses(self, value):
"""Set the value in the senaite setup
"""
setup = api.get_senaite_setup()
# setup is `None` during initial site content structure installation
if setup:
setup.setCategorizeSampleAnalyses(value)


registerType(BikaSetup, PROJECTNAME)
25 changes: 25 additions & 0 deletions src/senaite/core/content/senaitesetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ class ISetupSchema(model.Schema):
),
)

categorize_sample_analyses = schema.Bool(
title=_("title_senaitesetup_categorizesampleanalyses",
default=u"Categorize sample analyses"),
description=_(
"description_senaitesetup_categorizesampleanalyses",
default=u"Group analyses by category for samples"
),
default=False,
)

###
# Fieldsets
###
Expand All @@ -96,6 +106,7 @@ class ISetupSchema(model.Schema):
label=_("label_senaitesetup_fieldset_analyses", default=u"Analyses"),
fields=[
"immediate_results_entry",
"categorize_sample_analyses",
]
)

Expand Down Expand Up @@ -203,3 +214,17 @@ def setImmediateResultsEntry(self, value):
"""
mutator = self.mutator("immediate_results_entry")
return mutator(self, value)

@security.protected(permissions.View)
def getCategorizeSampleAnalyses(self):
"""Returns if analyses should be grouped by category for samples
"""
accessor = self.accessor("categorize_sample_analyses")
return accessor(self)

@security.protected(permissions.ModifyPortalContent)
def setCategorizeSampleAnalyses(self, value):
"""Enable/Disable grouping of analyses by category for samples
"""
mutator = self.mutator("categorize_sample_analyses")
return mutator(self, value)