~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to health/report/entreesortie.py

  • Committer: Naresh Choksy
  • Date: 2009-02-11 09:40:55 UTC
  • mto: (3547.3.3 trunk-extra-addons)
  • mto: This revision was merged to the branch mainline in revision 3558.
  • Revision ID: nch@tinyerp.com-20090211094055-8xmkr2cyycxq70vv
Heath module:work in progress....

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
# Copyright (c) 2007 EVI.  All Rights Reserved.
 
5
#
 
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
 
11
# Service Company
 
12
#
 
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.
 
17
#
 
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.
 
22
#
 
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.
 
26
#
 
27
##############################################################################
 
28
 
 
29
import time
 
30
import datetime
 
31
 
 
32
from report import report_sxw
 
33
 
 
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( {
 
38
            'time': time,
 
39
            '_entree':self._entree,
 
40
            '_sortie':self._sortie,
 
41
            '_absences':self._absences,
 
42
            'age':self.age,
 
43
        })
 
44
        self.context = context
 
45
        return None
 
46
    def _entree(self,form):
 
47
            res = []
 
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])
 
55
            
 
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])
 
62
                
 
63
                    periodefin=datetime.datetime(anneeperiodefin,moisperiodefin,jourperiodefin) 
 
64
                    periodedebut=datetime.datetime(anneeperiodefin,moisperiodedebut,jourperiodedebut) 
 
65
                    admission=datetime.datetime(anneeadmission,moisadmission,jouradmission) 
 
66
                    if a['motif_sortie']:
 
67
                        destination=a['motif_sortie'][1]
 
68
                    else:
 
69
                        destination=""
 
70
                    if a['room_id']:
 
71
                        chambre=a['room_id'][1]
 
72
                    else:
 
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']))
 
77
            return res
 
78
    def _sortie(self,form):
 
79
            res = []
 
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']):
 
83
                if a['date_sortie']:
 
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])
 
93
                    if a['room_id']:
 
94
                        chambre=a['room_id'][1]
 
95
                    else:
 
96
                        chambre = "Non defini"
 
97
                    if a['motif_sortie']:
 
98
                        destination=a['motif_sortie'][1]
 
99
                    else:
 
100
                        destination=""
 
101
 
 
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']))
 
108
            return res
 
109
 
 
110
    def _absences(self,form):
 
111
            res = []
 
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')
 
116
            for ab in absences:
 
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' :
 
123
                        motif= 'Autres'
 
124
                    if a['room_id']:
 
125
                        chambre=a['room_id'][1]
 
126
                    else:
 
127
                        chambre = "Non defini"
 
128
 
 
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']))
 
131
            return res
 
132
    
 
133
    def age(self,annee,annee2):
 
134
        return int(annee[0:4])-int(annee2[0:4])
 
135
 
 
136
    
 
137
 
 
138
report_sxw.report_sxw('report.health.entreesortie.report', 'health.patient','addons/health/report/entreesortie.rml', parser=entreesortie, header=False)
 
139