medic_clinic.py 9.1 KB

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