Projet

Général

Profil

0001-dossiers-merge-administrative-forms-into-one-form.patch

Jérôme Schneider, 25 juillet 2014 12:24

Télécharger (18,8 ko)

Voir les différences:

Subject: [PATCH] dossiers: merge administrative forms into one form

Closes #2739
 calebasse/dossiers/forms.py                        |  59 ++++------
 .../dossiers/patientrecord_tab2_fiche_adm.html     | 123 ++++++---------------
 calebasse/dossiers/templatetags/dossiers.py        |  29 +++++
 calebasse/dossiers/views.py                        |  12 +-
 4 files changed, 87 insertions(+), 136 deletions(-)
calebasse/dossiers/forms.py
106 106
                'pause_comment': forms.Textarea(attrs={'cols': 50, 'rows': 3}),
107 107
                }
108 108

  
109
class CivilStatusForm(ModelForm):
109
class AdministrativeForm(ModelForm):
110
    coordinators = make_ajax_field(PatientRecord, 'coordinators', 'worker', True)
110 111
    class Meta:
111 112
        model = PatientRecord
112
        fields = ('first_name', 'last_name', 'birthdate', 'birthplace', 'gender', 'nationality')
113
        # ID
114
        fields = ('first_name', 'last_name', 'birthdate', 'birthplace',
115
                'gender', 'nationality',)
116
        # inscription
117
        fields += ('analysemotive', 'familymotive', 'provenance',
118
            'advicegiver', 'provenanceplace',)
119
        # out
120
        fields += ('outmotive', 'outto',)
121
        # family
122
        fields += ('sibship_place', 'nb_children_family', 'parental_authority',
123
                'family_situation', 'child_custody', 'job_mother', 'job_father',
124
                'rm_mother', 'rm_father', 'family_comment',)
125
        # transport
126
        fields += ('transporttype', 'transportcompany',
127
                  'simple_appointment_transport', 'periodic_appointment_transport',)
128
        # Follow up
129
        fields += ('coordinators', 'externaldoctor', 'externalintervener',)
130
        widgets = {
131
                'family_comment': forms.Textarea(attrs={'cols': 50, 'rows': 1}),
132
                }
113 133

  
114 134

  
115 135
class PhysiologyForm(ModelForm):
......
148 168
                CodeCFTMEA.objects.filter(axe=3)
149 169

  
150 170

  
151
class InscriptionForm(ModelForm):
152
    class Meta:
153
        model = PatientRecord
154
        fields = ('analysemotive', 'familymotive', 'provenance',
155
            'advicegiver', 'provenanceplace')
156
        widgets = {}
157

  
158
class OutForm(ModelForm):
159
    class Meta:
160
        model = PatientRecord
161
        fields = ('outmotive', 'outto')
162
        widgets = {}
163

  
164
class FamilyForm(ModelForm):
165
    class Meta:
166
        model = PatientRecord
167
        fields = ('sibship_place', 'nb_children_family', 'parental_authority',
168
                'family_situation', 'child_custody', 'job_mother', 'job_father',
169
                'rm_mother', 'rm_father', 'family_comment')
170
        widgets = {
171
                'family_comment': forms.Textarea(attrs={'cols': 50, 'rows': 1}),
172
                }
173

  
174
class TransportFrom(ModelForm):
175
    class Meta:
176
        model = PatientRecord
177
        fields = ('transporttype', 'transportcompany',
178
                  'simple_appointment_transport', 'periodic_appointment_transport')
179

  
180 171
class PaperIDForm(ModelForm):
181 172
    class Meta:
182 173
        model = PatientRecord
......
191 182
                'contact_comment': forms.Textarea(attrs={'cols': 50, 'rows': 2}),
192 183
                }
193 184

  
194
class FollowUpForm(ModelForm):
195
    coordinators = make_ajax_field(PatientRecord, 'coordinators', 'worker', True)
196
    class Meta:
197
        model = PatientRecord
198
        fields = ('coordinators', 'externaldoctor', 'externalintervener')
