Exemplo n.º 1
0
def getAllCases():
    # get all the cases from the data base
    cases = PatientCases.find(session['username'])
    return render_template('case-view.html',
                           result={
                               'status': 'success',
                               'cases': cases
                           })
Exemplo n.º 2
0
def getAllCases():
    result = {'error': {}}
    #if username is in session then the call is web call, so use that username
    if 'username' in session and len(session['username']) > 0:
        username = session['username']
    else:
        if 'key' not in request.args or len(request.args['key']) == 0:
            result['error']['error'] = True
            result['error']['error_msgessage'] = "key not specified"
            return jsonify(result)

        auth_result = Auth.checkKeyValidity(request.args['key'])

        if not auth_result['valid']:
            result['error']['error'] = True
            result['error']['error_msgessage'] = "key not valid"
            return jsonify(result)

        username = auth_result['username']

    if 'page' in request.args:
        page = int(request.args['page'])
    else:
        page = None

    result['error']['error'] = False
    result['cases'] = []
    cases = PatientCases.find(username, page)
    #return str(cases)
    if cases is None:
        result['error']['error'] = True
        result['error']['error_msgessage'] = "No cases found"
        return jsonify(result)
    for case in cases:
        cs = {}
        cs['patient_name'] = case['patient_name']
        cs['patient_age'] = case['patient_age']
        cs['case_id'] = str(case["_id"])
        if 'case_name' in case:
            cs['case_name'] = case['case_name']
        if 'datetime' in case:
            cs['datetime'] = case['datetime']

        if 'ignore_images' not in request.args or request.args[
                'ignore_images'] == 'false':
            cs['files'] = []
            i = 0
            for series in case['files']:
                s = {}
                s['series_description'] = series['series_description']
                s['series_time'] = series['series_time']
                j = 0
                s['images'] = []
                for image in series['images']:
                    im = {}
                    im['url'] = BASE_URL + url_for(
                        'patient_cases_api.getImage',
                        case_id=str(case["_id"]),
                        index_1=i,
                        index_2=j)
                    im['filename'] = image['org_filename']
                    s['images'].append(im)
                    j += 1
                cs['files'].append(s)
                i += 1
        result['cases'].append(cs)
    return jsonify(result)