import pandas as pd
import pickle
import numpy as np


def sideEffectTreatments(new_person_data): 

    # Load the trained model
    with open('./Models/trained_model.pkl', 'rb') as file:
        diseasers_or_side_effects_1_model = pickle.load(file)
        diseasers_or_side_effects_2_model = pickle.load(file)
        treatments_1_model = pickle.load(file)
        treatments_2_model = pickle.load(file)

    # Make predictions for the new data
    diseasers_or_side_effects_1_prediction = diseasers_or_side_effects_1_model.predict(new_person_data)
    diseasers_or_side_effects_2_prediction = diseasers_or_side_effects_2_model.predict(new_person_data)
    treatments_1_prediction = treatments_1_model.predict(new_person_data)
    treatments_2_prediction = treatments_2_model.predict(new_person_data)

    # Round the predictions
    diseasers_or_side_effects_1_prediction = np.round(diseasers_or_side_effects_1_prediction)
    diseasers_or_side_effects_2_prediction = np.round(diseasers_or_side_effects_2_prediction)
    treatments_1_prediction = np.round(treatments_1_prediction)
    treatments_2_prediction = np.round(treatments_2_prediction)

    if diseasers_or_side_effects_1_prediction == 1:

        diseasers_or_side_effects_1 = 'Addiction'

    elif diseasers_or_side_effects_1_prediction == 2:

        diseasers_or_side_effects_1 = 'Agitation and restlessness'

    elif diseasers_or_side_effects_1_prediction == 3:

        diseasers_or_side_effects_1 = 'Anxiety and paranoia'

    elif diseasers_or_side_effects_1_prediction == 4:

        diseasers_or_side_effects_1 = 'Cardiovascular effects'

    elif diseasers_or_side_effects_1_prediction == 5:

        diseasers_or_side_effects_1 = 'Cognitive impairments'

    elif diseasers_or_side_effects_1_prediction == 6:

        diseasers_or_side_effects_1 = 'Constipation'

    elif diseasers_or_side_effects_1_prediction == 7:

        diseasers_or_side_effects_1 = 'Decreased appetite'

    elif diseasers_or_side_effects_1_prediction == 8:

        diseasers_or_side_effects_1 = 'Dental issues'

    elif diseasers_or_side_effects_1_prediction == 9:

        diseasers_or_side_effects_1 = 'Dizziness'

    elif diseasers_or_side_effects_1_prediction == 10:

        diseasers_or_side_effects_1 = 'Drowsiness and sedation'

    elif diseasers_or_side_effects_1_prediction == 11:

        diseasers_or_side_effects_1 = 'Dry mouth and throat'

    elif diseasers_or_side_effects_1_prediction == 12:

        diseasers_or_side_effects_1 = 'Elevated body temperature'

    elif diseasers_or_side_effects_1_prediction == 13:

        diseasers_or_side_effects_1 = 'Gastrointestinal problems'

    elif diseasers_or_side_effects_1_prediction == 14:

        diseasers_or_side_effects_1 = 'Headaches'

    elif diseasers_or_side_effects_1_prediction == 15:

        diseasers_or_side_effects_1 = 'Heart attak'

    elif diseasers_or_side_effects_1_prediction == 16:

        diseasers_or_side_effects_1 = 'Hormonal imbalances'

    elif diseasers_or_side_effects_1_prediction == 17:

        diseasers_or_side_effects_1 = 'Hypotension'

    elif diseasers_or_side_effects_1_prediction == 18:

        diseasers_or_side_effects_1 = 'Insomnia'

    elif diseasers_or_side_effects_1_prediction == 19:

        diseasers_or_side_effects_1 = 'Itching and skin infections'

    elif diseasers_or_side_effects_1_prediction == 20:

        diseasers_or_side_effects_1 = 'Liver and kidney damage'

    elif diseasers_or_side_effects_1_prediction == 21:

        diseasers_or_side_effects_1 = 'Mental confusion'

    elif diseasers_or_side_effects_1_prediction == 22:

        diseasers_or_side_effects_1 = 'Muscle spasms'

    elif diseasers_or_side_effects_1_prediction == 23:

        diseasers_or_side_effects_1 = 'Nausea and vomiting'

    elif diseasers_or_side_effects_1_prediction == 24:

        diseasers_or_side_effects_1 = 'Neurological effects'

    elif diseasers_or_side_effects_1_prediction == 25:

        diseasers_or_side_effects_1 = 'Red eyes'

    else:

     diseasers_or_side_effects_1 = 'Respiratory problems'

    if diseasers_or_side_effects_2_prediction == 1:

        diseasers_or_side_effects_2 = 'Addiction'

    elif diseasers_or_side_effects_2_prediction == 2:

        diseasers_or_side_effects_2 = 'Agitation and restlessness'

    elif diseasers_or_side_effects_2_prediction == 3:

        diseasers_or_side_effects_2 = 'Anxiety and paranoia'

    elif diseasers_or_side_effects_2_prediction == 4:

        diseasers_or_side_effects_2 = 'Cardiovascular effects'

    elif diseasers_or_side_effects_2_prediction == 5:

        diseasers_or_side_effects_2 = 'Cognitive impairments'

    elif diseasers_or_side_effects_2_prediction == 6:

        diseasers_or_side_effects_2 = 'Constipation'

    elif diseasers_or_side_effects_1_prediction == 7:

        diseasers_or_side_effects_2 = 'Decreased appetite'

    elif diseasers_or_side_effects_2_prediction == 8:

        diseasers_or_side_effects_2 = 'Dental issues'

    elif diseasers_or_side_effects_2_prediction == 9:

        diseasers_or_side_effects_2 = 'Dizziness'

    elif diseasers_or_side_effects_2_prediction == 10:

        diseasers_or_side_effects_2 = 'Drowsiness and sedation'

    elif diseasers_or_side_effects_2_prediction == 11:

        diseasers_or_side_effects_2 = 'Dry mouth and throat'

    elif diseasers_or_side_effects_2_prediction == 12:

        diseasers_or_side_effects_2 = 'Elevated body temperature'

    elif diseasers_or_side_effects_2_prediction == 13:

        diseasers_or_side_effects_2 = 'Gastrointestinal problems'

    elif diseasers_or_side_effects_2_prediction == 14:

        diseasers_or_side_effects_2 = 'Headaches'

    elif diseasers_or_side_effects_2_prediction == 15:

        diseasers_or_side_effects_2 = 'Heart attak'

    elif diseasers_or_side_effects_2_prediction == 16:

        diseasers_or_side_effects_2 = 'Hormonal imbalances'

    elif diseasers_or_side_effects_2_prediction == 17:

        diseasers_or_side_effects_2 = 'Hypotension'

    elif diseasers_or_side_effects_2_prediction == 18:

        diseasers_or_side_effects_2_model = 'Insomnia'

    elif diseasers_or_side_effects_2_prediction == 19:

        diseasers_or_side_effects_2 = 'Itching and skin infections'

    elif diseasers_or_side_effects_2_prediction == 20:

        diseasers_or_side_effects_2 = 'Liver and kidney damage'

    elif diseasers_or_side_effects_2_prediction == 21:

        diseasers_or_side_effects_2 = 'Mental confusion'

    elif diseasers_or_side_effects_2_prediction == 22:

        diseasers_or_side_effects_2 = 'Muscle spasms'

    elif diseasers_or_side_effects_2_prediction == 23:

        diseasers_or_side_effects_2 = 'Nausea and vomiting'

    elif diseasers_or_side_effects_2_prediction == 24:

        diseasers_or_side_effects_2 = 'Neurological effects'

    elif diseasers_or_side_effects_2_prediction == 25:

        diseasers_or_side_effects_2 = 'Red eyes'

    else:

        diseasers_or_side_effects_2 = 'Respiratory problems'


    if treatments_1_prediction == 1:

        treatments_1 = 'Behavioral Therapy, Medications, Support Groups, Inpatient Rehab,Outpatient Rehab'

    elif treatments_1_prediction == 2:

        treatments_1 = 'Antipsychotics,Talk therapy, If nothing else works, physical restraint may be needed'

    elif treatments_1_prediction == 3:

        treatments_1 = 'Cognitive behaviour therapy (CBT)'

    elif treatments_1_prediction == 4:

        treatments_1 = 'Do not smoke, Eat healthy foods, Control blood pressure, Get a cholesterol test, Manage diabetes, Exercise, Maintain a healthy weight, Manage stress'

    elif treatments_1_prediction == 5:

        treatments_1 = 'Using remediation techniques, compensatory strategies, adaptive approaches'

    elif treatments_1_prediction == 6:

        treatments_1 = 'Gradually increase your daily fiber intake, make sure you drink plenty of fluids, and try to get more exercise'

    elif treatments_1_prediction == 7:

        treatments_1 = 'Eating small meals regularly throughout the day, Managing any illnesses, infections or underlying conditions, Receiving IV nutrients which are liquid vitamins and minerals that you receive through a needle into your vein, Talking with a mental health specialist about your eating habits if they are irregular'

    elif treatments_1_prediction == 8:

        treatments_1 = 'Fluoride treatments, Tooth extractions, Fillings, Crowns, Root canals'

    elif treatments_1_prediction == 9:

        treatments_1 = 'Lie down until the dizziness passes, then get up slowly,move slowly and carefully, get plenty of rest, drink plenty of fluids, especially water, avoid coffee, cigarettes, alcohol and drugs'

    elif treatments_1_prediction == 10:

        treatments_1 = 'Treating underlying sleep disorders, Lifestyle changes, Address the underlying cause'

    elif treatments_1_prediction == 11:

        treatments_1 = 'Avoid alcohol (including alcohol-based mouthwashes), caffeine and smoking, suck on ice cubes'

    elif treatments_1_prediction == 12:

        treatments_1 = 'Take paracetamol or ibuprofen in appropriate doses to help bring your temperature down, Drink plenty of fluids, particularly water, Avoid alcohol, tea and coffee, Avoid taking cold baths or showers'

    elif treatments_1_prediction == 13:

        treatments_1 = 'Taking rest and drinking plenty of healthy liquids, Eating easily digestible foods, Avoiding spices, carbonated drinks, fried foods, alcohol, and other foods that are gastric irritants, Taking prescribed gastrointestinal medications'

    elif treatments_1_prediction == 14:

        treatments_1 = 'Drink water, Inadequate hydration may lead you to develop a headache,Limit alcohol, Get adequate sleep, Avoid foods high in histamine, Soothe pain with a cold compress'

    elif treatments_1_prediction == 15:

        treatments_1 = 'Clot-dissolving drugs (thrombolysis), balloon angioplasty (PCI), surgery'

    elif treatments_1_prediction == 16:

        treatments_1 = 'Hormone replacement therapy, take oral medication (pills) or injection medication'

    elif treatments_1_prediction == 17:

        treatments_1 = 'Use more salt, Drink more water, Wear compression stockings'

    elif treatments_1_prediction == 18:

        treatments_1 = 'Stimulus control therapy, Relaxation techniques, Sleep restriction, Remaining passively awake, Light therapy'

    elif treatments_1_prediction == 19:

        treatments_1 = 'Antibiotics, Antifungal medications, Moisturizers, Cool compresses, Avoiding triggers'

    elif treatments_1_prediction == 20:

        treatments_1 = 'Liver transplant'

    elif treatments_1_prediction == 21:

        treatments_1 = 'Find the source, Prioritize sleep, Make time to relax, Meditate, Feed yourself,Move your body'

    elif treatments_1_prediction == 22:

        treatments_1 = 'Stretch the affected area, Massage the affected area with your hands or a massage roller, Stand up and walk around, Apply heat or ice, Put an ice pack together or apply a heating pad, or take a nice warm bath, Take painkillers such as ibuprofen and acetaminophen'

    elif treatments_1_prediction == 23:

        treatments_1 = 'Drinking gradually larger amounts of clear liquids, Avoiding solid food until the vomiting episode has passed, Resting'

    elif treatments_1_prediction == 24:

        treatments_1 = 'Deep brain stimulation, Spinal cord stimulation, Rehabilitation/physical therapy after brain injury or stroke, Spinal surgery'

    elif treatments_1_prediction == 25:

        treatments_1 = 'Rest, Cool compresses over closed eyes, Lightly massaging your eyelids, Gently washing your eyelids'

    else:

        treatments_1 = 'Oxygen therapy, fluid therapy, pulmonary rehabilitation, Breathing exercises and surgery'


    if treatments_2_prediction == 1:

        treatments_2 = 'Behavioral Therapy, Medications, Support Groups, Inpatient Rehab,Outpatient Rehab'

    elif treatments_2_prediction == 2:

        treatments_2 = 'Antipsychotics,Talk therapy, If nothing else works, physical restraint may be needed'

    elif treatments_2_prediction == 3:

        treatments_2 = 'Cognitive behaviour therapy (CBT)'

    elif treatments_2_prediction == 4:

        treatments_2 = 'Do not smoke, Eat healthy foods, Control blood pressure, Get a cholesterol test, Manage diabetes, Exercise, Maintain a healthy weight, Manage stress'

    elif treatments_2_prediction == 5:

        treatments_2 = 'Using remediation techniques, compensatory strategies, adaptive approaches'

    elif treatments_2_prediction == 6:

        treatments_2 = 'Gradually increase your daily fiber intake, make sure you drink plenty of fluids, and try to get more exercise'

    elif treatments_2_prediction == 7:

        treatments_2 = 'Eating small meals regularly throughout the day, Managing any illnesses, infections or underlying conditions, Receiving IV nutrients which are liquid vitamins and minerals that you receive through a needle into your vein, Talking with a mental health specialist about your eating habits if they are irregular'

    elif treatments_2_prediction == 8:

        treatments_2 = 'Fluoride treatments, Tooth extractions, Fillings, Crowns, Root canals'

    elif treatments_2_prediction == 9:

        treatments_2 = 'Lie down until the dizziness passes, then get up slowly,move slowly and carefully, get plenty of rest, drink plenty of fluids, especially water, avoid coffee, cigarettes, alcohol and drugs'

    elif treatments_2_prediction == 10:

        treatments_2 = 'Treating underlying sleep disorders, Lifestyle changes, Address the underlying cause'

    elif treatments_2_prediction == 11:

        treatments_2 = 'Avoid alcohol (including alcohol-based mouthwashes), caffeine and smoking, suck on ice cubes'

    elif treatments_2_prediction == 12:

        treatments_2 = 'Take paracetamol or ibuprofen in appropriate doses to help bring your temperature down, Drink plenty of fluids, particularly water, Avoid alcohol, tea and coffee, Avoid taking cold baths or showers'

    elif treatments_2_prediction == 13:

        treatments_2 = 'Taking rest and drinking plenty of healthy liquids, Eating easily digestible foods, Avoiding spices, carbonated drinks, fried foods, alcohol, and other foods that are gastric irritants, Taking prescribed gastrointestinal medications'

    elif treatments_2_prediction == 14:

        treatments_2 = 'Drink water, Inadequate hydration may lead you to develop a headache,Limit alcohol, Get adequate sleep, Avoid foods high in histamine, Soothe pain with a cold compress'

    elif treatments_2_prediction == 15:

        treatments_2 = 'Clot-dissolving drugs (thrombolysis), balloon angioplasty (PCI), surgery'

    elif treatments_2_prediction == 16:

        treatments_2 = 'Hormone replacement therapy, take oral medication (pills) or injection medication'

    elif treatments_2_prediction == 17:

        treatments_2 = 'Use more salt, Drink more water, Wear compression stockings'

    elif treatments_2_prediction == 18:

        treatments_2 = 'Stimulus control therapy, Relaxation techniques, Sleep restriction, Remaining passively awake, Light therapy'

    elif treatments_2_prediction == 19:

        treatments_2 = 'Antibiotics, Antifungal medications, Moisturizers, Cool compresses, Avoiding triggers'

    elif treatments_2_prediction == 20:

        treatments_2 = 'Liver transplant'

    elif treatments_2_prediction == 21:

        treatments_2 = 'Find the source, Prioritize sleep, Make time to relax, Meditate, Feed yourself,Move your body'

    elif treatments_2_prediction == 22:

        treatments_2 = 'Stretch the affected area, Massage the affected area with your hands or a massage roller, Stand up and walk around, Apply heat or ice, Put an ice pack together or apply a heating pad, or take a nice warm bath, Take painkillers such as ibuprofen and acetaminophen'

    elif treatments_2_prediction == 23:

        treatments_2 = 'Drinking gradually larger amounts of clear liquids, Avoiding solid food until the vomiting episode has passed, Resting'

    elif treatments_2_prediction == 24:

        treatments_2 = 'Deep brain stimulation, Spinal cord stimulation, Rehabilitation/physical therapy after brain injury or stroke, Spinal surgery'

    elif treatments_2_prediction == 25:

        treatments_2 = 'Rest, Cool compresses over closed eyes, Lightly massaging your eyelids, Gently washing your eyelids'

    else:

        treatments_2 = 'Oxygen therapy, fluid therapy, pulmonary rehabilitation, Breathing exercises and surgery'

    # Print the predicted Diseasers_or_side_effects
    print('Predicted Diseasers or Side Effects 1:', diseasers_or_side_effects_1_prediction)
    print('Predicted Diseasers or Side Effects 2:', diseasers_or_side_effects_2_prediction)
    print('Predicted Treatments 1:', treatments_1_prediction)
    print('Predicted Treatments 2:', treatments_2_prediction)
    print(diseasers_or_side_effects_1)
    print(diseasers_or_side_effects_2)
    print(treatments_1)
    print(treatments_2)


    # Return the predictions if needed
    return {
        'Predicted Diseasers or Side Effects 1': diseasers_or_side_effects_1_prediction,
        'Predicted Diseasers or Side Effects 2': diseasers_or_side_effects_2_prediction,
        'Predicted Treatments 1': treatments_1_prediction,
        'Predicted Treatments 2': treatments_2_prediction,
        'Predicted Diseasers or Side Effects 1': diseasers_or_side_effects_1,
        'Predicted Diseasers or Side Effects 2': diseasers_or_side_effects_2,
        'Predicted Treatments 1': treatments_1,
        'Predicted Treatments 2': treatments_2
    }

