forked from hivam/doctor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doctor_data.py
187 lines (143 loc) · 6.31 KB
/
doctor_data.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
# -*- 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 _
class doctor_speciality(osv.osv):
_name = "doctor.speciality"
_columns = {
'code': fields.char('Code', size=3, required=True),
'name': fields.char('Speciality', size=64, required=True),
}
_sql_constraints = [('code_uniq', 'unique (code)', 'The Medical Speciality code must be unique')]
doctor_speciality()
class doctor_insurer(osv.osv):
_name = "doctor.insurer"
_rec_name = 'insurer'
_columns = {
'insurer': fields.many2one('res.partner', 'Insurer', help='Insurer'),
'code': fields.char('Code', size=6, required=True),
}
def name_get(self, cr, uid, ids, context={}):
if not len(ids):
return []
rec_name = 'insurer'
res = [(r['id'], r[rec_name][1])
for r in self.read(cr, uid, ids, [rec_name], context)]
return res
_sql_constraints = [('code_uniq', 'unique (code)', 'The insurer code must be unique')]
doctor_insurer()
class doctor_pharmaceutical_form(osv.osv):
_name = "doctor.pharmaceutical.form"
_columns = {
'code': fields.char('Code', size=10, required=True),
'name': fields.char('Pharmaceutical form', size=128, required=True),
}
_sql_constraints = [('code_uniq', 'unique (code)', 'The Pharmaceutical Form code must be unique')]
doctor_pharmaceutical_form()
class doctor_dose_unit(osv.osv):
_name = "doctor.dose.unit"
_columns = {
'code': fields.char('Abbreviation', size=10, required=True),
'name': fields.char('Dosage unit', size=128, required=True),
}
_sql_constraints = [('code_uniq', 'unique (code)', 'The Dose code must be unique')]
def name_get(self, cr, uid, ids, context={}):
if not len(ids):
return []
reads = self.read(cr, uid, ids, ['name', 'code'], context)
res = []
for record in reads:
name = record['name']
if record['code']:
name = record['code'] + ' - ' + name
res.append((record['id'], name))
return res
doctor_dose_unit()
class doctor_administration_route(osv.osv):
_name = "doctor.administration.route"
_columns = {
'code': fields.char('Code', size=10, required=True),
'name': fields.char('Administration route', size=128, required=True),
}
_sql_constraints = [('code_uniq', 'unique (code)', 'The Administration Route code must be unique')]
doctor_administration_route()
class doctor_measuring_unit(osv.osv):
_name = "doctor.measuring.unit"
_columns = {
'code': fields.char('Code', size=10, required=True),
'name': fields.char('Measuring unit', size=128, required=True),
}
_sql_constraints = [('code_uniq', 'unique (code)', 'The Measuring unit code must be unique')]
doctor_measuring_unit()
class doctor_drugs(osv.osv):
_name = "doctor.drugs"
_rec_name = 'atc_id'
_columns = {
'code': fields.char('Code', size=10, required=True),
'atc_id': fields.many2one('doctor.atc', 'ATC', required=True, ondelete='restrict'),
'pharmaceutical_form': fields.many2one('doctor.pharmaceutical.form', 'Pharmaceutical form', required=True,
ondelete='restrict'),
'drugs_concentration': fields.char('Drugs concentration', size=64, required=True),
'administration_route': fields.many2one('doctor.administration.route', 'Administration route', required=True,
ondelete='restrict'),
}
def name_get(self, cr, uid, ids, context={}):
if not len(ids):
return []
reads = self.read(cr, uid, ids,
['atc_id', 'pharmaceutical_form', 'drugs_concentration', 'administration_route'], context)
res = []
for record in reads:
name = record['atc_id'][1]
if record['pharmaceutical_form'] and record['drugs_concentration'] and record['administration_route']:
name = name + ' (' + record['drugs_concentration'] + ' - ' + record['pharmaceutical_form'][1] + ' - ' + \
record['administration_route'][1] + ')'
res.append((record['id'], name))
return res
doctor_drugs()
class doctor_atc(osv.osv):
_name = "doctor.atc"
_columns = {
'code': fields.char('Code', size=7, required=True),
'name': fields.char('Description', size=512, required=True),
}
def name_get(self, cr, uid, ids, context={}):
if not len(ids):
return []
reads = self.read(cr, uid, ids, ['name', 'code'], context)
res = []
for record in reads:
name = record['name']
if record['code']:
name = record['code'] + ' - ' + name
res.append((record['id'], name))
return res
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
args = args or []
ids = []
if name:
ids = self.search(cr, uid, [('code', 'ilike', name)] + args, limit=limit, context=context)
if not ids:
ids = self.search(cr, uid, [('name', operator, name)] + args, limit=limit, context=context)
else:
ids = self.search(cr, uid, args, limit=limit, context=context)
return self.name_get(cr, uid, ids, context)
doctor_atc()