Revision 0eec7968
Added by Mikaël Ates over 12 years ago
calebasse/dossiers/models.py | ||
---|---|---|
11 | 11 |
from calebasse.personnes.models import People |
12 | 12 |
from calebasse.ressources.models import ServiceLinkedAbstractModel |
13 | 13 |
from calebasse.dossiers.states import STATES, STATE_ACCUEIL |
14 |
from calebasse.actes.validation import are_all_acts_of_the_day_locked |
|
14 | 15 |
|
15 | 16 |
DEFAULT_ACT_NUMBER_DIAGNOSTIC = 6 |
16 | 17 |
DEFAULT_ACT_NUMBER_TREATMENT = 30 |
... | ... | |
258 | 259 |
return notification.end_date - today |
259 | 260 |
# END Specific to sessad healthcare |
260 | 261 |
|
262 |
# START Specific to cmpp healthcare |
|
263 |
def create_diag_healthcare(self, modifier): |
|
264 |
""" |
|
265 |
Gestion de l'inscription automatique. |
|
266 |
|
|
267 |
Si un premier acte est validé alors une prise en charge |
|
268 |
diagnostique est ajoutée. Cela fera basculer le dossier dans l'état |
|
269 |
en diagnostic. |
|
270 |
|
|
271 |
A voir si auto ou manuel : |
|
272 |
Si ce n'est pas le premier acte validé mais que l'acte précédement |
|
273 |
facturé a plus d'un an, on peut créer une prise en charge |
|
274 |
diagnostique. Même s'il y a une prise en charge de traitement |
|
275 |
expirée depuis moins d'un an donc renouvelable. |
|
276 |
|
|
277 |
""" |
|
278 |
acts = self.act_set.order_by('date') |
|
279 |
hcs = self.healthcare_set.order_by('-start_date') |
|
280 |
if not hcs: |
|
281 |
# Pas de prise en charge, on recherche l'acte facturable le plus |
|
282 |
# ancien, on crée une pc diag à la même date. |
|
283 |
for act in acts: |
|
284 |
if are_all_acts_of_the_day_locked(act.date) and \ |
|
285 |
act.is_state('VALIDE') and act.is_billable(): |
|
286 |
CmppHealthCareDiagnostic(patient=self, author=modifier, |
|
287 |
start_date=act.date).save() |
|
288 |
break |
|
289 |
else: |
|
290 |
# On recherche l'acte facturable non facturé le plus ancien et |
|
291 |
# l'on regarde s'il a plus d'un an |
|
292 |
try: |
|
293 |
last_billed_act = self.act_set.filter(is_billed=True).\ |
|
294 |
latest('date') |
|
295 |
if last_billed_act: |
|
296 |
for act in acts: |
|
297 |
if are_all_acts_of_the_day_locked(act.date) and \ |
|
298 |
act.is_state('VALIDE') and \ |
|
299 |
act.is_billable() and \ |
|
300 |
(act.date - last_billed_act.date).days >= 365: |
|
301 |
CmppHealthCareDiagnostic(patient=self, |
|
302 |
author=modifier, start_date=act.date).save() |
|
303 |
break |
|
304 |
except: |
|
305 |
pass |
|
306 |
|
|
307 |
def automated_switch_state(self, modifier): |
|
308 |
# Quel est le dernier acte facturable. |
|
309 |
acts = self.act_set.order_by('-date') |
|
310 |
# Si cet acte peut-être pris en charge en diagnostic c'est un acte de |
|
311 |
# diagnostic, sinon c'est un acte de traitement. |
|
312 |
for act in acts: |
|
313 |
if are_all_acts_of_the_day_locked(act.date) and \ |
|
314 |
act.is_state('VALIDE') and act.is_billable(): |
|
315 |
cared, hc = act.is_act_covered_by_diagnostic_healthcare() |
|
316 |
if hc: |
|
317 |
if self.get_state().state_name == 'CMPP_STATE_ACCUEIL' \ |
|
318 |
or self.get_state().state_name == \ |
|
319 |
'CMPP_STATE_TRAITEMENT': |
|
320 |
self.set_state('CMPP_STATE_DIAGNOSTIC', modifier, |
|
321 |
date_selected=act.date) |
|
322 |
# Sinon, si le dossier est en diag, s'il ne peut être couvert |
|
323 |
# en diag, il est en traitement. |
|
324 |
elif self.get_state().state_name == 'CMPP_STATE_DIAGNOSTIC': |
|
325 |
self.set_state('CMPP_STATE_TRAITEMENT', modifier, |
|
326 |
date_selected=act.date) |
|
327 |
break |
|
328 |
# END Specific to cmpp healthcare |
|
329 |
|
|
261 | 330 |
|
262 | 331 |
def create_patient(first_name, last_name, service, creator, |
263 | 332 |
date_selected=None): |
Also available in: Unified diff
dossiers: Create a CMPP diag healthcare and automatically switch state of PatientRecord.
The diagnostic healthcare for CMPP patient is a member function of
PatientRecord model.
The state of the PatientRecord for CMPP patients can be automatically switched
according to the healthcares associated to the patient.