Project

General

Profile

Download (2.64 KB) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / actes / views.py @ 90ff0811

1
import datetime
2

    
3
from django.db.models import Q
4
from django.shortcuts import redirect
5

    
6
from calebasse.cbv import ListView, UpdateView
7
from calebasse.agenda import views as agenda_views
8

    
9
import models
10
import forms
11

    
12
def redirect_today(request, service):
13
    '''If not date is given we redirect on the agenda for today'''
14
    return redirect(act_listing, date=datetime.date.today().strftime('%Y-%m-%d'),
15
            service=service)
16

    
17
class ActListingView(ListView):
18
    model=models.Act
19
    template_name='actes/act_listing.html'
20

    
21
    def get_queryset(self):
22
        qs = super(ActListingView, self).get_queryset()
23
        qs = qs.filter(patient__service=self.service)
24
        qs = qs.filter(date=self.date)
25
        self.search_form = forms.ActSearchForm(data=self.request.GET or None)
26
        last_name = self.request.GET.get('last_name')
27
        patient_record_id = self.request.GET.get('patient_record_id')
28
        social_security_number = self.request.GET.get('social_security_number')
29
        doctor_name = self.request.GET.get('doctor_name')
30
        filters = self.request.GET.getlist('filters')
31
        if last_name:
32
            qs = qs.filter(patient__last_name__istartswith=last_name)
33
        if patient_record_id:
34
            qs = qs.filter(patient__id=int(patient_record_id))
35
        if doctor_name:
36
            qs = qs.filter(doctors__last_name__icontains=doctor_name)
37
        if 'valide' in filters:
38
            qs = qs.filter(valide=True)
39
        if 'non-valide' in filters:
40
            qs = qs.filter(valide=False)
41
        if 'absent-or-canceled' in filters:
42
            # TODO : how to filter this without change the model ?
43
        if 'is-billable' in filters:
44
            qs = qs.filter(
45
                    (Q(act_type__billable=True) & Q(switch_billable=False)) | \
46
                    (Q(act_type__billable=False) & Q(switch_billable=True))
47
                    )
48
        if 'switch-billable' in filters:
49
            qs = qs.filter(switch_billable=True)
50
        if 'lost' in filters:
51
            qs = qs.filter(is_lost=True)
52
        if 'pause-invoicing' in filters:
53
            qs = qs.filter(pause=True)
54
        if 'invoiced' in filters:
55
            qs = qs.filter(is_billed=True)
56

    
57
        return qs.select_related()
58

    
59
    def get_context_data(self, **kwargs):
60
        ctx = super(ActListingView, self).get_context_data(**kwargs)
61
        ctx['search_form'] = self.search_form
62
        return ctx
63

    
64
act_listing = ActListingView.as_view()
65
act_new = agenda_views.NewAppointmentView.as_view()
66

    
67
class UpdateActView(UpdateView):
68
    model = models.Act
69
    form_class = forms.ActUpdate
70
    template_name = 'actes/act_update.html'
71
    success_url = '..'
72

    
73
update_act = UpdateActView.as_view()
74

    
(9-9/9)