0% found this document useful (0 votes)
21 views14 pages

AI Project

Uploaded by

23dr46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views14 pages

AI Project

Uploaded by

23dr46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

AIM:

The aim of the Chronic Disease Management


System is to help users manage their chronic health
conditions easily.
Algorithm:

1. Import Necessary Libraries

Import `tkinter` for the GUI.

Import `json` for data handling.

Import `os` for file management.

2. Define Sample Data

Create a dictionary `condition_data` containing chronic conditions, descriptions, and management


tips.

3. Define the Main Application Class (`ChronicDiseaseApp`)

Initialization (`__init__`)

Set up the main window.

Load existing user profiles.

Create buttons for profile management and UI elements for condition input, user data,
management tips.

4. User Profile Management

Create Profile

Prompt the user for their name, age, and conditions.

Validate input and save the profile to a JSON file.

Load Profile:

Prompt for a name to load the profile.

Display conditions in the entry field.

5. Get Management Tips:

Input Handling:

Read inputs for the chronic condition, blood sugar level, weight, and height.

Validate inputs and handle errors.


Condition Check:

If the condition is "diabetes", check the blood sugar level.

BMI Calculation:

Calculate BMI using weight and height.

Provide feedback based on BMI value.

Display Information:

Show condition description and management tips in the text area.

Save the condition to the history.

6. Blood Sugar Level Check:

Categorize blood sugar levels as low, normal, or high and display messages accordingly.

7. BMI Calculation and Feedback:

Calculate BMI using the formula and provide health feedback based on BMI ranges.

8. Save to History:

Append the condition to a history file for record-keeping.

9. Show History:

Load and display previously entered conditions from the history file.

10. Load and Save Profiles:

Load user profiles from a JSON file at startup.

Save user profiles whenever a new profile is created or modified.

11. Run the Application:

Create a Tkinter window and run the main event loop.

Key Functions Breakdown

create_profile(): Handles creating a new user profile and saving it.


load_profile(): Loads an existing profile based on user input.

get_tips(): Main function for processing the user input to get management tips.

check_sugar_level(level): Validates and categorizes blood sugar levels.

calculate_bmi(weight, height): Computes the BMI from weight and height.

provide_bmi_feedback(bmi): Offers feedback based on BMI value.

get_condition_info(condition): Fetches condition data from the predefined dictionary.

save_to_history(condition): Appends the condition to a history file.

show_history(): Displays a message box with the history of conditions.

PROGRAM:
import tkinter as tk

from tkinter import messagebox, simpledialog

import json

import os

# Sample data for chronic conditions and management tips

