예제 #1
0
def choose_study():
    allowed_studies = get_admins_allowed_studies_as_query_set()

    # If the admin is authorized to view exactly 1 study, redirect to that study
    if allowed_studies.count() == 1:
        return redirect('/view_study/{:d}'.format(
            allowed_studies.values_list('pk', flat=True).get()))

    # Otherwise, show the "Choose Study" page
    allowed_studies_json = Study.query_set_as_native_json(allowed_studies)
    return render_template('choose_study.html',
                           studies=allowed_studies_json,
                           allowed_studies=allowed_studies_json,
                           system_admin=admin_is_system_admin())
def data_api_web_form_page():
    researcher = Researcher.objects.get(username=session['admin_username'])
    warn_researcher_if_hasnt_yet_generated_access_key(researcher)
    allowed_studies = get_admins_allowed_studies_as_query_set()
    # dict of {study ids : list of user ids}
    users_by_study = {
        study.pk: [user.patient_id for user in study.participants.all()]
        for study in allowed_studies
    }
    return render_template("data_api_web_form.html",
                           allowed_studies=get_admins_allowed_studies(),
                           users_by_study=json.dumps(users_by_study),
                           ALL_DATA_STREAMS=ALL_DATA_STREAMS,
                           system_admin=admin_is_system_admin())