1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2007 EVI. All Rights Reserved.
6
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsability of assessing all potential
8
# consequences resulting from its eventual inadequacies and bugs
9
# End users who are looking for a ready-to-use solution with commercial
10
# garantees and support are strongly adviced to contract a Free Software
13
# This program is Free Software; you can redistribute it and/or
14
# modify it under the terms of the GNU General Public License
15
# as published by the Free Software Foundation; either version 2
16
# of the License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
##############################################################################
32
from report import report_sxw
34
class entreesortie(report_sxw.rml_parse):
35
def __init__(self, cr, uid, name, context):
36
super(entreesortie, self).__init__(cr, uid, name, context)
37
self.localcontext.update( {
39
'_entree':self._entree,
40
'_sortie':self._sortie,
41
'_absences':self._absences,
44
self.context = context
46
def _entree(self,form):
48
patient_obj = self.pool.get('health.patient')
49
patient_ids = patient_obj.search(self.cr,self.uid,[ ('active','in', ['f','t'])])
50
for a in patient_obj.read(self.cr, self.uid, patient_ids, ['name', 'room_id','provenance','date_sortie','motif_sortie','admission_date','girage']):
51
if a['admission_date']:
52
anneeadmission=int(a['admission_date'][0:4])
53
moisadmission=int(a['admission_date'][5:7])
54
jouradmission = int(a['admission_date'][8:10])
56
anneeperiodedebut=int(form['datedebut'][0:4])
57
anneeperiodefin=int(form['datefin'][0:4])
58
moisperiodedebut=int(form['datedebut'][5:7])
59
moisperiodefin=int(form['datefin'][5:7])
60
jourperiodedebut = int(form['datedebut'][8:10])
61
jourperiodefin = int(form['datefin'][8:10])
63
periodefin=datetime.datetime(anneeperiodefin,moisperiodefin,jourperiodefin)
64
periodedebut=datetime.datetime(anneeperiodefin,moisperiodedebut,jourperiodedebut)
65
admission=datetime.datetime(anneeadmission,moisadmission,jouradmission)
67
destination=a['motif_sortie'][1]
71
chambre=a['room_id'][1]
73
chambre = "Non defini"
74
if (admission <= periodefin) and (admission >=periodedebut):
75
res.append({'name':a['name'],'chambre':chambre,'entree':a['admission_date'],'provenance':a['provenance'],'sortie':a['date_sortie'],'destination':destination,'gir':a['girage']})
76
res.sort(lambda x, y: cmp(x['name'],y['name']))
78
def _sortie(self,form):
80
patient_obj = self.pool.get('health.patient')
81
patient_ids = patient_obj.search(self.cr,self.uid,[ ('active','in', ['f','t'])])
82
for a in patient_obj.read(self.cr, self.uid, patient_ids, ['name', 'active','room_id','provenance','date_sortie','motif_sortie','admission_date','girage']):
84
anneesortie=int(a['date_sortie'][0:4])
85
moissortie=int(a['date_sortie'][5:7])
86
joursortie = int(a['date_sortie'][8:10])
87
anneeperiodedebut=int(form['datedebut'][0:4])
88
anneeperiodefin=int(form['datefin'][0:4])
89
moisperiodedebut=int(form['datedebut'][5:7])
90
moisperiodefin=int(form['datefin'][5:7])
91
jourperiodedebut = int(form['datedebut'][8:10])
92
jourperiodefin = int(form['datefin'][8:10])
94
chambre=a['room_id'][1]
96
chambre = "Non defini"
98
destination=a['motif_sortie'][1]
102
periodefin=datetime.datetime(anneeperiodefin,moisperiodefin,jourperiodefin)
103
periodedebut=datetime.datetime(anneeperiodefin,moisperiodedebut,jourperiodedebut)
104
sortie=datetime.datetime(anneesortie,moissortie,joursortie)
105
if (sortie <= periodefin) and (sortie >=periodedebut):
106
res.append({'name':a['name'],'chambre':chambre,'entree':a['admission_date'],'provenance':a['provenance'],'sortie':a['date_sortie'],'destination':destination,'gir':a['girage']})
107
res.sort(lambda x, y: cmp(x['name'],y['name']))
110
def _absences(self,form):
112
absences_obj = self.pool.get('health.absences')
113
abs_ids = absences_obj.search(self.cr,self.uid,[('du','>=',form['datedebut']),('du','<=',form['datefin'])])+absences_obj.search(self.cr,self.uid,[('au','>=',form['datedebut']),('au','<=',form['datefin'])])
114
absences = absences_obj.read(self.cr,self.uid,abs_ids)
115
patient_obj = self.pool.get('health.patient')
117
for a in patient_obj.read(self.cr, self.uid, [ab['partner_id'][0]]):
118
if ab['categorie'] == '1' :
119
motif= 'Hospitalisation'
120
if ab['categorie'] == '2' :
121
motif= 'Convenance Personelle'
122
if ab['categorie'] == '3' :
125
chambre=a['room_id'][1]
127
chambre = "Non defini"
129
res.append({'name':a['name'],'chambre':chambre,'entree':ab['du'],'sortie':ab['au'],'motif_sortie':motif,'gir':a['girage']})
130
res.sort(lambda x, y: cmp(x['name'],y['name']))
133
def age(self,annee,annee2):
134
return int(annee[0:4])-int(annee2[0:4])
138
report_sxw.report_sxw('report.health.entreesortie.report', 'health.patient','addons/health/report/entreesortie.rml', parser=entreesortie, header=False)