changeset 5654:f1cd2b798db7

task #16207: Create imaging report. Improve view. Include patient age at evaluation time and request extra info
author Luis Falcon <falcon@gnuhealth.org>
date Sun, 15 Jan 2023 13:11:49 +0000
parents c36e43a61465
children 351b2695d905
files tryton/health_imaging/health_imaging.py tryton/health_imaging/view/imaging_test_result_form.xml
diffstat 2 files changed, 30 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/tryton/health_imaging/health_imaging.py
+++ b/tryton/health_imaging/health_imaging.py
@@ -19,7 +19,8 @@
 from trytond.pyson import Eval
 from trytond.pool import Pool
 
-from trytond.modules.health.core import get_health_professional
+from trytond.modules.health.core import (
+    get_health_professional, compute_age_from_dates)
 
 __all__ = [
     'ImagingTestType',
@@ -56,6 +57,16 @@
     'Imaging Test Request'
     __name__ = 'gnuhealth.imaging.test.request'
 
+    def get_rec_name(self, name):
+        res = ''
+        if self.urgent:
+            res = '**Urgent**'
+        if self.doctor:
+            res = f'{res} ({self.doctor.rec_name}) //'
+        if self.context:
+            res = f'{res} CONTEXT: {self.context.rec_name}'
+        return res
+
     patient = fields.Many2One('gnuhealth.patient', 'Patient', required=True)
     date = fields.DateTime('Date', required=True)
     requested_test = fields.Many2One(
@@ -155,6 +166,12 @@
     'Imaging Test Result'
     __name__ = 'gnuhealth.imaging.test.result'
 
+    def patient_age_at_evaluation(self, name):
+        if (self.patient.name.dob and self.date):
+            return compute_age_from_dates(
+                self.patient.name.dob, None, None, None, 'age',
+                self.date.date())
+
     patient = fields.Many2One('gnuhealth.patient', 'Patient', readonly=True)
     number = fields.Char('Number', readonly=True)
     date = fields.DateTime('Date', required=True)
@@ -163,13 +180,19 @@
         'gnuhealth.imaging.test', 'Test',
         required=True)
     request = fields.Many2One(
-        'gnuhealth.imaging.test.request', 'Request',
+        'gnuhealth.imaging.test.request', 'Request Info',
         readonly=True)
     order = fields.Char(
         'Order', readonly=True,
         help="The order ID containing this particular imaging study")
     doctor = fields.Many2One(
-        'gnuhealth.healthprofessional', 'Health prof', required=True)
+        'gnuhealth.healthprofessional', 'Evaluated by', required=True)
+
+    computed_age = fields.Function(fields.Char(
+            'Age',
+            help="Computed patient age at the moment of the evaluation"),
+            'patient_age_at_evaluation')
+
     comment = fields.Text('Additional Information')
     images = fields.One2Many('ir.attachment', 'resource', 'Images')
 
--- a/tryton/health_imaging/view/imaging_test_result_form.xml
+++ b/tryton/health_imaging/view/imaging_test_result_form.xml
@@ -10,6 +10,8 @@
 <form>
     <label name="patient"/>
     <field name="patient"/>
+    <label name="computed_age"/>
+    <field name="computed_age"/>
     <label name="number"/>
     <field name="number"/>
     <label name="date"/>
@@ -22,8 +24,9 @@
     <field name="doctor"/>
     <label name="order"/>
     <field name="order"/>
+    <newline/>
     <label name="request"/>
-    <field name="request"/>
+    <field name="request" colspan="3"/>
     <notebook>
         <page string="Images" id="images_page">
             <field name="images" colspan="4"/>