forked from hivam/doctor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoctor_person.py
151 lines (132 loc) · 6.77 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
# -*- 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/>.
#
##############################################################################
from openerp.osv import fields, osv
from openerp.tools.translate import _
import time
class doctor_professional(osv.osv):
_inherits = {
'res.users': 'user_id',
}
_name = "doctor.professional"
_description = "Information about the healthcare professional"
_rec_name = 'professional'
_columns = {
'professional': fields.many2one('res.partner', 'Healthcare Professional', required=True, ondelete='restrict',
domain=[('is_company', '=', False)]),
'username': fields.char('Username', size=64, required=True),
'photo': fields.related('professional', 'image_medium', type="binary", relation="res.partner", readonly=True),
'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=True, ondelete='restrict'),
'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"
_rec_name = 'patient'
def write(self, cr, uid, ids, vals, context=None):
if context is None:
context = {}
for patient in self.browse(cr, uid, ids, context=context):
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 "))
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 "))
return super(doctor_patient, self).create(cr, uid, vals, context=context)
_columns = {
'patient': fields.many2one('res.partner', 'Patient', required=True, ondelete='restrict',
domain=[('is_company', '=', False)]),
'photo': fields.related('patient', 'image_medium', type="binary", relation="res.partner", readonly=True),
'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'),
}
def name_get(self, cr, uid, ids, context={}):
if not len(ids):
return []
rec_name = 'patient'
res = [(r['id'], r[rec_name][1])
for r in self.read(cr, uid, ids, [rec_name], context)]
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()