|
import streamlit as st |
|
import pandas as pd |
|
import os |
|
import glob |
|
|
|
|
|
@st.cache(allow_output_mutation=True) |
|
def load_specialties(csv_file='Provider-Specialty.csv'): |
|
return pd.read_csv(csv_file) |
|
|
|
specialties = load_specialties() |
|
|
|
|
|
st.title('π Provider Specialty Analyzer') |
|
|
|
|
|
st.markdown(""" |
|
## Specialty Fields Description π |
|
- **Code**: Unique identifier for the specialty. |
|
- **Grouping**: General category the specialty belongs to. |
|
- **Classification**: More detailed classification within the grouping. |
|
- **Specialization**: Further specialization details if applicable. |
|
- **Definition**: Brief description of the specialty. |
|
- **Notes**: Any additional notes or historical information. |
|
- **Display Name**: The common name used to display the specialty. |
|
- **Section**: The section of healthcare the specialty falls under. |
|
""") |
|
|
|
|
|
specialty_options = specialties['Display Name'].unique() |
|
selected_specialty = st.selectbox('Select a Specialty π', options=specialty_options) |
|
|
|
|
|
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) |
|
|
|
|
|
def process_state_files(specialty_code): |
|
files = glob.glob('./*.txt') |
|
state_files = [file for file in files if len(os.path.basename(file).split('.')[0]) == 2] |
|
results = [] |
|
|
|
for file in state_files: |
|
state_df = pd.read_csv(file, names=['Code', 'Grouping', 'Classification', 'Specialization', 'Definition', 'Notes', 'Display Name', 'Section']) |
|
filtered_df = state_df[state_df['Code'] == specialty_code] |
|
if not filtered_df.empty: |
|
results.append((os.path.basename(file).split('.')[0], filtered_df)) |
|
|
|
return results |
|
|
|
|
|
if st.button('Analyze Text Files for Selected Specialty π'): |
|
specialty_code = specialties[specialties['Display Name'] == selected_specialty].iloc[0]['Code'] |
|
state_data = process_state_files(specialty_code) |
|
if state_data: |
|
for state, df in state_data: |
|
st.subheader(f"Providers in {state} with Specialty '{selected_specialty}':") |
|
st.dataframe(df) |
|
else: |
|
st.write("No matching records found in text files for the selected specialty. π«") |
|
|