Advertisement
Guest User

Untitled

a guest
Jul 14th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.84 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # GNU Health: The Free Health and Hospital Information System
  5. # Copyright (C) 2008-2016 Luis Falcon <lfalcon@gnusolidario.org>
  6. # Copyright (C) 2011-2016 GNU Solidario <health@gnusolidario.org>
  7. #
  8. # Copyright (C) 2011 Adrián Bernardi, Mario Puntin (health_invoice)
  9. #
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation, either version 3 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. ##############################################################################
  24. import datetime
  25. from trytond.model import ModelView, ModelSQL, fields, ModelSingleton, Unique
  26. from trytond.pyson import Eval, Equal
  27. from trytond.pool import Pool
  28. from boto.mws.response import Product
  29.  
  30.  
  31. __all__ = ['GnuHealthSequences', 'HealthPracticas', 'HealthPracticasLine']
  32.  
  33.  
  34. class GnuHealthSequences(ModelSingleton, ModelSQL, ModelView):
  35. "Standard Sequences for GNU Health"
  36. __name__ = "gnuhealth.sequences"
  37.  
  38. health_practicas_sequence = fields.Property(fields.Many2One('ir.sequence',
  39. 'Health Practicas Sequence', domain=[
  40. ('code', '=', 'gnuhealth.health_practicas')
  41. ], required=True))
  42.  
  43.  
  44. class HealthPracticas(ModelSQL, ModelView):
  45. 'Health Practicas'
  46. __name__ = 'gnuhealth.health_practicas'
  47.  
  48. STATES = {'readonly': Eval('state') == 'invoiced'}
  49.  
  50. name = fields.Char('ID', readonly=True)
  51. desc = fields.Char('Description')
  52. patient = fields.Many2One('gnuhealth.patient',
  53. 'Patient', required=True,
  54. states=STATES)
  55. institution = fields.Many2One('gnuhealth.institution', 'Institution')
  56.  
  57. practica_date = fields.Date('Date')
  58. practica_line = fields.One2Many('gnuhealth.health_practicas.line',
  59. 'name', 'Practice Line', help="Practicas Medicas")
  60. state = fields.Selection([
  61. ('draft', 'Draft'),
  62. ('invoiced', 'Invoiced'),
  63. ], 'State', readonly=True)
  64. appointment = fields.Many2One('gnuhealth.appointment', 'Appointment',
  65. help='Ingrese la consulta o ID de Consulta vinculada a esta Practica')
  66.  
  67. healthprof = fields.Many2One(
  68. 'gnuhealth.healthprofessional', 'Health Prof',
  69. select=True, help='Health Professional')
  70.  
  71. speciality = fields.Many2One(
  72. 'gnuhealth.specialty', 'Specialty',
  73. help='Medical Specialty / Sector')
  74.  
  75. insurance = fields.Function(fields.Char('Insurance'), 'get_insurance')
  76.  
  77. insurancecode = fields.Function(fields.Char('Insurance'), 'get_insurancecode')
  78.  
  79. insurancenumber = fields.Function(fields.Char('Insurance'), 'get_insurancenumber')
  80.  
  81.  
  82. @classmethod
  83. def __setup__(cls):
  84. super(HealthPracticas, cls).__setup__()
  85.  
  86. t = cls.__table__()
  87. cls._sql_constraints = [
  88. ('name_unique', Unique(t,t.name),
  89. 'The Practice ID must be unique'),
  90. ]
  91. cls._buttons.update({
  92. 'button_set_to_draft': {'invisible': Equal(Eval('state'),
  93. 'draft')}
  94. })
  95.  
  96. @staticmethod
  97. def default_state():
  98. return 'draft'
  99.  
  100. @staticmethod
  101. def default_practica_date():
  102. return datetime.date.today()
  103.  
  104. @staticmethod
  105. def default_institution():
  106. HealthInst = Pool().get('gnuhealth.institution')
  107. institution = HealthInst.get_institution()
  108. return institution
  109.  
  110. @classmethod
  111. @ModelView.button
  112. def button_set_to_draft(cls, practicas):
  113. cls.write(practicas, {'state': 'draft'})
  114.  
  115. @classmethod
  116. def create(cls, vlist):
  117. Sequence = Pool().get('ir.sequence')
  118. Config = Pool().get('gnuhealth.sequences')
  119.  
  120. vlist = [x.copy() for x in vlist]
  121. for values in vlist:
  122. if not values.get('name'):
  123. config = Config(1)
  124. values['name'] = Sequence.get_id(
  125. config.health_practicas_sequence.id)
  126. return super(HealthPracticas, cls).create(vlist)
  127.  
  128.  
  129. def get_insurance(self, name):
  130. res = ''
  131. if self.patient.current_insurance:
  132. res = self.patient.current_insurance.company.name
  133. return res
  134.  
  135. def get_insurancenumber(self, name):
  136. res = ''
  137. if self.patient.current_insurance:
  138. res = self.patient.current_insurance.number
  139. return res
  140.  
  141. def get_insurancecode(self, name):
  142. res = ''
  143. if self.patient.current_insurance:
  144. res = self.patient.current_insurance.company.ref
  145. return res
  146.  
  147.  
  148.  
  149. class HealthPracticasLine(ModelSQL, ModelView):
  150. 'Health Practicas'
  151. __name__ = 'gnuhealth.health_practicas.line'
  152.  
  153. name = fields.Many2One('gnuhealth.health_practicas', 'Practicas',
  154. readonly=True)
  155. desc = fields.Char('Description', required=True)
  156.  
  157. product = fields.Many2One('product.product', 'Product', required=True)
  158.  
  159. codenomenclador = fields.Function(fields.Char('Nomenclador'), 'get_nomenclador')
  160.  
  161. tipo = fields.Function(fields.Char('Nomenclador'), 'get_tipo')
  162.  
  163.  
  164. @fields.depends('product', 'desc')
  165. def on_change_product(self, name=None):
  166. if self.product:
  167. self.desc = self.product.name
  168.  
  169.  
  170. def get_nomenclador(self, name):
  171. res = ''
  172. pool = Pool()
  173. if (self.product.product):
  174. product = self.product.product.nomenclador
  175. product_id = self.product.id
  176.  
  177. product_obj = Pool().get('product.product')
  178. prod = product_obj.search(
  179. [('name', '=', product_id)], limit=1)[0]
  180. if prod.nomenclador:
  181. nomenclador = prod.nomenclador.codigo
  182. res = nomenclador
  183.  
  184. return res
  185.  
  186.  
  187. def get_tipo(self, name):
  188. res = ''
  189. pool = Pool()
  190. if (self.product.product):
  191. product = self.product.product.nomenclador
  192. product_id = self.product.id
  193.  
  194. product_obj = Pool().get('product.product')
  195. prod = product_obj.search(
  196. [('name', '=', product_id)], limit=1)[0]
  197. if prod.nomenclador:
  198. tipo_nomenclador = prod.nomenclador.tipo
  199. res = tipo_nomenclador
  200.  
  201. return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement