Projet

Général

Profil

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

Jérôme Schneider, 23 juillet 2014 09:41

Télécharger (20,4 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     | 92 +++++++++-------------
 calebasse/dossiers/templatetags/dossiers.py        | 29 +++++++
 calebasse/dossiers/views.py                        | 12 +--
 4 files changed, 92 insertions(+), 100 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
  <button class="save enable-on-change">Enregistrer</button>
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
        <tr><td class="width-limited">{{ form.last_name.label_tag }}</td><td><span class="lastname">{{ form.last_name }}</span></td><td>{{ form.last_name.errors }}</td></tr>
10
        <tr><td class="width-limited">{{ form.first_name.label_tag }}</td><td>{{ form.first_name }}</td><td>{{ form.first_name.errors }}</td></tr>
11
        <tr><td class="width-limited">{{ form.birthplace.label_tag }}</td><td>{{ form.birthplace }}</td><td>{{ form.birthplace.errors }}</td></tr>
12
        <tr><td class="width-limited">{{ form.birthdate.label_tag }}</td><td>{{ form.birthdate }}</td><td>{{ form.birthdate.errors }}</td></tr>
13
        <tr><td class="width-limited">{{ form.gender.label_tag }}</td><td>{{ form.gender }}</td><td>{{ form.gender.errors }}</td></tr>
14
        <tr><td class="width-limited">{{ form.nationality.label_tag }}</td><td>{{ form.nationality }}</td><td>{{ form.nationality.errors }}</td></tr>
14 15
        </tbody>
15 16
      </table>
16 17
      <input type="hidden"  name="tab"  value="1">
17 18
    </div>
18
  </form>
19 19

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

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

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

  
141
  <form method="post" action="tab2" id="transport-form" class="patientrecordform">
142
    {% csrf_token %}
143 131
    <div class="frame inline">
144 132
      <h3>Transport</h3>
145
      <button class="save">✔</button>
146 133
      <table class="basic">
147 134
        <tbody>
148
        {% for field in forms.transport %}
135
        {% get_fieldset transporttype,transportcompany,simple_appointment_transport,periodic_appointment_transport as transport_fields from form %}
136
        {% for field in transport_fields %}
149 137
        <tr><td class="width-limited">{{ field.label_tag }}</td><td>{{ field }}
150 138
            <button type="button"
151 139
              class="dialog-button"
......
168 156
        </tr>
169 157
      </table>
170 158
    </div>
171
  </form>
172 159

  
173
  <form method="post" action="tab2" id="followup-form" class="patientrecordform">{% csrf_token %}
174 160
    <div class="frame inline">
175 161
      <h3>Suivi du patient</h3>
176
      <button class="save">✔</button>
177 162
      <table class="basic">
178 163
        <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 }}
164
        <tr><td class="width-limited">{{ form.coordinators.label_tag  }}</td><td>{{ form.coordinators }}</td><td>{{ form.coordinators.errors }}</td></tr>
165
        <tr><td class="width-limited">{{ form.externaldoctor.label_tag  }}</td><td>{{ form.externaldoctor }}
181 166
            <button type="button"
182 167
              class="dialog-button"
183 168
              data-url="../../personnes/externaltherapist/new/ #form-content"
184 169
              data-default-button="Ajouter"
185 170
              data-next-url="{{ request.get_full_path }}#tab=1"
186 171
              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 }}
172
              title="Ajouter un médecin extérieur">+</button></td><td>{{ form.externaldoctor.errors }}</td></tr>
173
        <tr><td class="width-limited">{{ form.externalintervener.label_tag  }}</td><td>{{ form.externalintervener }}
189 174
            <button type="button"
190 175
              class="dialog-button"
191 176
              data-url="../../personnes/externalworker/new/ #form-content"
192 177
              data-default-button="Ajouter"
193 178
              data-next-url="{{ request.get_full_path }}#tab=1"
194 179
              data-add-select="#id_followup-externalintervener"
195
              title="Ajouter un intervenant extérieur">+</button></td><td>{{ forms.followup.externalintervener.errors }}</td></tr>
180
              title="Ajouter un intervenant extérieur">+</button></td><td>{{ form.externalintervener.errors }}</td></tr>
196 181
        </tbody>
197 182
      </table>
198 183
    </div>
199 184
    <input type="hidden"  name="tab"  value="1">
185
  <button class="save enable-on-change">Enregistrer</button>
200 186
  </form>
201 187

  
202 188
  <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, value) for key, value in form.fields.items() 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
-