~iratzio-gutierrez/oemedical/oemedical-csm

« back to all changes in this revision

Viewing changes to oemedical/oemedical_appointment/oemedical_appointment.py

  • Committer: Nhomar - Vauxoo
  • Date: 2013-10-23 03:02:27 UTC
  • mfrom: (83.1.120 openobject-oemedical)
  • Revision ID: nhomar@gmail.com-20131023030227-dwgs8z939r2f5al7
[MERGE] Federicos branch, several change and finishing a lot of concepts, sorry for the delay. Thanks, Note: See the commit log for the origin of the merge for more details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#/#############################################################################
22
22
from osv import osv
23
23
from osv import fields
 
24
import time
24
25
 
25
26
 
26
27
class OeMedicalAppointment(osv.Model):
27
28
    _name = 'oemedical.appointment'
28
29
 
29
30
    _columns = {
30
 
        'consultations': fields.many2one('product.product',
31
 
                                         string='Consultation Services',
32
 
                                          help='Consultation Services'),
33
31
        'patient_id': fields.many2one('oemedical.patient', string='Patient',
34
32
                                   required=True, select=True,
35
33
                                   help='Patient Name'),
36
34
        'name': fields.char(size=256, string='Appointment ID', readonly=True),
37
35
        'appointment_date': fields.datetime(string='Date and Time'),
 
36
        'appointment_day': fields.date(string='Date'),
 
37
        'appointment_hour': fields.selection([
 
38
            ('01', '01'),
 
39
            ('02', '02'),
 
40
            ('03', '03'),
 
41
            ('04', '04'),
 
42
            ('05', '05'),
 
43
            ('06', '06'),
 
44
            ('07', '07'),
 
45
            ('08', '08'),
 
46
            ('09', '09'),
 
47
            ('10', '10'),
 
48
            ('11', '11'),
 
49
            ('12', '12'),
 
50
            ('13', '13'),
 
51
            ('14', '14'),
 
52
            ('15', '15'),
 
53
            ('16', '16'),
 
54
            ('17', '17'),
 
55
            ('18', '18'),
 
56
            ('19', '19'),
 
57
            ('20', '20'),
 
58
            ('21', '21'),
 
59
            ('22', '22'),
 
60
            ('23', '23'),
 
61
             ],
 
62
            string='Hour'),
 
63
        'appointment_minute': fields.selection([
 
64
            ('05', '05'),
 
65
            ('10', '10'),
 
66
            ('15', '15'),
 
67
            ('20', '20'),
 
68
            ('25', '25'),
 
69
            ('30', '30'),
 
70
            ('35', '35'),
 
71
            ('40', '40'),
 
72
            ('45', '45'),
 
73
            ('50', '50'),
 
74
            ('55', '55'),
 
75
             ],
 
76
            string='Minute'),
 
77
 
38
78
        'duration': fields.float('Duration'),
39
79
        'doctor': fields.many2one('oemedical.physician',
40
80
                                  string='Physician',select=True, 
41
81
                                  help='Physician\'s Name'),
 
82
        'alias' : fields.char(size=256, string='Alias', ),
42
83
        'comments': fields.text(string='Comments'),
43
84
        'appointment_type': fields.selection([
44
85
            ('ambulatory', 'Ambulatory'),
47
88
        ], string='Type'),
48
89
        'institution': fields.many2one('res.partner',
49
90
                                       string='Health Center',
50
 
                                       help='Medical Center'),
 
91
                                       help='Medical Center'
 
92
                                        , domain="[('category_id', '=', 'Doctor Office')]"),
 
93
        'consultations': fields.many2one('product.product',
 
94
                                         string='Consultation Services',
 
95
                                          help='Consultation Services'
 
96
                                        , domain="[('type', '=', 'service'), ]"),
