1
|
import datetime
|
2
|
|
3
|
from django.db.models import Q
|
4
|
from django.views.generic.edit import ModelFormMixin
|
5
|
from django.shortcuts import redirect
|
6
|
|
7
|
from calebasse.cbv import ListView, UpdateView, FormView
|
8
|
from calebasse.agenda.views import NewAppointmentView
|
9
|
|
10
|
import models
|
11
|
import forms
|
12
|
|
13
|
def redirect_today(request, service):
|
14
|
'''If not date is given we redirect on the agenda for today'''
|
15
|
return redirect(act_listing, date=datetime.date.today().strftime('%Y-%m-%d'),
|
16
|
service=service)
|
17
|
|
18
|
class ActListingView(ListView):
|
19
|
model=models.Act
|
20
|
template_name='actes/act_listing.html'
|
21
|
|
22
|
def get_queryset(self):
|
23
|
qs = super(ActListingView, self).get_queryset()
|
24
|
qs = qs.filter(patient__service=self.service)
|
25
|
qs = qs.filter(date=self.date)
|
26
|
self.search_form = forms.ActSearchForm(data=self.request.GET or None)
|
27
|
last_name = self.request.GET.get('last_name')
|
28
|
patient_record_id = self.request.GET.get('patient_record_id')
|
29
|
social_security_number = self.request.GET.get('social_security_number')
|
30
|
doctor_name = self.request.GET.get('doctor_name')
|
31
|
filters = self.request.GET.getlist('filters')
|
32
|
if last_name:
|
33
|
qs = qs.filter(patient__last_name__istartswith=last_name)
|
34
|
if patient_record_id:
|
35
|
qs = qs.filter(patient__id=int(patient_record_id))
|
36
|
if doctor_name:
|
37
|
qs = qs.filter(doctors__last_name__icontains=doctor_name)
|
38
|
if 'valide' in filters:
|
39
|
qs = qs.exclude(last_validation_state__state_name__exact='VALIDE')
|
40
|
if 'pointe' in filters:
|
41
|
qs = qs.filter(last_validation_state__isnull=False). \
|
42
|
exclude(last_validation_state__state_name__exact='NON_VALIDE')
|
43
|
if 'non-pointe' in filters:
|
44
|
qs = qs.filter(Q(last_validation_state__isnull=True) | \
|
45
|
Q(last_validation_state__state_name__exact='NON_VALIDE'))
|
46
|
if 'absent-or-canceled' in filters:
|
47
|
qs = qs.filter(last_validation_state__state_name__in=('ABS_NON_EXC',
|
48
|
'ABS_EXC', 'ABS_INTER', 'ANNUL_NOUS',
|
49
|
'ANNUL_FAMILLE', 'REPORTE', 'ABS_ESS_PPS', 'ENF_HOSP'))
|
50
|
if 'is-billable' in filters:
|
51
|
qs = qs.filter(
|
52
|
(Q(act_type__billable=True) & Q(switch_billable=False)) | \
|
53
|
(Q(act_type__billable=False) & Q(switch_billable=True))
|
54
|
)
|
55
|
if 'switch-billable' in filters:
|
56
|
qs = qs.filter(switch_billable=True)
|
57
|
if 'lost' in filters:
|
58
|
qs = qs.filter(is_lost=True)
|
59
|
if 'pause-invoicing' in filters:
|
60
|
qs = qs.filter(pause=True)
|
61
|
if 'invoiced' in filters:
|
62
|
qs = qs.filter(is_billed=True)
|
63
|
|
64
|
return qs.select_related()
|
65
|
|
66
|
def get_context_data(self, **kwargs):
|
67
|
ctx = super(ActListingView, self).get_context_data(**kwargs)
|
68
|
ctx['search_form'] = self.search_form
|
69
|
return ctx
|
70
|
|
71
|
class NewAct(NewAppointmentView):
|
72
|
success_url = '.'
|
73
|
|
74
|
def form_valid(self, form):
|
75
|
self.object = form.save()
|
76
|
self.object.act.save()
|
77
|
return ModelFormMixin.form_valid(self, form)
|
78
|
|
79
|
act_listing = ActListingView.as_view()
|
80
|
act_new = NewAct.as_view()
|
81
|
|
82
|
class UpdateActView(UpdateView):
|
83
|
model = models.Act
|
84
|
form_class = forms.ActUpdate
|
85
|
template_name = 'actes/act_update.html'
|
86
|
success_url = '..'
|
87
|
|
88
|
update_act = UpdateActView.as_view()
|
89
|
|
90
|
class RebillActView(UpdateView):
|
91
|
model = models.Act
|
92
|
template_name = 'actes/act_rebill.html'
|
93
|
success_url = '..'
|
94
|
|
95
|
def post(self, request, *args, **kwarg):
|
96
|
act = models.Act.objects.get(pk=kwarg['pk'])
|
97
|
act.is_billed = False
|
98
|
act.healthcare = None
|
99
|
act.save()
|
100
|
return super(RebillActView, self).post(request, *args, **kwarg)
|
101
|
|
102
|
rebill_act = RebillActView.as_view()
|