Project

General

Profile

Download (7.26 KB) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / dossiers / forms.py @ 3e10c7d9

1
# -*- coding: utf-8 -*-
2

    
3
from datetime import date
4

    
5
from django import forms
6
from django.forms import ModelForm, Form
7

    
8
from calebasse.dossiers.models import (PatientRecord,
9
    PatientAddress, PatientContact, DEFAULT_ACT_NUMBER_TREATMENT,
10
    CmppHealthCareTreatment, CmppHealthCareDiagnostic,
11
    SessadHealthCareNotification)
12
from calebasse.dossiers.states import STATE_CHOICES
13
from calebasse.ressources.models import (HealthCenter, LargeRegime)
14

    
15
from ajax_select import make_ajax_field
16

    
17

    
18
class EditPatientRecordForm(ModelForm):
19
    class Meta:
20
        model = PatientRecord
21

    
22
class SearchForm(Form):
23
    last_name = forms.CharField(label=u'Nom', required=False)
24
    first_name = forms.CharField(label=u'Prénom', required=False)
25
    folder_id = forms.CharField(label=u'Numéro de dossier', required=False)
26
    social_security_id = forms.CharField(label=u"Numéro d'assuré social", required=False)
27
    states = forms.MultipleChoiceField(
28
            widget=forms.CheckboxSelectMultiple(attrs={'class':'checkbox_state'}),
29
            choices=STATE_CHOICES, initial=(0,1,2,3,4))
30

    
31
class StateForm(Form):
32
    patient_id = forms.IntegerField()
33
    service_id = forms.IntegerField()
34
    state_type = forms.CharField(max_length=40)
35
    date = forms.DateField(label=u'Date')
36
    comment = forms.CharField(label='Commentaire',
37
            required=False, widget=forms.Textarea)
38

    
39
class NewPatientRecordForm(ModelForm):
40
    date_selected = forms.DateField(label=u"Date de contact", initial=date.today())
41

    
42
    class Meta:
43
        model = PatientRecord
44
        fields = ('last_name', 'first_name')
45

    
46
class GeneralForm(ModelForm):
47
    class Meta:
48
        model = PatientRecord
49
        fields = ('comment', 'pause')
50
        widgets = {
51
                'comment': forms.Textarea(attrs={'cols': 50, 'rows': 5}),
52
                }
53

    
54
class CivilStatusForm(ModelForm):
55
    class Meta:
56
        model = PatientRecord
57
        fields = ('first_name', 'last_name', 'birthdate', 'gender', 'nationality')
58

    
59
class PhysiologyForm(ModelForm):
60
    class Meta:
61
        model = PatientRecord
62
        fields = ('size', 'weight', 'pregnancy_term')
63

    
64
class InscriptionForm(ModelForm):
65
    class Meta:
66
        model = PatientRecord
67
        fields = ('analysemotive', 'familymotive', 'advicegiver')
68
        widgets = {}
69

    
70
class FamilyForm(ModelForm):
71
    class Meta:
72
        model = PatientRecord
73
        fields = ('sibship_place', 'nb_children_family', 'parental_authority',
74
                'family_situation', 'child_custody')
75

    
76
class TransportFrom(ModelForm):
77
    class Meta:
78
        model = PatientRecord
79
        fields = ('transporttype', 'transportcompany')
80

    
81
class PaperIDForm(ModelForm):
82
    class Meta:
83
        model = PatientRecord
84
        fields = ('paper_id', )
85

    
86
class PolicyHolderForm(ModelForm):
87
    class Meta:
88
        model = PatientRecord
89
        fields = ('policyholder', )
90
        widgets = { 'policyholder': forms.RadioSelect() }
91

    
92
class FollowUpForm(ModelForm):
93
    coordinators = make_ajax_field(PatientRecord, 'coordinators', 'worker', True)
94
    class Meta:
95
        model = PatientRecord
96
        fields = ('coordinators', 'externaldoctor', 'externalintervener')
97

    
98
class PatientContactForm(ModelForm):
99
    addresses = make_ajax_field(PatientContact, 'addresses', 'addresses', True)
100
    health_org = forms.CharField(label=u"Numéro de l'organisme destinataire", required=False)
