C’est un module personnalisé que j’ai crée
Voici sa définition
class GnuHealthPatientExpTest(ModelSQL, ModelView):
'Exp Test Request'
__name__ = 'gnuhealth.patient.exp.test'
name = fields.Many2One(
'gnuhealth.exp.test_type', 'Test Type',
required=True )
date = fields.DateTime('Date' )
state = fields.Selection([
('draft', 'Draft'),
('tested', 'Tested'),
('ordered', 'Ordered'),
('cancel', 'Cancel'),
], 'State', readonly=True )
source_type = fields.Selection([
('patient', 'Patient'),
('other_source', 'Other')
], 'Source',
help='Sample source type.',
sort=False )
patient_id = fields.Many2One(
'gnuhealth.patient', 'Patient',
states={'invisible': (Eval('source_type') != 'patient')})
other_source = fields.Char('Other',
states={'invisible': (Eval('source_type') != 'other_source')},
help="Other sample source.")
source_name = fields.Function(
fields.Text('Source name'), 'get_source_name')
def get_source_name(self, name):
if self.is_patient():
return self.patient_id and self.patient_id.rec_name or ''
else:
return (self.other_source or '')
doctor_id = fields.Many2One(
'gnuhealth.healthprofessional', 'Health prof.',
help="Health professional who requests the exp test." )
context = fields.Many2One(
'gnuhealth.pathology', 'Context',
help="Health context for this order. It can be a suspected or"
" existing health condition, a regular health checkup, ...",)
request = fields.Integer('Order', readonly=True)
urgent = fields.Boolean('Urgent')
@classmethod
def __setup__(cls):
super(GnuHealthPatientExpTest, cls).__setup__()
cls._order.insert(0, ('date', 'DESC'))
cls._order.insert(1, ('request', 'DESC'))
cls._order.insert(2, ('name', 'ASC'))
@staticmethod
def default_date():
return datetime.now()
@staticmethod
def default_source_type():
return 'patient'
@staticmethod
def default_state():
return 'draft'
@staticmethod
def default_doctor_id():
return get_health_professional()
@classmethod
def contact(self, id):
transaction = Transaction()
cursor = transaction.connection.cursor()
#cursor = conn2.cursor()
f = cursor.execute("SELECT current_database()")
database_name = cursor.fetchone()[0]
#sql = "SELECT type, value FROM party_contact_mechanism JOIN party_party ON party_contact_mechanism.party = party_party.id JOIN gnuhealth_patient ON {} = gnuhealth_patient.id".format(id)
sql1 = "SELECT name FROM gnuhealth_patient where gnuhealth_patient.id = {}".format(id)
cursor.execute(sql1)
data1 = cursor.fetchone()
sql2 = "SELECT type, value FROM party_contact_mechanism WHERE party = {}".format(data1[0])
cursor.execute(sql2)
data2 = cursor.fetchall()
#print("Les différentes données ", data2[0][0])
list_phone = []
for item in data2 :
if item[0] == "phone" :
list_phone.append(item[1])
return ("/ ".join(list_phone))
@classmethod
def generate_code(cls, **pattern):
Config = Pool().get('gnuhealth.sequences')
pool = Pool()
ExpTest = pool.get("gnuhealth.patient.exp.test")
records = ExpTest.search([], order=[('id', 'DESC')], limit=1)
request = records[0].id + 1 if records else None
config = Config(1)
sequence = config.get_multivalue(
'exp_request_sequence', **pattern)
if request:
return request
else :
return 1
@classmethod
def create(cls, vlist):
vlist = [x.copy() for x in vlist]
for values in vlist:
values["request"] = cls.generate_code()
if not values.get('name'):
values['name'] = cls.generate_code()
return super(GnuHealthPatientExpTest, cls).create(vlist)
@classmethod
def copy(cls, tests, default=None):
if default is None:
default = {}
default = default.copy()
default['request'] = None
default['date'] = cls.default_date()
return super(GnuHealthPatientExpTest, cls).copy(
tests, default=default)
def is_patient(self):
return (self.source_type == 'patient')
def is_other_source(self):
return (self.source_type == 'other_source')