51
97
        'urgency': fields.selection([
52
98
            ('a', 'Normal'),
53
99
            ('b', 'Urgent'),
56
102
        'speciality': fields.many2one('oemedical.specialty',
57
103
                                      string='Specialty', 
58
104
                                      help='Medical Specialty / Sector'),
 
105
        'state': fields.selection([
 
106
            ('draft', 'Draft'),
 
107
            ('confirm', 'Confirm'),
 
108
            ('waiting', 'Wating'),
 
109
            ('in_consultation', 'In consultation'),
 
110
            ('done', 'Done'),
 
111
            ('canceled', 'Canceled'),
 
112
             ],
 
113
            string='State'),
 
114
        'history_ids' : fields.one2many('oemedical.appointment.history','appointment_id_history','History lines', states={'start':[('readonly',True)]}),
 
115
 
59
116
    }
60
117
    
61
118
    _defaults = {
62
 
         'name': lambda obj, cr, uid, context: 
 
119
        'name': lambda obj, cr, uid, context: 
63
120
            obj.pool.get('ir.sequence').get(cr, uid, 'oemedical.appointment'),
 
121
        'duration': 30.00,
 
122
        'urgency': 'a',
 
123
        'state': 'draft',
 
124
 
64
125
                 }
65
126
 
 
127
    def create(self, cr, uid, vals, context=None):
 
128
        val_history = {}
 
129
        ait_obj = self.pool.get('oemedical.appointment.history')
 
130
 
 
131
 
 
132
 
 
133
        val_history['name'] = uid
 
134
        val_history['date'] = time.strftime('%Y-%m-%d %H:%M:%S')
 
135
        val_history['action'] = "--------------------------------  Changed to Comfirm  ------------------------------------\n"
 
136
 
 
137
        vals['history_ids'] = val_history
 
138
 
 
139
        print "create", vals['history_ids'], val_history, '     ------    ', vals
 
140
 
 
141
        return super(OeMedicalAppointment, self).create(cr, uid, vals, context=context)
 
142
 
 
143
    def button_back(self, cr, uid, ids, context=None):
 
144
 
 
145
        val_history = {}
 
146
        ait_obj = self.pool.get('oemedical.appointment.history')
 
147
 
 
148
        for order in self.browse(cr, uid, ids, context=context):
 
149
            if order.state == 'confirm':
 
150
                self.write(cr, uid, ids, {'state':'draft'} ,context=context)
 
151
                val_history['action'] = "--------------------------------  Changed to Draft  ------------------------------------\n"
 
152
            if order.state == 'waiting':
 
153
                val_history['action'] = "--------------------------------  Changed to Confirm  ------------------------------------\n"
 
154
                self.write(cr, uid, ids, {'state':'confirm'} ,context=context)
 
155
            if order.state == 'in_consultation':
 
156
                val_history['action'] = "--------------------------------  Changed to Waiting  ------------------------------------\n"
 
157
                self.write(cr, uid, ids, {'state':'waiting'} ,context=context)
 
158
            if order.state == 'done':
 
159
                val_history['action'] = "--------------------------------  Changed to In Consultation  ------------------------------------\n"
 
160
                self.write(cr, uid, ids, {'state':'in_consultation'} ,context=context)
 
161
            if order.state == 'canceled':
 
162
                val_history['action'] = "--------------------------------  Changed to Draft  ------------------------------------\n"
 
163
                self.write(cr, uid, ids, {'state':'draft'} ,context=context)
 
164
 
 
165
        val_history['appointment_id_history'] = ids[0]
 
166
        val_history['name'] = uid
 
167
        val_history['date'] = time.strftime('%Y-%m-%d %H:%M:%S')
 
168
 
 
169
        ait_obj.create(cr, uid, val_history)
 
170
 
 
171
        return True
 
172
 
 
173
    def button_confirm(self, cr, uid, ids, context=None):
 
174
 
 
175
        val_history = {}
 
176
        ait_obj = self.pool.get('oemedical.appointment.history')
 
177
 
 
178
        self.write(cr, uid, ids, {'state':'confirm'} ,context=context)
 
179
 
 
180
        val_history['appointment_id_history'] = ids[0]
 
181
        val_history['name'] = uid
 
182
        val_history['date'] = time.strftime('%Y-%m-%d %H:%M:%S')
 
183
        val_history['action'] = "--------------------------------  Changed to Comfirm  ------------------------------------\n"
 
184
        ait_obj.create(cr, uid, val_history)
 
185
 
 
186
        return True
 
187
 
 
188
    def button_waiting(self, cr, uid, ids, context=None):
 
189
 
 
190
        val_history = {}
 
191
        ait_obj = self.pool.get('oemedical.appointment.history')
 
192
 
 
193
        self.write(cr, uid, ids, {'state':'waiting'} ,context=context)
 
194
 
 
195
        val_history['appointment_id_history'] = ids[0]
 
196
        val_history['name'] = uid
 
197
        val_history['date'] = time.strftime('%Y-%m-%d %H:%M:%S')
 
198
        val_history['action'] = "--------------------------------  Changed to Waiting  ------------------------------------\n"
 
199
        ait_obj.create(cr, uid, val_history)
 
200
 
 
201
        return True
 
202
 
 
203
    def button_in_consultation(self, cr, uid, ids, context=None):
 
204
 
 
205
        val_history = {}
 
206
        ait_obj = self.pool.get('oemedical.appointment.history')
 
207
 
 
208
        self.write(cr, uid, ids, {'state':'in_consultation'} ,context=context)
 
209
 
 
210
        val_history['appointment_id_history'] = ids[0]
 
211
        val_history['name'] = uid
 
212
        val_history['date'] = time.strftime('%Y-%m-%d %H:%M:%S')
 
213
        val_history['action'] = "--------------------------------  Changed to In Consultation  ------------------------------------\n"
 
214
        ait_obj.create(cr, uid, val_history)
 
215
 
 
216
        return True
 
217
 
 
218
    def button_done(self, cr, uid, ids, context=None):
 
219
 
 
220
        val_history = {}
 
221
        ait_obj = self.pool.get('oemedical.appointment.history')
 
222
 
 
223
        self.write(cr, uid, ids, {'state':'done'} ,context=context)
 
224
 
 
225
        val_history['appointment_id_history'] = ids[0]
 
226
        val_history['name'] = uid
 
227
        val_history['date'] = time.strftime('%Y-%m-%d %H:%M:%S')
 
228
        val_history['action'] = "--------------------------------  Changed to Done  ------------------------------------\n"
 
229
        ait_obj.create(cr, uid, val_history)
 
230
 
 
231
        return True
 
232
 
 
233
    def button_cancel(self, cr, uid, ids, context=None):
 
234
 
 
235
        val_history = {}
 
236
        ait_obj = self.pool.get('oemedical.appointment.history')
 
237
 
 
238
        self.write(cr, uid, ids, {'state':'canceled'} ,context=context)
 
239
 
 
240
        val_history['appointment_id_history'] = ids[0]
 
241
        val_history['name'] = uid
 
242
        val_history['date'] = time.strftime('%Y-%m-%d %H:%M:%S')
 
243
        val_history['action'] = "--------------------------------  Changed to Canceled  ------------------------------------\n"
 
244
        ait_obj.create(cr, uid, val_history)
 
245
 
 
246
        return True
 
247
 
 
248
 
66
249
OeMedicalAppointment()
 
250
 
 
251
class OeMedicalAppointment_history(osv.Model):
 
252
    _name = 'oemedical.appointment.history'
 
253
 
 
254
    _columns = {
 
255
        'appointment_id_history' :  fields.many2one('oemedical.appointment','History', ondelete='cascade'),
 
256
        'date': fields.datetime(string='Date and Time'),
 
257
        'name': fields.many2one('res.users', string='User', help=''),
 
258
            'action' : fields.text('Action'),
 
259
    }
 
260
    
 
261
    _defaults = {
 
262
                 }
 
263
 
 
264
OeMedicalAppointment_history()
67
265
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: