Skip to content

Eligibility Verification

Insurance Eligibility Check

Verifies whether a patient's insurance covers a specific medical service.

Contract

check_eligibility

Verify whether a patient is eligible for a specific medical service. Retrieves patient record, checks insurance coverage, and returns a combined eligibility determination.

Inputs
ParameterTypeDefault
patient_idstr
service_codestr
Output
returnEligibilityResult
EligibilityResult Eligibility determination for a medical service.
ParameterTypeDefault
eligible *bool
patient_id *str
reasonstr | NoneNone
planstr | NoneNone
copayfloat | NoneNone
deductible_remainingfloat | NoneNone

Execution Flow

Sequence diagram — check_eligibility

sequenceDiagram
    participant check_eligibility
    participant FetchPatientRecord as EHR / FetchPatientRecord
    check_eligibility->>+FetchPatientRecord: patient_id
    FetchPatientRecord-->>-check_eligibility: response

Source Code

def check_eligibility(patient_id: str, service_code: str) -> EligibilityResult:
    """Verify whether a patient is eligible for a specific medical service.

    Retrieves patient record, checks insurance coverage, and returns
    a combined eligibility determination.
    """
    patient = FetchPatientRecord().call(patient_id)

    try:
        coverage = VerifyInsuranceCoverage().call(
            patient.member_id, service_code
        )
    except ServiceError:
        return EligibilityResult(
            eligible=False,
            reason="Unable to verify insurance coverage",
            patient_id=patient_id,
        )

    if not coverage.active:
        return EligibilityResult(
            eligible=False,
            reason="Insurance plan is not active",
            patient_id=patient_id,
        )

    # Map service code to category
    service_category = service_code.split("-")[0] if "-" in service_code else service_code

    if service_category not in coverage.covered_services:
        return EligibilityResult(
            eligible=False,
            reason=f"Service category '{service_category}' is not covered by plan",
            patient_id=patient_id,
            plan=coverage.plan,
        )

    return EligibilityResult(
        eligible=True,
        patient_id=patient_id,
        plan=coverage.plan,
        copay=coverage.copay,
        deductible_remaining=coverage.deductible_remaining,
    )

Try it Live

Playground — check_eligibility

Verify whether a patient is eligible for a specific medical service. Retrieves patient record, checks insurance coverage, and returns a combined eligibility determination.

View source code
def check_eligibility(patient_id: str, service_code: str) -> EligibilityResult:
    """Verify whether a patient is eligible for a specific medical service.

    Retrieves patient record, checks insurance coverage, and returns
    a combined eligibility determination.
    """
    patient = FetchPatientRecord().call(patient_id)

    try:
        coverage = VerifyInsuranceCoverage().call(
            patient.member_id, service_code
        )
    except ServiceError:
        return EligibilityResult(
            eligible=False,
            reason="Unable to verify insurance coverage",
            patient_id=patient_id,
        )

    if not coverage.active:
        return EligibilityResult(
            eligible=False,
            reason="Insurance plan is not active",
            patient_id=patient_id,
        )

    # Map service code to category
    service_category = service_code.split("-")[0] if "-" in service_code else service_code

    if service_category not in coverage.covered_services:
        return EligibilityResult(
            eligible=False,
            reason=f"Service category '{service_category}' is not covered by plan",
            patient_id=patient_id,
            plan=coverage.plan,
        )

    return EligibilityResult(
        eligible=True,
        patient_id=patient_id,
        plan=coverage.plan,
        copay=coverage.copay,
        deductible_remaining=coverage.deductible_remaining,
    )
Mock configuration
Test cases
  • No test cases saved yet.

Patient Cost Estimation

Estimates the patient's out-of-pocket cost considering deductible, copay, and plan limits.

Contract

estimate_patient_cost

Estimate the patient's out-of-pocket cost for a service. Considers deductible, copay, and plan maximums.

Inputs
ParameterTypeDefault
patient_idstr
service_codestr
billed_amountfloat
Output
returnCostEstimate
CostEstimate Patient out-of-pocket cost estimate.
ParameterTypeDefault
covered *bool
reasonstr | NoneNone
planstr | NoneNone
billed_amountfloat | NoneNone
deductible_appliedfloat | NoneNone
copayfloat | NoneNone
patient_responsibility *float
insurance_paysfloat | NoneNone

Source Code

def estimate_patient_cost(patient_id: str, service_code: str, billed_amount: float) -> CostEstimate:
    """Estimate the patient's out-of-pocket cost for a service.

    Considers deductible, copay, and plan maximums.
    """
    eligibility = check_eligibility(patient_id, service_code)

    if not eligibility.eligible:
        return CostEstimate(
            covered=False,
            reason=eligibility.reason,
            patient_responsibility=billed_amount,
        )

    deductible = eligibility.deductible_remaining
    copay = eligibility.copay

    if billed_amount <= deductible:
        patient_pays = billed_amount
    else:
        patient_pays = deductible + copay

    return CostEstimate(
        covered=True,
        plan=eligibility.plan,
        billed_amount=billed_amount,
        deductible_applied=min(billed_amount, deductible),
        copay=copay if billed_amount > deductible else 0,
        patient_responsibility=round(patient_pays, 2),
        insurance_pays=round(billed_amount - patient_pays, 2),
    )

Try it Live

Playground — estimate_patient_cost

Estimate the patient's out-of-pocket cost for a service. Considers deductible, copay, and plan maximums.

View source code
def estimate_patient_cost(patient_id: str, service_code: str, billed_amount: float) -> CostEstimate:
    """Estimate the patient's out-of-pocket cost for a service.

    Considers deductible, copay, and plan maximums.
    """
    eligibility = check_eligibility(patient_id, service_code)

    if not eligibility.eligible:
        return CostEstimate(
            covered=False,
            reason=eligibility.reason,
            patient_responsibility=billed_amount,
        )

    deductible = eligibility.deductible_remaining
    copay = eligibility.copay

    if billed_amount <= deductible:
        patient_pays = billed_amount
    else:
        patient_pays = deductible + copay

    return CostEstimate(
        covered=True,
        plan=eligibility.plan,
        billed_amount=billed_amount,
        deductible_applied=min(billed_amount, deductible),
        copay=copay if billed_amount > deductible else 0,
        patient_responsibility=round(patient_pays, 2),
        insurance_pays=round(billed_amount - patient_pays, 2),
    )
Mock configuration
Test cases
  • No test cases saved yet.