lims_diagnosis: service: add default diagnosis template
This commit is contained in:
parent
4f76702399
commit
8359e13374
|
@ -4,6 +4,7 @@
|
|||
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
|
||||
|
||||
class Analysis(metaclass=PoolMeta):
|
||||
|
@ -12,6 +13,9 @@ class Analysis(metaclass=PoolMeta):
|
|||
diagnostician = fields.Many2One('lims.diagnostician', 'Diagnostician')
|
||||
not_block_diagnosis = fields.Boolean('Does not block diagnosis',
|
||||
help="This analysis is not necessary to begin diagnosing the sample")
|
||||
diagnosis_template = fields.Many2One('lims.diagnosis.template',
|
||||
'Diagnosis Template', states={'readonly': Eval('type') != 'group'},
|
||||
depends=['type'])
|
||||
|
||||
|
||||
class ProductType(metaclass=PoolMeta):
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "field:lims.analysis,diagnosis_template:"
|
||||
msgid "Diagnosis Template"
|
||||
msgstr "Plantilla de Diagnóstico"
|
||||
|
||||
msgctxt "field:lims.analysis,diagnostician:"
|
||||
msgid "Diagnostician"
|
||||
msgstr "Diagnosticador"
|
||||
|
|
|
@ -110,28 +110,23 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
|
|||
def _get_fields_from_samples(cls, samples, generate_report_form=None):
|
||||
pool = Pool()
|
||||
Notebook = pool.get('lims.notebook')
|
||||
Diagnostician = pool.get('lims.diagnostician')
|
||||
ReportTemplate = pool.get('lims.result_report.template')
|
||||
|
||||
detail_default = super()._get_fields_from_samples(samples,
|
||||
generate_report_form)
|
||||
|
||||
diagnostician_id = None
|
||||
diagnosis_template_id = None
|
||||
diagnosis_template = None
|
||||
for sample in samples:
|
||||
nb = Notebook(sample['notebook'])
|
||||
if not diagnostician_id:
|
||||
if nb.fraction.sample.diagnostician:
|
||||
diagnostician_id = nb.fraction.sample.diagnostician.id
|
||||
else:
|
||||
diagnostician_id = Diagnostician.get_diagnostician()
|
||||
if (not diagnosis_template_id and
|
||||
nb.fraction.sample.diagnosis_template):
|
||||
diagnosis_template_id = (
|
||||
nb.fraction.sample.diagnosis_template.id)
|
||||
diagnostician_id = cls._get_diagnostician_from_sample(nb)
|
||||
if not diagnosis_template:
|
||||
diagnosis_template = (
|
||||
cls._get_diagnosis_template_from_sample(nb))
|
||||
|
||||
if diagnosis_template_id:
|
||||
detail_default['diagnosis_template'] = diagnosis_template_id
|
||||
if diagnosis_template:
|
||||
detail_default['diagnosis_template'] = diagnosis_template.id
|
||||
elif 'template' in detail_default and detail_default['template']:
|
||||
result_template = ReportTemplate(detail_default['template'])
|
||||
if result_template.diagnosis_template:
|
||||
|
@ -143,6 +138,44 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
|
|||
|
||||
return detail_default
|
||||
|
||||
@classmethod
|
||||
def _get_diagnostician_from_sample(cls, notebook):
|
||||
pool = Pool()
|
||||
Diagnostician = pool.get('lims.diagnostician')
|
||||
|
||||
if notebook.fraction.sample.diagnostician:
|
||||
diagnostician_id = notebook.fraction.sample.diagnostician.id
|
||||
else:
|
||||
diagnostician_id = Diagnostician.get_diagnostician()
|
||||
return diagnostician_id
|
||||
|
||||
@classmethod
|
||||
def _get_diagnosis_template_from_sample(cls, notebook):
|
||||
pool = Pool()
|
||||
Service = pool.get('lims.service')
|
||||
|
||||
diagnosis_template = notebook.fraction.sample.diagnosis_template
|
||||
if not diagnosis_template:
|
||||
ok = True
|
||||
services = Service.search([
|
||||
('fraction', '=', notebook.fraction),
|
||||
('analysis.type', '=', 'group'),
|
||||
('annulled', '=', False),
|
||||
])
|
||||
for service in services:
|
||||
if service.analysis.diagnosis_template:
|
||||
if not diagnosis_template:
|
||||
diagnosis_template = (
|
||||
service.analysis.diagnosis_template)
|
||||
elif (diagnosis_template !=
|
||||
service.analysis.diagnosis_template):
|
||||
ok = False
|
||||
elif diagnosis_template:
|
||||
ok = False
|
||||
if not ok:
|
||||
diagnosis_template = None
|
||||
return diagnosis_template
|
||||
|
||||
@classmethod
|
||||
def _get_fields_not_overwrite(cls):
|
||||
fields = super()._get_fields_not_overwrite()
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?xml version="1.0"?>
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page[@id='report']" position="inside">
|
||||
<label name="diagnosis_template"/>
|
||||
<field name="diagnosis_template"/>
|
||||
<label name="diagnostician"/>
|
||||
<field name="diagnostician"/>
|
||||
<label name="not_block_diagnosis"/>
|
||||
|
|
|
@ -146,7 +146,7 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
|
|||
if not result_template:
|
||||
result_template = cls._get_result_template_from_sample(nb)
|
||||
if not resultrange_origin:
|
||||
resultrange_origin = nb.fraction.sample.resultrange_origin
|
||||
resultrange_origin = cls._get_resultrange_from_sample(nb)
|
||||
|
||||
if result_template:
|
||||
detail_default['template'] = result_template.id
|
||||
|
@ -212,6 +212,10 @@ class ResultsReportVersionDetail(metaclass=PoolMeta):
|
|||
|
||||
return result_template
|
||||
|
||||
@classmethod
|
||||
def _get_resultrange_from_sample(cls, notebook):
|
||||
return notebook.fraction.sample.resultrange_origin
|
||||
|
||||
@classmethod
|
||||
def _get_fields_not_overwrite(cls):
|
||||
fields = super()._get_fields_not_overwrite()
|
||||
|
|
Loading…
Reference in New Issue