199

  
200 185
class PatientContactForm(ModelForm):
201 186
    health_org = forms.CharField(label=u"Numéro de l'organisme destinataire", required=False)
202 187

  
calebasse/dossiers/templates/dossiers/patientrecord_tab2_fiche_adm.html
1
{% load dossiers %}
1 2
<div id="tabs-2">
2
  <form method="post" action="tab2" id="id-form" class="patientrecordform">{% csrf_token %}
3
  <form method="post" action="tab2" id="administrative-form" class="patientrecordform">{% csrf_token %}
4
    <p><button class="save enable-on-change">Enregistrer</button></p>
3 5
    <div class="frame inline">
4 6
      <h3>État civil</h3>
5
      <button class="save">✔</button>
6 7
      <table class="basic">
7 8
        <tbody>
8
        <tr><td class="width-limited">{{ forms.id.last_name.label_tag }}</td><td><span class="lastname">{{ forms.id.last_name }}</span></td><td>{{ forms.id.last_name.errors }}</td></tr>
9
        <tr><td class="width-limited">{{ forms.id.first_name.label_tag }}</td><td>{{ forms.id.first_name }}</td><td>{{ forms.id.first_name.errors }}</td></tr>
10
        <tr><td class="width-limited">{{ forms.id.birthplace.label_tag }}</td><td>{{ forms.id.birthplace }}</td><td>{{ forms.id.birthplace.errors }}</td></tr>
11
        <tr><td class="width-limited">{{ forms.id.birthdate.label_tag }}</td><td>{{ forms.id.birthdate }}</td><td>{{ forms.id.birthdate.errors }}</td></tr>
12
        <tr><td class="width-limited">{{ forms.id.gender.label_tag }}</td><td>{{ forms.id.gender }}</td><td>{{ forms.id.gender.errors }}</td></tr>
13
        <tr><td class="width-limited">{{ forms.id.nationality.label_tag }}</td><td>{{ forms.id.nationality }}</td><td>{{ forms.id.nationality.errors }}</td></tr>
9
        {% get_fieldset last_name,first_name,birthplace,birthdate,gender,nationality as id_fields from form %}
10
        {% for field in id_fields %}
11
        <tr>
12
          <td class="width-limited">{{ field.label_tag }}</td>
13
          <td>{{ field }}</td>
14
          <td>{{ field.errors }}</td>
15
        </tr>
16
        {% endfor %}
14 17
        </tbody>
15 18
      </table>
16 19
      <input type="hidden"  name="tab"  value="1">
17 20
    </div>
18
  </form>
19 21

  
20
  <form method="post" action="tab2" id="inscription-form" class="patientrecordform">
21
    {% csrf_token %}
22 22
    <div class="frame inline">
23 23
      <h3>Inscription</h3>
24
      <button class="save">✔</button>
25 24
      <table class="basic">
26 25
        <tbody>
27
        {% for field in forms.inscription %}
28
        <tr><td class="width-limited">{{ field.label_tag  }}</td><td>{{ field }}
26
        {% get_fieldset analysemotive,familymotive,provenance,advicegiver,provenanceplace as inscription_fields from form %}
27
        {% for field in inscription_fields %}
28
        <tr><td class="width-limited">{{ field.label_tag }}</td><td>{{ field }}
29 29
            <button type="button"
30 30
              class="dialog-button"
31 31
              data-url="../../ressources/{{ field.name }}/new/ #form-content"
......
39 39
      </table>
40 40
      <input type="hidden"  name="tab"  value="1">
41 41
    </div>
42
  </form>
43 42

  
44
  <form method="post" action="tab2" id="out-form" class="patientrecordform">
45
    {% csrf_token %}
46 43
    <div class="frame inline">
47 44
      <h3>Sortie</h3>
48
      <button class="save">✔</button>
49 45
      <table class="basic">
50 46
        <tbody>
51
        {% for field in forms.out %}
47
        {% get_fieldset outmotive,outto as out_fields from form %}
48
        {% for field in out_fields %}
52 49
        <tr><td class="width-limited">{{ field.label_tag  }}</td><td>{{ field }}
53 50
            <button type="button"
