changeset 4824:afc471962330

task #16043: Migration to GNU Health 4.0: Migrate health_icu package
author Luis Falcon <falcon@gnuhealth.org>
date Tue, 21 Dec 2021 21:38:21 +0000
parents aa1f80f2176e
children dd25162e1355
files tryton/health_icu/__init__.py tryton/health_icu/data/messages/messages.xml tryton/health_icu/exceptions.py tryton/health_icu/health_icu.py tryton/health_icu/tryton.cfg tryton/health_icu/view/gnuhealth_icu_chest_drainage_tree.xml
diffstat 6 files changed, 41 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/tryton/health_icu/__init__.py
+++ b/tryton/health_icu/__init__.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 ##############################################################################
 #
 #    GNU Health: The Free Health and Hospital Information System
@@ -22,16 +21,16 @@
 ##############################################################################
 
 from trytond.pool import Pool
-from .health_icu import *
+from . import health_icu
 
 
 def register():
     Pool.register(
-        InpatientRegistration,
-        InpatientIcu,
-        Glasgow,
-        ApacheII,
-        MechanicalVentilation,
-        ChestDrainageAssessment,
-        PatientRounding,
+        health_icu.InpatientRegistration,
+        health_icu.InpatientIcu,
+        health_icu.Glasgow,
+        health_icu.ApacheII,
+        health_icu.MechanicalVentilation,
+        health_icu.ChestDrainageAssessment,
+        health_icu.PatientRounding,
         module='health_icu', type_='model')
new file mode 100644
--- /dev/null
+++ b/tryton/health_icu/data/messages/messages.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<!-- This file is part of GNU Health.  The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
+<tryton>
+    <data grouped="1">
+        <record model="ir.message" id="msg_patient_already_in_icu">
+            <field name="text">Our records indicate that the patient is already in ICU</field>
+        </record>
+        <record model="ir.message" id="msg_patient_already_on_mv">
+            <field name="text">Our records indicate that the patient is already on Mechanical Ventilation</field>
+        </record>
+    </data>
+</tryton>
new file mode 100644
--- /dev/null
+++ b/tryton/health_icu/exceptions.py
@@ -0,0 +1,11 @@
+# This file is part of GNU Health.  The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+from trytond.exceptions import UserError, UserWarning
+from trytond.model.exceptions import ValidationError
+
+
+class PatientAlreadyInICU(ValidationError):
+    pass
+
+class PatientAlreadyOnMV(ValidationError):
+    pass
--- a/tryton/health_icu/health_icu.py
+++ b/tryton/health_icu/health_icu.py
@@ -25,6 +25,8 @@
 from dateutil.relativedelta import relativedelta
 from trytond.transaction import Transaction
 from trytond.pyson import Eval, Not, Bool, Equal
+from .exceptions import PatientAlreadyInICU
+from trytond.i18n import gettext
 
 
 __all__ = ['InpatientRegistration', 'InpatientIcu', 'Glasgow', 'ApacheII',
@@ -72,13 +74,6 @@
         'name', "Mechanical Ventilation History")
 
     @classmethod
-    def __setup__(cls):
-        super(InpatientIcu, cls).__setup__()
-        cls._error_messages.update({
-            'patient_already_at_icu': 'Our records indicate that the patient'
-                ' is already admitted at ICU'})
-
-    @classmethod
     def validate(cls, inpatients):
         super(InpatientIcu, cls).validate(inpatients)
         for inpatient in inpatients:
@@ -92,7 +87,8 @@
             WHERE (name = %s AND admitted)",
             (str(self.name.id),))
         if cursor.fetchone()[0] > 1:
-            self.raise_user_error('patient_already_at_icu')
+            raise PatientAlreadyInICU(
+                gettext('health_icu.msg_patient_already_in_icu'))
 
     @staticmethod
     def default_admitted():
@@ -447,13 +443,6 @@
     remarks = fields.Char('Remarks')
 
     @classmethod
-    def __setup__(cls):
-        super(MechanicalVentilation, cls).__setup__()
-        cls._error_messages.update({
-            'patient_already_on_mv': 'Our records indicate that the patient'
-                ' is already on Mechanical Ventilation !'})
-
-    @classmethod
     def validate(cls, inpatients):
         super(MechanicalVentilation, cls).validate(inpatients)
         for inpatient in inpatients:
@@ -467,7 +456,8 @@
             WHERE (name = %s AND current_mv)",
             (str(self.name.id),))
         if cursor.fetchone()[0] > 1:
-            self.raise_user_error('patient_already_on_mv')
+            raise PatientAlreadyOnMV(
+                gettext('health_icu.msg_patient_already_on_mv'))
 
     @staticmethod
     def default_current_mv():
--- a/tryton/health_icu/tryton.cfg
+++ b/tryton/health_icu/tryton.cfg
@@ -1,8 +1,9 @@
 [tryton]
-version=3.8.0
+version=3.9.0
 depends:
     health
     health_inpatient
     health_nursing
 xml:
     health_icu_view.xml
+    data/messages/messages.xml
--- a/tryton/health_icu/view/gnuhealth_icu_chest_drainage_tree.xml
+++ b/tryton/health_icu/view/gnuhealth_icu_chest_drainage_tree.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<tree editable="top">
+<tree editable="1">
     <field name="location" expand="1"/>
     <field name="suction"/>
     <field name="suction_pressure"/>