Exemplo n.º 1
0
def delete(id):
    patient = patient_repository.get(id)
    result = patient_repository.delete(patient)
    if result.success:
        flash_success('Paciente %s foi excluido com sucesso!' % patient.name)
    else:
        flash_error(result.error)

    return redirect(url_for('home.home'))
Exemplo n.º 2
0
def week_search():
    week_year = request.form.get('week', None)

    if not week_year:
        flash_error('Informe a data da consulta!')
        return render_template('dashboard.html')

    year = int(week_year[:4])
    week = int(week_year[-2:])
    return render_template('dashboard/week_visits.html',
                           week_visits=_week_visits(week, year))
Exemplo n.º 3
0
def delete(id):
    visit = visit_repository.get(id)
    plan = visit.plan

    result = visit_repository.delete(visit)
    if result.success:
        flash_success('Consulta foi excluída com sucesso!')
    else:
        flash_error(result.error)

    return redirect(url_for('plan.display', id=plan.id))
Exemplo n.º 4
0
def create_plan(id):
    patient = patient_repository.get(id)
    result = patient.new_plan()
    if result.failure:
        flash_error(result.error)
        return redirect(url_for('.get_plans', id=patient.id))

    form = PlanForm(obj=result.value)
    return render_template('plan.html',
                           patient=patient,
                           form=form,
                           readonly=False)
Exemplo n.º 5
0
def monthly_report():
    month_year = request.form.get('month', None)

    if not month_year:
        flash_error('Informe o Mês!')
        return render_template('finance/monthly.html')

    year = int(month_year[:4])
    month = int(month_year[-2:])

    plans = plan_repository.get_by_month(year, month)
    sorted_plans = _sort_plan_by_payment_type(plans)
    return render_template('finance/monthly.html', sorted_plans=sorted_plans, month=format_date(date(year, month, 1), 'MMMM yyyy'))
Exemplo n.º 6
0
def create():
    form = PatientForm()

    if form.validate_on_submit():
        patient = Patient()
        form.populate_obj(patient)
        result = patient_repository.create(patient)
        if result.success:
            flash_success('Paciente foi adicionado!')
            return redirect(url_for('.get_plans', id=patient.id))
        else:
            flash_error(result.error)

    return render_template('patient.html', form=form)
Exemplo n.º 7
0
def login():
    user_form = UserForm()

    if user_form.is_submitted():
        result = user_repository.authenticate(user_form.username.data,
                                              user_form.password.data)
        if result.success:
            login_user(result.value)
            flash_success('Login efetuado com sucesso.')
            return redirect(url_for('home.home'))

        flash_error(result.error)

    return render_template('login.html', form=user_form)
Exemplo n.º 8
0
def search():
    name = request.form.get('name', None)

    if not name:
        flash_error('Informe o nome do Paciente!')
        return render_template('home.html')

    patient_list = patient_repository.filter(Patient.name.like('%' + str(name) + '%')).all()

    if patient_list:
        patient_list.sort(key=lambda k: k.name)
    else:
        flash_warning('Paciente %s não encontrado!' % name)

    return render_template('home.html', patients=patient_list)
Exemplo n.º 9
0
def update(id):
    patient = patient_repository.get_or_404(id)
    form = PatientForm(obj=patient)

    if form.validate_on_submit():
        form.populate_obj(patient)

        result = patient_repository.save(patient)
        if result.success:
            flash_success('Paciente %s foi atualizado!' % patient.name)
            return redirect(url_for('home.home'))
        else:
            flash_error(result.error)

    return render_template('patient.html', form=form)
Exemplo n.º 10
0
def update(id):
    visit = visit_repository.get(id)
    form = VisitForm(obj=visit, plan=visit.plan)

    if form.validate_on_submit():
        form.populate_obj(visit)

        result = visit_repository.save(visit)

        if result.success:
            flash_success('Consulta foi atualizada com sucesso!')
            return redirect(
                url_for('patient.get_plans', id=visit.plan.patient_id))

        flash_error(result.error)

    return render_template('visit.html', form=form, plan=visit.plan)
