示例#1
0
    def test_calculate_pre_screen_results(self):
        """Test that calculating prescreening results works as expected."""
        add_service_data.main(self.app)
        daily_planet = Service.query.filter(Service.name == 'Daily Planet').first()
        result = calculate_pre_screen_results(
            fpl=0,
            has_health_insurance='no',
            is_eligible_for_medicaid='no',
            service_ids=[daily_planet.id]
        )[0]

        self.assertEquals(result['name'], daily_planet.name)
        self.assertEquals(result['eligible'], True)
        self.assertEquals(result['fpl_cutoff'], daily_planet.fpl_cutoff)
        self.assertEquals(result['fpl_eligible'], True)
        self.assertEquals(result['uninsured_only_yn'], daily_planet.uninsured_only_yn)
        self.assertEquals(
            result['medicaid_ineligible_only_yn'],
            daily_planet.medicaid_ineligible_only_yn
        )
        self.assertEquals(
            result['residence_requirement_yn'],
            daily_planet.residence_requirement_yn
        )
        self.assertEquals(
            result['time_in_area_requirement_yn'],
            daily_planet.time_in_area_requirement_yn
        )
        self.assertEquals(result['sliding_scale'], 'Nominal')
        self.assertEquals(result['sliding_scale_range'], 'between 0% and 100%')
        self.assertEquals(result['id'], daily_planet.id)
示例#2
0
    def test_calculate_pre_screen_results(self):
        """Test that calculating prescreening results works as expected."""
        add_service_data.main(self.app)
        daily_planet = Service.query.filter(
            Service.name == 'Daily Planet').first()
        result = calculate_pre_screen_results(fpl=0,
                                              has_health_insurance='no',
                                              is_eligible_for_medicaid='no',
                                              service_ids=[daily_planet.id])[0]

        self.assertEquals(result['name'], daily_planet.name)
        self.assertEquals(result['eligible'], True)
        self.assertEquals(result['fpl_cutoff'], daily_planet.fpl_cutoff)
        self.assertEquals(result['fpl_eligible'], True)
        self.assertEquals(result['uninsured_only_yn'],
                          daily_planet.uninsured_only_yn)
        self.assertEquals(result['medicaid_ineligible_only_yn'],
                          daily_planet.medicaid_ineligible_only_yn)
        self.assertEquals(result['residence_requirement_yn'],
                          daily_planet.residence_requirement_yn)
        self.assertEquals(result['time_in_area_requirement_yn'],
                          daily_planet.time_in_area_requirement_yn)
        self.assertEquals(result['sliding_scale'], 'Nominal')
        self.assertEquals(result['sliding_scale_range'], 'between 0% and 100%')
        self.assertEquals(result['id'], daily_planet.id)
示例#3
0
def patient_share(patient_id):
    """Displays the 'Share Patient' page, which includes prescreening
    results and allows users to send referrals.
    """
    patient = Patient.query.get(patient_id)
    patient.update_stats()
    services = Service.query.all()
    # Get ids of services where the patient already has open referrals,
    # to prevent user from sending duplicates.
    open_referral_service_ids = [
        r.to_service_id for r in patient.referrals
        if (r.in_sent_status() or r.in_received_status())
    ]

    return render_template(
        'patient_share.html',
        patient=patient,
        current_user=current_user,
        services=calculate_pre_screen_results(
            fpl=patient.fpl_percentage,
            has_health_insurance=patient.insurance_status,
            is_eligible_for_medicaid="",
            service_ids=[s.id for s in services]
        ),
        household_size=patient.household_members.count() + 1,
        household_income=patient.total_annual_income,
        fpl=patient.fpl_percentage,
        has_health_insurance=patient.insurance_status,
        is_eligible_for_medicaid="",
        referral_buttons=True,
        open_referral_service_ids=open_referral_service_ids
    )
示例#4
0
def prescreening_results():
    """Page with patient's prescreening results: which services she qualifies for and why,
    which sliding scale she'll fall into, and sample prices.
    """
    fpl = calculate_fpl(session['household_size'],
                        int(session['household_income']) * 12)
    return render_template(
        'prescreening_results.html',
        services=calculate_pre_screen_results(
            fpl=fpl,
            has_health_insurance=session['has_health_insurance'],
            is_eligible_for_medicaid=session['is_eligible_for_medicaid'],
            service_ids=session['service_ids']),
        household_size=session['household_size'],
        household_income=int(session['household_income']) * 12,
        fpl=fpl,
        has_health_insurance=session['has_health_insurance'],
        is_eligible_for_medicaid=session['is_eligible_for_medicaid'])
