changeset 1573:2418927376cb

health_inpatient : Complete task #13331: Make translatable the hospitalization status in the main patient form
author Luis Falcon <falcon@gnu.org>
date Thu, 23 Oct 2014 08:21:27 +0100
parents 1c80d9aa717e
children 960bfb63e5f2
files tryton/health/view/gnuhealth_patient_form.xml tryton/health_inpatient/health_inpatient.py tryton/health_inpatient/view/patient_form.xml
diffstat 3 files changed, 17 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/tryton/health/view/gnuhealth_patient_form.xml
+++ b/tryton/health/view/gnuhealth_patient_form.xml
@@ -38,7 +38,7 @@
                         <field height="100" name="general_info"/>
                     </group>
                     <newline/>
-                    <group colspan="4" col="8" id="patient_info_2">
+                    <group colspan="4" col="10" id="patient_info_2">
                         <label name="dob"/>
                         <field name="dob"/>
 <!--
--- a/tryton/health_inpatient/health_inpatient.py
+++ b/tryton/health_inpatient/health_inpatient.py
@@ -321,27 +321,32 @@
     'Inherit patient model and add the patient status to the patient.'
     __name__ = 'gnuhealth.patient'
 
-    patient_status = fields.Function(fields.Char('Hospitalization Status', help="Patient current Hospitalization Status"),
+    patient_status = fields.Function(fields.Boolean('Hospitalized',
+        help="Show the hospitalization status of the patient"),
         'get_patient_status')
 
     def get_patient_status(self, name):
+        
         cursor = Transaction().cursor
 
         def get_hospitalization_status(patient_dbid):
-            cursor.execute('SELECT state '
-                'FROM gnuhealth_inpatient_registration '
-                'WHERE patient = %s '
-                  'AND state = \'hospitalized\' ', (str(patient_dbid),))
-            try:
-                patient_status = str(cursor.fetchone()[0])
-            except:
-                patient_status = 'outpatient'
-            return patient_status
+            is_hospitalized = False
+
+            cursor.execute('SELECT count(state) \
+                FROM gnuhealth_inpatient_registration \
+                WHERE patient = %s \
+                AND state = \'hospitalized\' ', (patient_dbid,))
+            
+            if cursor.fetchone()[0] > 0:
+                is_hospitalized = True
+            
+            return is_hospitalized
 
         result = ''
 
         # Get the patient (DB) id to be used in the search on the medical
         # inpatient registration table lookup
+        
         patient_dbid = self.id
         if patient_dbid:
             result = get_hospitalization_status(patient_dbid)
--- a/tryton/health_inpatient/view/patient_form.xml
+++ b/tryton/health_inpatient/view/patient_form.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0"?>
 <data>
     <xpath expr="//field[@name=&quot;rh&quot;]" position="after">
+        <label name="patient_status"/>
         <field name="patient_status"/>
     </xpath>
 </data>