File size: 2,794 Bytes
553d692
 
 
 
 
 
be2d971
d56f2c2
553d692
 
 
 
 
be2d971
 
 
 
 
 
 
 
 
 
 
 
 
 
553d692
 
 
be2d971
553d692
 
be2d971
553d692
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be2d971
553d692
 
 
 
be2d971
553d692
 
 
 
 
 
 
be2d971
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
import streamlit as st
import pandas as pd
import os
import glob

# Load the provider specialty dataset CSV
@st.cache(allow_output_mutation=True)
def load_specialties(csv_file='Provider-Specialty.csv'):
    return pd.read_csv(csv_file)

specialties = load_specialties()

# User interface for specialty selection
st.title('πŸ” Provider Specialty Analyzer')

# Markdown outline for the fields description
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.
""")

# 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)

# Function to find and process text files with two-letter names
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

# 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_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. 🚫")