Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,23 +2,8 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
import glob
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
# Set page configuration with a title and favicon
|
| 8 |
-
st.set_page_config(
|
| 9 |
-
page_title="π©Ίπ Care Team Finder - Care Providers by Specialty and Location",
|
| 10 |
-
page_icon="π©Ί",
|
| 11 |
-
layout="wide",
|
| 12 |
-
initial_sidebar_state="expanded",
|
| 13 |
-
menu_items={
|
| 14 |
-
'Get Help': 'https://huggingface.co/awacke1',
|
| 15 |
-
'Report a bug': "https://huggingface.co/spaces/awacke1/WebDataDownload",
|
| 16 |
-
'About': "# π©Ίπ Care Team Finder By Aaron Wacker - https://huggingface.co/awacke1"
|
| 17 |
-
}
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
# Define headers for dataframe
|
| 22 |
headers = [
|
| 23 |
"NPI", "EntityTypeCode", "ReplacementNPI", "EmployerIdentificationNumberEIN",
|
| 24 |
"ProviderOrganizationNameLegalBusinessName", "ProviderLastNameLegalName",
|
|
@@ -43,6 +28,41 @@ headers = [
|
|
| 43 |
"HealthcareProviderPrimaryTaxonomySwitch"
|
| 44 |
]
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# Cache the loading of specialties for efficiency
|
| 47 |
@st.cache_resource
|
| 48 |
def load_specialties(csv_file='Provider-Specialty.csv'):
|
|
@@ -53,13 +73,36 @@ def load_specialties(csv_file='Provider-Specialty.csv'):
|
|
| 53 |
def find_state_files():
|
| 54 |
return [file for file in glob.glob('./*.csv') if len(os.path.basename(file).split('.')[0]) == 2]
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
|
|
|
| 60 |
st.markdown("# π©Ίπ Care Team Finder ")
|
| 61 |
st.markdown("#### Search for Care Providers by Specialty and Location")
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# Allows users to select or search for a specialty
|
| 64 |
specialty_options = specialties['Display Name'].unique()
|
| 65 |
selected_specialty = st.selectbox('Select a Specialty π©Ί', options=specialty_options)
|
|
@@ -81,17 +124,19 @@ selected_state = st.selectbox('Select a State (optional) πΊοΈ', options=state
|
|
| 81 |
# Checkbox to filter by selected state only
|
| 82 |
use_specific_state = st.checkbox('Filter by selected state only? β
', value=True)
|
| 83 |
|
|
|
|
| 84 |
def process_files(specialty_codes, specific_state='MN'):
|
| 85 |
results = []
|
| 86 |
file_to_process = f'./{specific_state}.csv' if use_specific_state else state_files
|
| 87 |
|
| 88 |
for file in [file_to_process] if use_specific_state else state_files:
|
| 89 |
-
#
|
| 90 |
-
state_df = pd.read_csv(file, header=
|
| 91 |
|
| 92 |
for code in specialty_codes:
|
| 93 |
-
filtered_df = state_df[state_df[
|
| 94 |
if not filtered_df.empty:
|
|
|
|
| 95 |
display_info = specialties[specialties['Code'] == code][['Code', 'Grouping', 'Classification']].iloc[0].to_dict()
|
| 96 |
results.append((os.path.basename(file).replace('.csv', ''), display_info, filtered_df))
|
| 97 |
|
|
@@ -101,6 +146,7 @@ def process_files(specialty_codes, specific_state='MN'):
|
|
| 101 |
if st.button('Analyze Text Files for Selected Specialty π'):
|
| 102 |
specialty_codes = filtered_specialties['Code'].tolist()
|
| 103 |
state_data = process_files(specialty_codes, selected_state if use_specific_state else None)
|
|
|
|
| 104 |
if state_data:
|
| 105 |
for state, info, df in state_data:
|
| 106 |
st.subheader(f"Providers in {state} with Specialties related to '{search_keyword or selected_specialty}':")
|
|
@@ -108,17 +154,3 @@ if st.button('Analyze Text Files for Selected Specialty π'):
|
|
| 108 |
st.dataframe(df)
|
| 109 |
else:
|
| 110 |
st.write("No matching records found in text files for the selected specialties.")
|
| 111 |
-
|
| 112 |
-
# Moved Help Information to the bottom
|
| 113 |
-
if st.expander('π©Ί Understand Provider Specialties π'):
|
| 114 |
-
st.markdown('''
|
| 115 |
-
## Discover Care Providers by Specialty & Location: Quick Guide
|
| 116 |
-
- **Code**: Unique ID identifies each specialty clearly. π
|
| 117 |
-
- **Grouping**: Broad category umbrella for general expertise area. π·οΈ
|
| 118 |
-
- **Classification**: Specifies type of practice within broader category. π―
|
| 119 |
-
- **Specialization**: Details focus within classification for precise expertise. π
|
| 120 |
-
- **Definition**: Concise overview of the specialty's scope. π
|
| 121 |
-
- **Notes**: Extra information or recent updates provided. ποΈ
|
| 122 |
-
- **Display Name**: Commonly recognized name of the specialty. π·οΈ
|
| 123 |
-
- **Section**: Healthcare segment the specialty belongs to. π
|
| 124 |
-
''')
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
import glob
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
headers = [
|
| 8 |
"NPI", "EntityTypeCode", "ReplacementNPI", "EmployerIdentificationNumberEIN",
|
| 9 |
"ProviderOrganizationNameLegalBusinessName", "ProviderLastNameLegalName",
|
|
|
|
| 28 |
"HealthcareProviderPrimaryTaxonomySwitch"
|
| 29 |
]
|
| 30 |
|
| 31 |
+
def process_files_new(specialty_codes, specific_state='MN', use_specific_state=True):
|
| 32 |
+
results = []
|
| 33 |
+
city_counts = {} # Dictionary to keep track of city counts
|
| 34 |
+
file_to_process = f'./{specific_state}.csv' if use_specific_state else state_files
|
| 35 |
+
|
| 36 |
+
for file in [file_to_process] if use_specific_state else state_files:
|
| 37 |
+
# Now using the 'names' parameter to specify column names
|
| 38 |
+
state_df = pd.read_csv(file, header=None, names=headers)
|
| 39 |
+
for code in specialty_codes:
|
| 40 |
+
filtered_df = state_df[state_df['HealthcareProviderTaxonomyCode'].isin([code])]
|
| 41 |
+
if not filtered_df.empty:
|
| 42 |
+
# Update city counts
|
| 43 |
+
for city in filtered_df['ProviderBusinessPracticeLocationAddressCityName'].unique():
|
| 44 |
+
city_counts[city] = city_counts.get(city, 0) + filtered_df[filtered_df['ProviderBusinessPracticeLocationAddressCityName'] == city].shape[0]
|
| 45 |
+
|
| 46 |
+
# Prepare display information (assuming 'specialties' DataFrame exists)
|
| 47 |
+
display_info = specialties[specialties['Code'] == code][['Code', 'Grouping', 'Classification']].iloc[0].to_dict()
|
| 48 |
+
results.append((os.path.basename(file).replace('.csv', ''), display_info, filtered_df))
|
| 49 |
+
|
| 50 |
+
# Plotting the city counts
|
| 51 |
+
cities = list(city_counts.keys())
|
| 52 |
+
counts = list(city_counts.values())
|
| 53 |
+
|
| 54 |
+
#plt.figure(figsize=(10, 6))
|
| 55 |
+
#plt.bar(cities, counts, color='skyblue')
|
| 56 |
+
#plt.xlabel('City')
|
| 57 |
+
#plt.ylabel('Count')
|
| 58 |
+
#plt.xticks(rotation=45, ha='right')
|
| 59 |
+
#plt.title('Counts per City')
|
| 60 |
+
#plt.tight_layout()
|
| 61 |
+
#plt.show()
|
| 62 |
+
|
| 63 |
+
return results
|
| 64 |
+
|
| 65 |
+
|
| 66 |
# Cache the loading of specialties for efficiency
|
| 67 |
@st.cache_resource
|
| 68 |
def load_specialties(csv_file='Provider-Specialty.csv'):
|
|
|
|
| 73 |
def find_state_files():
|
| 74 |
return [file for file in glob.glob('./*.csv') if len(os.path.basename(file).split('.')[0]) == 2]
|
| 75 |
|
| 76 |
+
# Set page configuration with a title and favicon
|
| 77 |
+
st.set_page_config(
|
| 78 |
+
page_title="π©Ίπ Care Team Finder - Care Providers by Specialty and Location",
|
| 79 |
+
page_icon="π©Ί",
|
| 80 |
+
layout="wide",
|
| 81 |
+
initial_sidebar_state="expanded",
|
| 82 |
+
menu_items={
|
| 83 |
+
'Get Help': 'https://huggingface.co/awacke1',
|
| 84 |
+
'Report a bug': "https://huggingface.co/spaces/awacke1/WebDataDownload",
|
| 85 |
+
'About': "# π©Ίπ Care Team Finder By Aaron Wacker - https://huggingface.co/awacke1"
|
| 86 |
+
}
|
| 87 |
+
)
|
| 88 |
|
| 89 |
+
specialties = load_specialties()
|
| 90 |
st.markdown("# π©Ίπ Care Team Finder ")
|
| 91 |
st.markdown("#### Search for Care Providers by Specialty and Location")
|
| 92 |
|
| 93 |
+
if st.expander('π©Ί Understand Provider Specialties π'):
|
| 94 |
+
st.markdown('''
|
| 95 |
+
## Discover Care Providers by Specialty & Location: Quick Guide
|
| 96 |
+
- **Code**: Unique ID identifies each specialty clearly. π
|
| 97 |
+
- **Grouping**: Broad category umbrella for general expertise area. π·οΈ
|
| 98 |
+
- **Classification**: Specifies type of practice within broader category. π―
|
| 99 |
+
- **Specialization**: Details focus within classification for precise expertise. π
|
| 100 |
+
- **Definition**: Concise overview of the specialty's scope. π
|
| 101 |
+
- **Notes**: Extra information or recent updates provided. ποΈ
|
| 102 |
+
- **Display Name**: Commonly recognized name of the specialty. π·οΈ
|
| 103 |
+
- **Section**: Healthcare segment the specialty belongs to. π
|
| 104 |
+
''')
|
| 105 |
+
|
| 106 |
# Allows users to select or search for a specialty
|
| 107 |
specialty_options = specialties['Display Name'].unique()
|
| 108 |
selected_specialty = st.selectbox('Select a Specialty π©Ί', options=specialty_options)
|
|
|
|
| 124 |
# Checkbox to filter by selected state only
|
| 125 |
use_specific_state = st.checkbox('Filter by selected state only? β
', value=True)
|
| 126 |
|
| 127 |
+
# Process files based on specialty codes and state selection
|
| 128 |
def process_files(specialty_codes, specific_state='MN'):
|
| 129 |
results = []
|
| 130 |
file_to_process = f'./{specific_state}.csv' if use_specific_state else state_files
|
| 131 |
|
| 132 |
for file in [file_to_process] if use_specific_state else state_files:
|
| 133 |
+
state_df = pd.read_csv(file, header=None) # Assuming no header for simplicity
|
| 134 |
+
#state_df = pd.read_csv(file, header=0) # Assuming no header for simplicity
|
| 135 |
|
| 136 |
for code in specialty_codes:
|
| 137 |
+
filtered_df = state_df[state_df[47].isin([code])] # Match against 48th column, adjust as needed
|
| 138 |
if not filtered_df.empty:
|
| 139 |
+
# Enhance the display to include 'Code', 'Grouping', and 'Classification' information
|
| 140 |
display_info = specialties[specialties['Code'] == code][['Code', 'Grouping', 'Classification']].iloc[0].to_dict()
|
| 141 |
results.append((os.path.basename(file).replace('.csv', ''), display_info, filtered_df))
|
| 142 |
|
|
|
|
| 146 |
if st.button('Analyze Text Files for Selected Specialty π'):
|
| 147 |
specialty_codes = filtered_specialties['Code'].tolist()
|
| 148 |
state_data = process_files(specialty_codes, selected_state if use_specific_state else None)
|
| 149 |
+
#state_data = process_files_new(specialty_codes, selected_state if use_specific_state else None)
|
| 150 |
if state_data:
|
| 151 |
for state, info, df in state_data:
|
| 152 |
st.subheader(f"Providers in {state} with Specialties related to '{search_keyword or selected_specialty}':")
|
|
|
|
| 154 |
st.dataframe(df)
|
| 155 |
else:
|
| 156 |
st.write("No matching records found in text files for the selected specialties.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|