Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jcunninghame committed May 24, 2023
2 parents 7cd1fe0 + e04d59d commit 14d701c
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 178 deletions.
44 changes: 24 additions & 20 deletions components.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,38 @@

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.
"""
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)
]
if len(year_values) == 1:
year_string = year_values[0]
else:
year_string = "{} - {}".format(year_values[0], year_values[-1])
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_values[-1]}")
st.markdown(f"### Spend Summary in {year_string}")

summary_stats_data = summary_stats_data.copy(deep=True)
summary_stats_data = summary_stats_data.loc[
summary_stats_data["year"] == year_values[-1]
]
col1, col2, col3 = st.columns(3)
col1.metric(
"Medical Spend",
util.human_format(summary_stats_data["medical_paid_amount"].iloc[0]),
)
col2.metric(
"Pharmacy Spend",
util.human_format(summary_stats_data["pharmacy_paid_amount"].iloc[0]),
)
col3.metric(
"Member Months",
util.human_format(summary_stats_data["member_month_count"].iloc[0]),
)
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
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))


def year_slider(year_values):
Expand Down
74 changes: 53 additions & 21 deletions main_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dotenv import load_dotenv
import os
import util
import components as comp

load_dotenv()

Expand All @@ -13,7 +14,39 @@


@st.cache_data
def summary_data():
def summary_stats():
query = """
with medical as (
select distinct
year(claim_end_date)::text year
, sum(paid_amount) as medical_paid_amount
from core.medical_claim
group by 1
)
, pharmacy as (
select
year(dispensing_date)::text year
, sum(paid_amount) as pharmacy_paid_amount
from core.pharmacy_claim
group by 1
), elig as (
select
substr(year_month, 0, 4) as year
, sum(member_month_count) as member_month_count
from pmpm._int_member_month_count
group by 1
)
select *
from medical
join pharmacy using(year)
join elig using(year)
"""
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,
COUNT(*) AS MEMBER_COUNT,
Expand All @@ -24,6 +57,9 @@ def summary_data():

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)

return data


Expand Down Expand Up @@ -58,47 +94,41 @@ def age_data():
return data


data = summary_data()
cost_data = summary_stats()
data = pmpm_data()
demo_gender = gender_data()
demo_race = race_data()
demo_age = age_data()

st.markdown("# Summary of Claims")
start_date, end_date = st.select_slider(
start_year, end_year = st.select_slider(
"Select date range for claims summary",
options=data["year_month"].sort_values(),
value=(data["year_month"].min(), data["year_month"].max()),
options=sorted(list(set(data["year"]))),
value=(data["year"].min(), data["year"].max()),
)
filtered_data = data.loc[
(data["year_month"] >= start_date) & (data["year_month"] <= end_date), :
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.sidebar.markdown("# Claims Summary")

# Summary Metrics
total_spend = filtered_data["medical_spend"].sum()
total_member_months = filtered_data["member_month_count"].sum()
avg_pmpm = total_spend / total_member_months
total_pharm_spend = filtered_data["pharmacy_spend"].sum()

col1, col2, col3, col4 = st.columns([1, 1, 1, 1])
col1.metric("Total Medical Spend", "${}".format(util.human_format(total_spend)))
col2.metric("Total Member Months", util.human_format(total_member_months))
col3.metric("Average PMPM", "${}".format(util.human_format(avg_pmpm)))
col4.metric("Total Pharmacy Spend", "${}".format(util.human_format(total_pharm_spend)))
comp.financial_bans(filtered_cost_data)

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

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

# Patient Demographic Section
st.divider()
Expand Down Expand Up @@ -128,6 +158,8 @@ def age_data():
legend=None,
use_container_width=True,
title="Counts by Age Group",
direction="horizontal",
height=300,
)

plost.bar_chart(
Expand Down
116 changes: 0 additions & 116 deletions pages/01_drilldown.py

This file was deleted.

Loading

0 comments on commit 14d701c

Please sign in to comment.