Revision c0014064
Added by Mikaël Ates over 12 years ago
calebasse/actes/models.py | ||
---|---|---|
4 | 4 |
|
5 | 5 |
from calebasse.agenda.models import Event, EventType |
6 | 6 |
from calebasse.agenda.managers import EventManager |
7 |
from calebasse.dossiers.models import SessadHealthCareNotification |
|
7 |
from calebasse.dossiers.models import SessadHealthCareNotification, \ |
|
8 |
CmppHealthCareDiagnostic, CmppHealthCareTreatment |
|
9 |
from calebasse.actes.validation import are_all_acts_of_the_day_locked |
|
8 | 10 |
|
9 | 11 |
from validation_states import VALIDATION_STATES |
10 | 12 |
|
... | ... | |
43 | 45 |
verbose_name=u'Facturé') |
44 | 46 |
switch_billable = models.BooleanField(default=False, |
45 | 47 |
verbose_name=u'Inverser type facturable') |
48 |
healthcare = models.ForeignKey('dossiers.HealthCare', |
|
49 |
blank=True, |
|
50 |
null=True, |
|
51 |
verbose_name=u'Prise en charge utilisée pour facturée (CMPP)') |
|
46 | 52 |
transport_company = models.ForeignKey('ressources.TransportCompany', |
47 | 53 |
blank=True, |
48 | 54 |
null=True, |
... | ... | |
94 | 100 |
return True |
95 | 101 |
# END Specific to sessad healthcare |
96 | 102 |
|
103 |
# START Specific to cmpp healthcare |
|
104 |
def is_act_covered_by_diagnostic_healthcare(self): |
|
105 |
# L'acte est déja pointé par une prise en charge |
|
106 |
if self.is_billed: |
|
107 |
# Sinon ce peut une refacturation, donc ne pas tenir compte qu'il |
|
108 |
# y est une healthcare non vide |
|
109 |
if self.healthcare and isinstance(self.healthcare, |
|
110 |
CmppHealthCareDiagnostic): |
|
111 |
return (False, self.healthcare) |
|
112 |
elif self.healthcare: |
|
113 |
return (False, None) |
|
114 |
# L'acte doit être facturable |
|
115 |
if not (are_all_acts_of_the_day_locked(self.date) and \ |
|
116 |
self.is_state('VALIDE') and self.is_billable()): |
|
117 |
return (False, None) |
|
118 |
# On prend la dernière prise en charge diagnostic, l'acte ne sera pas |
|
119 |
# pris en charge sur une prise en charge précédente |
|
120 |
# Il peut arriver que l'on ait ajouté une prise en charge de |
|
121 |
# traitement alors que tous les actes pour le diag ne sont pas encore facturés |
|
122 |
try: |
|
123 |
hc = CmppHealthCareDiagnostic.objects.\ |
|
124 |
filter(patient=self.patient).latest('start_date') |
|
125 |
except: |
|
126 |
return (False, None) |
|
127 |
if not hc: |
|
128 |
# On pourrait ici créer une prise en charge de diagnostic |
|
129 |
return (False, None) |
|
130 |
if self.date < hc.start_date: |
|
131 |
return (False, None) |
|
132 |
# Les acts facturés déja couvert par la prise en charge sont pointés |
|
133 |
# dans hc.act_set.all() |
|
134 |
nb_acts_billed = len(hc.act_set.all()) |
|
135 |
if nb_acts_billed >= hc.get_act_number(): |
|
136 |
return (False, None) |
|
137 |
# Il faut ajouter les actes facturables non encore facturés qui précède cet |
|
138 |
# acte |
|
139 |
acts_billable = [a for a in self.patient.act_set.\ |
|
140 |
filter(is_billed=False).order_by('date') \ |
|
141 |
if are_all_acts_of_the_day_locked(a.date) and \ |
|
142 |
a.is_state('VALIDE') and a.is_billable()] |
|
143 |
count = 0 |
|
144 |
for a in acts_billable: |
|
145 |
if nb_acts_billed + count >= hc.get_act_number(): |
|
146 |
return (False, None) |
|
147 |
if a.date >= hc.start_date: |
|
148 |
if a.id == self.id: |
|
149 |
return (True, hc) |
|
150 |
count = count + 1 |
|
151 |
return (False, None) |
|
152 |
|
|
153 |
def is_act_covered_by_treatment_healthcare(self): |
|
154 |
# L'acte est déja pointé par une prise en charge |
|
155 |
if self.is_billed: |
|
156 |
# Sinon ce peut une refacturation, donc ne pas tenir compte qu'il |
|
157 |
# y est une healthcare non vide |
|
158 |
if self.healthcare and isinstance(self.healthcare, |
|
159 |
CmppHealthCareTreatment): |
|
160 |
return (False, self.healthcare) |
|
161 |
elif self.healthcare: |
|
162 |
return (False, None) |
|
163 |
# L'acte doit être facturable |
|
164 |
if not (are_all_acts_of_the_day_locked(self.date) and \ |
|
165 |
self.is_state('VALIDE') and self.is_billable()): |
|
166 |
return (False, None) |
|
167 |
# On prend la dernière prise en charge diagnostic, l'acte ne sera pas |
|
168 |
# pris en charge sur une prise en charge précédente |
|
169 |
# Il peut arriver que l'on ait ajouté une prise en charge de |
|
170 |
# traitement alors que tous les actes pour le diag ne sont pas encore facturés |
|
171 |
try: |
|
172 |
hc = CmppHealthCareTreatment.objects.\ |
|
173 |
filter(patient=self.patient).latest('start_date') |
|
174 |
except: |
|
175 |
return (False, None) |
|
176 |
if not hc: |
|
177 |
return (False, None) |
|
178 |
if self.date < hc.start_date or self.date > hc.end_date: |
|
179 |
return (False, None) |
|
180 |
# Les acts facturés déja couvert par la prise en charge sont pointés |
|
181 |
# dans hc.act_set.all() |
|
182 |
nb_acts_billed = len(hc.act_set.all()) |
|
183 |
if nb_acts_billed >= hc.get_act_number(): |
|
184 |
return (False, None) |
|
185 |
# Il faut ajouter les actes facturables non encore facturés qui précède cet |
|
186 |
# acte |
|
187 |
acts_billable = [a for a in self.patient.act_set.\ |
|
188 |
filter(is_billed=False).order_by('date') \ |
|
189 |
if are_all_acts_of_the_day_locked(a.date) and \ |
|
190 |
a.is_state('VALIDE') and a.is_billable()] |
|
191 |
count = 0 |
|
192 |
for a in acts_billable: |
|
193 |
if nb_acts_billed + count >= hc.get_act_number(): |
|
194 |
return (False, None) |
|
195 |
if a.date >= hc.start_date and a.date <= hc.end_date: |
|
196 |
if a.id == self.id: |
|
197 |
return (True, hc) |
|
198 |
count = count + 1 |
|
199 |
return (False, None) |
|
200 |
# END Specific to cmpp healthcare |
|
201 |
|
|
97 | 202 |
def __unicode__(self): |
98 | 203 |
return '{0} le {1} pour {2} avec {3}'.format( |
99 | 204 |
self.act_type, self.date, self.patient, |
Also available in: Unified diff
actes: add function to determine if an act is covered by an healthcare at the CMPP.