|
1
|
|
|
2
|
from calebasse.cbv import ListView, MultiUpdateView
|
|
3
|
from calebasse.agenda.models import Occurrence
|
|
4
|
from calebasse.dossiers.models import PatientRecord
|
|
5
|
from calebasse.dossiers.forms import SearchForm, CivilStatusForm
|
|
6
|
from calebasse.dossiers.states import STATES_MAPPING, STATE_CHOICES_TYPE
|
|
7
|
|
|
8
|
|
|
9
|
class PatientRecordView(MultiUpdateView):
|
|
10
|
"""
|
|
11
|
"""
|
|
12
|
model = PatientRecord
|
|
13
|
forms_classes = {'civil_status': CivilStatusForm}
|
|
14
|
template_name = 'dossiers/patientrecord_update.html'
|
|
15
|
success_url = './'
|
|
16
|
|
|
17
|
def get_context_data(self, **kwargs):
|
|
18
|
ctx = super(PatientRecordView, self).get_context_data(**kwargs)
|
|
19
|
return ctx
|
|
20
|
|
|
21
|
patient_record = PatientRecordView.as_view()
|
|
22
|
|
|
23
|
class PatientRecordsHomepageView(ListView):
|
|
24
|
model = PatientRecord
|
|
25
|
template_name = 'dossiers/index.html'
|
|
26
|
|
|
27
|
def get_queryset(self):
|
|
28
|
qs = super(PatientRecordsHomepageView, self).get_queryset()
|
|
29
|
first_name = self.request.GET.get('first_name')
|
|
30
|
last_name = self.request.GET.get('last_name')
|
|
31
|
paper_id = self.request.GET.get('paper_id')
|
|
32
|
states = self.request.GET.getlist('states')
|
|
33
|
social_security_id = self.request.GET.get('social_security_id')
|
|
34
|
if last_name:
|
|
35
|
qs = qs.filter(last_name__icontains=last_name)
|
|
36
|
if first_name:
|
|
37
|
qs = qs.filter(first_name__icontains=first_name)
|
|
38
|
if paper_id:
|
|
39
|
qs = qs.filter(paper_id__contains=paper_id)
|
|
40
|
if social_security_id:
|
|
41
|
qs = qs.filter(social_security_id__contains=social_security_id)
|
|
42
|
if states:
|
|
43
|
status_types = []
|
|
44
|
for state in states:
|
|
45
|
status_types.append(STATE_CHOICES_TYPE[state])
|
|
46
|
qs = qs.filter(last_state__status__type__in=status_types)
|
|
47
|
return qs
|
|
48
|
|
|
49
|
def get_context_data(self, **kwargs):
|
|
50
|
ctx = super(PatientRecordsHomepageView, self).get_context_data(**kwargs)
|
|
51
|
ctx['search_form'] = SearchForm(data=self.request.GET or None)
|
|
52
|
ctx['patient_records'] = []
|
|
53
|
ctx['stats'] = {"dossiers": 0,
|
|
54
|
"En_contact": 0,
|
|
55
|
"Fin_daccueil": 0,
|
|
56
|
"Diagnostic": 0,
|
|
57
|
"Traitement": 0,
|
|
58
|
"Clos": 0}
|
|
59
|
if self.request.GET:
|
|
60
|
for patient_record in ctx['object_list'].filter():
|
|
61
|
ctx['stats']['dossiers'] += 1
|
|
62
|
next_rdv = {}
|
|
63
|
occurrence = Occurrence.objects.next_appoinment(patient_record)
|
|
64
|
if occurrence:
|
|
65
|
next_rdv['start_datetime'] = occurrence.start_time
|
|
66
|
next_rdv['participants'] = occurrence.event.participants.all()
|
|
67
|
next_rdv['act_type'] = occurrence.event.eventact.act_type
|
|
68
|
occurrence = Occurrence.objects.last_appoinment(patient_record)
|
|
69
|
last_rdv = {}
|
|
70
|
if occurrence:
|
|
71
|
last_rdv['start_datetime'] = occurrence.start_time
|
|
72
|
last_rdv['participants'] = occurrence.event.participants.all()
|
|
73
|
last_rdv['act_type'] = occurrence.event.eventact.act_type
|
|
74
|
occurrence = Occurrence.objects.next_appoinment(patient_record)
|
|
75
|
if STATES_MAPPING.has_key(patient_record.last_state.status.type):
|
|
76
|
state = STATES_MAPPING[patient_record.last_state.status.type]
|
|
77
|
else:
|
|
78
|
state = patient_record.last_state.status.name
|
|
79
|
ctx['patient_records'].append(
|
|
80
|
{
|
|
81
|
'object': patient_record,
|
|
82
|
'next_rdv': next_rdv,
|
|
83
|
'last_rdv': last_rdv,
|
|
84
|
'state': state
|
|
85
|
}
|
|
86
|
)
|
|
87
|
state = state.replace(' ', '_')
|
|
88
|
state = state.replace("'", '')
|
|
89
|
if not ctx['stats'].has_key(state):
|
|
90
|
ctx['stats'][state] = 0
|
|
91
|
ctx['stats'][state] += 1
|
|
92
|
|
|
93
|
return ctx
|
|
94
|
|