1
|
# -*- coding: utf-8 -*-
|
2
|
from datetime import datetime, date
|
3
|
|
4
|
from django.test import TestCase
|
5
|
from django.contrib.auth.models import User
|
6
|
|
7
|
from validation import automated_validation, are_all_acts_of_the_day_locked, \
|
8
|
get_days_with_acts_not_locked
|
9
|
from calebasse.dossiers.models import create_patient
|
10
|
from calebasse.agenda.models import EventWithAct
|
11
|
from calebasse.ressources.models import ActType, Service, WorkerType
|
12
|
from calebasse.personnes.models import Worker
|
13
|
|
14
|
|
15
|
class ActTest(TestCase):
|
16
|
fixtures = ['services', 'filestates']
|
17
|
def test_act_validation(self):
|
18
|
wtype = WorkerType.objects.create(name='ElDoctor', intervene=True)
|
19
|
therapist1 = Worker.objects.create(first_name='Bob', last_name='Leponge', type=wtype)
|
20
|
therapist2 = Worker.objects.create(first_name='Jean', last_name='Valjean', type=wtype)
|
21
|
therapist3 = Worker.objects.create(first_name='Pierre', last_name='PaulJacques', type=wtype)
|
22
|
act_type = ActType.objects.create(name='trepanation')
|
23
|
service = Service.objects.get(name='CMPP')
|
24
|
|
25
|
creator = User.objects.create(username='John')
|
26
|
patient = create_patient('John', 'Doe', service, creator)
|
27
|
patient2 = create_patient('Jimmy', 'Claff', service, creator)
|
28
|
patient3 = create_patient('Bouba', 'Lourson', service, creator)
|
29
|
|
30
|
act_event = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M X', patient,
|
31
|
[therapist1, therapist2], act_type, service,
|
32
|
start_datetime=datetime(2020, 10, 2, 7, 15),
|
33
|
end_datetime=datetime(2020, 10, 2, 9, 20),
|
34
|
periodicity=1, until=date(2020, 10, 2))
|
35
|
act_event2 = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M Y', patient, [therapist3],
|
36
|
act_type, service, start_datetime=datetime(2020, 10, 2, 10, 15),
|
37
|
end_datetime=datetime(2020, 10, 2, 12, 20),
|
38
|
periodicity=1, until=date(2020, 10, 2))
|
39
|
act_event3 = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M X', patient2,
|
40
|
[therapist1, therapist2], act_type, service,
|
41
|
start_datetime=datetime(2020, 10, 2, 7, 15),
|
42
|
end_datetime=datetime(2020, 10, 2, 9, 20),
|
43
|
periodicity=1, until=date(2020, 10, 2))
|
44
|
act_event4 = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M Y', patient3, [therapist3],
|
45
|
act_type, service, start_datetime=datetime(2020, 10, 2, 10, 15),
|
46
|
end_datetime=datetime(2020, 10, 2, 12, 20),
|
47
|
periodicity=1, until=date(2020, 10, 2))
|
48
|
act_event5 = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M Y', patient3, [therapist3],
|
49
|
act_type, service, start_datetime=datetime(2020, 10, 3, 10, 15),
|
50
|
end_datetime=datetime(2020, 10, 3, 12, 20),
|
51
|
periodicity=1, until=date(2020, 10, 2))
|
52
|
act_event6 = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M Z', patient, [therapist3],
|
53
|
act_type, service, start_datetime=datetime(2020, 10, 2, 10, 15),
|
54
|
end_datetime=datetime(2020, 10, 2, 12, 20),
|
55
|
periodicity=1, until=date(2020, 10, 2))
|
56
|
act_event7 = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M Z', patient, [therapist3],
|
57
|
act_type, service, start_datetime=datetime(2020, 10, 4, 10, 15),
|
58
|
end_datetime=datetime(2020, 10, 4, 12, 20),
|
59
|
periodicity=1, until=date(2020, 10, 4))
|
60
|
|
61
|
act_event3.act.set_state('ABS_EXC', creator)
|
62
|
act_event6.act.set_state('VALIDE', creator)
|
63
|
|
64
|
result = automated_validation(date(2020, 10, 2), service, creator, commit=False)
|
65
|
self.assertEqual(result, (5,2,2,0,1,0,0,0,0,0,0,0))
|
66
|
self.assertTrue(act_event.act.is_state('NON_VALIDE'))
|
67
|
self.assertTrue(act_event2.act.is_state('NON_VALIDE'))
|
68
|
self.assertTrue(act_event3.act.is_state('ABS_EXC'))
|
69
|
self.assertTrue(act_event4.act.is_state('NON_VALIDE'))
|
70
|
self.assertTrue(act_event5.act.is_state('NON_VALIDE'))
|
71
|
self.assertTrue(act_event6.act.is_state('VALIDE'))
|
72
|
|
73
|
result = automated_validation(date(2020, 10, 2), service, creator)
|
74
|
self.assertEqual(result, (5,2,2,0,1,0,0,0,0,0,0,0))
|
75
|
|
76
|
self.assertTrue(act_event.act.is_state('VALIDE'))
|
77
|
self.assertTrue(act_event2.act.is_state('ACT_DOUBLE'))
|
78
|
self.assertTrue(act_event3.act.is_state('ABS_EXC'))
|
79
|
self.assertTrue(act_event4.act.is_state('VALIDE'))
|
80
|
self.assertTrue(act_event5.act.is_state('NON_VALIDE'))
|
81
|
self.assertTrue(act_event6.act.is_state('ACT_DOUBLE'))
|
82
|
|
83
|
self.assertTrue(are_all_acts_of_the_day_locked(datetime(2020, 10, 2, 12, 20)))
|
84
|
self.assertFalse(are_all_acts_of_the_day_locked(datetime(2020, 10, 3, 12, 20)))
|
85
|
self.assertFalse(are_all_acts_of_the_day_locked(datetime(2020, 10, 4, 12, 20)))
|
86
|
self.assertEqual(get_days_with_acts_not_locked(datetime(2020, 10, 2), datetime(2020, 10, 4)),
|
87
|
[date(2020, 10, 3), date(2020, 10, 4)])
|
88
|
|
89
|
result = automated_validation(datetime(2020, 10, 2, 12, 20), service, creator, commit=False)
|
90
|
self.assertEqual(result, (5,2,2,0,1,0,0,0,0,0,0,0))
|
91
|
self.assertTrue(act_event.act.is_state('VALIDE'))
|
92
|
self.assertTrue(act_event2.act.is_state('ACT_DOUBLE'))
|
93
|
self.assertTrue(act_event3.act.is_state('ABS_EXC'))
|
94
|
self.assertTrue(act_event4.act.is_state('VALIDE'))
|
95
|
self.assertTrue(act_event5.act.is_state('NON_VALIDE'))
|
96
|
self.assertTrue(act_event6.act.is_state('ACT_DOUBLE'))
|
97
|
|
98
|
result = automated_validation(datetime(2020, 10, 2, 12, 20), service, creator)
|
99
|
self.assertEqual(result, (5,2,2,0,1,0,0,0,0,0,0,0))
|
100
|
self.assertTrue(act_event.act.is_state('VALIDE'))
|
101
|
self.assertTrue(act_event2.act.is_state('ACT_DOUBLE'))
|
102
|
self.assertTrue(act_event3.act.is_state('ABS_EXC'))
|
103
|
self.assertTrue(act_event4.act.is_state('VALIDE'))
|
104
|
self.assertTrue(act_event5.act.is_state('NON_VALIDE'))
|
105
|
self.assertTrue(act_event6.act.is_state('ACT_DOUBLE'))
|
106
|
|
107
|
result = automated_validation(datetime(2020, 10, 2, 12, 20), service, creator, commit=False)
|
108
|
self.assertEqual(result, (5,2,2,0,1,0,0,0,0,0,0,0))
|
109
|
self.assertTrue(act_event.act.is_state('VALIDE'))
|
110
|
self.assertTrue(act_event2.act.is_state('ACT_DOUBLE'))
|
111
|
self.assertTrue(act_event3.act.is_state('ABS_EXC'))
|
112
|
self.assertTrue(act_event4.act.is_state('VALIDE'))
|
113
|
self.assertTrue(act_event5.act.is_state('NON_VALIDE'))
|
114
|
self.assertTrue(act_event6.act.is_state('ACT_DOUBLE'))
|