Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- ##############################################################################
- #
- # GNU Health: The Free Health and Hospital Information System
- # Copyright (C) 2008-2016 Luis Falcon <lfalcon@gnusolidario.org>
- # Copyright (C) 2011-2016 GNU Solidario <health@gnusolidario.org>
- #
- # Copyright (C) 2011 Adrián Bernardi, Mario Puntin (health_invoice)
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- ##############################################################################
- import datetime
- from trytond.model import ModelView, ModelSQL, fields, ModelSingleton, Unique
- from trytond.pyson import Eval, Equal
- from trytond.pool import Pool
- from boto.mws.response import Product
- __all__ = ['GnuHealthSequences', 'HealthPracticas', 'HealthPracticasLine']
- class GnuHealthSequences(ModelSingleton, ModelSQL, ModelView):
- "Standard Sequences for GNU Health"
- __name__ = "gnuhealth.sequences"
- health_practicas_sequence = fields.Property(fields.Many2One('ir.sequence',
- 'Health Practicas Sequence', domain=[
- ('code', '=', 'gnuhealth.health_practicas')
- ], required=True))
- class HealthPracticas(ModelSQL, ModelView):
- 'Health Practicas'
- __name__ = 'gnuhealth.health_practicas'
- STATES = {'readonly': Eval('state') == 'invoiced'}
- name = fields.Char('ID', readonly=True)
- desc = fields.Char('Description')
- patient = fields.Many2One('gnuhealth.patient',
- 'Patient', required=True,
- states=STATES)
- institution = fields.Many2One('gnuhealth.institution', 'Institution')
- practica_date = fields.Date('Date')
- practica_line = fields.One2Many('gnuhealth.health_practicas.line',
- 'name', 'Practice Line', help="Practicas Medicas")
- state = fields.Selection([
- ('draft', 'Draft'),
- ('invoiced', 'Invoiced'),
- ], 'State', readonly=True)
- appointment = fields.Many2One('gnuhealth.appointment', 'Appointment',
- help='Ingrese la consulta o ID de Consulta vinculada a esta Practica')
- healthprof = fields.Many2One(
- 'gnuhealth.healthprofessional', 'Health Prof',
- select=True, help='Health Professional')
- speciality = fields.Many2One(
- 'gnuhealth.specialty', 'Specialty',
- help='Medical Specialty / Sector')
- insurance = fields.Function(fields.Char('Insurance'), 'get_insurance')
- insurancecode = fields.Function(fields.Char('Insurance'), 'get_insurancecode')
- insurancenumber = fields.Function(fields.Char('Insurance'), 'get_insurancenumber')
- @classmethod
- def __setup__(cls):
- super(HealthPracticas, cls).__setup__()
- t = cls.__table__()
- cls._sql_constraints = [
- ('name_unique', Unique(t,t.name),
- 'The Practice ID must be unique'),
- ]
- cls._buttons.update({
- 'button_set_to_draft': {'invisible': Equal(Eval('state'),
- 'draft')}
- })
- @staticmethod
- def default_state():
- return 'draft'
- @staticmethod
- def default_practica_date():
- return datetime.date.today()
- @staticmethod
- def default_institution():
- HealthInst = Pool().get('gnuhealth.institution')
- institution = HealthInst.get_institution()
- return institution
- @classmethod
- @ModelView.button
- def button_set_to_draft(cls, practicas):
- cls.write(practicas, {'state': 'draft'})
- @classmethod
- def create(cls, vlist):
- Sequence = Pool().get('ir.sequence')
- Config = Pool().get('gnuhealth.sequences')
- vlist = [x.copy() for x in vlist]
- for values in vlist:
- if not values.get('name'):
- config = Config(1)
- values['name'] = Sequence.get_id(
- config.health_practicas_sequence.id)
- return super(HealthPracticas, cls).create(vlist)
- def get_insurance(self, name):
- res = ''
- if self.patient.current_insurance:
- res = self.patient.current_insurance.company.name
- return res
- def get_insurancenumber(self, name):
- res = ''
- if self.patient.current_insurance:
- res = self.patient.current_insurance.number
- return res
- def get_insurancecode(self, name):
- res = ''
- if self.patient.current_insurance:
- res = self.patient.current_insurance.company.ref
- return res
- class HealthPracticasLine(ModelSQL, ModelView):
- 'Health Practicas'
- __name__ = 'gnuhealth.health_practicas.line'
- name = fields.Many2One('gnuhealth.health_practicas', 'Practicas',
- readonly=True)
- desc = fields.Char('Description', required=True)
- product = fields.Many2One('product.product', 'Product', required=True)
- codenomenclador = fields.Function(fields.Char('Nomenclador'), 'get_nomenclador')
- tipo = fields.Function(fields.Char('Nomenclador'), 'get_tipo')
- @fields.depends('product', 'desc')
- def on_change_product(self, name=None):
- if self.product:
- self.desc = self.product.name
- def get_nomenclador(self, name):
- res = ''
- pool = Pool()
- if (self.product.product):
- product = self.product.product.nomenclador
- product_id = self.product.id
- product_obj = Pool().get('product.product')
- prod = product_obj.search(
- [('name', '=', product_id)], limit=1)[0]
- if prod.nomenclador:
- nomenclador = prod.nomenclador.codigo
- res = nomenclador
- return res
- def get_tipo(self, name):
- res = ''
- pool = Pool()
- if (self.product.product):
- product = self.product.product.nomenclador
- product_id = self.product.id
- product_obj = Pool().get('product.product')
- prod = product_obj.search(
- [('name', '=', product_id)], limit=1)[0]
- if prod.nomenclador:
- tipo_nomenclador = prod.nomenclador.tipo
- res = tipo_nomenclador
- return res
Add Comment
Please, Sign In to add comment