1
|
import datetime
|
2
|
|
3
|
from django.shortcuts import redirect
|
4
|
|
5
|
from calebasse.cbv import ListView
|
6
|
from calebasse.agenda import views as agenda_views
|
7
|
|
8
|
import models
|
9
|
import forms
|
10
|
|
11
|
def redirect_today(request, service):
|
12
|
'''If not date is given we redirect on the agenda for today'''
|
13
|
return redirect(act_listing, date=datetime.date.today().strftime('%Y-%m-%d'),
|
14
|
service=service)
|
15
|
|
16
|
class ActListingView(ListView):
|
17
|
model=models.Act
|
18
|
template_name='actes/act_listing.html'
|
19
|
|
20
|
def get_queryset(self):
|
21
|
qs = super(ActListingView, self).get_queryset()
|
22
|
self.get_search_form()
|
23
|
qs = qs.filter(patient__service=self.service)
|
24
|
qs = qs.filter(date=self.date)
|
25
|
if self.request.method == 'POST' and self.search_form.is_valid():
|
26
|
cd = self.search_form.cleaned_data
|
27
|
last_name = cd['last_name']
|
28
|
if last_name:
|
29
|
qs = qs.filter(patient__last_name__icontains=last_name)
|
30
|
patient_record_id = cd['patient_record_id']
|
31
|
if patient_record_id:
|
32
|
qs = qs.filter(patient__id=int(patient_record_id))
|
33
|
social_security_number = cd['social_security_number']
|
34
|
# FIXME: what to do with the ssn ?
|
35
|
doctor_name = cd['doctor_name']
|
36
|
if doctor_name:
|
37
|
qs = qs.filter(doctors__last_name__icontains=doctor_name)
|
38
|
filters = cd['filters']
|
39
|
if 'non-invoicable' in filters:
|
40
|
pass # FIXME
|
41
|
if 'absent-or-canceled' in filters:
|
42
|
pass # FIXME
|
43
|
if 'lost' in filters:
|
44
|
pass # FIXME
|
45
|
if 'invoiced' in filters:
|
46
|
pass # FIXME
|
47
|
if 'last-invoicing' in filters:
|
48
|
pass # FIXME
|
49
|
if 'current-invoicing' in filters:
|
50
|
pass # FIXME
|
51
|
return qs
|
52
|
|
53
|
def get_search_form(self):
|
54
|
if self.request.method == 'POST':
|
55
|
self.search_form = forms.ActSearchForm(data=self.request.POST)
|
56
|
else:
|
57
|
self.search_form = forms.ActSearchForm()
|
58
|
return self.search_form
|
59
|
|
60
|
def post(self, *args, **kwargs):
|
61
|
return self.get(*args, **kwargs)
|
62
|
|
63
|
def get_context_data(self, **kwargs):
|
64
|
ctx = super(ActListingView, self).get_context_data(**kwargs)
|
65
|
ctx['search_form'] = self.search_form
|
66
|
return ctx
|
67
|
|
68
|
act_listing = ActListingView.as_view()
|
69
|
act_new = agenda_views.NewAppointmentView.as_view()
|