Exemplo n.º 11
0
def create_plan_post(id):
    patient = patient_repository.get(id)
    form = PlanForm()
    if form.validate_on_submit():
        plan = Plan(patient)
        form.populate_obj(plan)
        result = plan_repository.save(plan)
        if result.success:
            flash_success('Plano foi cadastrado com sucesso!')
            return redirect(url_for('.get_plans', id=patient.id))

        flash_error(result.error)

    return render_template('plan.html',
                           patient=patient,
                           form=form,
                           readonly=False)
Exemplo n.º 12
0
def _week_visits(week=None, year=None):
    week_visits = []

    for day in week_dates(week=week, year=year):
        day_visits = {}
        visit_list = []

        try:
            visit_list = list(visit_repository.find(date=day))
            visit_list.sort(key=lambda k: k.time)
        except Exception as error:
            flash_error(error)

        day_visits['day'] = day
        day_visits['visits'] = visit_list
        week_visits.append(day_visits)

    return week_visits
Exemplo n.º 13
0
def register_visit(id):
    plan = plan_repository.get(id)
    visit = Visit(plan=plan)
    if _is_get():
        visit.set_now()
        form = VisitForm(obj=visit, plan=plan)
        return render_template('visit.html', form=form, plan=plan)

    form = VisitForm(plan=plan)
    if form.validate_on_submit():
        form.populate_obj(visit)
        result = visit_repository.save(visit)
        if result.success:
            flash_success('Consulta registrada com sucesso!')
            return redirect(url_for('patient.get_plans', id=plan.patient_id))

        flash_error(result.error)

    return render_template('visit.html', form=form, plan=plan)
Exemplo n.º 14
0
def confirm_deposit(id):
    plan = plan_repository.get(id)

    if plan.is_payment_transfer_type():

        plan.verified_deposit = True
        result = plan_repository.save(plan)

        if result.success:
            flash_success('Depósito / PIX confirmado com sucesso!')
            return redirect(url_for('finance.open_deposit'))

        flash_error(result.error)
    else:
        flash_warning(
            'Não é possível confirmar o depósito, verifique a Forma de Pagamento!'
        )

    return redirect(url_for('finance.open_deposit'))
Exemplo n.º 15
0
def update(id):
    plan = plan_repository.get(id)
    form = PlanForm(obj=plan)

    if form.validate_on_submit():
        form.populate_obj(plan)

        result = plan_repository.save(plan)

        if result.success:
            flash_success('Plano foi atualizado com sucesso!')
            return redirect(url_for('patient.get_plans', id=plan.patient_id))

        flash_error(result.error)

    return render_template('plan.html',
                           form=form,
                           patient=plan.patient,
                           readonly=False)
Exemplo n.º 16
0
def annual_report():

    if request.method == 'POST':
        year = request.form.get('year', None)
        if not year:
            flash_error('Informe o Ano!')
            return render_template('finance/annual.html')
    else:
        year = datetime.now().year

    year_total = []
    MonthlyTotal = namedtuple('MonthlyTotal', ['month', 'total'])

    for month in range(1, 13):
        plans = plan_repository.get_by_month(year, month)
        if plans:
            total = reduce(operator.add, map(lambda x: x.total_amount, plans))
            year_total.append(MonthlyTotal(date(2021, month, 1).strftime("%B"), total))

    return render_template('finance/annual.html', year_total=year_total, year=year)
Exemplo n.º 17
0
def create_user():

    username = request.args.get('username')
    password = request.args.get('password')

    if not username or not password:
        flash_error('User not created.')
        return render_template('login.html')

    user = user_repository.new()

    user.username = username
    user.password = password
    user.gen_hash()

    result = user_repository.save(user)

    if result.success:
        flash_success('User created.')
    else:
        flash_error(result.error)

    return render_template('login.html')