agenda: improving multiple patients adding/updating for a schedule

Reverting "agenda: add multiple patients for a schedule"

This reverts commit 6fdbe2459b.

Closes #3118
This commit is contained in:
Serghei Mihai 2014-05-13 18:02:46 +02:00
parent 7d4712a3f4
commit f1a4cd5852
3 changed files with 41 additions and 13 deletions

View File

@ -22,7 +22,7 @@ class BaseForm(forms.ModelForm):
class NewAppointmentForm(BaseForm):
patients = AutoCompleteSelectMultipleField('patientrecord')
patient = AutoCompleteSelectMultipleField('patientrecord')
class Meta:
model = EventWithAct
@ -31,7 +31,7 @@ class NewAppointmentForm(BaseForm):
'date',
'time',
'duration',
'patients',
'patient',
'participants',
'ressource',
'act_type',
@ -54,7 +54,7 @@ class NewAppointmentForm(BaseForm):
self.service = service
self.fields['participants'].queryset = \
Worker.objects.for_service(service)
self.fields['patients'].queryset = \
self.fields['patient'].queryset = \
PatientRecord.objects.for_service(service)
self.fields['act_type'].queryset = \
ActType.objects.for_service(service) \
@ -67,8 +67,8 @@ class NewAppointmentForm(BaseForm):
except ValueError:
return 0
def clean_patients(self):
patients = self.cleaned_data['patients']
def clean_patient(self):
patients = self.cleaned_data['patient']
if patients:
return [patient for patient in PatientRecord.objects.filter(pk__in=patients)]
@ -79,10 +79,17 @@ class NewAppointmentForm(BaseForm):
if cleaned_data.has_key('date') and cleaned_data.has_key('time'):
cleaned_data['start_datetime'] = datetime.combine(cleaned_data['date'],
cleaned_data['time'])
if 'patient' in cleaned_data and isinstance(cleaned_data['patient'], list):
# nasty trick to store the list of patients and pass the form
# validation
cleaned_data['patients'] = cleaned_data['patient']
cleaned_data['patient'] = cleaned_data['patient'][0]
return cleaned_data
def save(self, commit=True):
for patient in self.cleaned_data.pop('patients'):
patients = self.cleaned_data.pop('patients')
for patient in patients:
appointment = forms.save_instance(self, self._meta.model(), commit=False)
appointment.start_datetime = datetime.combine(self.cleaned_data['date'],
self.cleaned_data['time'])
@ -98,6 +105,8 @@ class NewAppointmentForm(BaseForm):
class UpdateAppointmentForm(NewAppointmentForm):
patient = make_ajax_field(EventWithAct, 'patient', 'patientrecord', False)
class Meta(NewAppointmentForm.Meta):
fields = (
'start_datetime',
@ -110,6 +119,22 @@ class UpdateAppointmentForm(NewAppointmentForm):
'act_type',
)
def clean_patient(self):
return self.cleaned_data['patient']
def save(self, commit=True):
appointment = super(NewAppointmentForm, self).save(commit=False)
appointment.start_datetime = datetime.combine(self.cleaned_data['date'],
self.cleaned_data['time'])
appointment.end_datetime = appointment.start_datetime + timedelta(
minutes=self.cleaned_data['duration'])
appointment.creator = get_request().user
appointment.clean()
if commit:
appointment.save()
appointment.services = [self.service]
return appointment
class UpdatePeriodicAppointmentForm(NewAppointmentForm):
recurrence_periodicity = forms.ChoiceField(label=u"Périodicité",

View File

@ -47,11 +47,15 @@
{{ form.participants.errors }}
</div>
</td>
<td {% if form.patients.field.required %}class="required"{% endif %}>
<h4>{{ form.patients.label_tag }}</h4>
<div id="patients">
{{ form.patients }}
{{ form.patients.errors }}
<td {% if form.patient.field.required %}class="required"{% endif %}>
<h4>{{ form.patient.label_tag }}</h4>
<div id="patient">
{% if object.exception_to and not object.exception_to.canceled %}
{{ object.patient }}
{% else %}
{{ form.patient }}
{{ form.patient.errors }}
{% endif %}
</div>
</td>
<td {% if form.act_type.field.required %}class="required"{% endif %}>

View File

@ -1192,12 +1192,11 @@ a [class^="icon-"], a [class*=" icon-"] {
right: 10px;
}
#id_participants_on_deck, #id_patients_on_deck {
#id_participants_on_deck, #id_patient_on_deck {
max-height: 7em;
overflow-y: scroll;
}
ul.messages, ul.ajax_messages {
position: absolute;
width: 30em;