results_file.py 4.98 KB
Newer Older
1
2
# coding: utf8
import gluon.contrib.simplejson
3
4
import vidjil_utils

5
6
7
8
9
10
11
12
if request.env.http_origin:
    response.headers['Access-Control-Allow-Origin'] = request.env.http_origin  
    response.headers['Access-Control-Allow-Credentials'] = 'true'
    response.headers['Access-Control-Max-Age'] = 86400
    

## return admin_panel
def index():
13
    if auth.is_admin():
14
15
16
17
18

        query = db(
            (db.results_file.sequence_file_id==db.sequence_file.id)
            & (db.sequence_file.patient_id==db.patient.id)
            & (db.results_file.config_id==db.config.id)
19
20
21
        ).select(
            orderby = ~db.results_file.run_date
        )
22
23
24
25
26
27
28
29
30
        
        for row in query :
            if row.results_file.scheduler_task_id is None :
                row.status = '' 
            else:
                row.status = db.scheduler_task[row.results_file.scheduler_task_id ].status 
            pass
        
        ##sort result
31
32
33
        reverse = False
        if request.vars["reverse"] == "true" :
            reverse = True
34
        if request.vars["sort"] == "name" :
35
            query = query.sort(lambda row : row.patient.last_name, reverse=reverse)
36
        elif request.vars["sort"] == "run_date" :
37
            query = query.sort(lambda row : row.results_file.run_date, reverse=reverse)
38
        elif request.vars["sort"] == "config" :
39
            query = query.sort(lambda row : row.config.name, reverse=reverse)
40
        elif request.vars["sort"] == "patient" :
41
            query = query.sort(lambda row : row.patient.last_name, reverse=reverse)
42
        elif request.vars["sort"] == "status" :
43
            query = query.sort(lambda row : row.status, reverse=reverse)
44
        elif "sort" in request.vars and request.vars["sort"] != "":
45
            query = query.sort(lambda row : row.sequence_file[request.vars["sort"]], reverse=reverse)
46
47

        ##filter
48
49
        ##filter
        if "filter" not in request.vars :
50
            request.vars["filter"] = ""
51
52

        for row in query :
53
            row.string = [row.sequence_file.filename, row.config.name, row.patient.last_name, row.patient.first_name, row.sequence_file.producer, str(row.results_file.run_date), row.status]
54
        query = query.find(lambda row : vidjil_utils.filter(row.string,request.vars["filter"]) )
55
        
56
57
        return dict(query = query,
                    reverse=reverse)
58
59

def run_all():
60
    if auth.is_admin():
61
62
63
64
65
66
67
68
69
70
        query = db(
                (db.results_file_file.sequence_file_id==db.sequence_file.id)
                & (db.results_file.config_id==db.config.id)
            ).select()

        for row in query:
            schedule_run(row.sequence_file.id, row.config.id)

        res = {"success" : "true",
               "message" : "rerun all"}
71
        log.warning(res)
72
73
74
75
76
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))

## display run page result 
## need ["results_file_id"]
def info():
77
    if (auth.can_modify_patient(db.sequence_file[db.results_file[request.vars["results_file_id"]].sequence_file_id].patient_id ) ):
78
79
80
81
82
83
        return dict(message=T('result info'))
    else :
        res = {"message": "acces denied"}
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
    
def confirm():
84
    if (auth.can_modify_patient(db.sequence_file[db.results_file[request.vars["results_file_id"]].sequence_file_id].patient_id )
85
        & auth.can_process_file()):
86
87
88
89
90
91
92
        return dict(message=T('result confirm'))
    else :
        res = {"message": "acces denied"}
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
    
#
def delete():
93
    if (auth.can_modify_patient(db.sequence_file[db.results_file[request.vars["results_file_id"]].sequence_file_id].patient_id )
94
        & auth.can_process_file()):
95
96
97
98
        
        config_id = db.results_file[request.vars["results_file_id"]].config_id
        patient_id = db.sequence_file[db.results_file[request.vars["results_file_id"]].sequence_file_id].patient_id
        
Marc Duez's avatar
Marc Duez committed
99
        #delete results_file
100
        db(db.results_file.id == request.vars["results_file_id"]).delete()
Marc Duez's avatar
Marc Duez committed
101
102
103
104
105
106
107
108
109
110
111
112
113
        
        #delete fused_file 
        count = db((db.patient.id == patient_id) & 
                   (db.sequence_file.patient_id == db.patient.id) &
                   (db.sequence_file.id == db.results_file.sequence_file_id) &
                   (db.results_file.config_id == config_id)
                   ).count()
        
        if count == 0 :
            db((db.fused_file.patient_id == patient_id ) &
               (db.fused_file.config_id == config_id)
               ).delete()
        
114
115
116
117
        res = {"redirect": "patient/info",
               "args" : { "id" : patient_id,
                          "config_id" : config_id},
               "success": "true",
118
               "message": "[%s] (%s) c%s: process deleted " % (request.vars["results_file_id"], patient_id, config_id)}
119
        log.info(res)
120
121
122
123
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
    else :
        res = {"message": "acces denied"}
        return gluon.contrib.simplejson.dumps(res, separators=(',',':'))