Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
benhammondmusic committed Jun 17, 2024
2 parents 4ef7713 + fec6bf8 commit ec23d4d
Show file tree
Hide file tree
Showing 9 changed files with 560 additions and 439 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@
"yaml",
"yml",
"dockercompose"
],
"mypy-type-checker.args": [
"\"--config-file=pyproject.toml\""
]
}
253 changes: 157 additions & 96 deletions python/datasources/graphql_ahr.py

Large diffs are not rendered by default.

24 changes: 21 additions & 3 deletions python/ingestion/graphql_ahr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def generate_cols_map(prefixes: list[str], suffix: str):
return {prefix: prefix.replace(f"_{std_col.RAW_SUFFIX}", "") + f"_{suffix}" for prefix in prefixes}


AHR_BASE_MEASURES = {
'Voter Participation (Presidential)': 'voter_participation_pct_rate',
AHR_MEASURES_TO_RATES_MAP_18PLUS = {
'Asthma': 'asthma_per_100k',
'Avoided Care Due to Cost': 'avoided_care_pct_rate',
'Cardiovascular Diseases': 'cardiovascular_diseases_per_100k',
Expand All @@ -33,11 +32,30 @@ def generate_cols_map(prefixes: list[str], suffix: str):
'Diabetes': 'diabetes_per_100k',
'Excessive Drinking': 'excessive_drinking_per_100k',
'Frequent Mental Distress': 'frequent_mental_distress_per_100k',
'Preventable Hospitalizations': 'preventable_hospitalizations_per_100k',
'Non-Medical Drug Use - Past Year': 'non_medical_drug_use_per_100k',
}

AHR_MEASURES_TO_RATES_MAP_ALL_AGES = {
'Suicide': 'suicide_per_100k',
}

AHR_MEASURES_TO_RATES_MAP_CITIZENS_18PLUS = {
'Voter Participation (Presidential)': 'voter_participation_pct_rate',
}

AHR_MEASURES_TO_RATES_MAP_MEDICARE_18PLUS = {
'Preventable Hospitalizations': 'preventable_hospitalizations_per_100k',
}


AHR_BASE_MEASURES_TO_RATES_MAP = {
**AHR_MEASURES_TO_RATES_MAP_18PLUS,
**AHR_MEASURES_TO_RATES_MAP_CITIZENS_18PLUS,
**AHR_MEASURES_TO_RATES_MAP_MEDICARE_18PLUS,
**AHR_MEASURES_TO_RATES_MAP_ALL_AGES,
}

# AHR provides case per 100; HET needs per 100k
PCT_RATE_TO_PER_100K_TOPICS = [
"Asthma",
"Cardiovascular Diseases",
Expand Down
26 changes: 26 additions & 0 deletions python/ingestion/standardized_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@
PCT_REL_INEQUITY_SUFFIX = "pct_relative_inequity"
RAW_SUFFIX = "estimated_total"
POP_PCT_SUFFIX = 'population_pct'
RATIO_AGE_ADJUSTED_SUFFIX = "ratio_age_adjusted"
INDEX_SUFFIX = "index"

SUFFIXES = [
PER_100K_SUFFIX,
PCT_RATE_SUFFIX,
PCT_SHARE_SUFFIX,
PCT_REL_INEQUITY_SUFFIX,
SHARE_OF_KNOWN_SUFFIX,
RAW_SUFFIX,
POP_PCT_SUFFIX,
RATIO_AGE_ADJUSTED_SUFFIX,
INDEX_SUFFIX,
]

COVID_CASES_PREFIX = "covid_cases"
COVID_HOSP_PREFIX = "covid_hosp"
Expand Down Expand Up @@ -421,3 +435,15 @@ def generate_column_name(prefix, suffix):
suffix: a type of measurement (pct_share, per_100k)"""

return f'{prefix}_{suffix}'


def extract_prefix(col_name: str) -> str:
"""Extracts the prefix from a column name that contains one of out standard HET suffixes."""

for suffix in SUFFIXES:
underscore_suffix = f'_{suffix}'
if col_name.endswith(underscore_suffix):
prefix = col_name[: -len(underscore_suffix)]
return prefix

raise ValueError(f"Column {col_name} does not contain a standard suffix from {SUFFIXES}")
26 changes: 13 additions & 13 deletions python/tests/data/graphql_ahr/golden_data/age_national_current.csv
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
state_name,state_fips,age,voter_participation_pct_rate,asthma_per_100k,avoided_care_pct_rate,cardiovascular_diseases_per_100k,chronic_kidney_disease_per_100k,copd_per_100k,depression_per_100k,diabetes_per_100k,excessive_drinking_per_100k,frequent_mental_distress_per_100k,preventable_hospitalizations_per_100k,non_medical_drug_use_per_100k,suicide_per_100k,population,population_pct
United States,00,45-64,,10100.0,9.6,9100.0,3200.0,7700.0,19100.0,15100.0,15100.0,13500.0,,,,85333288.0,25.6
United States,00,15-24,,,,,,,,,,,,,15.2,43666116.0,13.1
United States,00,18-44,,9900.0,13.1,1900.0,1100.0,2700.0,22200.0,3400.0,23200.0,18400.0,,,,119279569.0,35.8
United States,00,24-34,,,,,,,,,,,,,19.5,,
United States,00,35-44,,,,,,,,,,,,,18.1,42845441.0,12.9
United States,00,45-54,,,,,,,,,,,,,18.2,42062109.0,12.6
United States,00,55-64,,,,,,,,,,,,,17.0,43271179.0,13.0
United States,00,65+,,8600.0,3.4,20600.0,7100.0,12300.0,14600.0,22600.0,7000.0,8500.0,,,16.9,53592546.0,16.1
United States,00,65-74,,,,,,,,,,,,,15.3,31968856.0,9.6
United States,00,75-84,,,,,,,,,,,,,19.6,15235011.0,4.6
United States,00,85+,,,,,,,,,,,,,22.4,6388679.0,1.9
United States,00,All,,9800.0,8.8,8000.0,3000.0,6200.0,20500.0,10900.0,17300.0,14700.0,2681.0,12.0,14.5,333036755.0,100.0
state_name,state_fips,age,voter_participation_pct_rate,asthma_per_100k,avoided_care_pct_rate,cardiovascular_diseases_per_100k,chronic_kidney_disease_per_100k,copd_per_100k,depression_per_100k,diabetes_per_100k,excessive_drinking_per_100k,frequent_mental_distress_per_100k,preventable_hospitalizations_per_100k,non_medical_drug_use_per_100k,suicide_per_100k,population,population_pct,suicide_estimated_total
United States,00,45-64,,10100.0,9.6,9100.0,3200.0,7700.0,19100.0,15100.0,15100.0,13500.0,,,,85333288.0,25.6,
United States,00,15-24,,,,,,,,,,,,,15.2,43666116.0,13.1,6637.0
United States,00,18-44,,9900.0,13.1,1900.0,1100.0,2700.0,22200.0,3400.0,23200.0,18400.0,,,,119279569.0,35.8,
United States,00,24-34,,,,,,,,,,,,,19.5,,,
United States,00,35-44,,,,,,,,,,,,,18.1,42845441.0,12.9,7755.0
United States,00,45-54,,,,,,,,,,,,,18.2,42062109.0,12.6,7655.0
United States,00,55-64,,,,,,,,,,,,,17.0,43271179.0,13.0,7356.0
United States,00,65+,,8600.0,3.4,20600.0,7100.0,12300.0,14600.0,22600.0,7000.0,8500.0,,,16.9,53592546.0,16.1,9057.0
United States,00,65-74,,,,,,,,,,,,,15.3,31968856.0,9.6,4891.0
United States,00,75-84,,,,,,,,,,,,,19.6,15235011.0,4.6,2986.0
United States,00,85+,,,,,,,,,,,,,22.4,6388679.0,1.9,1431.0
United States,00,All,,9800.0,8.8,8000.0,3000.0,6200.0,20500.0,10900.0,17300.0,14700.0,2681.0,12.0,14.5,333036755.0,100.0,48290.0
Loading

0 comments on commit ec23d4d

Please sign in to comment.