Project

General

Profile

« Previous | Next » 

Revision 786f0c97

Added by Mikaël Ates over 12 years ago

facturation: Add test for the act list for billing at the SESSAD.

View differences:

calebasse/facturation/tests.py
1
"""
2
This file demonstrates writing tests using the unittest module. These will pass
3
when you run "manage.py test".
4

  
5
Replace this with more appropriate tests for your application.
6
"""
1
# -*- coding: utf-8 -*-
2
from datetime import datetime
3
from dateutil import rrule
7 4

  
8 5
from django.test import TestCase
6
from django.contrib.auth.models import User
7

  
8
from calebasse.actes.validation import automated_validation, \
9
    are_all_acts_of_the_day_locked, \
10
    get_days_with_acts_not_locked
11
from calebasse.actes.models import EventAct
12
from calebasse.dossiers.models import create_patient, \
13
    SessadHealthCareNotification, CmppHealthCareTreatment, CmppHealthCareDiagnostic
14
from calebasse.ressources.models import ActType, Service, WorkerType
15
from calebasse.personnes.models import Worker
16

  
17
from list_acts import list_acts_for_billing_CAMSP
18

  
19

  
20
class FacturationTest(TestCase):
21
    def setUp(self):
22
        self.creator = User.objects.create(username='John')
23

  
24
        self.wtype = WorkerType.objects.create(name='ElDoctor', intervene=True)
25
        self.therapist1 = Worker.objects.create(first_name='Bob', last_name='Leponge', type=self.wtype)
26
        self.therapist2 = Worker.objects.create(first_name='Jean', last_name='Valjean', type=self.wtype)
27
        self.therapist3 = Worker.objects.create(first_name='Pierre', last_name='PaulJacques', type=self.wtype)
28
        self.act_type = ActType.objects.create(name='trepanation')
29

  
30
    def test_facturation_camsp(self):
31
        service_camsp = Service.objects.create(name='CAMSP')
32

  
33
        patient_a = create_patient('a', 'A', service_camsp, self.creator, date_selected=datetime(2020, 10, 5))
34
        act0 = EventAct.objects.create_patient_appointment(self.creator, 'RDV', patient_a, [self.therapist3],
35
                self.act_type, service_camsp, start_datetime=datetime(2020, 10, 6, 10, 15),
36
                end_datetime=datetime(2020, 10, 6, 12, 20))
37
        patient_a.set_state('CAMSP_STATE_SUIVI', self.creator, date_selected=datetime(2020, 10, 7))
38
        act1 = EventAct.objects.create_patient_appointment(self.creator, 'RDV', patient_a, [self.therapist3],
39
                self.act_type, service_camsp, start_datetime=datetime(2020, 10, 7, 10, 15),
40
                end_datetime=datetime(2020, 10, 7, 12, 20))
41
        act2 = EventAct.objects.create_patient_appointment(self.creator, 'RDV', patient_a, [self.therapist3],
42
                self.act_type, service_camsp, start_datetime=datetime(2020, 10, 7, 14, 15),
43
                end_datetime=datetime(2020, 10, 7, 16, 20))
44
        act3 = EventAct.objects.create_patient_appointment(self.creator, 'RDV', patient_a, [self.therapist3],
45
                self.act_type, service_camsp, start_datetime=datetime(2020, 10, 7, 16, 20),
46
                end_datetime=datetime(2020, 10, 7, 17, 20))
47
        patient_a.set_state('CAMSP_STATE_CLOS', self.creator, date_selected=datetime(2020, 10, 8))
48
        act4 = EventAct.objects.create_patient_appointment(self.creator, 'RDV', patient_a, [self.therapist3],
49
                self.act_type, service_camsp, start_datetime=datetime(2020, 10, 8, 10, 15),
50
                end_datetime=datetime(2020, 10, 8, 12, 20))
51

  
52
        patient_b = create_patient('b', 'B', service_camsp, self.creator, date_selected=datetime(2020, 10, 4))
53
        act5 = EventAct.objects.create_patient_appointment(self.creator, 'RDV', patient_b, [self.therapist3],
54
                self.act_type, service_camsp, start_datetime=datetime(2020, 10, 4, 10, 15),
55
                end_datetime=datetime(2020, 10, 4, 12, 20))
56
        act6 = EventAct.objects.create_patient_appointment(self.creator, 'RDV', patient_b, [self.therapist3],
57
                self.act_type, service_camsp, start_datetime=datetime(2020, 10, 5, 10, 15),
58
                end_datetime=datetime(2020, 10, 5, 12, 20))
59
        act6.set_state('ABS_EXC', self.creator)
60
        act7 = EventAct.objects.create_patient_appointment(self.creator, 'RDV', patient_b, [self.therapist3],
61
                self.act_type, service_camsp, start_datetime=datetime(2020, 10, 5, 10, 15),
62
                end_datetime=datetime(2020, 10, 5, 12, 20))
63
        act7.switch_billable = True
64
        act7.save()
65
        patient_b.set_state('CAMSP_STATE_SUIVI', self.creator, date_selected=datetime(2020, 10, 6))
