medic_clinic.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. # -*- coding: utf-8 -*-
  2. # License, author and contributors information in:
  3. # __openerp__.py file at the root folder of this module.
  4. from openerp import api, models, fields
  5. from openerp.exceptions import ValidationError, except_orm, Warning, RedirectWarning
  6. import logging
  7. _log = logging.getLogger(__name__)
  8. class MedicClinic(models.Model):
  9. _name = 'clinic.history'
  10. _description = 'Historial clínica médica'
  11. _inherit = ['mail.thread', 'ir.needaction_mixin']
  12. def _get_user(self):
  13. return self.env.uid
  14. def _get_number(self):
  15. return self.env['ir.sequence'].get('clinic.history') or '*'
  16. name = fields.Char(
  17. string=u'Codigo',
  18. readonly=True,
  19. default=_get_number
  20. )
  21. user_id = fields.Many2one(
  22. comodel_name='res.users',
  23. string='Médico',
  24. default=_get_user
  25. )
  26. paramedico_id = fields.Many2one(
  27. comodel_name='res.users',
  28. string='Paramédico',
  29. )
  30. partner_id = fields.Many2one(
  31. comodel_name='res.partner',
  32. string='Seguro'
  33. )
  34. paciente_id = fields.Many2one(
  35. comodel_name='res.partner',
  36. string='Paciente'
  37. )
  38. lugar_visita = fields.Selection([('A domicilio','A domicilio'),('Vía pública','Vía pública'),('Comercio','Comercio'),('Sanatorio','Sanatorio')],'Lugar atendido')
  39. tipo_paciente = fields.Selection([('directivo','Directivo'),('Cliente externo','Cliente externo'),('Trabajador','Trabajador'),('Particular','Particular'),('Otros','Otros')],'Tipo de paciente')
  40. line_ids = fields.One2many(
  41. comodel_name='clinic.history.line',
  42. inverse_name='clinichistory_id',
  43. string='Trabajos hechos'
  44. )
  45. uso_gel = fields.Selection([('si','Sí'),('no','No')],'Uso alcohol en gel?')
  46. # consumed_ids = fields.One2many(
  47. # comodel_name='clinic.history.consumed',
  48. # inverse_name='clinichistory_id ',
  49. # string='Productos y Servicios consumidos'
  50. # )
  51. order_date = fields.Datetime(
  52. string='Fecha de Carga',
  53. default=fields.Datetime.now
  54. )
  55. planned_start_date = fields.Datetime(
  56. string='Fecha y hora de Recepción'
  57. )
  58. planned_end_date = fields.Datetime(
  59. string='Fecha y hora de Atención'
  60. )
  61. programado = fields.Selection([('Programado','Programado')],'Programado')
  62. name_movil = fields.Char(
  63. string='Móvil'
  64. )
  65. edad_paciente = fields.Char(
  66. string='Edad'
  67. )
  68. antig_trabajo = fields.Char(
  69. string='Antiguedad'
  70. )
  71. at_base = fields.Char(
  72. string='At. Base'
  73. )
  74. nro_salida = fields.Char(
  75. string='N° de Salida'
  76. )
  77. seguro = fields.Char(
  78. string='Seguro'
  79. )
  80. nro_socio = fields.Char(
  81. string='N° de Socio'
  82. )
  83. alergico = fields.Selection([('Si','Sí'),('No','No')],'Alérgico?')
  84. respuesta_tratamiento = fields.Selection([('Mejora','Mejora'),('Sin cambios','Sin cambios'),('Desmejora','Desmejora')],'Respuesta al Tratamiento:')
  85. tipo_alergico = fields.Char(
  86. string='Alérgico a:'
  87. )
  88. embarazada = fields.Selection([('Si','Sí'),('No','No')],'Embarazada?')
  89. ost = fields.Boolean(string='OST' ,default = False)
  90. asm = fields.Boolean(string='ASM' ,default = False)
  91. card = fields.Boolean(string='CARD' ,default = False)
  92. acv = fields.Boolean(string='ACV' ,default = False)
  93. conv = fields.Boolean(string='CONV' ,default = False)
  94. hta = fields.Boolean(string='HTA' ,default = False)
  95. epoc = fields.Boolean(string='EPOC' ,default = False)
  96. otro = fields.Boolean(string='Otros' ,default = False)
  97. # antecedente_paciente = fields.Selection([('ost','OST'),('asm','ASM'),('card','CARD'),('acv','ACV'),('conv','CONV'),('hta','HTA'),('epoc','EPOC'),('otros','Otros')],'Antecedente')
  98. # antecedente_paciente = fields.Many2many('res.partner.category', string="many2many_tags")
  99. pa = fields.Char(
  100. string='P.A.'
  101. )
  102. fc = fields.Char(
  103. string='F.C.'
  104. )
  105. fr = fields.Char(
  106. string='F.R.'
  107. )
  108. temp = fields.Char(
  109. string='T.'
  110. )
  111. so = fields.Char(
  112. string='SO.'
  113. )
  114. hgt = fields.Char(
  115. string='HGT'
  116. )
  117. motivo = fields.Text(
  118. string='Motivo de la consulta'
  119. )
  120. diagnostic = fields.Text(
  121. string='Hallazgo Positivo'
  122. )
  123. indicacion = fields.Text(
  124. string='Indicación Médica'
  125. )
  126. # actions = fields.Text(
  127. # string='Insumos utilizados'
  128. # )
  129. insumos_ids = fields.One2many(
  130. comodel_name='clinic.insumos.line',
  131. inverse_name='clinichistory_id',
  132. string='Insumos Utilizados'
  133. )
  134. recommendations = fields.Text(
  135. string="Tratamiento Administrado"
  136. )
  137. epicrisis = fields.Char(
  138. string='Epicrisis'
  139. )
  140. presuntivo = fields.Char(
  141. string='Diagnóstico Presuntivo'
  142. )
  143. clasificacion = fields.Selection([('Emergencia','Emergencia'),('Urgencia','Urgencia'),('Consulta','Consulta'),('Suministro','Suministro'),('T.A.R','T.A.R'),('tbr','T.B.R')],'Clasificación de la Atención')
  144. informado = fields.Char(
  145. string='Informado a:'
  146. )
  147. entregado = fields.Char(
  148. string='Entrega de paciente a:'
  149. )
  150. signature_image_paramedico= fields.Binary(string='Firma Paramédico')
  151. signature_image_medico= fields.Binary(string='Firma Médico')
  152. signature_image_paciente = fields.Binary(string='Firma Paciente o Responsable')
  153. state = fields.Selection([
  154. ('draft', 'Programado'),
  155. ('redraft', 'Reprogramado'),
  156. ('in_progress', 'En progreso'),
  157. ('done', 'Hecho'),
  158. ('canceled', 'Cancelado')],
  159. string='Estado',
  160. default='draft'
  161. )
  162. # invoicehistory_ids = fields.One2many('account.invoice', 'clinichistory_invoice_id')
  163. # invoicehistory_count = fields.Integer(
  164. # string='Facturas',
  165. # compute='_get_invoice_count',
  166. # )
  167. # if self.invoicehistory_count > 0:
  168. # raise Warning('Este trabajo tiene una factura asociada')
  169. # if self.invoicehistory_count == 0:
  170. # for history in self:
  171. # history.write({'state': 'draft'})
  172. # return True
  173. #
  174. # @api.one
  175. # @api.depends('invoicehistory_ids')
  176. # def _get_invoice_count(self):
  177. # self.invoice_counthistory = len(self.invoicehistory_ids)
  178. @api.one
  179. def onchange_partner_id(self, partner_id):
  180. _log.info('-'*100)
  181. _log.info(partner_id)
  182. @api.one
  183. def button_in_progress(self):
  184. self.state = 'in_progress'
  185. @api.one
  186. def button_redraft(self):
  187. self.state = 'redraft'
  188. @api.one
  189. def button_in_progress_back(self):
  190. self.state = 'draft'
  191. @api.one
  192. def button_done(self):
  193. # product = self.line_ids
  194. works = self.line_ids
  195. if not works:
  196. raise Warning('El trabajo debe tener productos y trabajos asociados')
  197. else:
  198. self.state = 'done'
  199. @api.one
  200. def button_done_back(self):
  201. self.state = 'redraft'
  202. @api.one
  203. def button_redraft_back(self):
  204. self.state = 'in_progress'
  205. @api.one
  206. def button_cancel(self):
  207. self.state = 'canceled'
  208. # @api.multi
  209. # def Facturado(self):
  210. # inv_obj = self.env['account.invoice']
  211. # inv_line_obj = self.env['account.invoice.line']
  212. # customer = self.partner_id
  213. # if not customer.name:
  214. # raise osv.except_osv(_('UserError!'), _('Por favor seleccione el cliente.'))
  215. # company_id = self.env['res.users'].browse(1).company_id
  216. # self.ensure_one()
  217. # ir_values = self.env['ir.values']
  218. # inv_data = {
  219. # 'name': customer.name,
  220. # 'reference': customer.name,
  221. # 'account_id': customer.property_account_receivable.id,
  222. # 'partner_id': customer.id,
  223. # 'origin': self.name,
  224. # 'clinichistory_invoice_id ': self.id
  225. # }
  226. # inv_id = inv_obj.create(inv_data)
  227. # for records in self.consumed_ids:
  228. # if records.product_id.id:
  229. # income_account = records.product_id.categ_id.property_account_income_categ.id
  230. # if not income_account:
  231. # raise osv.except_osv(_('UserError!'), _('No hay cuenta definida '
  232. # 'para este producto: "%s".') % (records.product_id.name,))
  233. # inv_line_data = {
  234. # 'name': records.product_id.name,
  235. # 'account_id': income_account,
  236. # 'price_unit': records.price_unit,
  237. # 'quantity': records.quantity,
  238. # 'product_id': records.product_id.id,
  239. # 'invoice_id': inv_id.id,
  240. # 'invoice_line_tax_id': [(6, 0, [x.id for x in records.product_id.taxes_id])],
  241. # }
  242. # inv_line_obj.create(inv_line_data)
  243. # self.state = 'invoiced'
  244. # imd = self.env['ir.model.data']
  245. # action = imd.xmlid_to_object('account.action_invoice_tree1')
  246. # list_view_id = imd.xmlid_to_res_id('account.invoice_tree')
  247. # form_view_id = imd.xmlid_to_res_id('account.invoice_form')
  248. # result = {
  249. # 'name': action.name,
  250. # 'help': action.help,
  251. # 'type': 'ir.actions.act_window',
  252. # 'views': [[list_view_id, 'tree'], [form_view_id, 'form'], [False, 'graph'], [False, 'kanban'],
  253. # [False, 'calendar'], [False, 'pivot']],
  254. # 'target': action.target,
  255. # 'context': action.context,
  256. # 'res_model': 'account.invoice',
  257. # }
  258. # if len(inv_id) > 1:
  259. # result['domain'] = "[('id','in',%s)]" % inv_id.ids
  260. # elif len(inv_id) == 1:
  261. # result['views'] = [(form_view_id, 'form')]
  262. # result['res_id'] = inv_id.ids[0]
  263. # else:
  264. # result = {'type': 'ir.actions.act_window_close'}
  265. # invoiced_records = self.env['clinic.history']
  266. # total = 0
  267. # self.stage_id = 3
  268. # for rows in invoiced_records:
  269. # invoiced_date = rows.date
  270. # invoiced_date = invoiced_date[0:10]
  271. # if invoiced_date == str(date.today()):
  272. # total = total + rows.price_subtotal
  273. # inv_id.signal_workflow('invoice_open')
  274. # return result
  275. class ClinicHistoryLine(models.Model):
  276. _name = 'clinic.history.line'
  277. _description = 'Trabajos realizados'
  278. _inherit = ['mail.thread', 'ir.needaction_mixin']
  279. clinichistory_id = fields.Many2one(
  280. comodel_name='clinic.history',
  281. string='Clinic History')
  282. product_id = fields.Many2one(
  283. comodel_name='product.product',
  284. string='Servicio'
  285. )
  286. quantity = fields.Float(string='Cantidad', default=1.0)
  287. brand = fields.Char(string='Marca')
  288. number = fields.Char(string="Numero de serie")
  289. class ClinicInsumosLine(models.Model):
  290. _name = 'clinic.insumos.line'
  291. _description = 'Insumos Utilizados'
  292. _inherit = ['mail.thread', 'ir.needaction_mixin']
  293. clinichistory_id = fields.Many2one(
  294. comodel_name='clinic.history',
  295. string='Insumos Clinicos')
  296. product_id = fields.Many2one(
  297. comodel_name='product.product',
  298. string='Insumos'
  299. )
  300. quantity = fields.Float(string='Cantidad', default=1.0)
  301. brand = fields.Char(string='Marca')
  302. number = fields.Char(string="Numero de serie")