changeset 2026:799617bbcf40

health : Add code to patient evaluation model
author Luis Falcon <falcon@gnu.org>
date Thu, 30 Jul 2015 12:25:23 +0100
parents 32f26b083ef3
children d9fffe581263
files tryton/health/data/health_sequences.xml tryton/health/health.py tryton/health/view/gnuhealth_patient_evaluation.xml tryton/health/view/gnuhealth_patient_evaluation_tree.xml
diffstat 4 files changed, 56 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/tryton/health/data/health_sequences.xml
+++ b/tryton/health/data/health_sequences.xml
@@ -2,6 +2,26 @@
 <tryton>
     <data skiptest="1">
 
+<!-- Sequences for Patient Evaluation -->
+
+        <record id="seq_type_gnuhealth_patient_evaluation" model="ir.sequence.type">
+            <field name="name">Patient Evaluation</field>
+            <field name="code">gnuhealth.patient.evaluation</field>
+        </record>
+        <record id="seq_gnuhealth_patient_evaluation" model="ir.sequence">
+            <field name="name">Patient Evaluation</field>
+            <field name="code">gnuhealth.prescription.order</field>
+            <field name="prefix">EVAL ${year}/</field>
+            <field name="padding">6</field>
+            <field name="number_increment" eval="1"/>
+        </record>
+
+        <record model="ir.property" id="property_patient_evaluation_sequence">
+            <field name="field"
+                search="[('model.model', '=', 'gnuhealth.sequences'), ('name', '=', 'patient_evaluation_sequence')]"/>
+            <field name="value" eval="'ir.sequence,' + str(ref('seq_gnuhealth_patient_evaluation'))"/>
+        </record>
+
 <!-- Sequences for Prescriptions -->
 
         <record id="seq_type_gnuhealth_prescription" model="ir.sequence.type">
--- a/tryton/health/health.py
+++ b/tryton/health/health.py
@@ -2323,6 +2323,10 @@
         'ir.sequence', 'Patient Sequence', required=True,
         domain=[('code', '=', 'gnuhealth.patient')]))
 
+    patient_evaluation_sequence = fields.Property(fields.Many2One(
+        'ir.sequence', 'Patient Evaluation Sequence', required=True,
+        domain=[('code', '=', 'gnuhealth.patient.evaluation')]))
+
     appointment_sequence = fields.Property(fields.Many2One(
         'ir.sequence', 'Appointment Sequence', required=True,
         domain=[('code', '=', 'gnuhealth.appointment')]))
@@ -4079,6 +4083,9 @@
                     duration = str(int(round(delta.total_seconds()/60)))
         return duration
             
+    code = fields.Char('Code', help="Unique code that \
+        identifies the evaluation")
+    
     patient = fields.Many2One('gnuhealth.patient', 'Patient',
         states = STATES)
 
@@ -4667,6 +4674,29 @@
         super(PatientEvaluation, cls).__register__(module_name)
 
 
+    @classmethod
+    def __setup__(cls):
+        super(PatientEvaluation, cls).__setup__()
+        cls._sql_constraints = [
+            ('code', 'UNIQUE(code)',
+                'The evaluation code must be unique !'),
+        ]
+
+    @classmethod
+    def create(cls, vlist):
+        Sequence = Pool().get('ir.sequence')
+        Config = Pool().get('gnuhealth.sequences')
+
+        vlist = [x.copy() for x in vlist]
+        for values in vlist:
+            if not values.get('code'):
+                config = Config(1)
+                values['code'] = Sequence.get_id(
+                    config.patient_evaluation_sequence.id)
+
+        return super(PatientEvaluation, cls).create(vlist)
+
+
 # PATIENT EVALUATION DIRECTIONS
 class Directions(ModelSQL, ModelView):
     'Patient Directions'
--- a/tryton/health/view/gnuhealth_patient_evaluation.xml
+++ b/tryton/health/view/gnuhealth_patient_evaluation.xml
@@ -11,8 +11,8 @@
         <field name="visit_type"/>
         <label name="healthprof"/>
         <field name="healthprof"/>
-        <label name="evaluation_start"/>
-        <field name="evaluation_start"/>
+        <label name="code"/>
+        <field name="code"/>
     </group>
     <newline/>
 
@@ -35,13 +35,15 @@
             <newline/>
             <field name="evaluation_summary" colspan="4"/>
             <newline/>
-            <group colspan="4" col="12" id="group_eval_misc">
+            <group colspan="4" col="14" id="group_eval_misc">
                 <label name="evaluation_type"/>
                 <field name="evaluation_type"/>
                 <label name="specialty"/>
                 <field name="specialty"/>
                 <label name="urgency"/>
                 <field name="urgency"/>
+                <label name="evaluation_start"/>
+                <field name="evaluation_start"/>
                 <label name="evaluation_endtime"/>
                 <field name="evaluation_endtime"/>
                 <field name="state"/>
--- a/tryton/health/view/gnuhealth_patient_evaluation_tree.xml
+++ b/tryton/health/view/gnuhealth_patient_evaluation_tree.xml
@@ -1,5 +1,6 @@
 <?xml version="1.0"?>
 <tree string="Evaluations">
+    <field name="code" expand="1"/>
     <field name="patient" expand="1"/>
     <field name="sex"/>
     <field name="visit_type"/>