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

« back to all changes in this revision

Viewing changes to health/report/presence.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 presence(report_sxw.rml_parse):
 
35
    def __init__(self, cr, uid, name, context):
 
36
        super(presence, self).__init__(cr, uid, name, context)
 
37
        self.localcontext.update( {
 
38
            'time': time,
 
39
            '_entree':self._entree,
 
40
        })
 
41
        self.context = context
 
42
        return None
 
43
    def _entree(self,form):
 
44
            res = []
 
45
            patient_obj = self.pool.get('health.patient')
 
46
            patient_ids = patient_obj.search(self.cr,self.uid,[ ('active','in', ['f','t'])])
 
47
            for a in patient_obj.read(self.cr, self.uid, patient_ids, ['name', 'room_id','provenance','date_sortie','motif_sortie','admission_date','girage']):
 
48
                if a['admission_date']:
 
49
                    anneeadmission=int(a['admission_date'][0:4])
 
50
                    moisadmission=int(a['admission_date'][5:7])
 
51
                    jouradmission = int(a['admission_date'][8:10])
 
52
                
 
53
                    if a['date_sortie']:
 
54
                        anneesortie=int(a['date_sortie'][0:4])
 
55
                        moissortie=int(a['date_sortie'][5:7])
 
56
                        joursortie = int(a['date_sortie'][8:10])
 
57
                        sortie=True
 
58
                    else:
 
59
                        anneesortie=9999
 
60
                        moissortie=12
 
61
                        joursortie = 31
 
62
                        sortie=False
 
63
            
 
64
                    anneeperiodedebut=int(form['datedebut'][0:4])
 
65
                    moisperiodedebut=int(form['datedebut'][5:7])
 
66
                    jourperiodedebut = int(form['datedebut'][8:10])
 
67
        
 
68
                    anneeperiodefin=int(form['datefin'][0:4])
 
69
                    moisperiodefin=int(form['datefin'][5:7])
 
70
                    jourperiodefin = int(form['datefin'][8:10])
 
71
                
 
72
                    periodefin=datetime.datetime(anneeperiodefin,moisperiodefin,jourperiodefin) 
 
73
                    periodedebut=datetime.datetime(anneeperiodefin,moisperiodedebut,jourperiodedebut) 
 
74
                    admission=datetime.datetime(anneeadmission,moisadmission,jouradmission) 
 
75
                    datesortie=datetime.datetime(anneesortie,moissortie,joursortie) 
 
76
                    if a['motif_sortie']:
 
77
                        destination=a['motif_sortie'][1]
 
78
                    else:
 
79
                        destination=""
 
80
                    if a['room_id']:
 
81
                        chambre=a['room_id'][1]
 
82
                    else:
 
83
                        chambre = "Non defini"
 
84
                    if not sortie or ((datesortie <= periodefin) and (datesortie >=periodedebut)):
 
85
                        res.append({'name':a['name'],'chambre':chambre,'entree':a['admission_date'],'provenance':a['provenance'],'sortie':a['date_sortie'],'destination':destination,'gir':a['girage']})
 
86
            res.sort(lambda x, y: cmp(x['name'],y['name']))
 
87
            return res
 
88
 
 
89
    def _absences(self,form):
 
90
            res = []
 
91
            absences_obj = self.pool.get('health.absences')
 
92
            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'])])
 
93
            absences = absences_obj.read(self.cr,self.uid,abs_ids)
 
94
            patient_obj = self.pool.get('health.patient')
 
95
            for ab in absences:
 
96
                for a in patient_obj.read(self.cr, self.uid, [ab['partner_id'][0]]):
 
97
                    if ab['categorie'] == '1' :
 
98
                        motif= 'Hospitalisation'
 
99
                    if ab['categorie'] == '2' :
 
100
                        motif= 'Convenance Personelle'
 
101
                    if ab['categorie'] == '3' :
 
102
                        motif= 'Autres'
 
103
                    if a['room_id']:
 
104
                        chambre=a['room_id'][1]
 
105
                    else:
 
106
                        chambre = "Non defini"
 
107
 
 
108
                    res.append({'name':a['name'],'chambre':chambre,'entree':ab['du'],'sortie':ab['au'],'motif_sortie':motif,'gir':a['girage']})
 
109
            res.sort(lambda x, y: cmp(x['name'],y['name']))
 
110
            return res
 
111
    
 
112
    def age(self,annee,annee2):
 
113
        return int(annee[0:4])-int(annee2[0:4])
 
114
 
 
115
    
 
116
 
 
117
report_sxw.report_sxw('report.health.presence.report', 'health.patient','addons/health/report/presence.rml', parser=presence, header=False)
 
118