1
|
# -*- coding: utf-8 -*-
|
2
|
|
3
|
from datetime import datetime, timedelta
|
4
|
|
5
|
from django import forms
|
6
|
|
7
|
from calebasse.dossiers.models import PatientRecord
|
8
|
from calebasse.personnes.models import Worker
|
9
|
from calebasse.actes.models import EventAct
|
10
|
|
11
|
from ajax_select import make_ajax_field
|
12
|
|
13
|
class NewAppointmentForm(forms.ModelForm):
|
14
|
time = forms.TimeField(label=u'Heure de début')
|
15
|
duration = forms.CharField(label=u'Durée',
|
16
|
help_text=u'en minutes; vous pouvez utiliser la roulette de votre souris.')
|
17
|
|
18
|
participants = make_ajax_field(EventAct, 'participants', 'worker', True)
|
19
|
patient = make_ajax_field(EventAct, 'patient', 'patientrecord', False)
|
20
|
|
21
|
class Meta:
|
22
|
model = EventAct
|
23
|
fields = (
|
24
|
'date',
|
25
|
'time',
|
26
|
'duration',
|
27
|
'patient',
|
28
|
'participants',
|
29
|
'room',
|
30
|
'act_type',
|
31
|
)
|
32
|
|
33
|
|
34
|
def __init__(self, instance, service=None, **kwargs):
|
35
|
self.service = None
|
36
|
super(NewAppointmentForm, self).__init__(instance=instance, **kwargs)
|
37
|
self.fields['date'].css = 'datepicker'
|
38
|
if service:
|
39
|
self.service = service
|
40
|
self.fields['participants'].queryset = \
|
41
|
Worker.objects.for_service(service)
|
42
|
self.fields['patient'].queryset = \
|
43
|
PatientRecord.objects.for_service(service)
|
44
|
|
45
|
def save(self, commit=False):
|
46
|
start_datetime = datetime.combine(self.cleaned_data['date'],
|
47
|
self.cleaned_data['time'])
|
48
|
end_datetime = start_datetime + timedelta(
|
49
|
minutes=self.cleaned_data['duration'])
|
50
|
self.instance = EventAct.objects.create_patient_appointment(
|
51
|
title='title #FIXME#',
|
52
|
patient=self.cleaned_data['patient'],
|
53
|
participants=self.cleaned_data['participants'],
|
54
|
act_type=self.cleaned_data['act_type'],
|
55
|
service=self.service,
|
56
|
start_datetime=start_datetime,
|
57
|
end_datetime=end_datetime,
|
58
|
description='description #FIXME#',
|
59
|
room=self.cleaned_data['room'],
|
60
|
note=None,)
|
61
|
return self.instance
|
62
|
|