54 51
              class="dialog-button"
......
63 60
      </table>
64 61
      <input type="hidden"  name="tab"  value="1">
65 62
    </div>
66
  </form>
67 63

  
68
  <form method="post" action="tab2" id="family-form" class="patientrecordform">
69
    {% csrf_token %}
70 64
    <div class="frame inline">
71 65
      <h3>Famille</h3>
72
      <button class="save">✔</button>
73 66
      <table class="basic">
74 67
        <tbody>
75
        <tr><td class="width-limited">{{ forms.family.sibship_place.label_tag  }}</td><td>{{ forms.family.sibship_place }}</td><td>{{ forms.family.sibship_place.errors }}</td></tr>
76
        <tr><td class="width-limited">{{ forms.family.nb_children_family.label_tag  }}</td><td>{{ forms.family.nb_children_family }}</td><td>{{ forms.family.nb_children_family.errors }}</td></tr>
68
        <tr><td class="width-limited">{{ form.sibship_place.label_tag  }}</td><td>{{ form.sibship_place }}</td><td>{{ form.sibship_place.errors }}</td></tr>
69
        <tr><td class="width-limited">{{ form.nb_children_family.label_tag  }}</td><td>{{ form.nb_children_family }}</td><td>{{ form.nb_children_family.errors }}</td></tr>
77 70
        <tr><td class="width-limited"><label>Rang (gémellité) :  </label></td><td>{{ object.twinning_rank|default_if_none:"Aucun" }}</td><td></td></tr>
78
        <tr><td class="width-limited">{{ forms.family.parental_authority.label_tag  }}</td><td>{{ forms.family.parental_authority }}
71
        {% get_fieldset parental_authority,family_situation,child_custody,job_mother,job_father,rm_mother,rm_father as familly_fields from form %}
72
        {% for field in familly_fields %}
73
        <tr>
74
          <td class="width-limited">{{ field.label_tag }}</td><td>{{ field }}
79 75
            <button type="button"
80 76
              class="dialog-button"
81 77
              data-url="../../ressources/parentalauthoritytype/new/ #form-content"
82 78
              data-default-button="Ajouter"
83 79
              data-next-url="{{ request.get_full_path }}#tab=1"
84 80
              data-add-select="#id_family-parental_authority"
85
              title="Ajouter un type d'autorité parentale">+</button></td><td>{{ forms.family.parental_authority.errors }}</td></tr>
86
        <tr><td class="width-limited">{{ forms.family.family_situation.label_tag  }}</td><td>{{ forms.family.family_situation }}
87
            <button type="button"
88
              class="dialog-button"
89
              data-url="../../ressources/familysituationtype/new/ #form-content"
90
              data-default-button="Ajouter"
91
              data-next-url="{{ request.get_full_path }}#tab=1"
92
              data-add-select="#id_family-family_situation"
93
              title="Ajouter un type de situation familiale">+</button></td><td>{{ forms.family.family_situation.errors }}</td></tr>
94
        <tr><td class="width-limited">{{ forms.family.child_custody.label_tag  }}</td><td>{{ forms.family.child_custody }}
95
            <button type="button"
96
              class="dialog-button"
97
              data-url="../../ressources/parentalcustodytype/new/ #form-content"
98
              data-default-button="Ajouter"
99
              data-next-url="{{ request.get_full_path }}#tab=1"
100
              data-add-select="#id_family-child_custody"
101
              title="Ajouter un type de garde parentale">+</button></td><td>{{ forms.family.child_custody.errors }}</td></tr>
102
        <tr><td class="width-limited">{{ forms.family.job_mother.label_tag  }}</td><td>{{ forms.family.job_mother }}
103
            <button type="button"
104
              class="dialog-button"
105
              data-url="../../ressources/job/new/ #form-content"
106
              data-default-button="Ajouter"
107
              data-next-url="{{ request.get_full_path }}#tab=1"
108
              data-add-select="#id_family-job_mother"
109
              title="Ajouter un type de profession">+</button></td><td>{{ forms.family.job_mother.errors }}</td></tr>
