Update app.py
Browse files
app.py
CHANGED
@@ -3,32 +3,38 @@ import pandas as pd
|
|
3 |
import os
|
4 |
import glob
|
5 |
|
6 |
-
#
|
7 |
-
@st.
|
8 |
def load_specialties(csv_file='Provider-Specialty.csv'):
|
9 |
return pd.read_csv(csv_file)
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
specialties = load_specialties()
|
12 |
|
13 |
# User interface for specialty selection
|
14 |
-
st.title('
|
15 |
|
16 |
-
# Markdown outline
|
17 |
-
st.markdown(
|
18 |
-
## Specialty Fields Description
|
19 |
-
- **Code**: Unique identifier for the specialty
|
20 |
-
- **Grouping**: General category the specialty
|
21 |
-
- **Classification**:
|
22 |
-
- **Specialization**: Further
|
23 |
-
- **Definition**: Brief description of the specialty
|
24 |
-
- **Notes**:
|
25 |
-
- **Display Name**:
|
26 |
-
- **Section**:
|
27 |
-
|
28 |
|
29 |
# Dropdown for selecting a specialty
|
30 |
specialty_options = specialties['Display Name'].unique()
|
31 |
-
selected_specialty = st.selectbox('Select a Specialty
|
32 |
|
33 |
# Display specialties matching the selected option or search keyword
|
34 |
search_keyword = st.text_input('Or search for a keyword in specialties π')
|
@@ -39,27 +45,34 @@ else:
|
|
39 |
|
40 |
st.dataframe(filtered_specialties)
|
41 |
|
42 |
-
#
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
51 |
if not filtered_df.empty:
|
52 |
-
results.append((os.path.basename(file)
|
53 |
|
54 |
return results
|
55 |
|
56 |
# Show DataFrame UI for files matching the specialty code in the selected state
|
57 |
-
if st.button('Analyze Text Files for Selected Specialty
|
58 |
specialty_code = specialties[specialties['Display Name'] == selected_specialty].iloc[0]['Code']
|
59 |
-
state_data =
|
60 |
if state_data:
|
61 |
for state, df in state_data:
|
62 |
-
st.subheader(f"Providers in {state} with Specialty '{selected_specialty}':")
|
63 |
st.dataframe(df)
|
64 |
else:
|
65 |
-
st.write("No matching records found in text files for the selected specialty.
|
|
|
3 |
import os
|
4 |
import glob
|
5 |
|
6 |
+
# Decorator to cache loading of the CSV file and processing of text files
|
7 |
+
@st.cache_resource
|
8 |
def load_specialties(csv_file='Provider-Specialty.csv'):
|
9 |
return pd.read_csv(csv_file)
|
10 |
|
11 |
+
@st.cache_resource
|
12 |
+
def find_state_files():
|
13 |
+
# Adjusted to include .csv files specifically for states
|
14 |
+
return [file for file in glob.glob('./*.csv') if len(os.path.basename(file).split('.')[0]) == 2]
|
15 |
+
|
16 |
+
# Load the provider specialty dataset CSV
|
17 |
specialties = load_specialties()
|
18 |
|
19 |
# User interface for specialty selection
|
20 |
+
st.title('Provider Specialty Analyzer π')
|
21 |
|
22 |
+
# Markdown outline with emojis
|
23 |
+
st.markdown('''
|
24 |
+
## Specialty Fields Description π
|
25 |
+
- **Code**: Unique identifier for the specialty π
|
26 |
+
- **Grouping**: General category of the specialty π·οΈ
|
27 |
+
- **Classification**: Specific type of practice within the grouping π―
|
28 |
+
- **Specialization**: Further refinement of the classification if applicable π
|
29 |
+
- **Definition**: Brief description of the specialty π
|
30 |
+
- **Notes**: Additional information or updates about the specialty ποΈ
|
31 |
+
- **Display Name**: Common name of the specialty π·οΈ
|
32 |
+
- **Section**: Indicates the section of healthcare it belongs to π
|
33 |
+
''')
|
34 |
|
35 |
# Dropdown for selecting a specialty
|
36 |
specialty_options = specialties['Display Name'].unique()
|
37 |
+
selected_specialty = st.selectbox('Select a Specialty π©Ί', options=specialty_options)
|
38 |
|
39 |
# Display specialties matching the selected option or search keyword
|
40 |
search_keyword = st.text_input('Or search for a keyword in specialties π')
|
|
|
45 |
|
46 |
st.dataframe(filtered_specialties)
|
47 |
|
48 |
+
# Default state selection to MN for testing
|
49 |
+
default_state = 'MN'
|
50 |
+
state_files = find_state_files()
|
51 |
+
state_options = [os.path.basename(file).split('.')[0] for file in state_files]
|
52 |
+
state_options.insert(0, default_state) # Default MN added to the start of the list for testing
|
53 |
+
selected_state = st.selectbox('Select a State (optional) πΊοΈ', options=state_options, index=0)
|
54 |
+
use_specific_state = st.checkbox('Filter by selected state only? β
', value=True)
|
55 |
|
56 |
+
# Adjusted function to match specialty code with 48th column in state files
|
57 |
+
def process_files(specialty_code, specific_state=default_state):
|
58 |
+
results = []
|
59 |
+
files_to_process = [f for f in state_files if f.split('/')[-1].startswith(specific_state + '.csv')]
|
60 |
+
|
61 |
+
for file in files_to_process:
|
62 |
+
state_df = pd.read_csv(file, header=None) # Assuming no header for state files
|
63 |
+
filtered_df = state_df[state_df[47] == specialty_code] # Match with 48th column (index 47)
|
64 |
if not filtered_df.empty:
|
65 |
+
results.append((os.path.basename(file), filtered_df))
|
66 |
|
67 |
return results
|
68 |
|
69 |
# Show DataFrame UI for files matching the specialty code in the selected state
|
70 |
+
if st.button('Analyze Text Files for Selected Specialty π'):
|
71 |
specialty_code = specialties[specialties['Display Name'] == selected_specialty].iloc[0]['Code']
|
72 |
+
state_data = process_files(specialty_code, selected_state if use_specific_state else default_state)
|
73 |
if state_data:
|
74 |
for state, df in state_data:
|
75 |
+
st.subheader(f"Providers in {state.replace('.csv', '')} with Specialty '{selected_specialty}':")
|
76 |
st.dataframe(df)
|
77 |
else:
|
78 |
+
st.write("No matching records found in text files for the selected specialty.")
|