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

Lookup for dependent analysis in partitions #1871

Merged
merged 4 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.0.1 (unreleased)
------------------

- #1871 Allow calculations to rely on results of tests in subsamples (partitiones)
- #1864 Added UID reference field/widget for Dexterity Contents
- #1867 Fix error when invalidating samples with copies of analyses
- #1865 Fix indexing of temporary objects resulting in orphan entries in catalog
Expand Down
9 changes: 7 additions & 2 deletions src/bika/lims/content/abstractroutineanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,13 @@ def is_dependent(analysis):
query = dict(UID=services, getKeyword=self.getKeyword())
services = api.search(query, "bika_setup_catalog")
return len(services) > 0

siblings = self.getSiblings(with_retests=with_retests)

request = self.getRequest()
if request.isPartition():
siblings = request.getParentAnalysisRequest().getAnalyses(full_objects=True)
else:
siblings = self.getSiblings(with_retests=with_retests)

dependents = filter(lambda sib: is_dependent(sib), siblings)
if not recursive:
return dependents
Expand Down
34 changes: 34 additions & 0 deletions src/senaite/core/tests/doctests/ARAnalysesFieldWithPartitions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ Create some basic objects for the test:
>>> Fe = api.create(setup.bika_analysisservices, "AnalysisService", title="Iron", Keyword="Fe", Price="10", Category=category.UID())
>>> Au = api.create(setup.bika_analysisservices, "AnalysisService", title="Gold", Keyword="Au", Price="20", Category=category.UID())
>>> Mg = api.create(setup.bika_analysisservices, "AnalysisService", title="Magnesium", Keyword="Mg", Price="20", Category=category.UID())
>>> Ca = api.create(setup.bika_analysisservices, "AnalysisService", title="Calcium", Keyword="Ca", Price="20", Category=category.UID())
>>> THCaCO3 = api.create(setup.bika_analysisservices, "AnalysisService", title="Calcium", Keyword="THCaCO3", Price="20", Category=category.UID())
>>> calc = api.create(setup.bika_calculations, "Calculation", title="Total Hardness")
>>> calc.setFormula("[Ca] + [Mg]")
>>> THCaCO3.setCalculation(calc)


Creation of a Sample with a Partition
Expand Down Expand Up @@ -330,3 +335,32 @@ partition, nothing will happen:
[<Analysis at /plone/clients/client-1/W-0001/Mg>]
>>> partition.objectValues("Analysis")
[<Analysis at /plone/clients/client-1/W-0001-P01/Cu>, <Analysis at /plone/clients/client-1/W-0001-P01/Fe>, <Analysis at /plone/clients/client-1/W-0001-P01/Au>]


Test calculation when dependant service assigned to a partition subsample:
..........................................................................

Create a Sample and receive:

>>> sample2 = new_sample([Ca, Mg, THCaCO3])

Create a Partition containing of the Sample, containing the analysis `Ca`:

>>> ca = get_analysis_from(sample2, Ca)
>>> partition2 = create_partition(sample, request, [ca])

Set result values to analysis (Ca, Mg)

>>> analyses = sample2.getAnalyses(full_objects=True)
>>> ca_analysis = filter(lambda an: an.getKeyword()=="Ca", analyses)[0]
>>> mg_analysis = filter(lambda an: an.getKeyword()=="Mg", analyses)[0]
>>> ca_analysis.setResult(10)
>>> mg_analysis.setResult(10)

Calculate dependant result and make sure it's correct:
>>> th_analysis = filter(lambda an: an.getKeyword()=="THCaCO3", analyses)[0]
>>> th_analysis.calculateResult()
True
>>> th_analysis.getResult()
'20.0'