Skip to content

Commit

Permalink
Merge pull request #8 from jcunninghame/jcunni/pre-commit
Browse files Browse the repository at this point in the history
Jcunni/pre commit
  • Loading branch information
jcunninghame authored May 24, 2023
2 parents e04d59d + 14d701c commit fc1bcf7
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 130 deletions.
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
language_version: python3.10
31 changes: 20 additions & 11 deletions components.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,56 @@


def financial_bans(summary_stats_data):
# TODO: Add Year filter
"""Takes dataframe of financial summary data at the year level and displays BANs
for med spend, pharm spend, member months and average pmpm. Can handle dataframe with
multiple years or a single year. Dataframe should be pre-filtered to the time frame desired."""
multiple years or a single year. Dataframe should be pre-filtered to the time frame desired.
"""
year_values = sorted(list(set(summary_stats_data["year"])))
summary_stats_data = summary_stats_data.copy(deep=True)
summary_stats_data = summary_stats_data.loc[summary_stats_data["year"].isin(year_values)]
summary_stats_data = summary_stats_data.loc[
summary_stats_data["year"].isin(year_values)
]
if len(year_values) == 1:
year_string = year_values[0]
else:
year_string = "{} - {}".format(year_values[0], year_values[-1])
st.markdown(f"""
st.markdown(
f"""
These financial summary charts offer a concise and comprehensive snapshot of your organization's financial
performance, providing key metrics and insights at a glance.
The top three metrics you need to know about your data at all times are medical paid amount, pharmacy
paid amount and pmpm.
""")
paid amount and pmpm."""
)
st.markdown(f"### Spend Summary in {year_string}")

med_spend = summary_stats_data["medical_paid_amount"].sum()
pharm_spend = summary_stats_data["pharmacy_paid_amount"].sum()
member_mon_count = summary_stats_data["member_month_count"].sum()
avg_pmpm = med_spend/member_mon_count
avg_pmpm = med_spend / member_mon_count
col1, col2, col3, col4 = st.columns(4)
col1.metric("Medical Spend", util.human_format(med_spend))
col2.metric("Pharmacy Spend", util.human_format(pharm_spend))
col3.metric("Member Months", util.human_format(member_mon_count))
col4.metric('Average PMPM', util.human_format(avg_pmpm))
col4.metric("Average PMPM", util.human_format(avg_pmpm))


def year_slider(year_values):
st.divider()
st.markdown("""
st.markdown(
"""
Use the following time slider to cut the following charts by the year range of your interest.
""")
"""
)

start_year, end_year = st.select_slider(
label="Select a range of years",
options=year_values,
value=(year_values[0], year_values[-1]),
label_visibility='collapsed'
label_visibility="collapsed",
)
selected_range = year_values[year_values.index(start_year): year_values.index(end_year)+1]
selected_range = year_values[
year_values.index(start_year) : year_values.index(end_year) + 1
]
return selected_range
87 changes: 62 additions & 25 deletions main_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# Connect and fetch data
conn = util.connection()


@st.cache_data
def summary_stats():
query = """
Expand Down Expand Up @@ -43,37 +44,42 @@ def summary_stats():
data = util.safe_to_pandas(conn, query)
return data


@st.cache_data
def pmpm_data():
query = """SELECT PT.*, PB.MEMBER_COUNT, PHARMACY_SPEND FROM TUVA_PROJECT_DEMO.PMPM.PMPM_TRENDS PT
LEFT JOIN (SELECT CONCAT(LEFT(YEAR_MONTH, 4), '-', RIGHT(YEAR_MONTH, 2)) AS YEAR_MONTH,
LEFT JOIN (SELECT CONCAT(LEFT(YEAR_MONTH, 4), '-', RIGHT(YEAR_MONTH, 2)) AS YEAR_MONTH,
COUNT(*) AS MEMBER_COUNT,
SUM(PHARMACY_PAID) AS PHARMACY_SPEND
FROM TUVA_PROJECT_DEMO.PMPM.PMPM_BUILDER
GROUP BY YEAR_MONTH) AS PB
ON PT.YEAR_MONTH = PB.YEAR_MONTH;"""

data = util.safe_to_pandas(conn, query)
data['year_month'] = pd.to_datetime(data['year_month'], format='%Y-%m').dt.date
data['year'] = pd.to_datetime(data['year_month'], format='%Y-%m').dt.year
data['pharmacy_spend'] = data['pharmacy_spend'].astype(float)
data["year_month"] = pd.to_datetime(data["year_month"], format="%Y-%m").dt.date
data["year"] = pd.to_datetime(data["year_month"], format="%Y-%m").dt.year
data["pharmacy_spend"] = data["pharmacy_spend"].astype(float)

