Exemplo n.º 1
0
def create_patients():
    form = PatientsForm()

    # The user pressed the "Submit" button
    if 'submit' in request.form:
        if form.validate_on_submit():
            new_request = {
                k: v.capitalize()
                for k, v in request.form.items() if k not in
                ['csrf_token', 'submit', 'cancel', 'ct_scan', 'picture']
            }

            patient = Patient(**new_request, doctor=current_user)
            if form.picture.data:
                patient.picture = save_picture_patients(form.picture.data)

            db.session.add(patient)
            db.session.commit()
            flash('Your patient has been added!', 'success')
            return redirect(
                url_for('patients_blueprint.patients_profile',
                        patient_id=patient.id))

    # The user pressed the "Cancel" button
    if 'cancel' in request.form:
        return redirect(url_for('home_blueprint.index'))

    picture_file = url_for('static', filename='patients_pics/default.png')

    return render_template('edit_info.html',
                           title='Create',
                           heading='Create',
                           form=form,
                           picture_file=picture_file)
Exemplo n.º 2
0
def edit_info(patient_id):
    patient = Patient.query.get_or_404(patient_id)
    form = PatientsForm()

    # The user pressed the "Cancel" button
    if form.cancel.data:
        return redirect(
            url_for('patients_blueprint.patients_profile',
                    patient_id=patient.id))

    # The user pressed the "Submit" button
    if form.submit.data:
        if form.validate_on_submit():
            if form.picture.data:
                patient.picture = save_picture_patients(form.picture.data)

            if form.blood_drawn_date.data:
                patient.blood_drawn_date = datetime.strptime(
                    form.blood_drawn_date.data,
                    '%Y-%m-%d').strftime('%b %d, %Y')

            for field in form:
                if field.name not in [
                        'csrf_token', 'submit', 'cancel', 'ct_scan', 'picture',
                        'blood_drawn_date'
                ]:
                    setattr(patient, field.name, field.data)

            db.session.commit()
            flash('Your patient info has been updated!', 'success')
            return redirect(
                url_for('patients_blueprint.patients_profile',
                        patient_id=patient.id))

    elif request.method == 'GET':
        for field in form:
            if field.name not in [
                    'csrf_token', 'submit', 'cancel', 'ct_scan', 'picture',
                    'blood_drawn_date'
            ]:
                field.data = getattr(patient, field.name)
            elif field.name == 'blood_drawn_date':
                if field.data:
                    field.data = datetime.strptime(
                        patient.blood_drawn_date,
                        '%b %d, %Y').strftime('%Y-%m-%d')

    if patient.picture == '':
        picture_file = url_for('static', filename='patients_pics/default.png')
    else:
        picture_file = url_for('static',
                               filename='patients_pics/' + patient.picture)

    return render_template('edit_info.html',
                           title='Edit',
                           heading='Edit',
                           form=form,
                           picture_file=picture_file,
                           health_info_dict=health_info_dict)