awacke1 commited on
Commit
911163c
Β·
verified Β·
1 Parent(s): c308aba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -29
app.py CHANGED
@@ -3,32 +3,38 @@ import pandas as pd
3
  import os
4
  import glob
5
 
6
- # Load the provider specialty dataset CSV
7
- @st.cache(allow_output_mutation=True)
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('πŸ” Provider Specialty Analyzer')
15
 
16
- # Markdown outline for the fields description
17
- st.markdown("""
18
- ## Specialty Fields Description πŸ“‹
19
- - **Code**: Unique identifier for the specialty.
20
- - **Grouping**: General category the specialty belongs to.
21
- - **Classification**: More detailed classification within the grouping.
22
- - **Specialization**: Further specialization details if applicable.
23
- - **Definition**: Brief description of the specialty.
24
- - **Notes**: Any additional notes or historical information.
25
- - **Display Name**: The common name used to display the specialty.
26
- - **Section**: The section of healthcare the specialty falls under.
27
- """)
28
 
29
  # Dropdown for selecting a specialty
30
  specialty_options = specialties['Display Name'].unique()
31
- selected_specialty = st.selectbox('Select a Specialty πŸ“‚', options=specialty_options)
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
- # Function to find and process text files with two-letter names
43
- def process_state_files(specialty_code):
44
- files = glob.glob('./*.txt')
45
- state_files = [file for file in files if len(os.path.basename(file).split('.')[0]) == 2]
46
- results = []
 
 
47
 
48
- for file in state_files:
49
- state_df = pd.read_csv(file, names=['Code', 'Grouping', 'Classification', 'Specialization', 'Definition', 'Notes', 'Display Name', 'Section'])
50
- filtered_df = state_df[state_df['Code'] == specialty_code]
 
 
 
 
 
51
  if not filtered_df.empty:
52
- results.append((os.path.basename(file).split('.')[0], filtered_df))
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 = process_state_files(specialty_code)
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.")