condition_data = {

"diabetes": {

"description": "A chronic condition that affects the way the body processes blood sugar
(glucose).",

"management_tips": [

"Monitor your blood sugar levels regularly.",

"Maintain a balanced diet rich in whole grains, fruits, and vegetables.",

"Engage in regular physical activity.",

"Take medications as prescribed."

},

"hypertension": {

"description": "A condition in which the blood pressure in the arteries is persistently elevated.",

"management_tips": [

"Reduce sodium intake.",


"Stay physically active.",

"Manage stress through relaxation techniques.",

"Monitor your blood pressure regularly."

},

"asthma": {

"description": "A condition that affects the airways in the lungs, leading to difficulty breathing.",

"management_tips": [

"Avoid triggers like smoke, dust, and allergens.",

"Use inhalers as prescribed.",

"Keep your environment clean.",

"Regularly check your peak flow meter."

class ChronicDiseaseApp:

def _init_(self, root):

self.root = root

self.root.title("Chronic Disease Management System")

self.user_profiles = self.load_profiles()

self.current_user = None

# Create user profile management buttons

self.create_user_button = tk.Button(root, text="Create Profile", command=self.create_profile)

self.create_user_button.pack(pady=10)

self.load_user_button = tk.Button(root, text="Load Profile", command=self.load_profile)

self.load_user_button.pack(pady=10)

# Create input label and entry for chronic condition


self.label_condition = tk.Label(root, text="Enter a chronic condition (diabetes, hypertension,
asthma):")

self.label_condition.pack(pady=10)

self.condition_entry = tk.Entry(root, width=50)

self.condition_entry.pack(pady=5)

# Create input label and entry for blood sugar level

self.label_sugar = tk.Label(root, text="Enter your blood sugar level (only for diabetes):")

self.label_sugar.pack(pady=10)

self.sugar_entry = tk.Entry(root, width=50)

self.sugar_entry.pack(pady=5)

# Create input label and entry for weight

self.label_weight = tk.Label(root, text="Enter your weight (kg):")

self.label_weight.pack(pady=10)

self.weight_entry = tk.Entry(root, width=50)

self.weight_entry.pack(pady=5)

# Create input label and entry for height in cm

self.label_height = tk.Label(root, text="Enter your height (cm):")

self.label_height.pack(pady=10)

self.height_entry = tk.Entry(root, width=50)

self.height_entry.pack(pady=5)

# Create submit button

self.submit_button = tk.Button(root, text="Get Management Tips", command=self.get_tips)

self.submit_button.pack(pady=10)
# Create output area

self.output_text = tk.Text(root, width=60, height=15)

self.output_text.pack(pady=10)

# Create history button

self.history_button = tk.Button(root, text="Show History", command=self.show_history)

self.history_button.pack(pady=10)

# Load history

self.history_file = "history.json"

if not os.path.exists(self.history_file):

with open(self.history_file, 'w') as f:

json.dump([], f)

def create_profile(self):

"""Create a new user profile."""

name = simpledialog.askstring("Input", "Enter your name:")

age = simpledialog.askinteger("Input", "Enter your age:")

conditions = simpledialog.askstring("Input", "Enter your chronic conditions (comma-


separated):")

if name and age is not None and conditions:

profile = {

"name": name,

"age": age,

"conditions": [condition.strip() for condition in conditions.split(",")]

self.user_profiles[name] = profile

self.save_profiles()

messagebox.showinfo("Profile Created", f"Profile for {name} created successfully!")


else:

messagebox.showerror("Error", "All fields are required!")

def load_profile(self):

"""Load an existing user profile."""

name = simpledialog.askstring("Input", "Enter your name to load your profile:")

if name in self.user_profiles:

self.current_user = self.user_profiles[name]

messagebox.showinfo("Profile Loaded", f"Welcome back, {self.current_user['name']}!")

# Automatically fill in conditions (optional)

self.condition_entry.delete(0, tk.END)

self.condition_entry.insert(0, ", ".join(self.current_user["conditions"]))

else:

messagebox.showerror("Error", "Profile not found.")

def get_tips(self):

"""Get management tips for the entered condition."""

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)

if condition == "diabetes" and sugar_level:

try:

sugar_level = float(sugar_level)

self.check_sugar_level(sugar_level)

except ValueError:

messagebox.showerror("Error", "Please enter a valid number for blood sugar level.")

return
if weight and height:

try:

weight = float(weight)

height = float(height) / 100 # Convert height from cm to meters

if weight <= 0 or height <= 0:

messagebox.showerror("Error", "Weight and height must be greater than zero.")

return

bmi = self.calculate_bmi(weight, height)

self.output_text.insert(tk.END, f"\nYour BMI is: {bmi:.2f}\n")

self.provide_bmi_feedback(bmi)

except ValueError:

messagebox.showerror("Error", "Please enter valid numbers for weight and height.")

return

if info:

output = f"Condition: {condition.capitalize()}\n\n"

output += f"Description: {info['description']}\n\n"

output += "Management Tips:\n"

for tip in info['management_tips']:

output += f"- {tip}\n"

self.output_text.delete(1.0, tk.END)

self.output_text.insert(tk.END, output)

self.save_to_history(condition)

else:

messagebox.showerror("Error", "Condition not found. Please consult a healthcare


professional.")

def check_sugar_level(self, level):


"""Check if the blood sugar level is normal."""

if level < 70:

messagebox.showinfo("Blood Sugar Level", "Your blood sugar level is low. Please consult a
doctor.")

elif 70 <= level <= 130:

messagebox.showinfo("Blood Sugar Level", "Your blood sugar level is normal.")

else:

messagebox.showinfo("Blood Sugar Level", "Your blood sugar level is high. Please consult a
doctor.")

def calculate_bmi(self, weight, height):

"""Calculate BMI."""

return weight / (height ** 2)

def provide_bmi_feedback(self, bmi):

"""Provide feedback based on the BMI value."""

if bmi < 18.5:

messagebox.showinfo("BMI Feedback", "You are underweight. Consider consulting a


healthcare provider.")

elif 18.5 <= bmi < 24.9:

messagebox.showinfo("BMI Feedback", "You have a normal weight. Keep maintaining a


healthy lifestyle!")

elif 25 <= bmi < 29.9:

messagebox.showinfo("BMI Feedback", "You are overweight. Consider a balanced diet and


regular exercise.")

else:

messagebox.showinfo("BMI Feedback", "You are obese. It's advisable to consult a healthcare


provider for guidance.")

def get_condition_info(self, condition):

"""Get information and management tips based on the chronic condition."""

return condition_data.get(condition)
def save_to_history(self, condition):

"""Save the condition to history."""

with open(self.history_file, 'r') as f:

history = json.load(f)

history.append(condition)

with open(self.history_file, 'w') as f:

json.dump(history, f)

def show_history(self):

"""Show the history of entered conditions."""

with open(self.history_file, 'r') as f:

history = json.load(f)

if history:

history_str = "History of entered conditions:\n" + "\n".join(history)

messagebox.showinfo("History", history_str)

else:

messagebox.showinfo("History", "No history found.")

def load_profiles(self):

"""Load user profiles from a JSON file."""

if os.path.exists("profiles.json"):

with open("profiles.json", 'r') as f:

return json.load(f)

return {}

def save_profiles(self):

"""Save user profiles to a JSON file."""

with open("profiles.json", 'w') as f:

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

You might also like