22 |
22 |
|
23 |
23 |
|
24 |
24 |
class NewAppointmentForm(BaseForm):
|
25 |
|
patients = AutoCompleteSelectMultipleField('patientrecord')
|
|
25 |
patient = AutoCompleteSelectMultipleField('patientrecord')
|
26 |
26 |
|
27 |
27 |
class Meta:
|
28 |
28 |
model = EventWithAct
|
... | ... | |
31 |
31 |
'date',
|
32 |
32 |
'time',
|
33 |
33 |
'duration',
|
34 |
|
'patients',
|
|
34 |
'patient',
|
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['patients'].queryset = \
|
|
57 |
self.fields['patient'].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']
|
|
70 |
def clean_patient(self):
|
|
71 |
patients = self.cleaned_data['patient']
|
72 |
72 |
if patients:
|
73 |
73 |
return [patient for patient in PatientRecord.objects.filter(pk__in=patients)]
|
74 |
74 |
|
... | ... | |
79 |
79 |
if cleaned_data.has_key('date') and cleaned_data.has_key('time'):
|
80 |
80 |
cleaned_data['start_datetime'] = datetime.combine(cleaned_data['date'],
|
81 |
81 |
cleaned_data['time'])
|
|
82 |
if 'patient' in cleaned_data and isinstance(cleaned_data['patient'], list):
|
|
83 |
# nasty trick to store the list of patients and pass the form
|
|
84 |
# validation
|
|
85 |
cleaned_data['patients'] = cleaned_data['patient']
|
|
86 |
cleaned_data['patient'] = cleaned_data['patient'][0]
|
82 |
87 |
return cleaned_data
|
83 |
88 |
|
84 |
89 |
def save(self, commit=True):
|
85 |
|
for patient in self.cleaned_data.pop('patients'):
|
|
90 |
|
|
91 |
patients = self.cleaned_data.pop('patients')
|
|
92 |
for patient in patients:
|
86 |
93 |
appointment = forms.save_instance(self, self._meta.model(), commit=False)
|
87 |
94 |
appointment.start_datetime = datetime.combine(self.cleaned_data['date'],
|
88 |
95 |
self.cleaned_data['time'])
|
... | ... | |
98 |
105 |
|
99 |
106 |
class UpdateAppointmentForm(NewAppointmentForm):
|
100 |
107 |
|
|
108 |
patient = make_ajax_field(EventWithAct, 'patient', 'patientrecord', False)
|
|
109 |
|
101 |
110 |
class Meta(NewAppointmentForm.Meta):
|
102 |
111 |
fields = (
|
103 |
112 |
'start_datetime',
|
... | ... | |
110 |
119 |
'act_type',
|
111 |
120 |
)
|
112 |
121 |
|
|
122 |
def clean_patient(self):
|
|
123 |
return self.cleaned_data['patient']
|
|
124 |
|
|
125 |
def save(self, commit=True):
|
|
126 |
appointment = super(NewAppointmentForm, self).save(commit=False)
|
|
127 |
appointment.start_datetime = datetime.combine(self.cleaned_data['date'],
|
|
128 |
self.cleaned_data['time'])
|
|
129 |
appointment.end_datetime = appointment.start_datetime + timedelta(
|
|
130 |
minutes=self.cleaned_data['duration'])
|
|
131 |
appointment.creator = get_request().user
|
|
132 |
appointment.clean()
|
|
133 |
if commit:
|
|
134 |
appointment.save()
|
|
135 |
appointment.services = [self.service]
|
|
136 |
return appointment
|
|
137 |
|
113 |
138 |
|
114 |
139 |
class UpdatePeriodicAppointmentForm(NewAppointmentForm):
|
115 |
140 |
recurrence_periodicity = forms.ChoiceField(label=u"Périodicité",
|
agenda: improving multiple patients adding/updating for a schedule
Reverting "agenda: add multiple patients for a schedule"
This reverts commit 6fdbe2459bab5933e993022a4e85a7b9c3c91004.
Closes #3118