#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_PATIENTS 10

// Structure to store patient details
typedef struct {
    char name[50];
    int age;
    char symptoms[100];
    int severity; // Higher value means more severe
    int priority;
} Patient;

// Function to assign priority based on severity
void assignPriority(Patient patients[], int n) {
    for (int i = 0; i < n; i++) {
        patients[i].priority = patients[i].severity; // Priority is based on severity
    }
}

// Function to sort patients based on priority (Descending order)
void sortPatientsByPriority(Patient patients[], int n) {
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            if (patients[j].priority < patients[j + 1].priority) {
                Patient temp = patients[j];
                patients[j] = patients[j + 1];
                patients[j + 1] = temp;
            }
        }
    }
}

// Function to predict health condition based on symptoms
void predictDisease(Patient *p) {
    printf("\nPredicted Condition for %s:\n", p->name);
    
    if (strstr(p->symptoms, "fever") && strstr(p->symptoms, "cough")) {
        printf("Possible Disease: Flu or COVID-19\n");
    } else if (strstr(p->symptoms, "chest pain") || strstr(p->symptoms, "shortness of breath")) {
        printf("Possible Disease: Heart Issue\n");
    } else if (strstr(p->symptoms, "headache") && strstr(p->symptoms, "dizziness")) {
        printf("Possible Disease: Migraine or High BP\n");
    } else {
        printf("General Check-up Recommended.\n");
    }
}

// Function to display patient details after scheduling
void displayPatients(Patient patients[], int n) {
    printf("\nScheduled Patients List (Based on Priority):\n");
    printf("------------------------------------------------\n");
    printf("Priority | Name       | Age | Symptoms            | Severity\n");
    printf("------------------------------------------------\n");
    
    for (int i = 0; i < n; i++) {
        printf("%8d | %-10s | %3d | %-20s | %8d\n",
               patients[i].priority, patients[i].name, patients[i].age, patients[i].symptoms, patients[i].severity);
        predictDisease(&patients[i]);
    }
}

int main() {
    int n;
    printf("Enter the number of patients (max %d): ", MAX_PATIENTS);
    scanf("%d", &n);
    if (n > MAX_PATIENTS) {
        printf("Maximum number of patients is %d. Exiting...\n", MAX_PATIENTS);
        return 1;
    }

    Patient patients[MAX_PATIENTS];

    // Input patient details
    for (int i = 0; i < n; i++) {
        printf("\nEnter details for patient %d:\n", i + 1);
        printf("Name: ");
        scanf(" %[^\n]s", patients[i].name);
        printf("Age: ");
        scanf("%d", &patients[i].age);
        printf("Symptoms (comma-separated): ");
        scanf(" %[^\n]s", patients[i].symptoms);
        printf("Severity (1-10, 10 = Critical): ");
        scanf("%d", &patients[i].severity);
    }

    // Assign priority based on severity
    assignPriority(patients, n);

    // Sort patients based on priority
    sortPatientsByPriority(patients, n);

    // Display scheduled patients
    displayPatients(patients, n);

    return 0;
}
