changeset 2213:dd561c11f9e4

health / health crypto : task #13838: Update states on prescription and new create and validate buttons
author Luis Falcon <falcon@gnu.org>
date Thu, 10 Dec 2015 12:56:31 +0000
parents f03be8a58d92
children 8cfdb2c4016d
files tryton/health/health.py tryton/health/view/gnuhealth_prescription.xml tryton/health_crypto/health_crypto.py tryton/health_crypto/view/prescription_form.xml
diffstat 4 files changed, 53 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/tryton/health/health.py
+++ b/tryton/health/health.py
@@ -3920,27 +3920,32 @@
     __name__ = 'gnuhealth.prescription.order'
     _rec_name = 'prescription_id'
 
+    STATES = {'readonly': Not(Eval('state') == 'draft')}
+
     patient = fields.Many2One(
-        'gnuhealth.patient', 'Patient', required=True)
+        'gnuhealth.patient', 'Patient', required=True, states = STATES)
 
     prescription_id = fields.Char(
         'Prescription ID',
         readonly=True, help='Type in the ID of this prescription')
 
-    prescription_date = fields.DateTime('Prescription Date')
+    prescription_date = fields.DateTime('Prescription Date', states = STATES)
 # In 1.8 we associate the prescribing doctor to the physician name
 # instead to the old user_id (res.user)
     user_id = fields.Many2One('res.user', 'Prescribing Doctor', readonly=True)
 
     pharmacy = fields.Many2One(
-        'party.party', 'Pharmacy', domain=[('is_pharmacy', '=', True)])
+        'party.party', 'Pharmacy', domain=[('is_pharmacy', '=', True)],
+            states = STATES)
 
     prescription_line = fields.One2Many(
-        'gnuhealth.prescription.line', 'name', 'Prescription line')
-
-    notes = fields.Text('Prescription Notes')
+        'gnuhealth.prescription.line', 'name', 'Prescription line',
+            states = STATES)
+
+    notes = fields.Text('Prescription Notes', states = STATES)
     pregnancy_warning = fields.Boolean('Pregnancy Warning', readonly=True)
-    prescription_warning_ack = fields.Boolean('Prescription verified')
+    prescription_warning_ack = fields.Boolean('Prescription verified',
+        states = STATES)
 
     healthprof = fields.Many2One(
         'gnuhealth.healthprofessional', 'Prescribed by', readonly=True)
@@ -3950,6 +3955,11 @@
     report_prescription_time = fields.Function(fields.Time(
         'Prescription Time'), 'get_report_prescription_time')
 
+    state = fields.Selection([
+        ('draft', 'Draft'),
+        ('done', 'Done'),        
+        ], 'State', readonly=True, sort=False, states = STATES)
+
     @classmethod
     def __setup__(cls):
         super(PatientPrescriptionOrder, cls).__setup__()
@@ -3967,6 +3977,10 @@
 
         cls._order.insert(0, ('prescription_date', 'DESC'))
 
+        cls._buttons.update({
+            'create_prescription': {'invisible': Equal(Eval('state'), 'done')}
+            })
+
     @classmethod
     def validate(cls, prescriptions):
         super(PatientPrescriptionOrder, cls).validate(prescriptions)
@@ -4081,6 +4095,17 @@
 
         super(PatientPrescriptionOrder, cls).__register__(module_name)
 
+    @classmethod
+    @ModelView.button
+    def create_prescription(cls, prescriptions):
+        prescription = prescriptions[0]
+
+        # Change the state of the prescription to "Done"        
+
+        cls.write(prescriptions, {
+            'state': 'done',})
+
+
 
 # PRESCRIPTION LINE
 class PrescriptionLine(ModelSQL, ModelView):
--- a/tryton/health/view/gnuhealth_prescription.xml
+++ b/tryton/health/view/gnuhealth_prescription.xml
@@ -24,4 +24,11 @@
     <group string="Notes" id="group_prescription_notes">
         <field name="notes" colspan="4"/>
     </group>
+    <newline/>
+    <group id="group_prescription_footer">
+        <label name="state"/>
+        <field name="state"/>
+        <button name="create_prescription" help="Create the prescription" string="Create" icon="tryton-go-next" confirm="Create prescription ?"/>
+    </group>
+
 </form>
--- a/tryton/health_crypto/health_crypto.py
+++ b/tryton/health_crypto/health_crypto.py
@@ -25,7 +25,7 @@
 from trytond.rpc import RPC
 from trytond.pool import Pool
 from trytond.wizard import Wizard, StateAction, StateView, Button
-from trytond.pyson import Eval, Not, Bool, PYSONEncoder, Equal, And
+from trytond.pyson import Eval, Not, Bool, PYSONEncoder, Equal, And, Or
 import hashlib
 import json
 
@@ -57,10 +57,11 @@
 
     document_digest = fields.Char('Digest', readonly=True,
         help="Original Document Digest")
-    
+
     state = fields.Selection([
         ('draft', 'Draft'),
-        ('done', 'Done'),
+        ('done', 'Done'),        
+        ('validated', 'Validated'),        
         ], 'State', readonly=True, sort=False)
 
 
@@ -98,8 +99,13 @@
     def __setup__(cls):
         cls._buttons.update({
             'generate_prescription': {
-                'invisible': Equal(Eval('state'), 'done'),
+                'invisible': Equal(Eval('state'), 'validated'),
             },
+            'create_prescription': {
+                'invisible': Or(Equal(Eval('state'), 'done'),
+                    Equal(Eval('state'), 'validated'))
+            },
+
             })
         ''' Allow calling the set_signature method via RPC '''
         cls.__rpc__.update({
@@ -120,7 +126,7 @@
         cls.write(prescriptions, {
             'serializer': serial_doc,
             'document_digest': HealthCrypto().gen_hash(serial_doc),
-            'state': 'done',})
+            'state': 'validated',})
 
 
     @classmethod
@@ -185,12 +191,12 @@
         return result
  
     # Hide the group holding validation information when state is 
-    # draft
+    # not validated
     
     @classmethod
     def view_attributes(cls):
         return [('//group[@id="prescription_digest"]', 'states', {
-                'invisible': Eval('state') == 'draft',
+                'invisible': Not(Eval('state') == 'validated'),
                 })]
        
 
--- a/tryton/health_crypto/view/prescription_form.xml
+++ b/tryton/health_crypto/view/prescription_form.xml
@@ -22,9 +22,7 @@
         </group>
         <newline/>
         <group colspan="4" col="6" id="prescription_generate">
-            <label name="state"/>
-            <field name="state"/>
-            <button name="generate_prescription" help="Sign the prescription" string="Generate" icon="tryton-go-next" confirm="Generate prescription ?"/>
+            <button name="generate_prescription" help="Generate the prescription validation code" string="Generate Validation" icon="tryton-go-next" confirm="Generate Validation ?"/>
             <label name="digest_status"/>
             <field name="digest_status"/>
         </group>