AI Project
AI Project
Initialization (`__init__`)
Create buttons for profile management and UI elements for condition input, user data,
management tips.
Create Profile
Load Profile:
Input Handling:
Read inputs for the chronic condition, blood sugar level, weight, and height.
BMI Calculation:
Display Information:
Categorize blood sugar levels as low, normal, or high and display messages accordingly.
Calculate BMI using the formula and provide health feedback based on BMI ranges.
8. Save to History:
9. Show History:
Load and display previously entered conditions from the history file.
get_tips(): Main function for processing the user input to get management tips.
PROGRAM:
import tkinter as tk
import json
import os
condition_data = {
"diabetes": {
"description": "A chronic condition that affects the way the body processes blood sugar
(glucose).",
"management_tips": [
},
"hypertension": {
"description": "A condition in which the blood pressure in the arteries is persistently elevated.",
"management_tips": [
},
"asthma": {
"description": "A condition that affects the airways in the lungs, leading to difficulty breathing.",
"management_tips": [
class ChronicDiseaseApp:
self.root = root
self.user_profiles = self.load_profiles()
self.current_user = None
self.create_user_button.pack(pady=10)
self.load_user_button.pack(pady=10)
self.label_condition.pack(pady=10)
self.condition_entry.pack(pady=5)
self.label_sugar = tk.Label(root, text="Enter your blood sugar level (only for diabetes):")
self.label_sugar.pack(pady=10)
self.sugar_entry.pack(pady=5)
self.label_weight.pack(pady=10)
self.weight_entry.pack(pady=5)
self.label_height.pack(pady=10)
self.height_entry.pack(pady=5)
self.submit_button.pack(pady=10)
# Create output area
self.output_text.pack(pady=10)
self.history_button.pack(pady=10)
# Load history
self.history_file = "history.json"
if not os.path.exists(self.history_file):
json.dump([], f)
def create_profile(self):
profile = {
"name": name,
"age": age,
self.user_profiles[name] = profile
self.save_profiles()
def load_profile(self):
if name in self.user_profiles:
self.current_user = self.user_profiles[name]
self.condition_entry.delete(0, tk.END)
else:
def get_tips(self):
condition = self.condition_entry.get().lower()
sugar_level = self.sugar_entry.get()
weight = self.weight_entry.get()
height = self.height_entry.get()
info = self.get_condition_info(condition)
try:
sugar_level = float(sugar_level)
self.check_sugar_level(sugar_level)
except ValueError:
return
if weight and height:
try:
weight = float(weight)
return
self.provide_bmi_feedback(bmi)
except ValueError:
return
if info:
self.output_text.delete(1.0, tk.END)
self.output_text.insert(tk.END, output)
self.save_to_history(condition)
else:
messagebox.showinfo("Blood Sugar Level", "Your blood sugar level is low. Please consult a
doctor.")
else:
messagebox.showinfo("Blood Sugar Level", "Your blood sugar level is high. Please consult a
doctor.")
"""Calculate BMI."""
else:
return condition_data.get(condition)
def save_to_history(self, condition):
history = json.load(f)
history.append(condition)
json.dump(history, f)
def show_history(self):
history = json.load(f)
if history:
messagebox.showinfo("History", history_str)
else:
def load_profiles(self):
if os.path.exists("profiles.json"):
return json.load(f)
return {}
def save_profiles(self):
json.dump(self.user_profiles, f)
if _name_ == "_main_":
root = tk.Tk()
app = ChronicDiseaseApp(root)
root.mainloop()
OUTPUT:
.
RESULT:
The Chronic Disease Management System empowers users to effectively manage their chronic
conditions by providing personalized health information and feedback. It encourages healthier habits
and regular tracking of health metrics for improved well-being