Repository navigation
Expand file tree
/
Copy pathrules.py
More file actions
208 lines (187 loc) · 6.69 KB
/
Copy pathrules.py
File metadata and controls
208 lines (187 loc) · 6.69 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
"""
Rule-based risk calculation for anemia screening
This is NOT a medical diagnosis tool
"""
from ml_model import analyze_eye_image
def calculate_risk(answers, image_path=None):
"""
Calculate anemia risk based on answers
Args:
answers (dict): User responses to questions
image_path (str): Optional path to eye image
Returns:
tuple: (risk_level, score, details)
"""
score = 0
details = {
'factors': [],
'recommendations': []
}
# Age and gender factors
age = int(answers.get('age', 0))
gender = answers.get('gender', '').lower()
# Higher risk for children and women
if age < 18:
score += 1
details['factors'].append('Age under 18 (higher risk group)')
if gender == 'female':
score += 1
details['factors'].append('Female gender (higher risk due to menstruation)')
# Symptom-based scoring
symptoms = [
('fatigue', 'Frequent fatigue', 2),
('dizziness', 'Dizziness or lightheadedness', 2),
('pale_skin', 'Pale skin or lips', 2),
('breathlessness', 'Shortness of breath', 2),
('low_iron_diet', 'Low iron diet', 2),
('cold_hands', 'Cold hands or feet', 1),
('headaches', 'Frequent headaches', 1),
('weakness', 'Muscle weakness', 1)
]
for symptom_key, symptom_name, points in symptoms:
if answers.get(symptom_key) == 'yes':
score += points
details['factors'].append(symptom_name)
# Determine risk level
if score <= 3:
risk_level = 'Low Risk'
details['recommendations'] = [
'Your screening shows low risk for anemia.',
'Maintain a balanced diet rich in iron (meat, beans, leafy greens).',
'Consider routine health checkups annually.',
'Stay hydrated and get adequate sleep.'
]
elif score <= 7:
risk_level = 'Moderate Risk'
details['recommendations'] = [
'Your screening shows moderate risk for anemia.',
'Consider getting a Complete Blood Count (CBC) test.',
'Increase iron-rich foods in your diet.',
'Consult a healthcare provider if symptoms persist.',
'Vitamin C helps iron absorption - include citrus fruits.'
]
else:
risk_level = 'High Risk'
details['recommendations'] = [
'⚠️ Your screening shows high risk for anemia.',
'🏥 IMPORTANT: Please consult a doctor immediately.',
'Get a Complete Blood Count (CBC) and hemoglobin test.',
'Do NOT self-diagnose or self-medicate.',
'This screening is NOT a diagnosis - lab tests are required.'
]
# Add ML-based image analysis
ml_prediction = None
if image_path:
try:
ml_results = analyze_eye_image(image_path)
ml_prediction = ml_results['probability']
details['image_analyzed'] = True
details['ml_probability'] = ml_prediction
details['ml_confidence'] = ml_results['confidence']
details['factors'].append(f"Eye image analysis: {ml_results['interpretation']}")
# Adjust risk score based on ML prediction
if ml_prediction >= 0.7:
score += 3
details['factors'].append('ML model indicates HIGH risk from image analysis')
elif ml_prediction >= 0.5:
score += 2
details['factors'].append('ML model indicates MODERATE risk from image analysis')
elif ml_prediction >= 0.3:
score += 1
details['factors'].append('ML model indicates LOW-MODERATE risk from image analysis')
else:
details['factors'].append('ML model indicates LOW risk from image analysis')
# Re-evaluate risk level with ML input
if score <= 3:
risk_level = 'Low Risk'
elif score <= 8:
risk_level = 'Moderate Risk'
else:
risk_level = 'High Risk'
except Exception as e:
print(f"Error in ML prediction: {e}")
details['image_analyzed'] = True
details['factors'].append('Eye image uploaded (ML analysis unavailable)')
else:
details['image_analyzed'] = False
return risk_level, score, details
def get_questions():
"""
Return the list of screening questions
Returns:
list: List of question dictionaries
"""
questions = [
{
'id': 'age',
'type': 'number',
'text': 'What is your age?',
'required': True,
'min': 1,
'max': 120
},
{
'id': 'gender',
'type': 'choice',
'text': 'What is your gender?',
'required': True,
'options': ['Male', 'Female', 'Other']
},
{
'id': 'fatigue',
'type': 'choice',
'text': 'Do you feel tired or fatigued most days?',
'required': True,
'options': ['Yes', 'No']
},
{
'id': 'dizziness',
'type': 'choice',
'text': 'Do you experience dizziness or lightheadedness?',
'required': True,
'options': ['Yes', 'No']
},
{
'id': 'pale_skin',
'type': 'choice',
'text': 'Have you noticed pale skin, lips, or nail beds?',
'required': True,
'options': ['Yes', 'No']
},
{
'id': 'breathlessness',
'type': 'choice',
'text': 'Do you feel short of breath during normal activities?',
'required': True,
'options': ['Yes', 'No']
},
{
'id': 'low_iron_diet',
'type': 'choice',
'text': 'Is your diet low in iron-rich foods (meat, beans, leafy greens)?',
'required': True,
'options': ['Yes', 'No']
},
{
'id': 'cold_hands',
'type': 'choice',
'text': 'Do you often have cold hands or feet?',
'required': False,
'options': ['Yes', 'No']
},
{
'id': 'headaches',
'type': 'choice',
'text': 'Do you experience frequent headaches?',
'required': False,
'options': ['Yes', 'No']
},
{
'id': 'weakness',
'type': 'choice',
'text': 'Do you feel muscle weakness?',
'required': False,
'options': ['Yes', 'No']
}
]
return questions