-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdoctor_doctor.py
295 lines (212 loc) · 8.31 KB
/
doctor_doctor.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
290
291
292
293
294
295
# -*- 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
from openerp.osv import fields, osv;
from datetime import datetime, timedelta, date
from dateutil import parser
from dateutil import rrule
from dateutil.relativedelta import relativedelta
import time
import re
import pytz
import math
import copy
from openerp.tools.translate import _
from openerp import SUPERUSER_ID, tools
import urllib
import urllib2
_logger = logging.getLogger(__name__)
class doctor(osv.osv):
_name = 'doctor.doctor'
_columns = {
'test': fields.char('test')
}
def fecha_UTC(self,fecha_usuario,context=None):
if not context:
context = {}
#Obtener TimeZone Usuario
tz = context.get('tz','America/Bogota')
if not tz:
raise osv.except_osv(_('Zona Horaria - Clinica Digital'),
_('Por favor configure su zona horaria para acceder a esta funcionalidad del sistema o solicite soporte.'))
#Formato
localFormat = "%Y-%m-%d %H:%M:%S"
fecha_sin_tz = datetime.strptime(fecha_usuario, localFormat)
tz_usuario = pytz.timezone(tz)
fecha_tz = tz_usuario.localize(fecha_sin_tz)
fecha_con_utc = fecha_tz.astimezone(pytz.utc)
fecha_utc = fecha_con_utc.strftime(localFormat)
return fecha_utc
def _date_to_dateuser(self, cr, uid, date_begin):
date_begin_user = datetime.strptime(date_begin, "%Y-%m-%d %H:%M:%S")
user = self.pool.get('res.users').browse(cr, uid, uid)
tz = pytz.timezone(user.tz) if user.tz else pytz.utc
date_begin_user = pytz.utc.localize(date_begin_user).astimezone(tz)
date_begin_user = datetime.strftime(date_begin_user, "%Y-%m-%d %H:%M:%S")
return date_begin_user
def modulo_instalado(self, cr, uid, nombre_modulo,context=None):
modulo_instalado = self.pool.get('ir.module.module').search(cr,uid,[('name', '=', nombre_modulo), ('state', '=', 'installed')],context=context)
if modulo_instalado:
return True
return False
def company_nombre(self, cr, uid, context=None):
if not context:
context = {}
nombre_compania = self.pool.get("res.users").browse(cr, uid, uid, context=context).company_id.name
return nombre_compania
def finalidad_consulta_db(self, cr, uid, context=None):
finalidad_consulta = '10'
# if cr.dbname == 'DraConstanzaCastilla':
# finalidad_consulta = '04'
# if cr.dbname == 'Tomatis':
# finalidad_consulta = '10'
# if cr.dbname == 'DrCaceres':
# finalidad_consulta = '08'
return finalidad_consulta
def causa_externa(self, cr, uid, context=None):
causa_externa='13'
if cr.dbname == 'Tomatis':
causa_externa='15'
return causa_externa
def fecha_utc(self, cr, uid, time_begin):
time_begin_user = datetime.strptime(time_begin, "%Y-%m-%d %H:%M:%S")
user = self.pool.get('res.users').browse(cr, uid, uid)
tz = pytz.timezone(user.tz) if user.tz else pytz.utc
time_begin_user = pytz.utc.localize(time_begin_user).astimezone(tz)
time_begin_user = datetime.strftime(time_begin_user, "%Y-%m-%d %H:%M:%S")
return time_begin_user
def _model_default_get(self, cr, uid, model=False, fields=False, context=None):
"""
Retornar id de registro segun modelo
@param model: Modelo donde se encuentra el registro
@param fields: Condicionadores para encontrar registro ej. [ ('name', '=', 'ARMENIA') ]
@return: id registro
"""
if not context:
context = {}
#_logger.info('Object = %s' , model)
#_logger.info('field = %s' , fields)
objectPool = self.pool.get(model)
#Proceder a buscar el dato si, el modelo Existe
if objectPool:
objectSearch = objectPool.search(cr, uid,fields)
objectBrowse = self.pool.get(model).browse(cr,uid,objectSearch)
if objectBrowse:
idObject = 0
for obj in objectBrowse:
idObject = obj.id
return idObject
else:
return None
else :
_logger.warning('No se encontro el modelo (%s) , no se retornara el ID' , model)
return None
def tipo_documento(self, tipo):
nombre_tipo = None
if tipo == '13':
nombre_tipo = 'CC'
elif tipo == '11':
nombre_tipo = 'RC'
elif tipo == '12':
nombre_tipo = 'TI'
elif tipo == '21':
nombre_tipo = 'CE'
elif tipo == '41':
nombre_tipo = 'Pasaporte'
elif tipo == 'AS':
nombre_tipo = 'AS'
elif tipo == 'MS':
nombre_tipo = 'MS'
return nombre_tipo
def obtener_ultimas_atenciones_paciente(self, cr, uid, modelo_buscar, tiempo, paciente, fecha_atencion, context=None):
if modelo_buscar:
fecha_cita = datetime.strptime(fecha_atencion, "%Y-%m-%d %H:%M:%S")
fecha_atencion_horas_menos = fecha_cita - timedelta(hours=tiempo)
_logger.info("############################################")
_logger.info(fecha_cita)
_logger.info(fecha_atencion_horas_menos)
ids_atenciones = self.pool.get(modelo_buscar).search(cr, uid, [('patient_id', '=', paciente),
('date_attention', '>=', str(fecha_atencion_horas_menos)),
('date_attention', '<=', str(fecha_cita)),
('origin', '<>', None)], context=context)
if ids_atenciones:
_logger.info("Entra para saber si hay atenciones")
_logger.info(ids_atenciones)
raise osv.except_osv(_('ATENCION !!!'),_('El paciente ya fue atendido por otro profesional en la salud refresque la ventana'))
#_logger.info('asasasasas')
def tipo_historia(self, modelo):
if modelo == 'doctor_psychology':
return 'doctor.psicologia'
if modelo == 'doctor_control':
return 'doctor.hc.control'
if modelo == 'doctor_dental_care':
return 'doctor.hc.odontologia'
if modelo == 'doctor_biological_risk':
return 'doctor.atencion.ries.bio'
if modelo == 'doctor' or modelo == '10n_co_doctor':
return 'doctor.attentions'
#Eliminando espacios
def eliminar_antecedentes_vacios(self, cr, uid):
#Eliminando espacios vacios de revision por sistemas
review_systems_ids= self.pool.get('doctor.review.systems').search(cr, uid, [])
if review_systems_ids:
for x in self.pool.get('doctor.review.systems').browse(cr, uid, review_systems_ids):
if x.review_systems == False:
self.pool.get('doctor.review.systems').unlink(cr, uid, x.id)
#Eliminando espacios vacios de antecedentes
past_ids= self.pool.get('doctor.attentions.past').search(cr, uid, [])
if past_ids:
for x in self.pool.get('doctor.attentions.past').browse(cr, uid, past_ids):
if x.past == False:
self.pool.get('doctor.attentions.past').unlink(cr, uid, x.id)
return True
#funcion para retornar la posicion del carater
def return_position_character(self, cadena, inicial, final):
position=0
for x in range(final,inicial, -1):
if cadena[x] == ' ':
position= x
break;
return position + 1
def validation_text_large(self, cadena):
tamanio=200
data_text=[]
aux_tamanio= 0
cadena= cadena.encode('utf-8')
if cadena:
if len(cadena) >= 300:
while tamanio <= len(cadena):
position=self.return_position_character(cadena, aux_tamanio, tamanio)
data_text.append(str(cadena[aux_tamanio:position]))
aux_tamanio=position
tamanio= 200 + aux_tamanio
if (tamanio+200) > len(cadena):
break;
else:
data_text.append(str(cadena))
else:
data_text.append("")
return data_text
def doctor_validate_group(self, cr, uid, permission, type_message, message):
if permission:
permission='l10n_co_doctor.' + permission
if self.pool['res.users'].has_group(cr, uid, permission) == False:
raise osv.except_osv(_('Lo Sentimos!'),_('Para poder %s %s, debera tener el permiso necesario para esta acción \n Ponganse en contacto con el administrador') %(type_message, message))