110
        <tr><td class="width-limited">{{ forms.family.job_father.label_tag  }}</td><td>{{ forms.family.job_father }}
111
            <button type="button"
112
              class="dialog-button"
113
              data-url="../../ressources/job/new/ #form-content"
114
              data-default-button="Ajouter"
115
              data-next-url="{{ request.get_full_path }}#tab=1"
116
              data-add-select="#id_family-job_father"
117
              title="Ajouter un type de profession">+</button></td><td>{{ forms.family.job_father.errors }}</td></tr>
118
        <tr><td class="width-limited">{{ forms.family.rm_mother.label_tag  }}</td><td>{{ forms.family.rm_mother }}
119
            <button type="button"
120
              class="dialog-button"
121
              data-url="../../ressources/maritalstatustype/new/ #form-content"
122
              data-default-button="Ajouter"
123
              data-next-url="{{ request.get_full_path }}#tab=1"
124
              data-add-select="#id_family-rm_mother"
125
              title="Ajouter un type de régime">+</button></td><td>{{ forms.family.rm_mother.errors }}</td></tr>
126
        <tr><td class="width-limited">{{ forms.family.rm_father.label_tag  }}</td><td>{{ forms.family.rm_father }}
127
            <button type="button"
128
              class="dialog-button"
129
              data-url="../../ressources/maritalstatustype/new/ #form-content"
130
              data-default-button="Ajouter"
131
              data-next-url="{{ request.get_full_path }}#tab=1"
132
              data-add-select="#id_family-rm_father"
133
              title="Ajouter un type de régime">+</button></td><td>{{ forms.family.rm_father.errors }}</td></tr>
134
        <tr><td class="width-limited">{{ forms.family.family_comment.label_tag  }}</td><td>{{ forms.family.family_comment }}</td><td>{{ forms.family.family_comment.errors }}</td></tr>
81
              title="Ajouter {{ field.label.lower }}">+</button></td><td>{{ field.errors }}</td>
82
        </tr>
83
        {% endfor %}
84
        <tr><td class="width-limited">{{ form.family_comment.label_tag  }}</td><td>{{ form.family_comment }}</td><td>{{ form.family_comment.errors }}</td></tr>
135 85
        </tbody>
136 86
      </table>
137 87
      <input type="hidden"  name="tab"  value="1">
138 88
    </div>
139
  </form>
140 89

  
141
  <form method="post" action="tab2" id="transport-form" class="patientrecordform">
142
    {% csrf_token %}
143 90
    <div class="frame inline">
144 91
      <h3>Transport</h3>
145
      <button class="save">✔</button>
146 92
      <table class="basic">
147 93
        <tbody>
148
        {% for field in forms.transport %}
94
        {% get_fieldset transporttype,transportcompany,simple_appointment_transport,periodic_appointment_transport as transport_fields from form %}
95
        {% for field in transport_fields %}
149 96
        <tr><td class="width-limited">{{ field.label_tag }}</td><td>{{ field }}
150 97
            <button type="button"
151 98
              class="dialog-button"
......
168 115
        </tr>
169 116
      </table>
170 117
    </div>
171
  </form>
172 118

  
173
  <form method="post" action="tab2" id="followup-form" class="patientrecordform">{% csrf_token %}
174 119
    <div class="frame inline">
175 120
      <h3>Suivi du patient</h3>
176
      <button class="save">✔</button>
177 121
      <table class="basic">
178 122
        <tbody>
179
        <tr><td class="width-limited">{{ forms.followup.coordinators.label_tag  }}</td><td>{{ forms.followup.coordinators }}</td><td>{{ forms.followup.coordinators.errors }}</td></tr>
180
        <tr><td class="width-limited">{{ forms.followup.externaldoctor.label_tag  }}</td><td>{{ forms.followup.externaldoctor }}
123
        <tr><td class="width-limited">{{ form.coordinators.label_tag  }}</td><td>{{ form.coordinators }}</td><td>{{ form.coordinators.errors }}</td></tr>
124
        <tr><td class="width-limited">{{ form.externaldoctor.label_tag  }}</td><td>{{ form.externaldoctor }}
