Create backup.04012024.app.py
Browse files- backup.04012024.app.py +110 -0
backup.04012024.app.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import os
|
4 |
+
import glob
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
|
7 |
+
# Set page configuration with a title and favicon
|
8 |
+
st.set_page_config(
|
9 |
+
page_title="๐ฉบ๐ Care Team Finder - Care Providers by Specialty and Location",
|
10 |
+
page_icon="๐ฉบ",
|
11 |
+
layout="wide",
|
12 |
+
initial_sidebar_state="expanded",
|
13 |
+
menu_items={
|
14 |
+
'Get Help': 'https://huggingface.co/awacke1',
|
15 |
+
'Report a bug': "https://huggingface.co/spaces/awacke1/WebDataDownload",
|
16 |
+
'About': "# ๐ฉบ๐ Care Team Finder By Aaron Wacker - https://huggingface.co/awacke1"
|
17 |
+
}
|
18 |
+
)
|
19 |
+
|
20 |
+
headers = [
|
21 |
+
"NPI", "EntityTypeCode", "ReplacementNPI", "EmployerIdentificationNumberEIN",
|
22 |
+
"ProviderOrganizationNameLegalBusinessName", "ProviderLastNameLegalName",
|
23 |
+
"ProviderFirstName", "ProviderMiddleName", "ProviderNamePrefixText",
|
24 |
+
"ProviderNameSuffixText", "ProviderCredentialText", "ProviderOtherOrganizationName",
|
25 |
+
"ProviderOtherOrganizationNameTypeCode", "ProviderOtherLastName", "ProviderOtherFirstName",
|
26 |
+
"ProviderOtherMiddleName", "ProviderOtherNamePrefixText", "ProviderOtherNameSuffixText",
|
27 |
+
"ProviderOtherCredentialText", "ProviderOtherLastNameTypeCode",
|
28 |
+
"ProviderFirstLineBusinessMailingAddress", "ProviderSecondLineBusinessMailingAddress",
|
29 |
+
"ProviderBusinessMailingAddressCityName", "ProviderBusinessMailingAddressStateName",
|
30 |
+
"ProviderBusinessMailingAddressPostalCode", "ProviderBusinessMailingAddressCountryCodeIfoutsideUS",
|
31 |
+
"ProviderBusinessMailingAddressTelephoneNumber", "ProviderBusinessMailingAddressFaxNumber",
|
32 |
+
"ProviderFirstLineBusinessPracticeLocationAddress", "ProviderSecondLineBusinessPracticeLocationAddress",
|
33 |
+
"ProviderBusinessPracticeLocationAddressCityName", "ProviderBusinessPracticeLocationAddressStateName",
|
34 |
+
"ProviderBusinessPracticeLocationAddressPostalCode", "ProviderBusinessPracticeLocationAddressCountryCodeIfoutsideUS",
|
35 |
+
"ProviderBusinessPracticeLocationAddressTelephoneNumber", "ProviderBusinessPracticeLocationAddressFaxNumber",
|
36 |
+
"ProviderEnumerationDate", "LastUpdateDate", "NPIDeactivationReasonCode",
|
37 |
+
"NPIDeactivationDate", "NPIReactivationDate", "ProviderGenderCode",
|
38 |
+
"AuthorizedOfficialLastName", "AuthorizedOfficialFirstName", "AuthorizedOfficialMiddleName",
|
39 |
+
"AuthorizedOfficialTitleorPosition", "AuthorizedOfficialTelephoneNumber",
|
40 |
+
"HealthcareProviderTaxonomyCode", "ProviderLicenseNumber", "ProviderLicenseNumberStateCode",
|
41 |
+
"HealthcareProviderPrimaryTaxonomySwitch"
|
42 |
+
]
|
43 |
+
|
44 |
+
# Cache the loading of specialties for efficiency
|
45 |
+
@st.cache_resource
|
46 |
+
def load_specialties(csv_file='Provider-Specialty.csv'):
|
47 |
+
return pd.read_csv(csv_file)
|
48 |
+
|
49 |
+
# Cache the finding of state files to avoid repeated file system access
|
50 |
+
@st.cache_resource
|
51 |
+
def find_state_files():
|
52 |
+
return [file for file in glob.glob('./*.csv') if len(os.path.basename(file).split('.')[0]) == 2]
|
53 |
+
|
54 |
+
specialties = load_specialties()
|
55 |
+
st.markdown("# ๐ฉบ๐ Care Team Finder ")
|
56 |
+
st.markdown("#### Search for Care Providers by Specialty and Location")
|
57 |
+
|
58 |
+
# Allows users to select or search for a specialty
|
59 |
+
specialty_options = specialties['Display Name'].unique()
|
60 |
+
selected_specialty = st.selectbox('Select a Specialty ๐ฉบ', options=specialty_options)
|
61 |
+
|
62 |
+
# Keyword search functionality
|
63 |
+
search_keyword = st.text_input('Or search for a keyword in specialties ๐')
|
64 |
+
if search_keyword:
|
65 |
+
filtered_specialties = specialties[specialties.apply(lambda row: row.astype(str).str.contains(search_keyword, case=False).any(), axis=1)]
|
66 |
+
else:
|
67 |
+
filtered_specialties = specialties[specialties['Display Name'] == selected_specialty]
|
68 |
+
|
69 |
+
st.dataframe(filtered_specialties[['Code', 'Grouping', 'Classification', 'Specialization', 'Definition']])
|
70 |
+
|
71 |
+
# State selection UI with default selection for testing
|
72 |
+
state_files = find_state_files()
|
73 |
+
state_options = sorted([os.path.basename(file).split('.')[0] for file in state_files])
|
74 |
+
selected_state = st.selectbox('Select a State (optional) ๐บ๏ธ', options=state_options, index=state_options.index('MN') if 'MN' in state_options else 0)
|
75 |
+
|
76 |
+
# Checkbox to filter by selected state only
|
77 |
+
use_specific_state = st.checkbox('Filter by selected state only? โ
', value=True)
|
78 |
+
|
79 |
+
# Process files based on specialty codes and state selection
|
80 |
+
def process_files(specialty_codes, specific_state='MN'):
|
81 |
+
results = []
|
82 |
+
file_to_process = f'./{specific_state}.csv' if use_specific_state else state_files
|
83 |
+
|
84 |
+
for file in [file_to_process] if use_specific_state else state_files:
|
85 |
+
#state_df = pd.read_csv(file, header=0) # Assuming no header for simplicity
|
86 |
+
state_df = pd.read_csv(file, header=None) # Assuming no header for simplicity
|
87 |
+
#state_df = pd.read_csv(file, header=0) # Assuming no header for simplicity
|
88 |
+
|
89 |
+
for code in specialty_codes:
|
90 |
+
filtered_df = state_df[state_df[47].isin([code])] # Match against 48th column, adjust as needed
|
91 |
+
#filtered_df = state_df[state_df['ProviderBusinessPracticeLocationAddressStateName'].isin([code])] # Match against 48th column, adjust as needed
|
92 |
+
if not filtered_df.empty:
|
93 |
+
# Enhance the display to include 'Code', 'Grouping', and 'Classification' information
|
94 |
+
display_info = specialties[specialties['Code'] == code][['Code', 'Grouping', 'Classification']].iloc[0].to_dict()
|
95 |
+
results.append((os.path.basename(file).replace('.csv', ''), display_info, filtered_df))
|
96 |
+
|
97 |
+
return results
|
98 |
+
|
99 |
+
# Button to initiate the analysis
|
100 |
+
if st.button('Analyze Text Files for Selected Specialty ๐'):
|
101 |
+
specialty_codes = filtered_specialties['Code'].tolist()
|
102 |
+
state_data = process_files(specialty_codes, selected_state if use_specific_state else None)
|
103 |
+
#state_data = process_files_new(specialty_codes, selected_state if use_specific_state else None)
|
104 |
+
if state_data:
|
105 |
+
for state, info, df in state_data:
|
106 |
+
st.subheader(f"Providers in {state} with Specialties related to '{search_keyword or selected_specialty}':")
|
107 |
+
st.markdown(f"**Code**: {info['Code']}, **Grouping**: {info['Grouping']}, **Classification**: {info['Classification']}")
|
108 |
+
st.dataframe(df)
|
109 |
+
else:
|
110 |
+
st.write("No matching records found in text files for the selected specialties.")
|