senaite.core
senaite.core copied to clipboard
Results import fails if not formula specified
Steps to reproduce
Create a calculation but do not provide a formula and assign calculation to an instrument
Current behavior
On importing of results for that instrument, import fails.
Expected behavior
Results are imported successfully.
Screenshot (optional)
User shouldn't be able to create a Calculation without a formula. I suggest to set the field Formula
with required=True
and check the validator is working as expected
Thanks for reviewing @xispa. The use case for this is the first of a two stage testing of a blood sample for a drug, just checking whether it is present. If positive, a reflex rule kicks in for Quantitive testing.
The Analyst wants to review all of the key spectrogram information, often for more than one ion, and then select positive/negative manually, or capture a numeric result, less likely. In rare cases they might actually import Interims and an actual result itself.
The easiest way to get these into the LIMS would be to utilise the existing Calculations engine, from where Methods and eventually Analysis Services inherit the config
Suggested solution is to keep the Analysis' results field editable when the Interims are uploaded and there is no Calculation?
We have a new prospect that runs a TB testing lab. They conduct the same test on the same sample that is split into 4 wells. Their instruments are not connect so all results will be recorded manually. Our proposed solution is to create one AS with 4 interims (one for each test result) and no formula. Test results are entered manually into the interims and the final Yes/No result is captured manually. But this presupposes formula on a calculation is optional and once the interims are captured the result is still editable. How would you configure this?
I suggest to reproduce a reflex testing scenario by means of a calculation as an additional python library. Basically, I would create one service for the manual entry of results (e.g. say "TB well count") and another service for the final result (e.g. say "TB Final Result"). Then, I would create a calculation "TB Final Result Calculation". The idea is this calculation to automatically create a new "TB well count" each time a result for a previous "TB well count" test is submitted. This calculation would also be in charge to assign and submit the final result "Yes/No" for "TB Final Result" once the result for the 4th "TB well count" test is submitted.
For this, you need to create a custom .py in your add-on that will be in charge of the logic explained above. Then, you can import this python as an additional library in "TB Final Result Calculation":
The module could be my.lims
and a function handle_tb(analysis)
.
Then, make the formula call your function and delegate all the logic there, e.g:
handle_tb(context)
This formula would create a new "TB Well count" analysis each time a result is submitted for a previous "TB Well count", as much as 3 times. Will return "Yes" or "No" after then. Note this formula needs to "know" the results of "TB Well count" tests submitted previously. Fortunately, context
is passed in globals when the function is evaluated in calculateResults
: https://github.com/senaite/senaite.core/blob/master/bika/lims/content/abstractanalysis.py#L559
The context
is the analysis the calculation is assigned to, so you can get the AnalysisRequest
object from it with getRequest()
and retrieve the "TB Well count" analyses assigned to the sample therefore.
The function structure might look similar to:
def handle_tb(analysis):
if not IRequestAnalysis.providedBy(context):
raise TypeError("Type not supported: {}".format(context))
sample = analysis.getRequest()
analyses = sample.getAnalyses(full_objects=True)
analyses = filter(lambda an: an.getKeyword() == "TBWELL", analyses)
if len(analyses) < 4:
# Add a new analysis to the request
analysis = create_analysis(sample, "TBWELL")
....
return ""
# Calculate final result
....
return result
Thanks @xispa. We need all 4 interims at registration for WS Creation. The analyst captures the 4 interim results and the final result at the same time. In the TB case there are no reflex tests that follow.