return data


@st.cache_data
def gender_data():
query = """SELECT GENDER, COUNT(*) AS COUNT FROM TUVA_PROJECT_DEMO.CORE.PATIENT GROUP BY 1;"""
data = util.safe_to_pandas(conn, query)
return data


@st.cache_data
def race_data():
query = """SELECT RACE, COUNT(*) AS COUNT FROM TUVA_PROJECT_DEMO.CORE.PATIENT GROUP BY 1;"""
data = util.safe_to_pandas(conn, query)
return data


@st.cache_data
def age_data():
query = """SELECT CASE
query = """SELECT CASE
WHEN div0(current_date() - BIRTH_DATE, 365) < 49 THEN '34-48'
WHEN div0(current_date() - BIRTH_DATE, 365) >= 49 AND div0(current_date() - BIRTH_DATE, 365) < 65 THEN '49-64'
WHEN div0(current_date() - BIRTH_DATE, 365) >= 65 AND div0(current_date() - BIRTH_DATE, 365) < 79 THEN '65-78'
Expand All @@ -95,43 +101,74 @@ def age_data():
demo_age = age_data()

st.markdown("# Summary of Claims")
start_year, end_year = st.select_slider("Select date range for claims summary",
options=sorted(list(set(data['year']))),
value=(data['year'].min(), data['year'].max()))
filtered_cost_data = cost_data.loc[(cost_data['year'] >= str(start_year)) & (cost_data['year'] <= str(end_year)), :]
filtered_pmpm_data = data.loc[(data['year'] >= start_year) & (data['year'] <= end_year), :]
start_year, end_year = st.select_slider(
"Select date range for claims summary",
options=sorted(list(set(data["year"]))),
value=(data["year"].min(), data["year"].max()),
)
filtered_cost_data = cost_data.loc[
(cost_data["year"] >= str(start_year)) & (cost_data["year"] <= str(end_year)), :
]
filtered_pmpm_data = data.loc[
(data["year"] >= start_year) & (data["year"] <= end_year), :
]


st.markdown("### High Level Summary")
st.markdown("""At a glance, see the total medical spend and PMPM for the chosen time period. As well as a trend
graph for other important financial metrics""")
st.markdown(
"""At a glance, see the total medical spend and PMPM for the chosen time period. As well as a trend
graph for other important financial metrics"""
)
st.sidebar.markdown("# Claims Summary")
comp.financial_bans(filtered_cost_data)

st.divider()
y_axis = st.selectbox('Select Metric for Trend Line', [x for x in data.columns if 'year' not in x])
y_axis = st.selectbox(
"Select Metric for Trend Line", [x for x in data.columns if "year" not in x]
)

if y_axis:
st.line_chart(filtered_pmpm_data, x='year_month', y=y_axis)
st.line_chart(filtered_pmpm_data, x="year_month", y=y_axis)

# Patient Demographic Section
st.divider()
st.markdown('### Patient Demographics')
st.markdown("""The patient population during this claims period was mostly `female`, `white` and largely
over the age of 65, with nearly half of patients falling into the `65-78` age group""")
st.write(' Please note that patient data is static, and not filtered by claims date sliders currently')
st.markdown("### Patient Demographics")
st.markdown(
"""The patient population during this claims period was mostly `female`, `white` and largely
over the age of 65, with nearly half of patients falling into the `65-78` age group"""
)
st.write(
" Please note that patient data is static, and not filtered by claims date sliders currently"
)

demo_col1, demo_col2 = st.columns([1, 2])
with demo_col1:
plost.donut_chart(demo_gender, theta='count',
color=dict(field='gender', scale=dict(range=['#F8B7CD', '#67A3D9'])), legend='left',
title='Gender Breakdown')
plost.donut_chart(
demo_gender,
theta="count",
color=dict(field="gender", scale=dict(range=["#F8B7CD", "#67A3D9"])),
legend="left",
title="Gender Breakdown",
)
with demo_col2:
plost.bar_chart(
demo_age, bar='age_group', value='count', legend=None, use_container_width=True,
title='Counts by Age Group', direction='horizontal', height=300
demo_age,
bar="age_group",
value="count",
legend=None,
use_container_width=True,
title="Counts by Age Group",
direction="horizontal",
height=300,
)

plost.bar_chart(
demo_race, bar='race', value='count', color='race', legend='bottom', use_container_width=True,
title='Counts by Race', height=400
demo_race,
bar="race",
value="count",
color="race",
legend="bottom",
use_container_width=True,
title="Counts by Race",
height=400,
)
Loading

0 comments on commit fc1bcf7

Please sign in to comment.