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

Dynamic Analysis Specifications #1492

Merged
merged 29 commits into from
Jan 28, 2020
Merged

Dynamic Analysis Specifications #1492

merged 29 commits into from
Jan 28, 2020

Conversation

ramonski
Copy link
Contributor

@ramonski ramonski commented Dec 15, 2019

Description of the issue/feature this PR addresses

This PR adds the ability to link dynamic analysis specifications to the standard analysis specifications.

It is primarily meant to provide the basis for this requested functionality:
https://community.senaite.org/t/age-and-gender-based-specifications-in-senaite-health/102

Current behavior before PR

Analysis Specifications (Result Ranges) can be defined per Sample Type.
If different ranges are needed for Methods, Sample Points, Sample Conditions etc., different Analysis Specifications need to be created.

Desired behavior after PR is merged

An Excel file can be uploaded to a "Dynamic Analysis Specification" object.
This object can be linked to a common Analysis Specification for a given Sample Type.
In the Excel file the columns are used to match the values per row against the values of the Analysis or the Analysis Request. If all values match, the given result range will be used.

Example

Given is an Excel with the following minimal set of columns:

Keyword Method min max
H2O Method-1 1 2
H2O Method-2 3 4

This Excel is uploaded to an Dynamic Analysis Specification object, which is linked to an Analysis Specification for the Sample Type "Water".

A new "Water" Sample is created with an containing H2O sample to be tested with Method-2.
The results range selected will be [3;4]

Supported Results Range columns

The following column names have to be chosen to define a valid results range:

warn_min, min, min_operator, warn_max, max, max_operator, error

Defining a custom Dynamic Results Range Adapter

Sometimes it is needed to define more complex matches, e.g. to match the Gender or Age of a Patient to find a specification. In that case, it is supported to define a custom Adapter like this:

<configure
    xmlns="http://namespaces.zope.org/zope">

  <!-- Dynamic Results Range Adapter
       Looked up in `abstractroutineanalysis.getResultsRange` -->
  <adapter
      for="my.lims.interfaces.IRoutineAnalysis"
      factory=".dynamicresultsrange.DynamicResultsRange"
      provides="bika.lims.interfaces.IDynamicResultsRange"
      />

  <class class="bika.lims.content.analysis.Analysis">
    <implements interface="my.lims.interfaces.IRoutineAnalysis" />
  </class>

</configure>

Contents of dynamicresultsrange.py:

# -*- coding: utf-8 -*-

from bika.lims.interfaces import IDynamicResultsRange
from zope.interface import implementer

marker = object()


@implementer(IDynamicResultsRange)
class DynamicResultsRange(object):
    """Default Dynamic Results Range Adapter

    Matches all columns against the Analysis field values with the same names.
    """

    def __init__(self, analysis):
        self.analysis = analysis
        self.analysisrequest = analysis.getRequest()
        self.specification = self.analysisrequest.getSpecification()
        self.dynamicspec = None
        if self.specification:
            self.dynamicspec = self.specification.getDynamicAnalysisSpec()

    def __call__(self):
        # calculate a dynamic analysis specification for `self.analysis`

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

@shamut
Copy link

shamut commented Jan 24, 2020

Great functionality, this will make analysis specifications much easier to configure, manage and generally work with

Kudos

Copy link
Member

@xispa xispa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff

@xispa xispa merged commit 65c7234 into master Jan 28, 2020
@xispa xispa deleted the dynamic-analysisspecs branch January 28, 2020 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants