medic_clinic.py 9.6 KB

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