-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdoctor_person.py
289 lines (240 loc) · 11.6 KB
/
doctor_person.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# -*- coding: utf-8 -*-
# #############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging
_logger = logging.getLogger(__name__)
from openerp.osv import fields, osv
from openerp.tools.translate import _
import time
import unicodedata
class doctor_professional(osv.osv):
_name = "doctor.professional"
_description = "Information about the healthcare professional"
_rec_name = 'username'
def write(self, cr, uid, ids, vals, context=None):
datos = {'lastname': '', 'surname': '', 'firstname': '', 'middlename': ''}
nombre = ''
if context is None:
context = {}
for professional in self.browse(cr, uid, ids, context=context):
if 'lastname' in vals:
datos['lastname'] = vals['lastname'] or ' '
if 'surname' in vals:
datos['surname'] = vals['surname'] or ' '
if 'firstname' in vals:
datos['firstname'] = vals['firstname'] or ' '
if 'middlename' in vals:
datos['middlename'] = vals['middlename'] or ' '
nombre = "%s %s %s %s" % (datos['lastname'] or professional.lastname, datos['surname'] or professional.surname or '',
datos['firstname'] or professional.firtsname , datos['middlename'] or professional.middlename or '')
vals['nombreUsuario'] = nombre.upper()
return super(doctor_professional, self).write(cr, uid, ids, vals, context=context)
_columns = {
'professional': fields.many2one('res.partner', 'Healthcare Professional', ondelete='cascade',
domain=[('is_company', '=', False)]),
'username': fields.char('Username', size=64, required=True),
'photo': fields.binary('patient'),
'speciality_id': fields.many2one('doctor.speciality', 'Speciality', required=True),
'professional_card': fields.char('Professional card', size=64, required=True),
'authority': fields.char('Authority', size=64, required=True),
'work_phone': fields.char('Work Phone', size=64),
'work_mobile': fields.char('Work Mobile', size=64),
'work_email': fields.char('Work Email', size=240),
'user_id': fields.many2one('res.users', 'User', help='Related user name', required=False, ondelete='cascade'),
'active': fields.boolean('Active'),
'procedures_ids': fields.many2many('product.product', id1='professional_ids', id2='procedures_ids',
string='My health procedures', required=False, ondelete='restrict'),
}
_defaults = {
'active': lambda *a: 1,
}
def name_get(self, cr, uid, ids, context={}):
if not len(ids):
return []
rec_name = 'professional'
res = [(r['id'], r[rec_name][1])
for r in self.read(cr, uid, ids, [rec_name], context)]
return res
def onchange_photo(self, cr, uid, ids, professional, photo, context=None):
values = {}
if not professional:
return values
professional_data = self.pool.get('res.partner').browse(cr, uid, professional, context=context)
professional_img = professional_data.image_medium
values.update({
'photo': professional_img,
})
return {'value': values}
def onchange_user(self, cr, uid, ids, user_id, context=None):
work_email = False
if user_id:
work_email = self.pool.get('res.users').browse(cr, uid, user_id, context=context).email
return {'value': {'work_email': work_email}}
def onchange_username(self, cr, uid, ids, username, context=None):
if self.pool.get('res.users').search(cr, uid, [('login', '=', username),], context):
return {'value': {'username': False,}, 'warning': {'title': 'The username exists', 'message': "Please change the username"}}
else:
user_id = self.pool.get('res.users').create(cr, uid, {'login': username, 'name': username})
return {'value': {'user_id': user_id, },}
doctor_professional()
class doctor_patient(osv.osv):
_name = "doctor.patient"
_description = "Information about the patient"
def write(self, cr, uid, ids, vals, context=None):
datos = {'lastname': '', 'surname': '', 'firstname': '', 'middlename': ''}
nombre = ''
u = {}
if context is None:
context = {}
for patient in self.browse(cr, uid, ids, context=context):
partner_id = patient.patient
if 'birth_date' in vals:
birth_date = vals['birth_date']
current_date = time.strftime('%Y-%m-%d')
if birth_date > current_date:
raise osv.except_osv(_('Warning !'), _("Birth Date Can not be a future date "))
if 'lastname' in vals:
datos['lastname'] = vals['lastname'] or ' '
if 'surname' in vals:
datos['surname'] = vals['surname'] or ' '
if 'firstname' in vals:
datos['firstname'] = vals['firstname'] or ' '
if 'middlename' in vals:
datos['middlename'] = vals['middlename'] or ' '
if (('lastname' in vals) or ('surname' in vals) or ('firstname' in vals) or ('middlename' in vals)):
nombre = "%s %s %s %s" % (datos['lastname'] or patient.lastname, datos['surname'] or patient.surname or '',
datos['firstname'] or patient.firstname , datos['middlename'] or patient.middlename or '')
firstname = vals['firstname'] if 'firstname' in vals else partner_id.firtsname
lastname = vals['lastname'] if 'lastname' in vals else partner_id.lastname
surname = vals['surname'] if 'surname' in vals else partner_id.surname
middlename = vals['middlename'] if 'middlename' in vals else partner_id.middlename
u['name'] = unicodedata.normalize('NFKD', nombre.decode('utf-8')).encode('ASCII', 'ignore').upper()
u['display_name'] = unicodedata.normalize('NFKD', nombre.decode('utf-8')).encode('ASCII', 'ignore').upper()
vals['nombre'] = unicodedata.normalize('NFKD', nombre.decode('utf-8')).encode('ASCII', 'ignore').upper()
if 'ref' in vals:
u['ref'] = vals['ref']
if 'firstname' in vals:
if(type(firstname) is unicode):
u['firtsname'] = unicodedata.normalize('NFKD', firstname).encode('ASCII', 'ignore').upper()
elif(type(firstname) is str):
u['firtsname'] = firstname.upper()
else:
u['firtsname'] = ' '
if 'lastname' in vals:
if(type(lastname) is unicode):
u['lastname'] = unicodedata.normalize('NFKD', lastname).encode('ASCII', 'ignore').upper()
elif(type(lastname) is str):
u['lastname'] = lastname.upper()
else:
u['lastname'] = ' '
if 'surname' in vals:
if(type(surname) is unicode):
u['surname'] = unicodedata.normalize('NFKD', surname).encode('ASCII', 'ignore').upper()
elif(type(surname) is str) :
u['surname'] = surname.upper()
else:
u['surname'] = ' '
if 'middlename' in vals:
if(type(middlename) is unicode):
u['middlename'] = unicodedata.normalize('NFKD', middlename).encode('ASCII', 'ignore').upper()
elif(type(middlename) is str):
u['middlename'] = middlename.upper()
else:
u['middlename'] = ' '
if 'nombre' in vals:
id_partner = self.search(cr, uid, [('id', '=', ids[0])], context=context)
if id_partner:
for partner in self.browse(cr, uid, id_partner, context=context):
id_partner = partner.patient.id
self.pool.get('res.partner').write(cr, uid, id_partner, u, context=context)
return super(doctor_patient, self).write(cr, uid, ids, vals, context=context)
def create(self, cr, uid, vals, context=None):
if 'birth_date' in vals:
birth_date = vals['birth_date']
current_date = time.strftime('%Y-%m-%d')
if birth_date > current_date:
raise osv.except_osv(_('Warning !'), _("Birth Date Can not be a future date "))
if vals['middlename']:
vals.update({'middlename': vals['middlename'].upper() })
if vals['surname']:
vals.update({'surname': vals['surname'].upper() })
vals.update({'lastname': vals['lastname'].upper() })
vals.update({'firstname': vals['firstname'].upper() })
vals.update({'name' : "%s %s %s %s" % (vals['lastname'] , vals['surname'] or '' , vals['firstname'] , vals['middlename'] or '')})
vals.update({'nombre' : vals['name'].upper()})
if not vals['es_profesionalsalud']:
id_tercero = self.pool.get('res.partner').create(cr, uid, {'ref': vals['ref'], 'tdoc': vals['tdoc'], 'middlename' : vals['middlename'] or '', 'surname' : vals['surname'] or '', 'lastname': vals['lastname'], 'firtsname': vals['firstname'], 'name': vals['name'], 'image': vals['photo'], 'city_id': vals['city_id'], 'state_id': vals['state_id'], 'street': vals['street'], 'phone': vals['telefono'], 'mobile': vals['movil'], 'email': vals['email'],'es_paciente': True, 'es_profesional_salud': False}, context)
vals.update({'patient' : id_tercero}) #una vez creamos el tercero podemos añadir el partner al campo patient.
else:
partner_id = self.pool.get('res.partner').search(cr, uid, [('ref','=', vals['ref'])])
self.pool.get('res.partner').write(cr, uid, partner_id, {'es_paciente': True}, context=context)
return super(doctor_patient, self).create(cr, uid, vals, context=context)
def _get_profesional_id(self, cr, uid, ids, field_name, arg, context=None):
res = {}
for datos in self.browse(cr, uid, ids):
doctor_id = self.pool.get('doctor.professional').search(cr,uid,[('user_id','=',uid)],context=context)
if doctor_id:
res[datos.id] = doctor_id[0]
else:
res[datos.id] = False
return res
_columns = {
'patient': fields.many2one('res.partner', 'Paciente', ondelete='cascade',
domain=[('is_company', '=', False)]),
'firstname' : fields.char('Primer Nombre', size=15, required=True),
'middlename' : fields.char('Segundo Nombre', size=15),
'lastname' : fields.char('Primer Apellido', size=15, required=True),
'surname' : fields.char('Segundo Apellido', size=15),
'photo': fields.binary('patient'),
'birth_date': fields.date('Date of Birth', required=True),
'sex': fields.selection([('m', 'Male'), ('f', 'Female'), ], 'Sex', select=True, required=True),
'blood_type': fields.selection([('A', 'A'), ('B', 'B'), ('AB', 'AB'), ('O', 'O'), ], 'Blood Type'),
'rh': fields.selection([('+', '+'), ('-', '-'), ], 'Rh'),
'insurer': fields.many2one('doctor.insurer', 'Insurer', required=False, help='Insurer'),
'deceased': fields.boolean('Deceased', help="Mark if the patient has died"),
'death_date': fields.date('Date of Death'),
'death_cause': fields.many2one('doctor.diseases', 'Cause of Death'),
'attentions_ids': fields.one2many('doctor.attentions', 'patient_id', 'Attentions'),
'appointments_ids': fields.one2many('doctor.appointment', 'patient_id', 'Attentions'),
'get_professional_id': fields.function(_get_profesional_id, type="integer", store= False,
readonly=True, method=True),
}
def name_get(self,cr,uid,ids,context=None):
if context is None:
context = {}
if not ids:
return []
if isinstance(ids,(long,int)):
ids=[ids]
res=[]
for record in self.browse(cr,uid,ids):
res.append((record['id'],record.nombre or ''))
return res
def onchange_patient_data(self, cr, uid, ids, patient, photo, context=None):
values = {}
if not patient:
return values
patient_data = self.pool.get('res.partner').browse(cr, uid, patient, context=context)
patient_img = patient_data.image_medium
values.update({
'photo': patient_img,
})
return {'value': values}
doctor_patient()