Skip to content

Commit

Permalink
Update ranges when sample is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
xispa committed Jan 24, 2024
1 parent ec106d1 commit 6de0216
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
7 changes: 4 additions & 3 deletions src/senaite/patient/subscribers/analysisrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def update_results_ranges(sample):
of birth are updated
"""
# reset the result ranges so dynamic specs are grabbed again
for analysis in sample.getAnalyses(full_objects=True):
rr = analysis.getResultsRange()
analysis.setResultsRange(rr)
spec = sample.getSpecification()
if spec:
ranges = spec.getResultsRange()
sample.setResultsRange(ranges, recursive=False)
2 changes: 1 addition & 1 deletion src/senaite/patient/subscribers/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!-- Sample modified -->
<subscriber
for="bika.lims.interfaces.IAnalysisRequest
Products.Archetypes.interfaces.IObjectEditedEvent"
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".analysisrequest.on_object_edited"
/>

Expand Down
37 changes: 14 additions & 23 deletions src/senaite/patient/tests/doctests/DynamicResultRanges.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,19 @@ Test Setup

Needed imports:

>>> from DateTime import DateTime
>>> from six import StringIO
>>> import csv
>>> from bika.lims import api
>>> from bika.lims.utils.analysisrequest import create_analysisrequest
>>> from bika.lims.workflow import doActionFor as do_action_for
>>> from DateTime import DateTime
>>> from openpyxl import Workbook
>>> from openpyxl.writer.excel import save_virtual_workbook
>>> from plone.app.testing import TEST_USER_ID
>>> from plone.app.testing import setRoles
>>> from plone.namedfile.file import NamedBlobFile
>>> from senaite.patient.api import get_birth_date
>>> import csv
>>> from six import StringIO
>>> from zope.lifecycleevent import modified

Functional Helpers:

Expand All @@ -101,11 +102,9 @@ Functional Helpers:
... rr = ht.getResultsRange()
... return rr["min"], rr["max"]

>>> def reset_specification(sample):
... # TODO Reset specification when sample is updated
... specification = sample.getSpecification()
... sample.setSpecification(None)
... sample.setSpecification(specification)
>>> def edit(sample, **kwargs):
... api.edit(sample, **kwargs)
... modified(sample)

>>> def new_sample(services, specification=None):
... values = {
Expand Down Expand Up @@ -182,33 +181,29 @@ Since there is no patient assigned, the system returns the generic range:
Make the sample belong to a newborn:

>>> dob = get_birth_date("0d", on_date=sampled)
>>> sample.setDateOfBirth(dob)
>>> reset_specification(sample)
>>> edit(sample, DateOfBirth=dob)
>>> get_range(ht)
('45', '67')

Make the sample belong to a baby (0 to 12 months old):

>>> dob = get_birth_date("5m", on_date=sampled)
>>> sample.setDateOfBirth(dob)
>>> reset_specification(sample)
>>> edit(sample, DateOfBirth=dob)
>>> get_range(ht)
('29', '41')

Make the sample belong to a toddler (1 to 3 years old). Note min age is
inclusive, while max age is exclusive:

>>> dob = get_birth_date("2y", on_date=sampled)
>>> sample.setDateOfBirth(dob)
>>> reset_specification(sample)
>>> edit(sample, DateOfBirth=dob)
>>> get_range(ht)
('34', '40')

Make the sample belong to a toddler (12 to 18 years old):

>>> dob = get_birth_date("13y", on_date=sampled)
>>> sample.setDateOfBirth(dob)
>>> reset_specification(sample)
>>> edit(sample, DateOfBirth=dob)

Returns the generic range because sex is not specified:

Expand All @@ -217,21 +212,17 @@ Returns the generic range because sex is not specified:

But returns the valid range if sex is defined:

>>> sample.setSex("m")
>>> reset_specification(sample)
>>> edit(sample, Sex="m")
>>> get_range(ht)
('36', '51')

>>> sample.setSex("f")
>>> reset_specification(sample)
>>> edit(sample, Sex="f")
>>> get_range(ht)
('33', '51')

Make the sample belong to an adult (> 18 years old):

>>> dob = get_birth_date("18y", on_date=sampled)
>>> sample.setDateOfBirth(dob)
>>> sample.setSex("m")
>>> reset_specification(sample)
>>> edit(sample, DateOfBirth=dob, Sex="m")
>>> get_range(ht)
('39', '54')

0 comments on commit 6de0216

Please sign in to comment.