示例#5
0
def prescreening_results():
    """Page with patient's prescreening results: which services she qualifies for and why,
    which sliding scale she'll fall into, and sample prices.
    """
    fpl = calculate_fpl(session['household_size'], int(session['household_income']) * 12)
    return render_template(
        'prescreening_results.html',
        services=calculate_pre_screen_results(
            fpl=fpl,
            has_health_insurance=session['has_health_insurance'],
            is_eligible_for_medicaid=session['is_eligible_for_medicaid'],
            service_ids=session['service_ids']
        ),
        household_size=session['household_size'],
        household_income=int(session['household_income']) * 12,
        fpl=fpl,
        has_health_insurance=session['has_health_insurance'],
        is_eligible_for_medicaid=session['is_eligible_for_medicaid']
    )
示例#6
0
def patient_share(patient_id):
    """Displays the 'Share Patient' page, which includes prescreening
    results and allows users to send referrals.
    """
    check_patient_permission(patient_id)
    patient = Patient.query.get(patient_id)
    patient.update_stats()
    services = Service.query.all()

    if not current_user.is_patient_user() and current_user.service:
        allowed_referral_service_ids = [
            service.id
            for service in current_user.service.can_send_referrals_to
        ]
    else:
        allowed_referral_service_ids = []

    # Get ids of services where the patient already has open referrals,
    # to prevent user from sending duplicates.
    open_referral_service_ids = [
        r.to_service_id for r in patient.referrals
        if (r.in_sent_status() or r.in_sent_status())
    ]

    return render_template(
        'patient_share.html',
        patient=patient,
        current_user=current_user,
        servicesAll=Service.query.all(),
        services=calculate_pre_screen_results(
            fpl=patient.fpl_percentage,
            has_health_insurance=patient.insurance_status,
            is_eligible_for_medicaid="",
            service_ids=[s.id for s in services if s.has_screening_yn == 'Y']),
        household_size=patient.household_members.count() + 1,
        household_income=patient.total_annual_income,
        fpl=patient.fpl_percentage,
        has_health_insurance=patient.insurance_status,
        is_eligible_for_medicaid="",
        referral_buttons=True,
        allowed_referral_service_ids=allowed_referral_service_ids,
        open_referral_service_ids=open_referral_service_ids)
示例#7
0
def patient_overview(id):

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

    # If this patient has a referral to the current organization in SENT status,
    # update it to RECEIVED
    sent_referrals = [
        r for r in patient.referrals
        if r.to_service_id == current_user.service_id
        and r.in_sent_status()
    ]
    for referral in sent_referrals:
        referral.mark_received()
    if sent_referrals:
        db.session.commit()

    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 = [
        (str(option.id), option.scale_name) for option in sliding_scale_options
    ] or [("", "N/A")]
    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_received_status()
        ]
        for referral in open_referrals:
            referral.mark_completed()

        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 = [
        (str(option.id), option.scale_name) for option in sliding_scale_options
    ] or [("", "N/A")]

    return render_template(
        'patient_overview.html',
        patient=patient,
        form=new_form,
        service=prescreen_results[0],
        past_results=past_results
    )
示例#8
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
    )
示例#9
0
def patient_overview(id):

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

    # If this patient has a referral to the current organization in SENT status,
    # update it to RECEIVED
    sent_referrals = [
        r for r in patient.referrals
        if r.to_service_id == current_user.service_id and r.in_sent_status()
    ]
    for referral in sent_referrals:
        referral.mark_received()
    if sent_referrals:
        db.session.commit()

    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 = [
        (str(option.id), option.scale_name) for option in sliding_scale_options
    ] or [("", "N/A")]
    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_received_status()
        ]
        for referral in open_referrals:
            referral.mark_completed()

        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 = [
        (str(option.id), option.scale_name) for option in sliding_scale_options
    ] or [("", "N/A")]

    return render_template('patient_overview.html',
                           patient=patient,
                           form=new_form,
                           service=prescreen_results[0],
                           past_results=past_results)
示例#10
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)