101

    
102
    class Meta:
103
        model = PatientContact
104
        widgets = {
105
                'contact_comment': forms.Textarea(attrs={'cols': 50, 'rows': 2}),
106
                'key': forms.TextInput(attrs={'size': 4}),
107
                'twinning_rank': forms.TextInput(attrs={'size': 4}),
108
                'health_org': forms.TextInput(attrs={'size': 9}),
109
                }
110

    
111
    def __init__(self, *args, **kwargs):
112
        super(PatientContactForm, self).__init__(*args,**kwargs)
113
        if self.instance and self.instance.health_center:
114
            print self.instance.health_center
115
            self.fields['health_org'].initial = self.instance.health_center.large_regime.code + self.instance.health_center.health_fund + self.instance.health_center.code
116

    
117
    def clean(self):
118
        cleaned_data = super(PatientContactForm, self).clean()
119
        health_org = cleaned_data.get('health_org')
120
        if health_org:
121
            msg = None
122
            lr = None
123
            hc = None
124
            if len(health_org) < 5:
125
                msg = u"Numéro inférieur à 5 chiffres."
126
            else:
127
                try:
128
                    lr = LargeRegime.objects.get(code=health_org[:2])
129
                except:
130
                    msg = u"Grand régime %s inconnu." % health_org[:2]
131
                else:
132
                    hcs = HealthCenter.objects.filter(health_fund=health_org[2:5], large_regime=lr)
133
                    if not hcs:
134
                        msg = u"Caisse %s inconnue." % health_org[2:5]
135
                    elif len(hcs) == 1:
136
                        hc = hcs[0]
137
                    else:
138
                        if len(health_org) == 9:
139
                            hcs = hcs.filter(code=health_org[5:9])
140
                            if not hcs:
141
                                msg = u"Centre %s inconnu." % health_org[5:9]
142
                            elif len(hcs) == 1:
143
                                hc = hcs[0]
144
                            else:
145
                                msg = u"Ceci ne devrait pas arriver, %s n'est pas unique." % health_org
146
                        else:
147
                            msg = "Plusieurs centres possibles, précisez parmi :"
148
                            for hc in hcs:
149
                                msg += " %s" % str(hc)
150
            if msg:
151
                self._errors["health_org"] = self.error_class([msg])
152
            else:
153
                cleaned_data['large_regime'] = lr.code
154
                cleaned_data['health_center'] = hc
155
        return cleaned_data
156

    
157

    
158
class PatientAddressForm(ModelForm):
159

    
160
    class Meta:
161
        model = PatientAddress
162
        widgets = {
163
                'comment': forms.Textarea(attrs={'cols': 40, 'rows': 4}),
164
                'zip_code': forms.TextInput(attrs={'size': 10}),
165
                'number': forms.TextInput(attrs={'size': 10}),
166
                }
167

    
168
class CmppHealthCareTreatmentForm(ModelForm):
169
    class Meta:
170
        model = CmppHealthCareTreatment
171
        fields = ('start_date', 'act_number',
172
                'prolongation', 'comment', 'patient', 'author')
173
        widgets = {
174
                'comment': forms.Textarea(attrs={'cols': 40, 'rows': 4}),
175
                'patient': forms.HiddenInput(),
176
                'author': forms.HiddenInput(),
177
                }
178

    
179
class CmppHealthCareDiagnosticForm(ModelForm):
180
    class Meta:
181
        model = CmppHealthCareDiagnostic
182
        fields = ('start_date', 'act_number',
183
                'comment', 'patient', 'author')
184
        widgets = {
185
                'comment': forms.Textarea(attrs={'cols': 39, 'rows': 4}),
186
                'patient': forms.HiddenInput(),
187
                'author': forms.HiddenInput(),
188
                }
189

    
190
class SessadHealthCareNotificationForm(ModelForm):
191
    class Meta:
192
        model = SessadHealthCareNotification
193
        fields = ('start_date', 'end_date',
194
                'comment', 'patient', 'author')
195
        widgets = {
196
                'comment': forms.Textarea(attrs={'cols': 40, 'rows': 4}),
197
                'patient': forms.HiddenInput(),
198
                'author': forms.HiddenInput(),
199
                }
(3-3/9)