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