10 |
10 |
from ..middleware.request import get_request
|
11 |
11 |
|
12 |
12 |
from ajax_select import make_ajax_field
|
13 |
|
from ajax_select.fields import AutoCompleteSelectField
|
|
13 |
from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultipleField
|
14 |
14 |
from models import Event, EventWithAct, EventType
|
15 |
15 |
|
16 |
16 |
class BaseForm(forms.ModelForm):
|
... | ... | |
22 |
22 |
|
23 |
23 |
|
24 |
24 |
class NewAppointmentForm(BaseForm):
|
25 |
|
patient = make_ajax_field(EventWithAct, 'patient', 'patientrecord', False)
|
|
25 |
patients = AutoCompleteSelectMultipleField('patientrecord')
|
26 |
26 |
|
27 |
27 |
class Meta:
|
28 |
28 |
model = EventWithAct
|
... | ... | |
31 |
31 |
'date',
|
32 |
32 |
'time',
|
33 |
33 |
'duration',
|
34 |
|
'patient',
|
|
34 |
'patients',
|
35 |
35 |
'participants',
|
36 |
36 |
'ressource',
|
37 |
37 |
'act_type',
|
... | ... | |
54 |
54 |
self.service = service
|
55 |
55 |
self.fields['participants'].queryset = \
|
56 |
56 |
Worker.objects.for_service(service)
|
57 |
|
self.fields['patient'].queryset = \
|
|
57 |
self.fields['patients'].queryset = \
|
58 |
58 |
PatientRecord.objects.for_service(service)
|
59 |
59 |
self.fields['act_type'].queryset = \
|
60 |
60 |
ActType.objects.for_service(service) \
|
... | ... | |
67 |
67 |
except ValueError:
|
68 |
68 |
return 0
|
69 |
69 |
|
|
70 |
def clean_patients(self):
|
|
71 |
patients = self.cleaned_data['patients']
|
|
72 |
if patients:
|
|
73 |
return [patient for patient in PatientRecord.objects.filter(pk__in=patients)]
|
|
74 |
|
70 |
75 |
def clean(self):
|
71 |
76 |
cleaned_data = super(NewAppointmentForm, self).clean()
|
72 |
77 |
if not cleaned_data.get('recurrence_periodicity'):
|
... | ... | |
77 |
82 |
return cleaned_data
|
78 |
83 |
|
79 |
84 |
def save(self, commit=True):
|
80 |
|
appointment = super(NewAppointmentForm, self).save(commit=False)
|
81 |
|
appointment.start_datetime = datetime.combine(self.cleaned_data['date'],
|
82 |
|
self.cleaned_data['time'])
|
83 |
|
appointment.end_datetime = appointment.start_datetime + timedelta(
|
|
85 |
for patient in self.cleaned_data.pop('patients'):
|
|
86 |
appointment = forms.save_instance(self, self._meta.model(), commit=False)
|
|
87 |
appointment.start_datetime = datetime.combine(self.cleaned_data['date'],
|
|
88 |
self.cleaned_data['time'])
|
|
89 |
appointment.end_datetime = appointment.start_datetime + timedelta(
|
84 |
90 |
minutes=self.cleaned_data['duration'])
|
85 |
|
appointment.creator = get_request().user
|
86 |
|
appointment.clean()
|
87 |
|
if commit:
|
88 |
|
appointment.save()
|
89 |
|
appointment.services = [self.service]
|
90 |
|
return appointment
|
|
91 |
appointment.creator = get_request().user
|
|
92 |
appointment.clean()
|
|
93 |
if commit:
|
|
94 |
appointment.patient = patient
|
|
95 |
appointment.save()
|
|
96 |
self.save_m2m()
|
|
97 |
appointment.services = [self.service]
|
91 |
98 |
|
92 |
99 |
class UpdateAppointmentForm(NewAppointmentForm):
|
93 |
100 |
|
agenda: add multiple patients for a schedule
Closes #3118