mohitrajdeo
commited on
Commit
·
a1a5f27
1
Parent(s):
06e6ec0
feat: add health score assessment module
Browse filesIntroduce a new health score assessment module to the application. This module allows users to evaluate their health risks based on various factors such as lifestyle, medical history, and vital signs. The module calculates an overall health score and provides personalized recommendations for improving health. The changes include the addition of the `health_score.py` file and integration with the main application to display the health score assessment option in the navigation menu.
- __pycache__/health_score.cpython-312.pyc +0 -0
- app.py +13 -1
- health_score.py +386 -0
__pycache__/health_score.cpython-312.pyc
ADDED
Binary file (24.3 kB). View file
|
|
app.py
CHANGED
@@ -13,6 +13,7 @@ import google.generativeai as genai
|
|
13 |
from dotenv import load_dotenv
|
14 |
from transformers import pipeline
|
15 |
|
|
|
16 |
# Set page config with icon
|
17 |
st.set_page_config(page_title="Disease Prediction", page_icon="🩺", layout="wide")
|
18 |
|
@@ -57,12 +58,17 @@ except FileNotFoundError:
|
|
57 |
st.error("Error: Model files not found. Please upload the model files.")
|
58 |
st.stop()
|
59 |
|
|
|
|
|
|
|
60 |
with st.sidebar:
|
61 |
st.title("🩺 Disease Prediction")
|
62 |
|
63 |
selected = option_menu(
|
64 |
menu_title="Navigation",
|
65 |
-
options=['Home','Health Score' , 'Diabetes Prediction','Hypertension Prediction',
|
|
|
|
|
66 |
icons=['house', 'activity', 'lungs', 'heart-pulse', 'brain', 'bar-chart', 'chat'],
|
67 |
menu_icon="cast",
|
68 |
default_index=0,
|
@@ -126,6 +132,9 @@ if selected == 'Home':
|
|
126 |
However, this tool has **not undergone clinical validation** and should be used **for informational and educational purposes only**. It is not intended to serve as a substitute for professional medical diagnosis or treatment. Always consult a qualified healthcare provider for medical advice.
|
127 |
""")
|
128 |
|
|
|
|
|
|
|
129 |
if selected == 'Diabetes Prediction':
|
130 |
st.title('🩸 Diabetes Prediction using ML (SVC)')
|
131 |
st.image("https://cdn-icons-png.flaticon.com/512/2919/2919950.png", width=100)
|
@@ -454,6 +463,9 @@ from huggingface_hub import login
|
|
454 |
|
455 |
# login(token=os.environ.get("HF_TOKEN"))
|
456 |
|
|
|
|
|
|
|
457 |
try:
|
458 |
# For Streamlit Cloud or Spaces deployment
|
459 |
hf_token = st.secrets["HF_TOKEN"]
|
|
|
13 |
from dotenv import load_dotenv
|
14 |
from transformers import pipeline
|
15 |
|
16 |
+
load_dotenv()
|
17 |
# Set page config with icon
|
18 |
st.set_page_config(page_title="Disease Prediction", page_icon="🩺", layout="wide")
|
19 |
|
|
|
58 |
st.error("Error: Model files not found. Please upload the model files.")
|
59 |
st.stop()
|
60 |
|
61 |
+
# Import the health_score module
|
62 |
+
import health_score
|
63 |
+
|
64 |
with st.sidebar:
|
65 |
st.title("🩺 Disease Prediction")
|
66 |
|
67 |
selected = option_menu(
|
68 |
menu_title="Navigation",
|
69 |
+
options=['Home','Health Score' , 'Diabetes Prediction','Hypertension Prediction', # Keep Health Score in this list
|
70 |
+
'Cardiovascular Disease Prediction', 'Stroke Prediction','Asthma Prediction',
|
71 |
+
'Sleep Health Analysis','Mental-Analysis','Medical Consultant', 'Data Visualization'],
|
72 |
icons=['house', 'activity', 'lungs', 'heart-pulse', 'brain', 'bar-chart', 'chat'],
|
73 |
menu_icon="cast",
|
74 |
default_index=0,
|
|
|
132 |
However, this tool has **not undergone clinical validation** and should be used **for informational and educational purposes only**. It is not intended to serve as a substitute for professional medical diagnosis or treatment. Always consult a qualified healthcare provider for medical advice.
|
133 |
""")
|
134 |
|
135 |
+
if selected == 'Health Score':
|
136 |
+
health_score.show_health_score() # This should be placed before other disease predictions
|
137 |
+
|
138 |
if selected == 'Diabetes Prediction':
|
139 |
st.title('🩸 Diabetes Prediction using ML (SVC)')
|
140 |
st.image("https://cdn-icons-png.flaticon.com/512/2919/2919950.png", width=100)
|
|
|
463 |
|
464 |
# login(token=os.environ.get("HF_TOKEN"))
|
465 |
|
466 |
+
hf_token = os.environ.get("HF_TOKEN")
|
467 |
+
|
468 |
+
|
469 |
try:
|
470 |
# For Streamlit Cloud or Spaces deployment
|
471 |
hf_token = st.secrets["HF_TOKEN"]
|
health_score.py
ADDED
@@ -0,0 +1,386 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import plotly.express as px
|
6 |
+
import plotly.graph_objects as go
|
7 |
+
from plotly.subplots import make_subplots
|
8 |
+
|
9 |
+
# Initialize session state variables if they don't exist
|
10 |
+
def init_session_state():
|
11 |
+
if 'current_step' not in st.session_state:
|
12 |
+
st.session_state.current_step = 0
|
13 |
+
if 'assessment_data' not in st.session_state:
|
14 |
+
st.session_state.assessment_data = {}
|
15 |
+
if 'results_calculated' not in st.session_state:
|
16 |
+
st.session_state.results_calculated = False
|
17 |
+
if 'risk_data' not in st.session_state:
|
18 |
+
st.session_state.risk_data = []
|
19 |
+
if 'health_score' not in st.session_state:
|
20 |
+
st.session_state.health_score = 0
|
21 |
+
if 'recommendations' not in st.session_state:
|
22 |
+
st.session_state.recommendations = []
|
23 |
+
|
24 |
+
# Define steps for the assessment
|
25 |
+
steps = [
|
26 |
+
{"title": "Basic Information", "fields": ["age", "gender", "height", "weight"]},
|
27 |
+
{"title": "Lifestyle", "fields": ["smoking_status", "alcohol_consumption", "physical_activity", "diet_type"]},
|
28 |
+
{"title": "Medical History", "fields": ["family_history_diabetes", "family_history_heart_disease",
|
29 |
+
"family_history_hypertension", "previous_diagnoses"]},
|
30 |
+
{"title": "Vital Signs", "fields": ["systolic_bp", "diastolic_bp", "resting_heart_rate"]},
|
31 |
+
{"title": "Mental Health", "fields": ["stress_level", "sleep_quality", "sleep_duration"]},
|
32 |
+
{"title": "Nutrition", "fields": ["daily_water_intake", "daily_fruit_veg_servings"]},
|
33 |
+
{"title": "Additional Metrics", "fields": ["waist_circumference", "body_fat_percentage"]},
|
34 |
+
{"title": "Additional Health Information", "fields": ["family_history_asthma", "family_history_obesity",
|
35 |
+
"family_history_depression", "allergies",
|
36 |
+
"chronic_pain", "mental_health_history"]}
|
37 |
+
]
|
38 |
+
|
39 |
+
# Function to calculate risk for different diseases
|
40 |
+
def calculate_risk(disease, data):
|
41 |
+
risk = 0
|
42 |
+
|
43 |
+
if disease == "Diabetes":
|
44 |
+
if data.get("age", 0) > 45: risk += 10
|
45 |
+
if float(data.get("bmi", 0)) > 30: risk += 15
|
46 |
+
if data.get("family_history_diabetes", False): risk += 15
|
47 |
+
if data.get("physical_activity", "") == "sedentary": risk += 10
|
48 |
+
|
49 |
+
elif disease == "Heart Disease":
|
50 |
+
if data.get("age", 0) > 55: risk += 10
|
51 |
+
if data.get("systolic_bp", 0) > 140 or data.get("diastolic_bp", 0) > 90: risk += 15
|
52 |
+
if data.get("family_history_heart_disease", False): risk += 15
|
53 |
+
if data.get("smoking_status", "") == "current": risk += 15
|
54 |
+
|
55 |
+
elif disease == "Hypertension":
|
56 |
+
if data.get("systolic_bp", 0) > 140 or data.get("diastolic_bp", 0) > 90: risk += 20
|
57 |
+
if data.get("family_history_hypertension", False): risk += 15
|
58 |
+
if data.get("alcohol_consumption", "") == "heavy": risk += 10
|
59 |
+
|
60 |
+
elif disease == "Obesity":
|
61 |
+
if float(data.get("bmi", 0)) > 30: risk += 30
|
62 |
+
if data.get("physical_activity", "") == "sedentary": risk += 15
|
63 |
+
if data.get("family_history_obesity", False): risk += 10
|
64 |
+
|
65 |
+
elif disease == "Asthma":
|
66 |
+
if data.get("family_history_asthma", False): risk += 20
|
67 |
+
if data.get("smoking_status", "") == "current": risk += 15
|
68 |
+
allergies = data.get("allergies", "").lower()
|
69 |
+
if "pollen" in allergies or "dust" in allergies: risk += 10
|
70 |
+
|
71 |
+
elif disease == "Depression":
|
72 |
+
if data.get("family_history_depression", False): risk += 15
|
73 |
+
if data.get("stress_level", 0) > 7: risk += 15
|
74 |
+
if data.get("sleep_quality", "") == "poor": risk += 10
|
75 |
+
mental_health = data.get("mental_health_history", "").lower()
|
76 |
+
if "depression" in mental_health or "anxiety" in mental_health: risk += 20
|
77 |
+
|
78 |
+
return min(risk, 100)
|
79 |
+
|
80 |
+
# Function to generate recommendations
|
81 |
+
def generate_recommendations(data):
|
82 |
+
recommendations = []
|
83 |
+
|
84 |
+
if data.get("physical_activity", "") in ["sedentary", "light"]:
|
85 |
+
recommendations.append("Increase your daily physical activity to at least 30 minutes of moderate exercise.")
|
86 |
+
|
87 |
+
if data.get("daily_fruit_veg_servings", 0) < 5:
|
88 |
+
recommendations.append("Increase your daily intake of fruits and vegetables to at least 5 servings.")
|
89 |
+
|
90 |
+
if data.get("daily_water_intake", 0) < 2000:
|
91 |
+
recommendations.append("Increase your daily water intake to at least 2 liters (2000ml).")
|
92 |
+
|
93 |
+
if data.get("sleep_duration", 0) < 7 or data.get("sleep_quality", "") in ["poor", "fair"]:
|
94 |
+
recommendations.append("Aim for 7-9 hours of quality sleep per night to improve overall health.")
|
95 |
+
|
96 |
+
if data.get("stress_level", 0) > 7:
|
97 |
+
recommendations.append("Practice stress-reduction techniques such as meditation or deep breathing exercises.")
|
98 |
+
|
99 |
+
if data.get("smoking_status", "") == "current":
|
100 |
+
recommendations.append("Consider quitting smoking to significantly reduce your risk of heart disease and other health problems.")
|
101 |
+
|
102 |
+
if data.get("alcohol_consumption", "") == "heavy":
|
103 |
+
recommendations.append("Reduce alcohol consumption to moderate levels or consider abstaining completely.")
|
104 |
+
|
105 |
+
if float(data.get("bmi", 0)) > 25:
|
106 |
+
recommendations.append("Work on maintaining a healthy weight through a balanced diet and regular exercise.")
|
107 |
+
|
108 |
+
if data.get("chronic_pain", "") != "none":
|
109 |
+
recommendations.append("Consult with a healthcare professional about managing your chronic pain and consider physical therapy or pain management techniques.")
|
110 |
+
|
111 |
+
if data.get("mental_health_history", "") != "":
|
112 |
+
recommendations.append("Continue to prioritize your mental health. Consider regular check-ins with a mental health professional.")
|
113 |
+
|
114 |
+
return recommendations
|
115 |
+
|
116 |
+
# Function to calculate results
|
117 |
+
def calculate_results():
|
118 |
+
# Calculate BMI if not already done
|
119 |
+
if "bmi" not in st.session_state.assessment_data:
|
120 |
+
height_m = st.session_state.assessment_data.get("height", 170) / 100
|
121 |
+
weight = st.session_state.assessment_data.get("weight", 70)
|
122 |
+
bmi = weight / (height_m * height_m)
|
123 |
+
st.session_state.assessment_data["bmi"] = round(bmi, 1)
|
124 |
+
|
125 |
+
# Calculate risk for each disease
|
126 |
+
diseases = ["Diabetes", "Heart Disease", "Hypertension", "Obesity", "Asthma", "Depression"]
|
127 |
+
risk_data = []
|
128 |
+
|
129 |
+
for disease in diseases:
|
130 |
+
risk = calculate_risk(disease, st.session_state.assessment_data)
|
131 |
+
risk_data.append({"disease": disease, "risk": risk})
|
132 |
+
|
133 |
+
st.session_state.risk_data = risk_data
|
134 |
+
|
135 |
+
# Calculate overall health score (scaled to 0-100)
|
136 |
+
total_risk = sum(item["risk"] for item in risk_data)
|
137 |
+
health_score = round(100 * (1 - total_risk / (len(diseases) * 100)))
|
138 |
+
st.session_state.health_score = health_score
|
139 |
+
|
140 |
+
# Generate recommendations
|
141 |
+
st.session_state.recommendations = generate_recommendations(st.session_state.assessment_data)
|
142 |
+
|
143 |
+
st.session_state.results_calculated = True
|
144 |
+
|
145 |
+
# Function to handle form submission for each step
|
146 |
+
def process_step(step_index):
|
147 |
+
# Save form data to session state
|
148 |
+
for field in steps[step_index]["fields"]:
|
149 |
+
if field in st.session_state:
|
150 |
+
st.session_state.assessment_data[field] = st.session_state[field]
|
151 |
+
|
152 |
+
# Move to next step or calculate results
|
153 |
+
if step_index < len(steps) - 1:
|
154 |
+
st.session_state.current_step += 1
|
155 |
+
else:
|
156 |
+
calculate_results()
|
157 |
+
|
158 |
+
# Function to go back to previous step
|
159 |
+
def go_back():
|
160 |
+
if st.session_state.current_step > 0:
|
161 |
+
st.session_state.current_step -= 1
|
162 |
+
|
163 |
+
# Function to restart assessment
|
164 |
+
def restart_assessment():
|
165 |
+
st.session_state.current_step = 0
|
166 |
+
st.session_state.assessment_data = {}
|
167 |
+
st.session_state.results_calculated = False
|
168 |
+
st.session_state.risk_data = []
|
169 |
+
st.session_state.health_score = 0
|
170 |
+
st.session_state.recommendations = []
|
171 |
+
|
172 |
+
# Main function for the Health Score module
|
173 |
+
def show_health_score():
|
174 |
+
st.title("🏥 Health Score Assessment")
|
175 |
+
|
176 |
+
# Initialize session state
|
177 |
+
init_session_state()
|
178 |
+
|
179 |
+
# Display results if calculated
|
180 |
+
if st.session_state.results_calculated:
|
181 |
+
st.header("Your Health Assessment Results")
|
182 |
+
|
183 |
+
# Create columns for layout
|
184 |
+
col1, col2 = st.columns(2)
|
185 |
+
|
186 |
+
with col1:
|
187 |
+
# Bar chart for disease risks
|
188 |
+
risk_df = pd.DataFrame(st.session_state.risk_data)
|
189 |
+
fig = px.bar(
|
190 |
+
risk_df,
|
191 |
+
x='disease',
|
192 |
+
y='risk',
|
193 |
+
title='Disease Risk Assessment',
|
194 |
+
labels={'disease': 'Disease', 'risk': 'Risk Score'},
|
195 |
+
color='risk',
|
196 |
+
color_continuous_scale=[(0, 'green'), (0.5, 'yellow'), (1, 'red')]
|
197 |
+
)
|
198 |
+
st.plotly_chart(fig, use_container_width=True)
|
199 |
+
|
200 |
+
with col2:
|
201 |
+
# Radar chart for disease risks
|
202 |
+
fig = go.Figure()
|
203 |
+
|
204 |
+
fig.add_trace(go.Scatterpolar(
|
205 |
+
r=[item["risk"] for item in st.session_state.risk_data],
|
206 |
+
theta=[item["disease"] for item in st.session_state.risk_data],
|
207 |
+
fill='toself',
|
208 |
+
name='Risk Profile'
|
209 |
+
))
|
210 |
+
|
211 |
+
fig.update_layout(
|
212 |
+
polar=dict(
|
213 |
+
radialaxis=dict(
|
214 |
+
visible=True,
|
215 |
+
range=[0, 100]
|
216 |
+
)
|
217 |
+
),
|
218 |
+
title="Health Risk Radar"
|
219 |
+
)
|
220 |
+
|
221 |
+
st.plotly_chart(fig, use_container_width=True)
|
222 |
+
|
223 |
+
# Health score gauge
|
224 |
+
fig = go.Figure(go.Indicator(
|
225 |
+
mode="gauge+number",
|
226 |
+
value=st.session_state.health_score,
|
227 |
+
domain={'x': [0, 1], 'y': [0, 1]},
|
228 |
+
title={'text': "Overall Health Score"},
|
229 |
+
gauge={
|
230 |
+
'axis': {'range': [0, 100]},
|
231 |
+
'bar': {'color': "darkblue"},
|
232 |
+
'steps': [
|
233 |
+
{'range': [0, 30], 'color': "red"},
|
234 |
+
{'range': [30, 70], 'color': "yellow"},
|
235 |
+
{'range': [70, 100], 'color': "green"}
|
236 |
+
]
|
237 |
+
}
|
238 |
+
))
|
239 |
+
|
240 |
+
st.plotly_chart(fig, use_container_width=True)
|
241 |
+
|
242 |
+
# Recommendations
|
243 |
+
st.subheader("Recommendations")
|
244 |
+
for i, recommendation in enumerate(st.session_state.recommendations):
|
245 |
+
st.markdown(f"- {recommendation}")
|
246 |
+
|
247 |
+
# Button to restart assessment
|
248 |
+
if st.button("Retake Assessment"):
|
249 |
+
restart_assessment()
|
250 |
+
|
251 |
+
# Display assessment form if results not calculated
|
252 |
+
else:
|
253 |
+
current_step = st.session_state.current_step
|
254 |
+
step = steps[current_step]
|
255 |
+
|
256 |
+
st.header(f"Comprehensive Health Assessment")
|
257 |
+
st.subheader(f"{step['title']} (Step {current_step + 1} of {len(steps)})")
|
258 |
+
|
259 |
+
# Create a centered container with smaller width
|
260 |
+
col1, form_col, col3 = st.columns([1, 2, 1])
|
261 |
+
|
262 |
+
with form_col:
|
263 |
+
with st.form(f"step_{current_step}_form"):
|
264 |
+
# Basic Information
|
265 |
+
if "age" in step["fields"]:
|
266 |
+
st.session_state.age = st.number_input("Age", 0, 120, st.session_state.assessment_data.get("age", 30))
|
267 |
+
|
268 |
+
if "gender" in step["fields"]:
|
269 |
+
st.session_state.gender = st.selectbox("Gender",
|
270 |
+
["male", "female", "other"],
|
271 |
+
["male", "female", "other"].index(st.session_state.assessment_data.get("gender", "male")))
|
272 |
+
|
273 |
+
if "height" in step["fields"]:
|
274 |
+
st.session_state.height = st.number_input("Height (cm)", 100, 250, st.session_state.assessment_data.get("height", 170))
|
275 |
+
|
276 |
+
if "weight" in step["fields"]:
|
277 |
+
st.session_state.weight = st.number_input("Weight (kg)", 30, 300, st.session_state.assessment_data.get("weight", 70))
|
278 |
+
|
279 |
+
# Lifestyle
|
280 |
+
if "smoking_status" in step["fields"]:
|
281 |
+
st.session_state.smoking_status = st.selectbox("Smoking Status",
|
282 |
+
["never", "former", "current"],
|
283 |
+
["never", "former", "current"].index(st.session_state.assessment_data.get("smoking_status", "never")))
|
284 |
+
|
285 |
+
if "alcohol_consumption" in step["fields"]:
|
286 |
+
st.session_state.alcohol_consumption = st.selectbox("Alcohol Consumption",
|
287 |
+
["none", "moderate", "heavy"],
|
288 |
+
["none", "moderate", "heavy"].index(st.session_state.assessment_data.get("alcohol_consumption", "moderate")))
|
289 |
+
|
290 |
+
if "physical_activity" in step["fields"]:
|
291 |
+
st.session_state.physical_activity = st.selectbox("Physical Activity Level",
|
292 |
+
["sedentary", "light", "moderate", "vigorous"],
|
293 |
+
["sedentary", "light", "moderate", "vigorous"].index(st.session_state.assessment_data.get("physical_activity", "moderate")))
|
294 |
+
|
295 |
+
if "diet_type" in step["fields"]:
|
296 |
+
st.session_state.diet_type = st.selectbox("Diet Type",
|
297 |
+
["balanced", "high-carb", "high-protein", "vegetarian", "vegan"],
|
298 |
+
["balanced", "high-carb", "high-protein", "vegetarian", "vegan"].index(st.session_state.assessment_data.get("diet_type", "balanced")))
|
299 |
+
|
300 |
+
# Medical History
|
301 |
+
if "family_history_diabetes" in step["fields"]:
|
302 |
+
st.session_state.family_history_diabetes = st.checkbox("Family History of Diabetes", st.session_state.assessment_data.get("family_history_diabetes", False))
|
303 |
+
|
304 |
+
if "family_history_heart_disease" in step["fields"]:
|
305 |
+
st.session_state.family_history_heart_disease = st.checkbox("Family History of Heart Disease", st.session_state.assessment_data.get("family_history_heart_disease", False))
|
306 |
+
|
307 |
+
if "family_history_hypertension" in step["fields"]:
|
308 |
+
st.session_state.family_history_hypertension = st.checkbox("Family History of Hypertension", st.session_state.assessment_data.get("family_history_hypertension", False))
|
309 |
+
|
310 |
+
if "previous_diagnoses" in step["fields"]:
|
311 |
+
st.session_state.previous_diagnoses = st.text_input("Previous Diagnoses (comma separated)", st.session_state.assessment_data.get("previous_diagnoses", ""))
|
312 |
+
|
313 |
+
# Vital Signs
|
314 |
+
if "systolic_bp" in step["fields"]:
|
315 |
+
st.session_state.systolic_bp = st.number_input("Systolic Blood Pressure", 70, 220, st.session_state.assessment_data.get("systolic_bp", 120))
|
316 |
+
|
317 |
+
if "diastolic_bp" in step["fields"]:
|
318 |
+
st.session_state.diastolic_bp = st.number_input("Diastolic Blood Pressure", 40, 130, st.session_state.assessment_data.get("diastolic_bp", 80))
|
319 |
+
|
320 |
+
if "resting_heart_rate" in step["fields"]:
|
321 |
+
st.session_state.resting_heart_rate = st.number_input("Resting Heart Rate", 40, 120, st.session_state.assessment_data.get("resting_heart_rate", 70))
|
322 |
+
|
323 |
+
# Mental Health
|
324 |
+
if "stress_level" in step["fields"]:
|
325 |
+
st.session_state.stress_level = st.slider("Stress Level (1-10)", 1, 10, st.session_state.assessment_data.get("stress_level", 5))
|
326 |
+
|
327 |
+
if "sleep_quality" in step["fields"]:
|
328 |
+
st.session_state.sleep_quality = st.selectbox("Sleep Quality",
|
329 |
+
["poor", "fair", "good", "excellent"],
|
330 |
+
["poor", "fair", "good", "excellent"].index(st.session_state.assessment_data.get("sleep_quality", "good")))
|
331 |
+
|
332 |
+
if "sleep_duration" in step["fields"]:
|
333 |
+
st.session_state.sleep_duration = st.number_input("Sleep Duration (hours)", 3.0, 12.0, float(st.session_state.assessment_data.get("sleep_duration", 7.0)), 0.5)
|
334 |
+
|
335 |
+
# Nutrition
|
336 |
+
if "daily_water_intake" in step["fields"]:
|
337 |
+
st.session_state.daily_water_intake = st.number_input("Daily Water Intake (ml)", 0, 5000, st.session_state.assessment_data.get("daily_water_intake", 2000), 100)
|
338 |
+
|
339 |
+
if "daily_fruit_veg_servings" in step["fields"]:
|
340 |
+
st.session_state.daily_fruit_veg_servings = st.number_input("Daily Fruit & Vegetable Servings", 0, 10, st.session_state.assessment_data.get("daily_fruit_veg_servings", 3))
|
341 |
+
|
342 |
+
# Additional Metrics
|
343 |
+
if "waist_circumference" in step["fields"]:
|
344 |
+
st.session_state.waist_circumference = st.number_input("Waist Circumference (cm)", 50, 200, st.session_state.assessment_data.get("waist_circumference", 80))
|
345 |
+
|
346 |
+
if "body_fat_percentage" in step["fields"]:
|
347 |
+
st.session_state.body_fat_percentage = st.number_input("Body Fat Percentage", 5.0, 50.0, float(st.session_state.assessment_data.get("body_fat_percentage", 20.0)), 0.5)
|
348 |
+
|
349 |
+
# Additional Health Information
|
350 |
+
if "family_history_asthma" in step["fields"]:
|
351 |
+
st.session_state.family_history_asthma = st.checkbox("Family History of Asthma", st.session_state.assessment_data.get("family_history_asthma", False))
|
352 |
+
|
353 |
+
if "family_history_obesity" in step["fields"]:
|
354 |
+
st.session_state.family_history_obesity = st.checkbox("Family History of Obesity", st.session_state.assessment_data.get("family_history_obesity", False))
|
355 |
+
|
356 |
+
if "family_history_depression" in step["fields"]:
|
357 |
+
st.session_state.family_history_depression = st.checkbox("Family History of Depression", st.session_state.assessment_data.get("family_history_depression", False))
|
358 |
+
|
359 |
+
if "allergies" in step["fields"]:
|
360 |
+
st.session_state.allergies = st.text_input("Allergies (comma separated)", st.session_state.assessment_data.get("allergies", ""))
|
361 |
+
|
362 |
+
if "chronic_pain" in step["fields"]:
|
363 |
+
st.session_state.chronic_pain = st.selectbox("Chronic Pain Level",
|
364 |
+
["none", "mild", "moderate", "severe"],
|
365 |
+
["none", "mild", "moderate", "severe"].index(st.session_state.assessment_data.get("chronic_pain", "none")))
|
366 |
+
|
367 |
+
if "mental_health_history" in step["fields"]:
|
368 |
+
st.session_state.mental_health_history = st.text_area("Mental Health History", st.session_state.assessment_data.get("mental_health_history", ""))
|
369 |
+
|
370 |
+
# Form buttons
|
371 |
+
col1, col2 = st.columns(2)
|
372 |
+
with col1:
|
373 |
+
if current_step > 0:
|
374 |
+
back_button = st.form_submit_button("Back")
|
375 |
+
if back_button:
|
376 |
+
go_back()
|
377 |
+
|
378 |
+
with col2:
|
379 |
+
if current_step < len(steps) - 1:
|
380 |
+
next_button = st.form_submit_button("Next")
|
381 |
+
if next_button:
|
382 |
+
process_step(current_step)
|
383 |
+
else:
|
384 |
+
submit_button = st.form_submit_button("Submit Assessment")
|
385 |
+
if submit_button:
|
386 |
+
process_step(current_step)
|