awacke1 commited on
Commit
cc3f266
β€’
1 Parent(s): 17291fc

Create backup3.app.py

Browse files
Files changed (1) hide show
  1. backup3.app.py +78 -0
backup3.app.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ It is not showing the fields I asked. If you search for asthma for instance you get the two records below. search the state files for the code of each record but show the first three fields from first search rresult which shows the title for the taxonomy we are searching for: 2 207K00000X Allopathic & Osteopathic Physicians Allergy & Immunology "An allergist-immunologist is trained in evaluation, physical and laboratory diagnosis, and management of disorders involving the immune system. Selected examples of such conditions include asthma, anaphylaxis, rhinitis, eczema, and adverse reactions to drugs, foods, and insect stings as well as immune deficiency diseases (both acquired and congenital), defects in host defense, and problems related to autoimmune disease, organ transplantation, or malignancies of the immune system."
2
+ 64 207RP1001X Allopathic & Osteopathic Physicians Internal Medicine Pulmonary Disease "An internist who treats diseases of the lungs and airways. The pulmonologist diagnoses and treats cancer, pneumonia, pleurisy, asthma, occupational and environmental diseases, bronchitis, sleep disorders, emphysema and other complex disorders of the lungs." Also always use cache_resource as shown in corrected code listing: import streamlit as st
3
+ import pandas as pd
4
+ import os
5
+ import glob
6
+
7
+ # Cache the loading of specialties for efficiency
8
+ @st.cache_resource
9
+ def load_specialties(csv_file='Provider-Specialty.csv'):
10
+ return pd.read_csv(csv_file)
11
+
12
+ # Cache the finding of state files to avoid repeated file system access
13
+ @st.cache_resource
14
+ def find_state_files():
15
+ return [file for file in glob.glob('./*.csv') if len(os.path.basename(file).split('.')[0]) == 2]
16
+
17
+ specialties = load_specialties()
18
+
19
+ # UI for specialty selection with an engaging title
20
+ st.title('Provider Specialty Analyzer with Code Grouping and Classification πŸ“Š')
21
+
22
+ st.markdown('''
23
+ ## Specialty Fields Description πŸ“
24
+ - **Code**: Unique identifier for the specialty πŸ†”
25
+ - **Grouping**: General category of the specialty 🏷️
26
+ - **Classification**: Specific type of practice within the grouping 🎯
27
+ - **Specialization**: Further refinement of the classification if applicable πŸ”
28
+ - **Definition**: Brief description of the specialty πŸ“–
29
+ - **Notes**: Additional information or updates about the specialty πŸ—’οΈ
30
+ - **Display Name**: Common name of the specialty 🏷️
31
+ - **Section**: Indicates the section of healthcare it belongs to πŸ“š
32
+ ''')
33
+
34
+ # Allows users to select or search for a specialty
35
+ specialty_options = specialties['Display Name'].unique()
36
+ selected_specialty = st.selectbox('Select a Specialty 🩺', options=specialty_options)
37
+
38
+ # Keyword search functionality
39
+ search_keyword = st.text_input('Or search for a keyword in specialties πŸ”')
40
+ if search_keyword:
41
+ filtered_specialties = specialties[specialties.apply(lambda row: row.astype(str).str.contains(search_keyword, case=False).any(), axis=1)]
42
+ else:
43
+ filtered_specialties = specialties[specialties['Display Name'] == selected_specialty]
44
+
45
+ st.dataframe(filtered_specialties)
46
+
47
+ # State selection UI with default selection for testing
48
+ state_files = find_state_files()
49
+ state_options = sorted([os.path.basename(file).split('.')[0] for file in state_files])
50
+ selected_state = st.selectbox('Select a State (optional) πŸ—ΊοΈ', options=state_options, index=state_options.index('MN') if 'MN' in state_options else 0)
51
+
52
+ # Checkbox to filter by selected state only
53
+ use_specific_state = st.checkbox('Filter by selected state only? βœ…', value=True)
54
+
55
+ # Process files based on specialty codes and state selection
56
+ def process_files(specialty_codes, specific_state='MN'):
57
+ results = []
58
+ file_to_process = f'./{specific_state}.csv' if use_specific_state else state_files
59
+
60
+ for file in [file_to_process] if use_specific_state else state_files:
61
+ state_df = pd.read_csv(file, header=None) # Assuming no header for simplicity
62
+ filtered_df = state_df[state_df[47].isin(specialty_codes)] # Assuming the code is in the 48th column
63
+ if not filtered_df.empty:
64
+ results.append((os.path.basename(file).replace('.csv', ''), filtered_df))
65
+
66
+ return results
67
+
68
+ # Button to initiate the analysis
69
+ if st.button('Analyze Text Files for Selected Specialty πŸ”'):
70
+ specialty_codes = filtered_specialties['Code'].tolist()
71
+ state_data = process_files(specialty_codes, selected_state if use_specific_state else None)
72
+ if state_data:
73
+ for state, df in state_data:
74
+ st.subheader(f"Providers in {state} with Specialties related to '{search_keyword or selected_specialty}':")
75
+ st.dataframe(df)
76
+ else:
77
+ st.write("No matching records found in text files for the selected specialties.")
78
+