Project

General

Profile

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

calebasse / scripts / check_double.py @ 2e9a060e

1
import calebasse.settings
2
import django.core.management
3

    
4
django.core.management.setup_environ(calebasse.settings)
5

    
6
from calebasse.dossiers.models import PatientRecord
7
from calebasse.actes.models import Act
8

    
9
def main():
10
    seen = []
11
    i = 0
12
    for patient in PatientRecord.objects.all():
13
        acts = Act.objects.filter(patient=patient)
14
        for act in acts:
15
            if not (patient.id, act.date, act.time) in seen:
16
                seen.append((patient.id, act.date, act.time))
17
                same_acts = Act.objects.filter(patient=patient, date=act.date, time=act.time)
18
                nb = same_acts.count()
19
                if nb > 1:
20
                    keep = None
21
                    for a in same_acts:
22
                        state = a.get_state()
23
                        if state and state.state_name != 'NON_VALIDE' and a.validation_locked == True:
24
                            keep = a
25
                            break
26
                    if not keep:
27
                        lockeds = same_acts.filter(validation_locked=True)
28
                        if lockeds.count() >= 1:
29
                            keep = lockeds[0]
30
                        else:
31
                            for a in same_acts:
32
                                state = a.get_state()
33
                                if state and state.state_name != 'NON_VALIDE':
34
                                    keep = a
35
                                    break
36
                            if not keep:
37
                                keep = same_acts[0]
38
                    same_acts.exclude(pk=keep.pk).delete()
39
                    i += 1
40
    print "Nb actes redondants traites: %d" % i
41

    
42
if __name__ == "__main__":
43
    main()
(5-5/33)