medic_clinic.py 11 KB

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