Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
benhammondmusic committed May 3, 2024
2 parents 4fc06be + c7aa67b commit dc2f7d6
Show file tree
Hide file tree
Showing 33 changed files with 299 additions and 386 deletions.
6 changes: 3 additions & 3 deletions frontend/playwright-tests/ami.ci.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { test } from '@playwright/test';
test('PHRMA: Medicare AMI', async ({ page }) => {
await page.goto('/exploredata?mls=1.medicare_cardiovascular-3.12&group1=85PLUS&dt1=medicare_ami&demo=age');
await page.locator('#rate-map').getByRole('heading', { name: 'Rates of Acute MI in Florida' }).click();
await page.getByRole('heading', { name: 'Ages 85+, Medicare' }).click();
await page.getByRole('heading', { name: 'Medicare Beneficiaries diagnosed with AMI, Ages 85+' }).click();
await page.getByLabel('Legend for rate map').getByRole('img').click();
await page.locator('li').filter({ hasText: 'Total Medicare Population:' }).click();
await page.locator('#rate-chart').getByText('Medication Utilization and Disease Rates in the Medicare Population (data from 2020)').click();
await page.locator('li').filter({ hasText: 'Total population of Medicare Beneficiaries diagnosed with AMI, Ages 18+:' }).click();
await page.locator('#rate-chart').getByText('Medicare Administrative Data (data from 2020) ').click();
await page.locator('#unknown-demographic-map').getByRole('note').click();
await page.getByRole('button', { name: 'Population vs. distribution' }).click();
await page.getByLabel('Comparison bar chart showing').getByRole('img').click();
Expand Down
2 changes: 1 addition & 1 deletion frontend/playwright-tests/arv_adherence.nightly.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('ARV Adherence', async ({ page }) => {
name: 'Population adherent to antiretrovirals in the United States',
})
.click()
await page.locator('#rate-map').getByRole('heading', { name: 'Medicare beneficiaries' }).click();
await page.locator('#rate-map').getByRole('heading', { name: 'Medicare ARV Beneficiaries, Ages 18+' }).click();
await page.getByText('Demographic', { exact: true }).nth(2).click()
await page.getByText('Off').nth(1).click()
await page.locator('#menu- div').first().click()
Expand Down
4 changes: 2 additions & 2 deletions frontend/playwright-tests/bb_ami.nightly.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ test('PHRMA: Beta Blockers after Heart Attack (AMI)', async ({ page }) => {
await page.getByText('Medicare eligibility:').click();
await page.getByRole('button', { name: 'Eligible due to disability', exact: true }).click();
await page.locator('#rate-map').getByRole('heading', { name: 'Population Persistent to Beta' }).click();
await page.getByRole('heading', { name: 'Eligible due to disability,' }).click();
await page.getByRole('heading', { name: 'Medicare Beta-Blocker Beneficiaries, Eligible due to disability, Ages 18+' }).click();
await page.getByLabel('Legend for rate map').getByRole('img').click();
await page.locator('li').filter({ hasText: 'Total Medicare Population:' }).click();
await page.locator('li').filter({ hasText: 'Total population of Medicare Beta-Blocker Beneficiaries, Ages 18+:' }).click();
await page.locator('#rate-chart').getByRole('heading', { name: 'Population Persistent to Beta' }).click();
await page.getByRole('button', { name: 'Unknown demographic map' }).click();
await page.getByText('No unknown values for').click();
Expand Down
4 changes: 2 additions & 2 deletions frontend/playwright-tests/hiv_prep.nightly.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test('HIV PrEP', async ({ page }) => {
await page.getByRole('heading', { name: 'Share of total PrEP' }).click()
await page
.locator('#unknown-demographic-map')
.getByRole('heading', { name: 'Ages 13+' })
.getByRole('heading', { name: 'Ages 16+' })
.click()
await page.getByText('No unknown values for sex').click()
await page
Expand Down Expand Up @@ -98,7 +98,7 @@ test('HIV PrEP', async ({ page }) => {
.click()
await page
.locator('#population-vs-distribution')
.getByRole('heading', { name: 'Ages 13+' })
.getByRole('heading', { name: 'Ages 16+' })
.click()
await page
.getByRole('heading', { name: 'Breakdown summary for PrEP' })
Expand Down
2 changes: 1 addition & 1 deletion frontend/playwright-tests/medicare_hiv.nightly.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('PHRMA HIV conditions and medication adherence', async ({ page }) => {

await page.locator('#rate-chart').getByRole('heading', { name: 'Rates of HIV cases in the United States' }).click()
await page.locator('#rate-chart').getByRole('heading', { name: 'Medicare beneficiaries' }).click()
await page.locator('#rate-chart').getByText('Sources: Medication').click()
await page.locator('#rate-chart').getByText('Sources: Medicare Administrative Data').click()

await page.locator('#unknown-demographic-map').getByRole('heading', { name: 'Share of total beneficiaries living with HIV with unknown race and ethnicity in the United States' }).click()
await page.locator('#unknown-demographic-map').getByRole('heading', { name: 'Medicare beneficiaries' }).click()
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/cards/DisparityBarChartCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ function DisparityBarChartCardWithKey(props: DisparityBarChartCardProps) {
const chartTitle = generateChartTitle(
/* chartTitle: */
metricConfig?.populationComparisonMetric?.chartTitle ??
metricConfig.chartTitle,
metricConfig.chartTitle,
/* fips: */ props.fips
)

const subtitle = generateSubtitle(
ALL,
props.demographicType,
metricConfig.metricId
props.dataTypeConfig
)

const HASH_ID: ScrollableHashId = 'population-vs-distribution'
Expand Down
22 changes: 17 additions & 5 deletions frontend/src/cards/MapCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { useGuessPreloadHeight } from '../utils/hooks/useGuessPreloadHeight'
import { generateChartTitle, generateSubtitle } from '../charts/utils'
import { useLocation } from 'react-router-dom'
import { type ScrollableHashId } from '../utils/hooks/useStepObserver'
import { useEffect, useMemo, useState } from 'react'
import { useEffect, useState } from 'react'
import { getHighestLowestGroupsByFips } from '../charts/mapHelperFunctions'
import { Legend } from '../charts/Legend'
import GeoContext, {
Expand Down Expand Up @@ -73,6 +73,8 @@ import { type MadLibId } from '../utils/MadLibs'
import { useIsBreakpointAndUp } from '../utils/hooks/useIsBreakpointAndUp'
import HetLinkButton from '../styles/HetComponents/HetLinkButton'
import HetDivider from '../styles/HetComponents/HetDivider'
import { dataSourceMetadataMap } from '../data/config/MetadataMap'
import { DatasetId } from '../data/config/DatasetMetadata'

const SIZE_OF_HIGHEST_LOWEST_GEOS_RATES_LIST = 5
const HASH_ID: ScrollableHashId = 'rate-map'
Expand Down Expand Up @@ -207,8 +209,7 @@ function MapCardWithKey(props: MapCardProps) {

const initialMetridIds = [metricConfig.metricId]

const subPopulationId =
props.dataTypeConfig.metrics.sub_population_count?.metricId
const subPopulationId = metricConfig?.rateDenominatorMetric?.metricId
if (subPopulationId) initialMetridIds.push(subPopulationId)

const queries = [
Expand Down Expand Up @@ -253,7 +254,7 @@ function MapCardWithKey(props: MapCardProps) {
let subtitle = generateSubtitle(
activeDemographicGroup,
demographicType,
metricId
props.dataTypeConfig
)
if (highestLowestGeosMode)
subtitle += ` (only ${props.fips.getPluralChildFipsTypeDisplayName() ?? 'places'
Expand All @@ -278,6 +279,7 @@ function MapCardWithKey(props: MapCardProps) {
isCompareCard={props.isCompareCard}
>
{(queryResponses, metadata, geoData) => {

// contains rows for sub-geos (if viewing US, this data will be STATE level)
const childGeoQueryResponse: MetricQueryResponse = queryResponses[0]
// contains data rows current level (if viewing US, this data will be US level)
Expand All @@ -296,8 +298,17 @@ function MapCardWithKey(props: MapCardProps) {
const totalPopulationPhrase = getTotalACSPopulationPhrase(
acsPopulationQueryResponse.data
)

let subPopSourceLabel = Object.values(dataSourceMetadataMap).find((metadata) => metadata.dataset_ids.includes(parentGeoQueryResponse.consumedDatasetIds[0] as DatasetId))?.data_source_acronym ?? ''

// US Congress denominators come from @unitestedstates not CAWP
if (props.dataTypeConfig.dataTypeId === 'women_in_us_congress') {
subPopSourceLabel = '@unitedstates'
}

const subPopulationPhrase = getSubPopulationPhrase(
parentGeoQueryResponse.data,
subPopSourceLabel,
demographicType,
props.dataTypeConfig
)
Expand Down Expand Up @@ -417,9 +428,10 @@ function MapCardWithKey(props: MapCardProps) {
)

const highestLowestGroupsByFips = getHighestLowestGroupsByFips(
props.dataTypeConfig,
mapQueryResponse.data,
props.demographicType,
metricId
metricId,
)

const isPhrmaAdherence =
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/cards/RateTrendsChartCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
type DemographicGroup,
NON_HISPANIC,
AIAN_API,
ALL,
} from '../data/utils/Constants'
import MissingDataAlert from './ui/MissingDataAlert'
import { splitIntoKnownsAndUnknowns } from '../data/utils/datasetutils'
Expand All @@ -33,6 +34,7 @@ import Hiv2020Alert from './ui/Hiv2020Alert'
import ChartTitle from './ChartTitle'
import { type ElementHashIdHiddenOnScreenshot } from '../utils/hooks/useDownloadCardImage'
import UnknownPctRateGradient from './UnknownPctRateGradient'
import { generateSubtitle } from '../charts/utils'

/* minimize layout shift */
const PRELOAD_HEIGHT = 668
Expand Down Expand Up @@ -70,7 +72,7 @@ export default function RateTrendsChartCard(props: RateTrendsChartCardProps) {

let hasUnknowns = Boolean(metricConfigPctShares)

const isWisqars = props.dataTypeConfig.categoryId === 'community-safety'
const isWisqarsByRace = props.dataTypeConfig.categoryId === 'community-safety' && props.demographicType === 'race_and_ethnicity'

const breakdowns = Breakdowns.forFips(props.fips).addBreakdown(
props.demographicType,
Expand Down Expand Up @@ -103,6 +105,12 @@ export default function RateTrendsChartCard(props: RateTrendsChartCardProps) {
} in ${props.fips.getSentenceDisplayName()}`
}

const subtitle = generateSubtitle(
ALL,
props.demographicType,
props.dataTypeConfig
)

const isCawp = CAWP_METRICS.includes(metricConfigRates.metricId)
const isCawpStateLeg = metricConfigRates.metricId === 'pct_share_of_state_leg'

Expand Down Expand Up @@ -212,6 +220,7 @@ export default function RateTrendsChartCard(props: RateTrendsChartCardProps) {
<TrendsChart
data={nestedRatesData}
chartTitle={getTitleText()}
chartSubTitle={subtitle}
unknown={nestedUnknownPctShareData}
axisConfig={{
type: metricConfigRates.type,
Expand All @@ -233,7 +242,7 @@ export default function RateTrendsChartCard(props: RateTrendsChartCardProps) {
setExpanded={setUnknownsExpanded}
hasUnknowns={hasUnknowns}
/>
{isWisqars && <MissingDataAlert
{isWisqarsByRace && <MissingDataAlert
dataName={`single-race historical data earlier than 2018 for ${metricConfigRates.chartTitle}`}
demographicTypeString={
DEMOGRAPHIC_DISPLAY_TYPES_LOWER_CASE[props.demographicType]
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/cards/ShareTrendsChartCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { type ScrollableHashId } from '../utils/hooks/useStepObserver'
import { CAWP_METRICS, getWomenRaceLabel } from '../data/providers/CawpProvider'
import { type Row } from '../data/utils/DatasetTypes'
import { hasNonZeroUnknowns } from '../charts/trendsChart/helpers'
import { generateChartTitle } from '../charts/utils'
import { generateChartTitle, generateSubtitle } from '../charts/utils'
import { HIV_METRICS } from '../data/providers/HivProvider'
import Hiv2020Alert from './ui/Hiv2020Alert'
import ChartTitle from './ChartTitle'
Expand Down Expand Up @@ -93,6 +93,11 @@ export default function ShareTrendsChartCard(props: ShareTrendsChartCardProps) {
/* fips: */ props.fips
)

const subtitle = generateSubtitle(
ALL,
props.demographicType,
props.dataTypeConfig
)
const HASH_ID: ScrollableHashId = 'inequities-over-time'
const cardHeaderTitle = reportProviderSteps[HASH_ID].label

Expand Down Expand Up @@ -211,6 +216,7 @@ export default function ShareTrendsChartCard(props: ShareTrendsChartCardProps) {
<TrendsChart
data={nestedInequityData}
chartTitle={chartTitle}
chartSubTitle={subtitle}
unknown={nestedUnknowns}
axisConfig={{
type: metricConfigInequitable.type,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/cards/SimpleBarChartCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function SimpleBarChartCardWithKey(props: SimpleBarChartCardProps) {
const subtitle = generateSubtitle(
ALL,
props.demographicType,
metricConfig.metricId
props.dataTypeConfig
)
const filename = `${chartTitle}, by ${DEMOGRAPHIC_DISPLAY_TYPES[props.demographicType]
}`
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/cards/TableCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,12 @@ export default function TableCard(props: TableCardProps) {
'#card-options-menu',
]

const subtitle = generateSubtitle(ALL, props.demographicType, metricIds[0])
const subtitle = generateSubtitle(ALL, props.demographicType, props.dataTypeConfig)

return (
<CardWrapper
downloadTitle={`Table card for ${
props.dataTypeConfig.fullDisplayName
} in ${props.fips.getSentenceDisplayName()}`}
downloadTitle={`Table card for ${props.dataTypeConfig.fullDisplayName
} in ${props.fips.getSentenceDisplayName()}`}
minHeight={preloadHeight}
queries={[query]}
scrollToHash={HASH_ID}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/cards/UnknownsMapCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ function UnknownsMapCardWithKey(props: UnknownsMapCardProps) {
const subtitle = generateSubtitle(
ALL,
props.demographicType,
metricConfig.metricId
props.dataTypeConfig

)

const HASH_ID: ScrollableHashId = 'unknown-demographic-map'
Expand Down
28 changes: 17 additions & 11 deletions frontend/src/cards/ui/GeoContext.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { dataSourceMetadataMap } from '../../data/config/MetadataMap'
import { DataTypeConfig, METRIC_CONFIG } from '../../data/config/MetricConfig'
import { MetricQueryResponse } from '../../data/query/MetricQuery'
import { Row } from '../../data/utils/DatasetTypes'
import {
getSubPopulationPhrase,
Expand All @@ -19,65 +21,67 @@ describe('test getTotalACSPopulationPhrase()', () => {
const normalPopPhrase = getTotalACSPopulationPhrase(
/* data */ nationalACSPopData
)
expect(normalPopPhrase).toEqual('Total Population (from 2022 ACS): 328,016,242')
expect(normalPopPhrase).toEqual('Total population: 328,016,242 (from ACS 2022)')
})
})

describe('test getSubPopulationPhrase()', () => {
const nationalPhrmaData: Row[] = [
{
medicare_population: 41816007,
statins_beneficiaries_estimated_total: 41816007,
race_and_ethnicity: 'All',
fips: '00',
fips_name: 'United States',
},
{
medicare_population: 216860,
statins_beneficiaries_estimated_total: 216860,
race_and_ethnicity: 'American Indian and Alaska Native (NH)',
fips: '00',
fips_name: 'United States',
},
{
medicare_population: 1209171,
statins_beneficiaries_estimated_total: 1209171,
race_and_ethnicity: 'Asian, Native Hawaiian, and Pacific Islander (NH)',
fips: '00',
fips_name: 'United States',
},
{
medicare_population: 4330893,
statins_beneficiaries_estimated_total: 4330893,
race_and_ethnicity: 'Black or African American (NH)',
fips: '00',
fips_name: 'United States',
},
{
medicare_population: 2987102,
statins_beneficiaries_estimated_total: 2987102,
race_and_ethnicity: 'Hispanic or Latino',
fips: '00',
fips_name: 'United States',
},
{
medicare_population: 332663,
statins_beneficiaries_estimated_total: 332663,
race_and_ethnicity: 'Two or more races & Unrepresented race (NH)',
fips: '00',
fips_name: 'United States',
},
{
medicare_population: 32003930,
statins_beneficiaries_estimated_total: 32003930,
race_and_ethnicity: 'White (NH)',
fips: '00',
fips_name: 'United States',
},
]
const statinsAdherenceConfig: DataTypeConfig =
METRIC_CONFIG.medicare_cardiovascular[0]
METRIC_CONFIG.medicare_cardiovascular[1]

test('phrma medicare national population', () => {

const medicarePopPhrase = getSubPopulationPhrase(
/* data */ nationalPhrmaData,
/* subPopulationSourceLabel */ dataSourceMetadataMap.phrma.data_source_acronym,
/* demographicType */ 'race_and_ethnicity',
/* dataTypeConfig */ statinsAdherenceConfig
)
expect(medicarePopPhrase).toEqual('Total Medicare Population: 41,816,007')
expect(medicarePopPhrase).toEqual('Total population of Medicare Statins Beneficiaries, Ages 18+: 41,816,007 (from CMS)')
})

const countyPhrmaData: Row[] = [
Expand Down Expand Up @@ -107,10 +111,11 @@ describe('test getSubPopulationPhrase()', () => {
test('phrma medicare metric expects extra subpop breadcrumb, but pop data is unavailable', () => {
const medicarePopPhrase = getSubPopulationPhrase(
/* data */ countyPhrmaData,
/* subPopulationSourceLabel */ dataSourceMetadataMap.phrma.data_source_acronym,
/* demographicType */ 'sex',
/* dataTypeConfig */ statinsAdherenceConfig
)
expect(medicarePopPhrase).toEqual('Total Medicare Population: unavailable')
expect(medicarePopPhrase).toEqual('Total population of Medicare Statins Beneficiaries, Ages 18+: unavailable (from CMS)')
})

const nationalCovidData: Row[] = [
Expand Down Expand Up @@ -163,6 +168,7 @@ describe('test getSubPopulationPhrase()', () => {
test('covid should not get a subpopulation', () => {
const emptyCovidSubPopPhrase = getSubPopulationPhrase(
/* data */ nationalCovidData,
/* subPopulationSourceLabel */ dataSourceMetadataMap.cdc_restricted.data_source_acronym,
/* demographicType */ 'race_and_ethnicity',
/* dataTypeConfig */ covidCasesConfig
)
Expand Down
Loading

0 comments on commit dc2f7d6

Please sign in to comment.