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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import folium
|
| 3 |
+
from folium.plugins import MarkerCluster
|
| 4 |
+
from streamlit_folium import folium_static
|
| 5 |
+
import googlemaps
|
| 6 |
+
from datetime import datetime
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
# Initialize Google Maps
|
| 10 |
+
gmaps = googlemaps.Client(key=os.getenv('GOOGLE_KEY'))
|
| 11 |
+
|
| 12 |
+
# Function to fetch directions
|
| 13 |
+
def get_directions_and_coords(source, destination):
|
| 14 |
+
now = datetime.now()
|
| 15 |
+
directions_info = gmaps.directions(source, destination, mode='driving', departure_time=now)
|
| 16 |
+
if directions_info:
|
| 17 |
+
steps = directions_info[0]['legs'][0]['steps']
|
| 18 |
+
coords = [(step['start_location']['lat'], step['start_location']['lng']) for step in steps]
|
| 19 |
+
return steps, coords
|
| 20 |
+
else:
|
| 21 |
+
return None, None
|
| 22 |
+
|
| 23 |
+
# Function to render map with directions
|
| 24 |
+
def render_folium_map(coords):
|
| 25 |
+
m = folium.Map(location=[coords[0][0], coords[0][1]], zoom_start=13)
|
| 26 |
+
folium.PolyLine(coords, color="blue", weight=2.5, opacity=1).add_to(m)
|
| 27 |
+
return m
|
| 28 |
+
|
| 29 |
+
# Function to add medical center paths and annotate distance
|
| 30 |
+
def add_medical_center_paths(m, source, med_centers):
|
| 31 |
+
for name, lat, lon, specialty, city in med_centers:
|
| 32 |
+
_, coords = get_directions_and_coords(source, (lat, lon))
|
| 33 |
+
if coords:
|
| 34 |
+
folium.PolyLine(coords, color="red", weight=2.5, opacity=1).add_to(m)
|
| 35 |
+
folium.Marker([lat, lon], popup=name).add_to(m)
|
| 36 |
+
distance_info = gmaps.distance_matrix(source, (lat, lon), mode='driving')
|
| 37 |
+
distance = distance_info['rows'][0]['elements'][0]['distance']['text']
|
| 38 |
+
folium.PolyLine(coords, color='red').add_to(m)
|
| 39 |
+
folium.map.Marker(
|
| 40 |
+
[coords[-1][0], coords[-1][1]],
|
| 41 |
+
icon=folium.DivIcon(
|
| 42 |
+
icon_size=(150, 36),
|
| 43 |
+
icon_anchor=(0, 0),
|
| 44 |
+
html=f'<div style="font-size: 10pt; color : red;">{distance}</div>',
|
| 45 |
+
)
|
| 46 |
+
).add_to(m)
|
| 47 |
+
|
| 48 |
+
# Driving Directions Sidebar
|
| 49 |
+
st.sidebar.header('Directions π')
|
| 50 |
+
source_location = st.sidebar.text_input("Source Location", "4 Brotherton Way, Auburn, MA 01501")
|
| 51 |
+
destination_location = st.sidebar.text_input("Destination Location", "366 Shrewsbury Street, Worcester, MA, 01604")
|
| 52 |
+
|
| 53 |
+
# Fetch and Display Directions
|
| 54 |
+
if st.sidebar.button('Get Directions'):
|
| 55 |
+
steps, coords = get_directions_and_coords(source_location, destination_location)
|
| 56 |
+
if steps and coords:
|
| 57 |
+
st.subheader('Driving Directions:')
|
| 58 |
+
for i, step in enumerate(steps):
|
| 59 |
+
st.write(f"{i+1}. {step['html_instructions']}")
|
| 60 |
+
st.subheader('Route on Map:')
|
| 61 |
+
m1 = render_folium_map(coords)
|
| 62 |
+
folium_static(m1)
|
| 63 |
+
else:
|
| 64 |
+
st.write("No available routes.")
|
| 65 |
+
|
| 66 |
+
# Massachusetts Medical Centers
|
| 67 |
+
st.markdown("### πΊοΈ Maps - π₯ Massachusetts Medical Centers π³")
|
| 68 |
+
m2 = folium.Map(location=[42.3601, -71.0589], zoom_start=8)
|
| 69 |
+
marker_cluster = MarkerCluster().add_to(m2)
|
| 70 |
+
|
| 71 |
+
massachusetts_med_centers = [
|
| 72 |
+
('The Endoscopy Center', 42.2098, -71.8356, '4 Brotherton Way, (508) 425-5446', 'Auburn'),
|
| 73 |
+
('ReadyMED β Auburn', 42.2090, -71.8358, '460 Southbridge Street, (508) 595-2700', 'Auburn'),
|
| 74 |
+
('Durable Medical Equipment', 42.2115, -71.8370, '42 Southbridge Street, (508) 407-7700', 'Auburn'),
|
| 75 |
+
('Auburn', 42.2098, -71.8356, '4 Brotherton Way, (508) 832-9621', 'Auburn'),
|
| 76 |
+
('Framingham', 42.2793, -71.4162, '761 Worcester Rd, (508) 872-1107', 'Framingham'),
|
| 77 |
+
('Holden', 42.3518, -71.8634, '64 Boyden Road, (508) 829-6765', 'Holden'),
|
| 78 |
+
('ReadyMED β Hudson', 42.3912, -71.5662, '234 Washington Street, (508) 595-2700', 'Hudson'),
|
| 79 |
+
('ReadyMED β Leominster', 42.5251, -71.7598, '241 North Main Street, (508) 595-2700', 'Leominster'),
|
| 80 |
+
('Leominster', 42.5204, -71.7717, '225 New Lancaster Road, (978) 534-6500', 'Leominster'),
|
| 81 |
+
('ReadyMED β Milford', 42.1487, -71.5152, '340 East Main Street, (508) 595-2700', 'Milford'),
|
| 82 |
+
('Milford', 42.1398, -71.5163, '101 Cedar Street, (508) 634-3100', 'Milford'),
|
| 83 |
+
('The Surgery Center', 42.2924, -71.7131, '151 Main St, (844) 258-4272', 'Shrewsbury'),
|
| 84 |
+
('Shrewsbury Occupational Medicine', 42.2930, -71.7240, '222 Boston Turnpike, (508) 853-2854', 'Shrewsbury'),
|
| 85 |
+
('Shrewsbury', 42.2865, -71.7147, '378 Maple Ave, (508) 368-7820', 'Shrewsbury'),
|
| 86 |
+
('Southborough', 42.3057, -71.5256, '24-28 Newton Street, (508) 481-5500', 'Southborough'),
|
| 87 |
+
('Webster', 42.0474, -71.8801, '344 Thompson Road, (508) 671-4050', 'Webster'),
|
| 88 |
+
('Westborough', 42.2695, -71.6161, '900 Union Street, (508) 366-8836', 'Westborough'),
|
| 89 |
+
('Worcester β Saint Vincent Cancer and Wellness Center', 42.2626, -71.8027, '1 Eaton Place, (508) 368-5430', 'Worcester'),
|
| 90 |
+
('Worcester β Neponset Street', 42.2614, -71.8007, '5 Neponset Street, (508) 368-7800', 'Worcester'),
|
| 91 |
+
('Worcester Medical Center', 42.2614, -71.8006, '123 Summer Street, (508) 852-0600', 'Worcester'),
|
| 92 |
+
('Worcester β Harding Street Rehabilitation & Sports Medicine', 42.2605, -71.8000, '112 Harding Street, (508) 964-5592', 'Worcester'),
|
| 93 |
+
('Worcester β Gold Star Boulevard Rehabilitation and Sports Medicine', 42.2910, -71.7999, '50 Gold Star Boulevard, (508) 856-9510', 'Worcester'),
|
| 94 |
+
('Worcester β Front Street', 42.2619, -71.8008, '100 Front Street, (508) 595-2000', 'Worcester'),
|
| 95 |
+
('Surgical Eye Experts', 42.2620, -71.8029, '385 Grove Street, (508) 453-8802', 'Worcester'),
|
| 96 |
+
('ReadyMED PLUS β Worcester', 42.2612, -71.8010, '366 Shrewsbury Street, (508) 595-2700', 'Worcester')
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
# Dropdown to select medical center to focus on
|
| 101 |
+
medical_center_names = [center[0] for center in massachusetts_med_centers]
|
| 102 |
+
selected_medical_center = st.selectbox("Select Medical Center to Focus On:", medical_center_names)
|
| 103 |
+
|
| 104 |
+
# Zoom into the selected medical center
|
| 105 |
+
for name, lat, lon, specialty, city in massachusetts_med_centers:
|
| 106 |
+
if name == selected_medical_center:
|
| 107 |
+
m2 = folium.Map(location=[lat, lon], zoom_start=15)
|
| 108 |
+
|
| 109 |
+
# Annotate distances and paths for each medical center
|
| 110 |
+
add_medical_center_paths(m2, source_location, massachusetts_med_centers)
|
| 111 |
+
|
| 112 |
+
folium_static(m2)
|
| 113 |
+
|
| 114 |
+
def Fairness():
|
| 115 |
+
# List of 10 Types of Bias π
|
| 116 |
+
st.markdown("### 10 Types of Bias in Geographical Healthcare Data π©ββοΈπ")
|
| 117 |
+
st.markdown("""
|
| 118 |
+
1. **Sampling Bias**: When the clinics or medical centers chosen for analysis do not represent the entire population.
|
| 119 |
+
2. **Confirmation Bias**: Picking clinics or centers that confirm pre-existing assumptions.
|
| 120 |
+
3. **Location Bias**: Focusing only on urban or rural areas.
|
| 121 |
+
4. **Temporal Bias**: Not considering the seasonality or time-sensitive factors.
|
| 122 |
+
5. **Accessibility Bias**: Overlooking clinics that are hard to reach but may offer unique specialties.
|
| 123 |
+
6. **Economic Bias**: Focusing only on wealthy areas.
|
| 124 |
+
7. **Size Bias**: Ignoring smaller clinics or new centers.
|
| 125 |
+
8. **Technology Bias**: Assuming higher tech facilities provide better care.
|
| 126 |
+
9. **Specialization Bias**: Overemphasis on one type of specialty.
|
| 127 |
+
10. **Reporting Bias**: Basing judgments on self-reported data without validation.
|
| 128 |
+
""")
|
| 129 |
+
|
| 130 |
+
# List of 10 Types of Fairness π
|
| 131 |
+
st.markdown("### 10 Types of Fairness in Geographical Healthcare Data ππ©ββοΈ")
|
| 132 |
+
st.markdown("""
|
| 133 |
+
1. **Geographical Fairness**: Equal representation of urban and rural areas.
|
| 134 |
+
2. **Socioeconomic Fairness**: Diverse economic statuses in the sample.
|
| 135 |
+
3. **Healthcare Need Fairness**: Clinics catering to various healthcare needs.
|
| 136 |
+
4. **Accessibility Fairness**: Including centers reachable by public transportation.
|
| 137 |
+
5. **Specialization Fairness**: A balanced view across various medical specialties.
|
| 138 |
+
6. **Temporal Fairness**: Data that accounts for seasonal or time-sensitive changes.
|
| 139 |
+
7. **Cultural Fairness**: Inclusion of centers serving diverse cultural communities.
|
| 140 |
+
8. **Demographic Fairness**: Representation across different age groups and genders.
|
| 141 |
+
9. **Quality of Care Fairness**: Balanced data on patient satisfaction and quality of care.
|
| 142 |
+
10. **Resource Allocation Fairness**: Fair distribution of resources among different centers.
|
| 143 |
+
""")
|
| 144 |
+
|
| 145 |
+
Fairness()
|
| 146 |
+
|
| 147 |
+
def Fairness2():
|
| 148 |
+
st.title("Bias and Fairness in Geographical Healthcare Data ππ©ββοΈ")
|
| 149 |
+
|
| 150 |
+
st.markdown("### 10 Types of Bias in Geographical Healthcare Data π©ββοΈπ")
|
| 151 |
+
bias_types = {
|
| 152 |
+
"Sampling Bias": r"\frac{\text{Unrepresented Population}}{\text{Total Population}}",
|
| 153 |
+
"Confirmation Bias": r"\frac{\text{Data Confirming Assumptions}}{\text{Total Data Points}}",
|
| 154 |
+
"Location Bias": r"\left| \frac{\text{Urban Centers}}{\text{Rural Centers}} - 1 \right|",
|
| 155 |
+
"Temporal Bias": r"\frac{\text{Time-Sensitive Data Ignored}}{\text{Total Data Points}}",
|
| 156 |
+
"Accessibility Bias": r"\frac{\text{Inaccessible Clinics}}{\text{Total Clinics}}",
|
| 157 |
+
"Economic Bias": r"\frac{\text{Wealthy Area Clinics}}{\text{Total Clinics}}",
|
| 158 |
+
"Size Bias": r"\frac{\text{Ignored Small Clinics}}{\text{Total Clinics}}",
|
| 159 |
+
"Technology Bias": r"\frac{\text{High-Tech Clinics}}{\text{Total Clinics}}",
|
| 160 |
+
"Specialization Bias": r"\frac{\text{Overemphasized Specialties}}{\text{Total Specialties}}",
|
| 161 |
+
"Reporting Bias": r"\frac{\text{Unvalidated Reports}}{\text{Total Reports}}"
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
for bias, formula in bias_types.items():
|
| 165 |
+
st.markdown(f"**{bias}**")
|
| 166 |
+
st.latex(f"{formula}")
|
| 167 |
+
|
| 168 |
+
st.markdown("### 10 Types of Fairness in Geographical Healthcare Data ππ©ββοΈ")
|
| 169 |
+
fairness_types = {
|
| 170 |
+
"Geographical Fairness": r"1 - \left| \frac{\text{Urban Centers}}{\text{Rural Centers}} - 1 \right|",
|
| 171 |
+
"Socioeconomic Fairness": r"\frac{\text{Diverse Economic Clinics}}{\text{Total Clinics}}",
|
| 172 |
+
"Healthcare Need Fairness": r"\frac{\text{Various Healthcare Need Clinics}}{\text{Total Clinics}}",
|
| 173 |
+
"Accessibility Fairness": r"\frac{\text{Accessible Clinics}}{\text{Total Clinics}}",
|
| 174 |
+
"Specialization Fairness": r"1 - \left| \frac{\text{Specialized Clinics}}{\text{General Clinics}} - 1 \right|",
|
| 175 |
+
"Temporal Fairness": r"1 - \frac{\text{Time-Sensitive Data Ignored}}{\text{Total Data Points}}",
|
| 176 |
+
"Cultural Fairness": r"\frac{\text{Diverse Cultural Clinics}}{\text{Total Clinics}}",
|
| 177 |
+
"Demographic Fairness": r"\frac{\text{Diverse Demographic Clinics}}{\text{Total Clinics}}",
|
| 178 |
+
"Quality of Care Fairness": r"\frac{\text{High-Quality Clinics}}{\text{Total Clinics}}",
|
| 179 |
+
"Resource Allocation Fairness": r"\frac{\text{Evenly Distributed Resources}}{\text{Total Resources}}"
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
for fairness, formula in fairness_types.items():
|
| 183 |
+
st.markdown(f"**{fairness}**")
|
| 184 |
+
st.latex(f"{formula}")
|
| 185 |
+
|
| 186 |
+
if __name__ == "__main__":
|
| 187 |
+
Fairness2()
|