66
        act8 = EventAct.objects.create_patient_appointment(self.creator, 'RDV', patient_b, [self.therapist3],
67
                self.act_type, service_camsp, start_datetime=datetime(2020, 10, 7, 10, 15),
68
                end_datetime=datetime(2020, 10, 7, 12, 20))
69
        act9 = EventAct.objects.create_patient_appointment(self.creator, 'RDV', patient_b, [self.therapist3],
70
                self.act_type, service_camsp, start_datetime=datetime(2020, 10, 7, 14, 15),
71
                end_datetime=datetime(2020, 10, 7, 16, 20))
72
        act10 = EventAct.objects.create_patient_appointment(self.creator, 'RDV', patient_b, [self.therapist3],
73
                self.act_type, service_camsp, start_datetime=datetime(2020, 10, 7, 16, 20),
74
                end_datetime=datetime(2020, 10, 7, 17, 20))
75
        act11 = EventAct.objects.create_patient_appointment(self.creator, 'RDV', patient_b, [self.therapist3],
76
                self.act_type, service_camsp, start_datetime=datetime(2020, 10, 8, 10, 15),
77
                end_datetime=datetime(2020, 10, 8, 12, 20))
78
        patient_b.set_state('CAMSP_STATE_CLOS', self.creator, date_selected=datetime(2020, 10, 9))
79

  
80
        automated_validation(datetime(2020, 10, 5), service_camsp, self.creator)
81
        automated_validation(datetime(2020, 10, 6), service_camsp, self.creator)
82
        automated_validation(datetime(2020, 10, 7), service_camsp, self.creator)
83
        automated_validation(datetime(2020, 10, 8), service_camsp, self.creator)
84

  
85
        not_locked, days_not_locked, not_valide, not_billable, rejected, selected = \
86
            list_acts_for_billing_CAMSP(datetime(2020, 10, 4), datetime(2020, 10, 8), service_camsp)
87

  
88
        self.assertEqual(len(days_not_locked), 1)
89

  
90
        self.assertTrue(act1 in selected[patient_a])
91
        self.assertTrue(act2 in selected[patient_a])
92
        self.assertTrue(act3 in selected[patient_a])
93
        acts_rejected = [x[0] for x in rejected[patient_a]]
94
        self.assertTrue(act0 in acts_rejected)
95
        self.assertTrue(act4 in acts_rejected)
96

  
97
        acts_not_locked = [x[0] for x in not_locked[patient_b]]
98
        self.assertTrue(act5 in acts_not_locked)
99
        acts_not_valide = [x[0] for x in not_valide[patient_b]]
100
        self.assertTrue(act6 in acts_not_valide)
101
        self.assertTrue(act7 in not_billable[patient_b])
102
        self.assertTrue(act8 in selected[patient_b])
103
        self.assertTrue(act9 in selected[patient_b])
104
        self.assertTrue(act10 in selected[patient_b])
105
        self.assertTrue(act11 in selected[patient_b])
9 106

  
107
        states = patient_b.get_states_history()
108
        patient_b.change_day_selected_of_state(states[2], datetime(2020, 10, 7))
109
        not_locked, days_not_locked, not_valide, not_billable, rejected, selected = \
110
            list_acts_for_billing_CAMSP(datetime(2020, 10, 4), datetime(2020, 10, 8), service_camsp)
111
        acts_not_locked = [x[0] for x in not_locked[patient_b]]
112
        self.assertTrue(act5 in acts_not_locked)
113
        acts_not_valide = [x[0] for x in not_valide[patient_b]]
114
        self.assertTrue(act6 in acts_not_valide)
115
        self.assertTrue(act7 in not_billable[patient_b])
116
        acts_rejected = [x[0] for x in rejected[patient_b]]
117
        self.assertTrue(act8 in acts_rejected)
118
        self.assertTrue(act9 in acts_rejected)
119
        self.assertTrue(act10 in acts_rejected)
120
        self.assertTrue(act11 in acts_rejected)
10 121

  
11
class SimpleTest(TestCase):
12
    def test_basic_addition(self):
13
        """
14
        Tests that 1 + 1 always equals 2.
15
        """
16
        self.assertEqual(1 + 1, 2)
122
        states = patient_b.get_states_history()
123
        patient_b.change_day_selected_of_state(states[2], datetime(2020, 10, 9))
124
        patient_b.change_day_selected_of_state(states[1], datetime(2020, 10, 8))
125
        not_locked, days_not_locked, not_valide, not_billable, rejected, selected = \
126
            list_acts_for_billing_CAMSP(datetime(2020, 10, 4), datetime(2020, 10, 8), service_camsp)
127
        acts_not_locked = [x[0] for x in not_locked[patient_b]]
128
        self.assertTrue(act5 in acts_not_locked)
129
        acts_not_valide = [x[0] for x in not_valide[patient_b]]
130
        self.assertTrue(act6 in acts_not_valide)
131
        self.assertTrue(act7 in not_billable[patient_b])
132
        acts_rejected = [x[0] for x in rejected[patient_b]]
133
        self.assertTrue(act8 in acts_rejected)
134
        self.assertTrue(act9 in acts_rejected)
135
        self.assertTrue(act10 in acts_rejected)
136
        self.assertTrue(act11 in selected[patient_b])

Also available in: Unified diff