Esempio n. 1
0
def view_user_list():
    if not current_user.has_view_user_permission:
        abort(403)

    units = get_units_for_user_with_permissions(current_user, [UnitUser.has_view_user_permission])
    unit_choices = group_list_to_choices(units, include_blank=True)

    disease_groups = get_disease_groups_for_user_with_permissions(current_user, [DiseaseGroupUser.has_view_user_permission])
    disease_group_choices = group_list_to_choices(disease_groups, include_blank=True)

    form = UserSearchForm(formdata=request.args, csrf_enabled=False)
    form.unit_id.choices = unit_choices
    form.disease_group_id.choices = disease_group_choices

    builder = UserQueryBuilder(current_user)

    if form.validate():
        if form.username.data:
            builder.username(form.username.data)

        if form.email.data:
            builder.email(form.email.data)

        if form.first_name.data:
            builder.first_name(form.first_name.data)

        if form.last_name.data:
            builder.last_name(form.last_name.data)

        # Filter by disease group access
        if form.disease_group_id.data:
            builder.disease_group(form.disease_group_id.data)

        # Filter by unit access
        if form.unit_id.data:
            builder.unit(form.unit_id.data)

    query = builder.build()

    query, ordering = order_query(query, ORDER_BY, 'username')
    pagination = paginate_query(query)
    users = pagination.items

    users = [(x, get_user_data(x)) for x in users]

    context = dict(
        users=users,
        form=form,
        disease_groups=disease_groups,
        units=units,
        pagination=pagination,
        ordering=ordering,
    )

    return render_template('users.html', **context)
Esempio n. 2
0
def view_result_list(patient_id):
    patient = Patient.query.get_or_404(patient_id)

    if not patient.can_view(current_user):
        abort(403)

    context = dict(patient=patient, patient_data=get_patient_data(patient))

    form = SelectResultGroupForm(formdata=request.args, csrf_enabled=False)
    result_group_choices = get_result_group_choices()
    result_group_choices.insert(0, ("", "All"))
    form.result_group_definition_id.choices = result_group_choices

    if form.validate():
        result_group_definition_id = form.result_group_definition_id.data
    else:
        result_group_definition_id = None

    query = (
        Result.query.join(Result.result_group)
        .join(Result.result_definition)
        .join(ResultGroup.result_group_definition)
        .join(ResultGroup.facility)
        .filter(ResultGroup.patient == patient)
    )

    if result_group_definition_id is not None:
        result_group_definition = ResultGroupDefinition.query.get_or_404(result_group_definition_id)
        query = query.filter(ResultGroup.result_group_definition == result_group_definition)
        context["result_group_definition"] = result_group_definition

    query, ordering = order_query(query, LIST_ORDER_BY, "date", DESCENDING)

    query = query.order_by(desc(ResultGroup.date), ResultGroupDefinition.name, ResultDefinition.name)

    pagination = paginate_query(query, default_per_page=50)
    results = pagination.items

    context.update(dict(pagination=pagination, ordering=ordering, results=results, form=form))

    return render_template("patient/results_list.html", **context)