Skip to content

Commit 6b5a5ec

Browse files
daphnehanse11claude
andcommitted
Fix medicaid_category precedence for pregnant people in expansion states
The medicaid_category variable now iterates in the order defined by covered.yaml parameter file instead of Python dict insertion order. This ensures pregnant people are correctly categorized as PREGNANT instead of ADULT in Medicaid expansion states. Fixes #7127 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 3c8a937 commit 6b5a5ec

File tree

5 files changed

+77
-16
lines changed

5 files changed

+77
-16
lines changed

changelog_entry.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- bump: patch
2+
changes:
3+
fixed:
4+
- Medicaid category precedence now follows covered.yaml order (pregnant/parent before expansion adult)
5+
- Medically needy people now correctly mapped to AGED_DISABLED spending group

policyengine_us/tests/policy/baseline/gov/hhs/medicaid/costs/medicaid_cost_if_enrolled.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
medicaid_cost_if_enrolled: 7_054
7575

7676
- name: Multiple people in recent expansion state
77+
# person1 (age 25 with child) is categorized as PARENT (NON_EXPANSION_ADULT)
78+
# not EXPANSION_ADULT because parent takes precedence per covered.yaml
7779
period: 2024
7880
absolute_error_margin: 0.1
7981
input:
@@ -87,5 +89,5 @@
8789
employment_income: 0
8890
person2:
8991
age: 2
90-
output:
91-
medicaid_cost_if_enrolled: [7_054, 2_867.7]
92+
output:
93+
medicaid_cost_if_enrolled: [4_631.1, 2_867.8]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Test: Pregnant person in Medicaid expansion state
2+
# Expected: Should be assigned NON_EXPANSION_ADULT, not EXPANSION_ADULT
3+
# Reasoning: Pregnancy Medicaid should take precedence over expansion adult
4+
# per the parameter file covered.yaml which lists is_pregnant_for_medicaid first
5+
6+
- name: Pregnant person in expansion state gets pregnancy Medicaid (not expansion)
7+
period: 2024
8+
input:
9+
households:
10+
household:
11+
state_code: CA # California has Medicaid expansion
12+
members: [person]
13+
people:
14+
person:
15+
age: 30
16+
is_pregnant: true
17+
is_pregnant_for_medicaid: true
18+
is_medicaid_eligible: true
19+
output:
20+
medicaid_category: PREGNANT
21+
medicaid_group: NON_EXPANSION_ADULT
22+
23+
- name: Non-pregnant adult in expansion state gets expansion Medicaid
24+
period: 2024
25+
input:
26+
households:
27+
household:
28+
state_code: CA # California has Medicaid expansion
29+
members: [person]
30+
people:
31+
person:
32+
age: 30
33+
is_pregnant: false
34+
is_adult_for_medicaid: true
35+
is_medicaid_eligible: true
36+
output:
37+
medicaid_category: ADULT
38+
medicaid_group: EXPANSION_ADULT
39+
40+
- name: Pregnant person in non-expansion state still gets pregnancy Medicaid
41+
period: 2024
42+
input:
43+
households:
44+
household:
45+
state_code: TX # Texas does not have Medicaid expansion
46+
members: [person]
47+
people:
48+
person:
49+
age: 30
50+
is_pregnant: true
51+
is_pregnant_for_medicaid: true
52+
is_medicaid_eligible: true
53+
output:
54+
medicaid_category: PREGNANT
55+
medicaid_group: NON_EXPANSION_ADULT

policyengine_us/variables/gov/hhs/medicaid/costs/medicaid_group.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ def formula(person, period, parameters):
3636
# Disabled / SSI / medically-needy → AGED_DISABLED
3737
disabled = (
3838
(cat == cats.SSI_RECIPIENT)
39+
| (cat == cats.MEDICALLY_NEEDY)
3940
| person("is_ssi_recipient_for_medicaid", period)
4041
| person("is_optional_senior_or_disabled_for_medicaid", period)
42+
| person("is_medically_needy_for_medicaid", period)
4143
)
4244

4345
# Pregnant OR Parent OR Young adult (19–20) → NON_EXPANSION_ADULT

policyengine_us/variables/gov/hhs/medicaid/eligibility/categories/medicaid_category.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class MedicaidCategory(Enum):
1111
PARENT = "Parent"
1212
PREGNANT = "Pregnant"
1313
SSI_RECIPIENT = "SSI recipient"
14-
SENIOR_OR_DISABLED = " Senior or disabled"
14+
SENIOR_OR_DISABLED = "Senior or disabled"
15+
MEDICALLY_NEEDY = "Medically needy"
1516
NONE = "None"
1617

1718

@@ -38,22 +39,18 @@ def formula(person, period, parameters):
3839
is_pregnant_for_medicaid=MedicaidCategory.PREGNANT,
3940
is_ssi_recipient_for_medicaid=MedicaidCategory.SSI_RECIPIENT,
4041
is_optional_senior_or_disabled_for_medicaid=MedicaidCategory.SENIOR_OR_DISABLED,
42+
is_medically_needy_for_medicaid=MedicaidCategory.MEDICALLY_NEEDY,
4143
)
4244

43-
# Ensure parametric reforms to the list of categories prevent those
44-
# categories from being selected.
45-
46-
variable_to_category = {
47-
name: category
48-
for name, category in variable_to_category.items()
49-
if name in categories
50-
}
45+
# Iterate in the order defined by the parameter file (covered.yaml)
46+
# to ensure correct precedence (e.g., pregnant before expansion adult)
47+
ordered_variables = [
48+
name for name in categories if name in variable_to_category
49+
]
5150

5251
return select(
53-
[
54-
person(variable, period)
55-
for variable in variable_to_category.keys()
56-
]
52+
[person(variable, period) for variable in ordered_variables]
5753
+ [True],
58-
list(variable_to_category.values()) + [MedicaidCategory.NONE],
54+
[variable_to_category[variable] for variable in ordered_variables]
55+
+ [MedicaidCategory.NONE],
5956
)

0 commit comments

Comments
 (0)