Ejemplo n.º 1
0
def patient_screening_history(patient_id):
    """Display a patient's past referrals and screening results, and a form
    to enter new screening results.
    """
    check_patient_permission(patient_id)
    patient = Patient.query.get(patient_id)
    patient.update_stats()
    form = ReferralCommentForm()

    if form.validate_on_submit():
        referral = PatientReferral.query.get(form.referral_id.data)
        referral_comment = PatientReferralComment()
        referral_comment.patient_referral_id = form.referral_id.data
        referral_comment.notes = form.notes.data
        db.session.add(referral_comment)
        db.session.commit()
        send_referral_comment_email(
            service=referral.to_service,
            patient=patient,
            referral=referral,
            commented_user=current_user
        )

    return render_template('patient_screening_history.html', patient=patient, form=form)
Ejemplo n.º 2
0
def patient_screening_history(patient_id):
    """Display a patient's past referrals and screening results, and a form
    to enter new screening results.
    """
    check_patient_permission(patient_id)
    patient = Patient.query.get(patient_id)
    patient.update_stats()
    form = ReferralCommentForm()

    if form.validate_on_submit():
        referral = PatientReferral.query.get(form.referral_id.data)
        referral_comment = PatientReferralComment()
        referral_comment.patient_referral_id = form.referral_id.data
        referral_comment.notes = form.notes.data
        db.session.add(referral_comment)
        db.session.commit()
        send_referral_comment_email(service=referral.to_service,
                                    patient=patient,
                                    referral=referral,
                                    commented_user=current_user)

    return render_template('patient_screening_history.html',
                           patient=patient,
                           form=form)
Ejemplo n.º 3
0
def patient_overview(id):

    check_patient_permission(id)
    patient = Patient.query.get(id)
    patient.update_stats()

    prescreen_results = calculate_pre_screen_results(
        fpl=patient.fpl_percentage,
        has_health_insurance=patient.insurance_status,
        is_eligible_for_medicaid="",
        service_ids=[current_user.service_id]
    )

    form = ScreeningResultForm()
    sliding_scale_options = SlidingScale.query.filter(
        SlidingScale.service_id == current_user.service_id
    )
    form.sliding_scale_id.choices = [("", "N/A")] + [
        (str(option.id), option.scale_name) for option in sliding_scale_options
    ]

    if form.validate_on_submit():
        screening_result = PatientScreeningResult()
        screening_result.service_id = current_user.service_id
        screening_result.eligible_yn = form.eligible_yn.data
        screening_result.sliding_scale_id = form.sliding_scale_id.data or None
        screening_result.notes = form.notes.data
        patient.screening_results.append(screening_result)

        # If the patient has an open referral to the current organization, mark
        # as completed
        open_referrals = [
            r for r in patient.referrals
            if r.to_service_id == current_user.service.id
            and r.in_sent_status()
        ]
        if open_referrals:
            screening_result.patient_referral_id = open_referrals[0].id
        for referral in open_referrals:
            referral.mark_completed()
            send_referral_closed_email(
                service=referral.to_service,
                patient=patient,
                from_app_user=referral.from_app_user,
                closed_user=current_user
            )

        db.session.commit()

    past_results = [r for r in patient.screening_results
                    if r.service_id == current_user.service_id]
    new_form = ScreeningResultForm(formdata=None)
    new_form.sliding_scale_id.choices = [("", "N/A")] + [
        (str(option.id), option.scale_name) for option in sliding_scale_options
    ]

    # if there is no referral id, then this is a screening result being saved
    # that is not associated to a referral

    if request.form and 'referral_id' in request.form:

        referral_form = ReferralCommentForm()

        if referral_form.validate_on_submit() and referral_form.notes.data != '':
            referral = PatientReferral.query.get(referral_form.referral_id.data)
            referral_comment = PatientReferralComment()
            referral_comment.patient_referral_id = referral_form.referral_id.data
            referral_comment.notes = referral_form.notes.data
            db.session.add(referral_comment)
            db.session.commit()
            send_referral_comment_email(
                service=referral.to_service,
                patient=patient,
                referral=referral,
                commented_user=current_user
            )
    else:
        referral_form = ReferralCommentForm(formdata=None)

    has_open_referral = bool(   
        [r for r in patient.referrals 
         if r.status == 'SENT' and r.to_service_id == current_user.service.id]
    )

    return render_template(
        'patient_overview.html',
        patient=patient,
        form=new_form,
        service=prescreen_results[0],
        past_results=past_results,
        referral_form=referral_form,
        has_open_referral=has_open_referral
    )
Ejemplo n.º 4
0
def patient_overview(id):

    check_patient_permission(id)
    patient = Patient.query.get(id)
    patient.update_stats()

    prescreen_results = calculate_pre_screen_results(
        fpl=patient.fpl_percentage,
        has_health_insurance=patient.insurance_status,
        is_eligible_for_medicaid="",
        service_ids=[current_user.service_id])

    form = ScreeningResultForm()
    sliding_scale_options = SlidingScale.query.filter(
        SlidingScale.service_id == current_user.service_id)
    form.sliding_scale_id.choices = [("", "N/A")] + [
        (str(option.id), option.scale_name) for option in sliding_scale_options
    ]

    if form.validate_on_submit():
        screening_result = PatientScreeningResult()
        screening_result.service_id = current_user.service_id
        screening_result.eligible_yn = form.eligible_yn.data
        screening_result.sliding_scale_id = form.sliding_scale_id.data or None
        screening_result.notes = form.notes.data
        patient.screening_results.append(screening_result)

        # If the patient has an open referral to the current organization, mark
        # as completed
        open_referrals = [
            r for r in patient.referrals if
            r.to_service_id == current_user.service.id and r.in_sent_status()
        ]
        if open_referrals:
            screening_result.patient_referral_id = open_referrals[0].id
        for referral in open_referrals:
            referral.mark_completed()
            send_referral_closed_email(service=referral.to_service,
                                       patient=patient,
                                       from_app_user=referral.from_app_user,
                                       closed_user=current_user)

        db.session.commit()

    past_results = [
        r for r in patient.screening_results
        if r.service_id == current_user.service_id
    ]
    new_form = ScreeningResultForm(formdata=None)
    new_form.sliding_scale_id.choices = [("", "N/A")] + [
        (str(option.id), option.scale_name) for option in sliding_scale_options
    ]

    # if there is no referral id, then this is a screening result being saved
    # that is not associated to a referral

    if request.form and 'referral_id' in request.form:

        referral_form = ReferralCommentForm()

        if referral_form.validate_on_submit(
        ) and referral_form.notes.data != '':
            referral = PatientReferral.query.get(
                referral_form.referral_id.data)
            referral_comment = PatientReferralComment()
            referral_comment.patient_referral_id = referral_form.referral_id.data
            referral_comment.notes = referral_form.notes.data
            db.session.add(referral_comment)
            db.session.commit()
            send_referral_comment_email(service=referral.to_service,
                                        patient=patient,
                                        referral=referral,
                                        commented_user=current_user)
    else:
        referral_form = ReferralCommentForm(formdata=None)

    has_open_referral = bool([
        r for r in patient.referrals
        if r.status == 'SENT' and r.to_service_id == current_user.service.id
    ])

    return render_template('patient_overview.html',
                           patient=patient,
                           form=new_form,
                           service=prescreen_results[0],
                           past_results=past_results,
                           referral_form=referral_form,
                           has_open_referral=has_open_referral)