181 125
            <button type="button"
182 126
              class="dialog-button"
183 127
              data-url="../../personnes/externaltherapist/new/ #form-content"
184 128
              data-default-button="Ajouter"
185 129
              data-next-url="{{ request.get_full_path }}#tab=1"
186 130
              data-add-select="#id_followup-externaldoctor"
187
              title="Ajouter un médecin extérieur">+</button></td><td>{{ forms.followup.externaldoctor.errors }}</td></tr>
188
        <tr><td class="width-limited">{{ forms.followup.externalintervener.label_tag  }}</td><td>{{ forms.followup.externalintervener }}
131
              title="Ajouter un médecin extérieur">+</button></td><td>{{ form.externaldoctor.errors }}</td></tr>
132
        <tr><td class="width-limited">{{ form.externalintervener.label_tag  }}</td><td>{{ form.externalintervener }}
189 133
            <button type="button"
190 134
              class="dialog-button"
191 135
              data-url="../../personnes/externalworker/new/ #form-content"
192 136
              data-default-button="Ajouter"
193 137
              data-next-url="{{ request.get_full_path }}#tab=1"
194 138
              data-add-select="#id_followup-externalintervener"
195
              title="Ajouter un intervenant extérieur">+</button></td><td>{{ forms.followup.externalintervener.errors }}</td></tr>
139
              title="Ajouter un intervenant extérieur">+</button></td><td>{{ form.externalintervener.errors }}</td></tr>
196 140
        </tbody>
197 141
      </table>
198 142
    </div>
199 143
    <input type="hidden"  name="tab"  value="1">
144
    <p><button class="save enable-on-change">Enregistrer</button></p>
200 145
  </form>
201 146

  
202 147
  <div class="frame">
calebasse/dossiers/templatetags/dossiers.py
1
import copy
2

  
1 3
from django import template
4
from django import forms
5
from django.utils.datastructures import SortedDict
2 6

  
3 7
register = template.Library()
4 8

  
9
def get_fieldset(parser, token):
10
    try:
11
        name, fields, as_, variable_name, from_, form = token.split_contents()
12
    except ValueError:
13
        raise template.TemplateSyntaxError('bad arguments for %r'  % token.split_contents()[0])
14

  
15
    return FieldSetNode(fields.split(','), variable_name, form)
16

  
17
get_fieldset = register.tag(get_fieldset)
18

  
19

  
20
class FieldSetNode(template.Node):
21
    def __init__(self, fields, variable_name, form_variable):
22
        self.fields = fields
23
        self.variable_name = variable_name
24
        self.form_variable = form_variable
25

  
26
    def render(self, context):
27
        form = template.Variable(self.form_variable).resolve(context)
28
        new_form = copy.copy(form)
29
        new_form.fields = SortedDict([(key, form.fields[key]) for key in self.fields if key in self.fields])
30
        context[self.variable_name] = new_form
31

  
32
        return u''
33

  
5 34
def phone(value):
6 35
    result = ""
7 36
    if len(value) == 10:
calebasse/dossiers/views.py
290 290

  
291 291
tab1_general = PatientRecordGeneralView.as_view()
292 292

  
293
class PatientRecordAdmView(cbv.ServiceViewMixin, cbv.MultiUpdateView):
293
class PatientRecordAdmView(cbv.UpdateView):
294 294
    model = PatientRecord
295
    forms_classes = {
296
            'id': forms.CivilStatusForm,
297
            'inscription': forms.InscriptionForm,
298
            'out': forms.OutForm,
299
            'family': forms.FamilyForm,
300
            'transport': forms.TransportFrom,
301
            'followup': forms.FollowUpForm,
302
            }
295
    form_class = forms.AdministrativeForm
303 296
    template_name = 'dossiers/patientrecord_tab2_fiche_adm.html'
304 297
    success_url = './view#tab=1'
305 298

  
306

  
307 299
    def get_context_data(self, **kwargs):
308 300
        ctx = super(PatientRecordAdmView, self).get_context_data(**kwargs)
309 301
        try:
310
-