PolicyEngine / PolicyEngine/policyengine-us

Refactor medicaid_group to use state-level override pattern for state-funded Medicaid programs

Open
#7,026 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
163
Forks
213
Avg merge
3d 3h
Merged PRs (30d)
96

Description

## Problem

PR #7005 (Illinois HBI) adds state-specific logic directly into the federal `medicaid_group` variable. This approach doesn't scale well - if other states add similar programs (like California FFYP), the federal file will become cluttered with state-specific code.

Current implementation in `medicaid_group.py`:
```python
# Illinois HBI-specific mapping (for those who fail immigration check
# but are eligible via state-funded HBI program)
il_hbi_eligible = person("il_hbi_eligible", period)
age = person("age", period)
p_hbi = parameters(period).gov.states.il.hfs.hbi.eligibility
il_hbi_child = il_hbi_eligible & (age <= p_hbi.child.max_age)
# ... more Illinois-specific logic
```

## Proposed Solution

Create a generic state override pattern:

1. **New file**: `policyengine_us/variables/gov/states/il/hfs/hbi/il_hbi_medicaid_group.py`
- Returns appropriate `MedicaidGroup` for HBI-eligible people
- Returns `NONE` for everyone else

2. **New file**: `policyengine_us/variables/gov/hhs/medicaid/costs/state_medicaid_group_override.py`
- Aggregates all state-level Medicaid group overrides
- Future state programs just add their variable to this file

3. **Edit**: `policyengine_us/variables/gov/hhs/medicaid/costs/medicaid_group.py`
- Remove state-specific logic
- Add generic check for state override at the end:
```python
state_override = person("state_medicaid_group_override", period)
has_override = state_override != MedicaidGroup.NONE
return where(has_override, state_override, federal_group)
```

## Benefits

- Keeps federal variables clean of state-specific logic
- Scales to multiple states without modifying federal files
- State logic stays in state folders (`gov/states/il/...`)
- Follows existing patterns (similar to how `is_medicaid_eligible` handles state programs)

## Related

- #7005 - Illinois Medicaid for undocumented immigrants

Contributor guide

Open the contributing guide

Research direction

Start with policyengine_us/variables/gov/hhs/medicaid/costs/medicaid_group.py and inspect the existing is_medicaid_eligible state-program pattern. Then review the Illinois HBI logic and create the two named override variables in the state and Medicaid costs paths; done means federal logic no longer contains Illinois-specific handling and state overrides are aggregated generically.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.