Projet

Général

Profil

« Précédent | Suivant » 

Révision 6fdbe245

Ajouté par Serghei Mihai il y a presque 10 ans

agenda: add multiple patients for a schedule

Closes #3118

Voir les différences:

calebasse/agenda/forms.py
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

  
calebasse/agenda/templates/agenda/appointment.html
47 47
           {{ form.participants.errors }}
48 48
           </div>
49 49
           </td>
50
           <td {% if form.patient.field.required %}class="required"{% endif %}>
51
           <h4>{{ form.patient.label_tag }}</h4>
52
           {% if object.exception_to and not object.exception_to.canceled %}
53
           {{ object.patient }}
54
           {% else %}
55
           {{ form.patient }}
56
           {{ form.patient.errors }}
57
           {% endif %}
50
           <td {% if form.patients.field.required %}class="required"{% endif %}>
51
           <h4>{{ form.patients.label_tag }}</h4>
52
           <div id="patients">
53
           {{ form.patients }}
54
           {{ form.patients.errors }}
55
           </div>
58 56
           </td>
59 57
           <td {% if form.act_type.field.required %}class="required"{% endif %}>
60 58
           <h4>{{ form.act_type.label_tag }}</h4>
calebasse/static/css/style.css
1192 1192
	right: 10px;
1193 1193
}
1194 1194

  
1195
#id_participants_on_deck {
1195
#id_participants_on_deck, #id_patients_on_deck {
1196 1196
  max-height: 7em;
1197 1197
  overflow-y: scroll;
1198 1198
}

Formats disponibles : Unified diff