Project

General

Profile

« Previous | Next » 

Revision 86aa738f

Added by Mikaël Ates over 10 years ago

statistics: active files at the CAMSP are also CLOS and BILAN for act synthesis.

View differences:

calebasse/statistics/statistics.py
1018 1018
    patients = PatientRecord.objects.filter(id__in=[patient[0]
1019 1019
        for patient in patients])
1020 1020

  
1021
    TS = ('TRAITEMENT', 'DIAGNOSTIC', 'SUIVI')
1021
    active_states = None
1022
    if statistic.in_service.name == 'CMPP':
1023
        active_states = ('TRAITEMENT', 'DIAGNOSTIC', )
1024
    elif statistic.in_service.name == 'CAMSP':
1025
        active_states = ('SUIVI', 'BILAN', 'CLOS', )
1026
    else:
1027
        active_states = ('TRAITEMENT', )
1028

  
1022 1029
    inscriptions = []
1023 1030
    for patient in patients:
1024 1031
        # Select patient if she has been in treament between the selected dates
1025
        traitement_states_tmp = FileState.objects.filter(patient=patient, status__type__in=TS, date_selected__lte=statistic.in_end_date).order_by('date_selected')
1032
        traitement_states_tmp = FileState.objects.filter(patient=patient, status__type__in=active_states, date_selected__lte=statistic.in_end_date).order_by('date_selected')
1026 1033
        traitement_states = []
1027 1034
        for ts in traitement_states_tmp:
1028 1035
            if not ts.get_next_state() or ts.get_next_state().date_selected >= statistic.in_start_date:
......
1039 1046
                openings.append(opening)
1040 1047
                opening = []
1041 1048
                start = False
1042
            if ts.get_next_state() and not ts.get_next_state().status.type in TS and ts.get_next_state().get_next_state() and ts.get_next_state().get_next_state().status.type in TS:
1049
            if ts.get_next_state() and not ts.get_next_state().status.type in active_states and ts.get_next_state().get_next_state() and ts.get_next_state().get_next_state().status.type in active_states:
1043 1050
                start = True
1044 1051
            opening.append(ts)
1045 1052
        openings.append(opening)
......
1051 1058
        for opening in openings:
1052 1059
            if len(opening) >= 1:
1053 1060
                first_ts = opening[0]
1054
                while first_ts.previous_state and first_ts.previous_state.status.type in TS:
1061
                while first_ts.previous_state and first_ts.previous_state.status.type in active_states:
1055 1062
                    first_ts = first_ts.previous_state
1056 1063
                contact = None
1057 1064
                if first_ts.previous_state and first_ts.previous_state.status.type=='ACCUEIL':
......
1344 1351
        statistic.in_end_date = datetime.today()
1345 1352
    if not statistic.in_start_date:
1346 1353
        statistic.in_start_date = datetime(statistic.in_end_date.year, 1, 1)
1354

  
1347 1355
    data_tables_set = []
1348 1356
    data_tables = []
1349 1357
    data = []
......
1393 1401
    data_tables.append(data)
1394 1402
    data_tables_set.append(data_tables)
1395 1403

  
1396
    for act_type, acts in acts_types.iteritems():
1404
    for act_type, acts in sorted(acts_types.items(), key=lambda t: t[0].name):
1397 1405
        data_tables=[]
1398 1406
        analysis = {'Non pointés': 0,
1399 1407
            'Reportés': 0, 'Absents': 0, 'Présents': 0}

Also available in: Unified diff