Challenge

Project - Design a Hospital Management system

Healthcare management system

Learning to explore different Web technologies like HTML, JavaScript, etc

  • Technological innovations have improved the quality of patient care by giving patients broader access to their medical records; adapting medical care to patients' schedules; developing safer medical procedures, tests, and studies; and using technology to gather patient data, analyze it, and apply it in new ways.
  • These are web-based or computer-based software which can be used to manage the daily work in a hospital like electronic medical records (EMR), patient information, doctor/nurse schedules, inventory, billing and much more. As these are complicated software, many of these can be procured on payment.

Healthcare management is currently undergoing substantial changes, and reshaping our perception of the medical field. One spectrum is that of the considerable changes that we see in surgical machines and equipment, and the way the procedures are performed. Computing power, Internet and associated technologies are transforming surgical operations into model based procedures. The other spectrum is the management side of healthcare, which is equally critical to the medical profession. In particular, recent advances in the field of Information Technology (IT) is assisting in better management of health appointments and record management. With the proliferation of IT and management, data is now playing a vital role in diagnostics, drug administration and management of healthcare services. With the advancement in data processing, large amounts of medical data collected by medical centres and providers, can now be mined and analysed to assist in planning and making appropriate decisions. In this article, we shall provide an overview of the role of IT that have been reshaping the healthcare management, hospital, health profession and industry.

Keywords: Healthcare, IT applications, Healthcare management, Ubiquitous, Robots, Internet of medical things, Big medical data analytics, HMIS

Introduction

Internet and Web 2.0 have been instrumental in evolving most of the Information Technology (IT) applications that we are now accustomed to. Barely 20 years ago, we had not imagined the technological advancements, which are now implemented into our lives. Technological advancement, riding on the wave of disruptive technologies of the last quarter of a century, is reshaping and redefining the world’s social order and norms. The medical field is part and parcel of our lives and is perhaps one that we care the most about. In the recent times, this field has undergone vast changes. The medical profession today has evolved greatly since the beginning of this century. Not only the medical procedures, the medical data flow and management has also undergone considerable improvement. Advance data transfer and management techniques have made improvements in disease diagnostic and have been a critical role in national health planning and efficient record keeping. In particular, the medical profession has undergone substantial changes through the capabilities of database management, which has given rise to the Healthcare Information Systems (HIS). Medical data collected from different institutions can now be mined and analysed in time using Big Data Analytics tools.

Technology used:

AngularJS, HTML, CSS, JQuery, MongoDB, HIPAA, Node.js, Express.js, Google Cloud Services, Payment gateways, Chat SDKs

Project Overview:

The Client of this Project wanted to build a full-fledged Software Solution that will help Hospitals of all sizes and scales to efficiently manage every aspect of hospital operation and hence, focus more on providing quality medical care to patients rather than spending time in administrative and organizational tasks. So in this Project, We developed a hospital Management Software with features that would streamline workflow and help Hospitals grow over time.

Here’s an overview of the main features:

  • Patient Management System- This feature facilitates medical staff to keep track of in-patients, out-patients, as well as occupied and available beds.
  • Patient registration functionality allows staff to schedule appointments and record patient information.
  • Information Management Portal which holds medical data of every patient. Physicians can access this data, which increases efficiency significantly in cases where different doctors are working on the same case.
  • We also developed an Inventory Management System that helps administration keep track of the medical supplies and supports automatic reordering of supplies after specific periods.
  • Billing Management system-This feature automatically calculates total charges that include consultation fees, lab tests, admissions, etc.
  • Laboratory Management system facilitates staff to directly send patient testing requests to the lab and receive lab reports.
  • Payroll system which helps hospital administrations to manage and automate payrolls.

Hospital management system is a computer system that helps manage the information related to health care and aids in the job completion of health care providers effectively. They manage the data related to all departments of healthcare such as,

  • Clinical
  • Financial
  • Laboratory
  • Inpatient
  • Outpatient
  • Operation theater
  • Materials
  • Nursing
  • Pharmaceutical
  • Radiology
  • Pathology etc.

HMS came into the picture of hospital management as early as 1960 and have ever since been evolving and synchronizing with the technologies while modernizing healthcare facilities. In today’s world, the management of healthcare starts from the hands of the patients through their mobile phones and facilitates the needs of the patient.

Why is HMS important for a hospital?

HMS was introduced to solve the complications coming from managing all the paper works of every patient associated with the various departments of hospitalization with confidentiality. HMS provides the ability to manage all the paperwork in one place, reducing the work of staff in arranging and analyzing the paperwork of the patients. HMS does many works like:

  • Maintain the medical records of the patient
  • Maintain the contact details of the patient
  • Keep track of the appointment dates
  • Save the insurance information for later reference
  • Tracking the bill payments.

The advantages of HMS can be pinpointed to the following:

  • Time-saving Technology
  • Improved Efficiency by avoiding human errors
  • Reduces scope for Error
  • Data security and correct data retrieval made possible
  • Cost effective and easily manageable
  • Easy access to patient data with correct patient history
  • Improved patient care made possible
  • Easy monitoring of supplies in inventory
  • Reduces the work of documentation
  • Better Audit controls and policy compliance.

Features of Hospital Management System:

Appointment Management

  • For hospitals having their own site, appointment widgets will be integrated onto the site. Patients visiting the hospital’s website can book online appointments with ease.

Billing Management

  • Integrated Billing with treatments, Lab and Radiology. Alerts will be sent on Discount Authorisation. Automatic due capture, Option to bill before and after consultation.

Prescription Management

  • Manage commonly and recently used medicines. Option to show medicines available in the pharmacy. SMS prescriptions to Patients.

Discharge Summary

  • Template based Discharge Summary. ICD10 integration. Option to prevent discharge summary till IP bill is closed.

Operation Theatre Management

  • Automatic notification can be sent to customers on test results. Lab notifications like email, SMS of the test reports sent from the Automated Lab notification module.

Pharmacy Management

  • Comprehensive Pharmacy Management handles stock, Prescription Integration, Ward Request, Stock Management, Stock Moment and intelligent reports.

Lab Management

  • Comprehensive Lab Management handles complete order management, Custom Reports, Smart Notifications, Credit Settlement, detailed MIS Reports, Analytics and App for Phlebotomist.

Master Information Systems

  • Lets you access entire MIS data from your palm.

Manage Multiple Locations

  • Any number of branches can be added and managed using a single account.


Benefits of Hospital Management System:

  • We have so far clarified on the importance of HMS, it is your responsibility to pick out the right kind of HMS for your needs and purposes.
  • Here we give more information on the benefits of various HMS and the impact it creates on hospital systems.

Easy Patient data retrieval:

  • HMS makes it possible to access all the data related to a patient via a system by the means of a few simple clicks.
  • Information like patient history, current illness, doctors involved, tests reports taken, billing information and many more can be made visible to the user.
  • These data will help to connect the dots about the patient, like specific diagnosis, related treatment, and medication.

The Electronic Medical Record (EMR) or Electronic Health Record (EHR):

  • This electronic-based medical record system can be viewed as a patient’s health chart.
  • It retrieves information based on the patient’s name or medical record number or the physician’s record number.

Increased Data security:

  • The patient data can be kept a hundred percent safe by using HMS in your hospital.
  • It can be made accessible by only a limited amount of authorized personnel.
  • With HMS, all the data is stored on a server or cloud and kept safe by just securing the login information safe.

Improve Visibility and Transparency:

  • Hospital Management System (HMS) improves the visibility and transparency in the complete management process and in all records.

Streamline Accurate Reporting:

  • It helps in streamlining the accurate reporting with the help of updated and accurate records.

Improved Quality Control:

  • Hospital Management System improves the quality control on the products and services of the hospital.

Improved Management Visibility:

  • It also improves the management visibility of hospital, all information, and data regarding the patient, doctor and medicine could be seen by any department easily.

Ease to Access System Facilities:

  • Hospital Management System makes it easy to get access to the management system facilities for the authorized users and keep it safe from unauthorized users.

Cost Effective:

  • Cost-effectiveness analysis is a way to examine both the costs and health outcomes of one or more interventions.
  • It compares an intervention to another intervention (or the status quo) by estimating how much it costs to gain a unit of a health outcome, like a life year gained or a death prevented.

Functional Requirements:

There are a lot of software requirements specifications included in the functional requirements of the Hospital Management System, which contains various processes, namely Registration, Check out, Report Generation, and Database.

Registration Process of SRS (Software Requirements Specification)

● Adding Patients: The Hospital Management enables the staff at the front desk to include new patients in the system.

● Assigning an ID to the patients: The HMS enables the staff at the front desk to provide a unique ID for each patient and then add them to the record sheet of the patient. The patients can utilize the ID throughout their hospital stay.

Check Out of SRS:

● Deleting Patient ID: The staff in the administration section of the ward can delete the patient ID from the system when the patient checkout from the hospital.

● Adding to the beds available list: The Staff in the administration section of the ward can put the bed empty in the list of beds available.

Report Generation of SRS:

● Information of the Patient: The Hospital Management System generates a report on every patient regarding various information like patients name, Phone number, bed number, the doctor's name whom its assigns, ward name, and more.

● Availability of the Bed: The Hospital Management system also helps in generating reports on the availability of the bed regarding information like bed numbers unoccupied or occupied, ward name, and more.

Database of SRS:

● Mandatory Patient Information: Every patient has some necessary data like phone number, their first and last name, personal health number, postal code, country, address, city, 'patient's ID number, etc.

● Updating information of the Patient: The hospital management system enables users to update the information of the patient as described in the mandatory information included.

Non Functional Requirements

There are a lot of software requirements specifications included in the non-functional requirements of the Hospital Management System, which contains various processes, namely Security, Performance, Maintainability, and Reliability.

Security:

● Patient Identification: The system needs the patient to recognize herself or himself using the phone.

● Logon ID: Any users who make use of the system need to hold a Logon ID and password.

● Modifications: Any modifications like insert, delete, update, etc. for the database can be synchronized quickly and executed only by the ward administrator.

● Front Desk Staff Rights: The staff at the front desk can view any data in the Hospital Management system, and add new patients record to the HMS but they don't have any rights to alter any data in it.

● Administrator rights: The administrator can view as well as alter any information in the Hospital Management System.

Performance:

● Response Time: The system provides acknowledgment in just one second once the 'patient's information is checked.

● Capacity: The system needs to support at least 1000 people at once.

● User-Interface: The user interface acknowledges within five seconds.

● Conformity: The system needs to ensure that the guidelines of the Microsoft accessibilities are followed.

Maintainability:

● Back-Up: The system offers efficiency for data backup.

● Errors: The system will track every mistake as well as keep a log of it.

Reliability:

● Availability: The system is available all the time.

COMPONENTS OF HOSPITAL INFORMATION SYSTEM

When the hospital considers applying this approach, it is necessary to learn how to develop a hospital management system. Planning and setting priorities is one of the important stages. It outlines the functions and benefits that the medical institution expects to get at the final point. The qualified developers usually suggest the list of the recommended hospital management system project modules. They will ensure the efficient administration of your medical institution.

Their number might differ depending on the clinic needs, however, it usually includes some basic hospital information system modules.

Patient management

It is used to control patient flow. It can be used to register them, get the data of the patients’ health condition, view the treatment and check the medical history and reports.

Appointment module in hospital management

Appointment module in hospital management arranges the schedule of doctors due to the patients’ application. It helps to organize the availability of medical specialists at any convenient time. Some hospital can even offer remote visits when you need immediate assistance.

Facility management

The facility management module is responsible for tracking and maintaining the room availability, the occupancy status as well as various kinds of administrative documentation.

Inventory management

Inventory management module controls the amount of clinic inventory. The entire supply chain is automated for the convenience of the staff that can concentrate on the patients’ need firstly.

Staff Management

Staff management module provides the human resources administration. It updates the job description of employees, updates the hospital structure, tracks the recruiting records.

Accounting

Accounting module organizes the financial affairs of both customers and the medical institution. It stores and presents all the patient payment details, hospital financial records on expenses and overall profit.

Insurance services integration

Insurance module can record patients’ insurance details. It includes the policy number, the insurance company, information about their policies.

Medicine management

Medicine management module contains the list of drugs that usually used for the specific treatment. It keeps records of every patient’ drugs used during their treatment.

Laboratory and tests management

Lab management module shows the test results of the particular patient. The lab data can be viewed by the staff and generated for the patients’ reports. It is usually integrated with other hospital information system modules for the better overall functionality of the system.

Reporting

Report management part stores the already processed detailed information. This module helps management collect, analyze and view the performance data in a comprehensive format. The business intelligence subsystem helps define problematic aspects and successfully eliminate them to keep the business profitability as well the high customer satisfaction level.

Helpdesk & support

Helpdesk support module specializes in handling different issues, problems, and requests. It ensures that the operations are maintained properly, the data is valid and reported in accordance.

All mentioned hospital information system modules perform, control and support the general working process. Also, you should not forget about the hospital management system design and functionality. The software developers can usually suggest what modules you should choose for efficient work and meeting all the expectations.

  • HMS not only saves time in the hospital but also is cost-effective in decreasing the number of people working on the system of manual entry of data and paperwork. The implementation of His will decrease the human intervention into the system thereby avoiding human-caused errors.
  • This article shall provide an overview of the involvement, importance and benefits of IT and how data management is contributing to the medical science field. In particular, the following will be discussed:
  1. Artificial intelligence and robotics in healthcare
  2. Virtual, augmented and mixed reality in medical education and procedures
  3. Centralized monitoring of hospital patients
  4. Historical background of HRIS
  5. Patient and data management
  6. Big medical data analytics
  7. Privacy and security of healthcare data

Artificial intelligence in healthcare

Artificial Intelligence (AI) is a field of computer Science which has its roots in logic (mathematics), psychology, philosophy, linguistics, arts, science and management among others. Many AI-dominant tools and applications can be found in games, auto spare parts, heavy machinery and various medical instrumentations. According to , many programs are developed with the help of AI to perform specific tasks which make use of many activities including medical diagnostic, time sharing, interactive interpreters, graphical user interfaces and the computer mouse, rapid development environments, the linked list data structure, automatic storage management, symbolic, functional, dynamic, and object-oriented programming. Here are some other examples.

Pharmaceutical developments involve extensive clinical trials in real environment and may take many years, sometimes more than a decade. This process requires a considerable amount of resources and can cost billions of dollars. In order to save lives and money, it is desirable to expedite this time consuming process to make healthcare cheaper. An urgency of this nature was witnessed during the Ebola crisis in some West African nations. An urgency of this nature was witnessed during the Ebola crisis in some West African nations , where a program powered by AI was used to scan existing medicines that could be redesigned to fight the disease.

Digital consultation

Nowadays medical consultation, with the help of an online illness database, can take place without the direct interaction of a medical practitioner. An example of such a practice can be found in . Advantages of such consultations lies in the fact that the symptoms presented online by the patients are matched with those of about ten thousand known diseases , whereas doctors can only match the symptoms against a fraction of the known diseases which they are familiar without the intervention of an IT database. Likewise virtual nursing to support patients online is also available from . Yet another app developed by Boston Children Hospital provides basic health information and advice for parents of ill children.

Virtual, augmented and mixed reality simulations

Concept and related technology of Virtual Reality (VR), Augmented Reality (AR) and Mixed Reality (MR), which originate from image processing and make extensive use of AI, have been in use for decades in games and movies. For some time now, the VR, AR and MR tools and technology are assisting the medical field in a significant way. Virtual reality has been used in robotic surgery to develop simulators to train surgeons in a stress free environment using realistic models and surgical simulation, without adversely affecting operating time or patient safety . An account of AR and VR technologies, including the advantages and disadvantages can be found in . The AR and VR technology can be very useful in medical and healthcare education, an account of which can be found in. Applications of VR, AR and MR can also be very helpful in Urolo

Historical background of health management information systems

Healthcare Management Information Systems (HMIS) is the generic name for many kinds of information systems used in healthcare industry. The use of HMIS is widespread in various units of hospitals, clinics, and insurance companies. A doctor records patient data (habits, complaints, prescriptions, vital signs, etc.) in one such system they use. A number of hospital/clinic units like Radiology, Pathology, and Pharmacy store patient data in these systems for later retrieval and usage by different stakeholders as shown in Fig. 1. Appointment System itself can also be part of a HMIS or a standalone system. Modern healthcare without HMIS cannot be comprehended.

Data flow of patient consultation

An information system or electronic system dealing includes a database system, sometimes known as the backend of the main system. A database is a collection of data, tailored to the information needs of an organisation for a specific purpose. It can grow bigger or shrink to a smaller size depending on the needs of different times. A database in itself would be of no use unless it was coupled with a software system known as the Database Management System (DBMS), which facilitates various functions and processes like Data Entry and Storage, Retrieval, and Update, Data Redundancy, Data Sharing, Data Consistency, Data Integrity, Concurrency, and Data Privacy & Security. More information about database systems can be found in .

Data in an information system can be organised in several different ways. Classical representation of data is tabular. Most tables can be regarded as mathematical relations, for this reason, a DBMS with tabular data organisation is known as relational. Relational databases have by far been dominant in the business organisations until recently. In the eighties and nineties of the last century, object-oriented and semantic data models were also introduced. In particular, object-oriented databases became very popular for managing audio-visual data. Semantic database technology , although very efficient for search queries, did not reach its expected peak, perhaps because of its complex data model dealing with ontologies. A comparative study of relational, object oriented and semantic database systems is carried out in .

Evolution of healthcare systems

Although the evolution of Information technologies began much earlier, however, its implementation by businesses and corporations occurred in the second half of the last century. The healthcare industry a bit slow to take the advantage of the technology. Earlier, medical records and systems were paper based. Thus the first phase of the usage of information technology and systems in hospital and healthcare management was to transform paper based records to database systems. Not only did it change paper based systems to electronic ones but also allowed data manipulation. As a result, more data could be processed in a very short time, which was critical in making timely decisions. A discussion of early stages of this transformation can be found in . Consolidation of this technology resulted in Healthcare Management Information Systems (HMIS). Timely decision is critical in all walks of life but it assumes a much greater urgency in some healthcare cases. HMIS is capable to transferring data from one location or application to another within split of a second, as opposed to days without the help of electronic systems. This allows users to access, use and manipulate data instantly and concurrently. As the technology continues to evolve and refine, the performance of information systems operations, in particular those of HMIS, is bound to improve.

Ubiquitous healthcare system

Ubiquitous health system is meant to provide healthcare services remotely. According to , Ubiquitous Healthcare system means the environment that users can receive the medical treatment regardless of the location and time. Essentially, a Ubiquitous healthcare system would monitor daily or periodic activities of patients and alert the patients or health workers of problems, if any. A discussion of national healthcare systems in Korea, including the concept of u-Hospitals, is discussed in . A rich picture of a Ubiquitous Healthcare System is shown in Fig.

The administrative and clinical system

This system is required for all healthcare facilities. It provides patient information, reports and statistics. After entering patient data, the system generates a report. Also, using this module, hospital employees can view various statistics on diseases, attendance, etc.

The operational and tactical system

The operational system is used to classify medical information. It allows you to ensure reliable and fast work with data and identify inconsistencies in the system. Dedicated work with information will provide any hospital with the necessary base for quality work, both with patients and internal issues.

Task-based systems

The task-based system helps categorize work tasks. It automatically prioritizes and distributes tasks among staff depending on the current situation in the hospital. Such a system is focused on specific tasks (for example, hospital admission, hospital discharge, transfer to the operating room, etc.)

Subject-based systems

Subject-based systems are needed to store patient information digitally. Hospitals primarily use them to manage and keep complete digital patient histories. Compared to paper records, subject-based systems help avoid data duplication because all information is stored in a single file that changes over time.

Financial systems

Financial systems are responsible for managing the finances of a healthcare facility. These systems help keep track of waste and cash receipts. By using the financial system, hospitals control their budget.

Internet of medical of things and big data analytics

Internet of Things (IoT) is an emerging technology. Data in organisations, including hospitals, clinics, and insurance companies, is increasing every day. To process this large data, advanced data processing techniques are combined into what is now known as the Big Data Analytics.

Internet of medical things

Internet of Things (IoT) is a general paradigm. When dealing with medical environment, it is known as Internet of Medical of things (IoMT), which is same as the Medical Internet of Things. A discussion of IoMT can be found in . The fundamental objective of IOT is to provide ubiquitous access to numerous devices and machines on service providers (SPs) , covering many areas such as location based services (LBS), smart home, smart city, E-Health . These tools, devices and machines cover service providers in many areas of location based services. A few other could be smart home, street or city, elements of ubiquitous health systems, tools for electronic learning and electronic business, the number which is increasing day by day and it may reach fifty billions in 2020 . We have conceptualised this in Fig. 3. The IoT applications invariably use cloud storage coupled with fog computing.

Fig. 3

Internet of medical things

Big medical data analytics

Data in organisations is growing at a rapid rate. Some organisations have collected huge pile from their operations. Organisational data needs to be mined and analysed on a regular basis to uncover hidden patterns, unknown correlations, market trends, customers, patients and treatment records to help organizations to plan and make more informed decisions. Mining and analysis of big data captures the immense wealth of intelligence hidden in organisational data, makes information transparent and usable at much higher frequency, and enhance performance. All of these contribute to providing higher value in efficient decision making. When data grows, it cannot be handled manually, often big data organisations use robotic arm to perform data loading and unloading operations.

Medical data is also growing at a rapid rate in many hospitals, clinics and insurance companies. Mining and analysis of healthcare data is even more critical as it relates to the wellbeing of the society. Data centric research is highly desirable to find answers to questions on many chronical diseases, and to plan and manage national and international health programs. Potential befits of big data analytics in healthcare are discussed in . In particular, authors have provided five strategies for success with big data. These are (1) implementing big data governance, (2) developing an information sharing culture, (3) training key personnel to use big data analytics, (4) incorporating cloud computing into the organization’s big data analytics, and (5) generating new business ideas from big data analytics. A survey of big data analytics in healthcare and government is conducted in , where the need for the analytics is linked to the provision and improvement of patient centric services, detection of diseases before they spread, monitoring the quality of services in hospitals, improving methods of treatment, and provision of quality medical education. Authors in identify medical signals as a major source of big data, discuss analytical techniques of such data. Some of the well known tools used for big data analytics are

  • Apache™ Hadoop® is highly scalable storage platform. It provides cost-effective storage solution for large data volumes. It doesn’t require any particular format.
  • Apache Spark is an open source, in-memory processing machine. Its performance is much faster than that of Hadoop.
  • MapReduce is used for iterative algorithms or interactive data mining.

Data centric issues in healthcare

There are always security and privacy concerns associated with data. Protection of privacy and security is a responsibility of data holding organisations. With medical data these concerns assumes higher pronounce and priority. Medical data can be very sensitive, and may be linked to life and death of the patients. Often socio political issues are linked with medical data. It is well known that India was divided into two countries giving rise to Pakistan in 1947. Mohammad Ali Jinnah, very clever and shrewd, was the leader of Pakistan campaign, Larry Collins and Dominique Lapierre argue that the partition of India could have been avoided if “the most closely guarded secret in India” had become known. Jinnah was suffering from tuberculosis which was slowly but surely killing him. In, privacy issues of data are discussed.

Conclusions

Healthcare procedures and management are now greatly relying on IT applications, which are providing realtime access to data and utilities. Without these applications, healthcare will be limited, compromised and prone to major problems. Many of the medical equipments, which are used in procedures, are highly dependent on technology. AI, Robots, VR, AR, MR, IoMT, ubiquitous medical services, and big data analytics are all directly or indirectly related to IT. HMIS is critical for efficient management of records, appointment systems, diagnostics and their needs of medical centres. As the technology advances, the healthcare is likely to further improve.

Project Overview:

The hospital management system (HMS) is integrated software that handles different directions of clinic workflows. It manages the smooth healthcare performance along with administrative, medical, legal, and financial control. That is a cornerstone for the successful operation of the healthcare facility.

This application has both the backend and the frontend part of a hospital management system. You can use the backend application if you have any frontend graphical user interface of a hospital management system. In that case, you will need to use the main.py file for the glue code. This HMS application is completely designed in Python for specifically SQL Database.

Psycopg2 and Kivy module is used for creating the database connection and frontend part. Here different algorithms have been implanted from the developer’s point of view. It is suitable for a mid-level hospital or clinic. Working strategy plays a vital role to keep this application running smoothly.

Source Code:

Complete Source code of HMS Application in Python:

Main.py

import psycopg2
import os
import doctor
import patient
import employee
import login
import admin
import kivy


print(kivy.deps.__version__)

Here we are Imporing the Multiple modules for HMS



DBConfig.py

we need to connect with the database for storing and retrival of the data
import constant
HOST = constant.grab_constant(True,"HOST")
PORT = int(constant.grab_constant(True,"PORT"))
ADMIN_DATABASE = constant.grab_constant(True,"ADMIN_DATABASE")
DATABASE = constant.grab_constant(True,"DATABASE")
USER = constant.grab_constant(True,"USER")
PASSWORD = constant.grab_constant(True,"PASSWORD")


def admin_config():
    config_dict = {"host":HOST, "port":PORT, "database":ADMIN_DATABASE, "user":USER, "password":PASSWORD}
    return config_dict


def config():
    config_dict = {"host":HOST, "port":PORT, "database":DATABASE, "user":USER, "password":PASSWORD}
    return config_dict


Login.py

import psycopg2 import os from getpass import getpass from DB_config import config import datetime def DB_pass(username, category): with psycopg2.connect(**config()) as find_pass: cur1 = find_pass.cursor() cur1.execute(f""" SELECT password FROM {category} WHERE username = '{username.lower()}'; """) rows = cur1.fetchall() cur1.close() find_pass.close() return rows[0][0] def login(category, username, password): logged_in = False if password == DB_pass(username,category): logged_in = True return logged_in def signup(category, *args): if category == "admin": username, fullname, email, date_of_birth, password = args date_of_birth = datetime.datetime.strptime(date_of_birth,"%Y-%m-%d") notifications = "Logged in" with psycopg2.connect(**config()) as default_admin: cur0 = default_admin.cursor() cur0.execute(""" INSERT INTO admin ( username, fullname, email, date_of_birth, password, notifications ) VALUES ( %s, %s, %s, DATE %s, %s, %s ) ON CONFLICT(username) DO NOTHING; """, (username, fullname, email, date_of_birth, password, notifications)) elif category == "doctor": username, fullname, email, date_of_birth, password, specialty, price = args date_of_birth = datetime.datetime.strptime(date_of_birth.strip(),"%Y-%m-%d") notifications = "Logged in" with psycopg2.connect(**config()) as doctor_signup: cur1 = doctor_signup.cursor() cur1.execute(""" INSERT INTO doctor ( username, fullname, email, date_of_birth, password, specialty, price, notifications ) VALUES ( %s, %s, %s, DATE %s, %s, %s, %s, %s ) ON CONFLICT(username) DO NOTHING; """, (username, fullname, email, date_of_birth, password, specialty, price, notifications)) print(cur1.statusmessage) print("Successfully Signed Up") cur1.close() doctor_signup.commit() doctor_signup.close() elif category == "patient": username, fullname, email, date_of_birth, password, problem = args date_of_birth = datetime.datetime.strptime(date_of_birth.strip(),"%Y-%m-%d") reports = "(initial_registration++This_frontend_url_will_be_generated_automatically)" notifications = "Logged in" requested_doctor_username = None appointment_timestamp = None approved_doctor_username = "hpt" with psycopg2.connect(**config()) as patient_signup: cur1 = patient_signup.cursor() cur1.execute(""" INSERT INTO patient ( username, fullname, email, date_of_birth, password, problem, requested_doctor_username, approved_doctor_username, appointment_timestamp, reports, notifications ) VALUES ( %s, %s, %s, DATE %s, %s, %s, %s, %s, %s, %s, %s ) ON CONFLICT(username) DO NOTHING; """, (username, fullname, email, date_of_birth, password, problem, requested_doctor_username, approved_doctor_username, appointment_timestamp, reports, notifications)) print(cur1.statusmessage) print("Successfully Signed Up") cur1.close() patient_signup.commit() patient_signup.close() else: username, fullname, email, date_of_birth, password, work, salary = args date_of_birth = datetime.datetime.strptime(date_of_birth.strip(),"%Y-%m-%d") work_of_doctors = "hpt" notifications = "Logged in" with psycopg2.connect(**config()) as employee_signup: cur1 = employee_signup.cursor() cur1.execute(""" INSERT INTO employee ( username, fullname, email, date_of_birth, password, work, work_of_doctors, salary, notifications ) VALUES ( %s, %s, %s, DATE %s, %s, %s, %s, %s, %s ); """, (username, fullname, email, date_of_birth, password, work, work_of_doctors, salary, notifications)) print(cur1.statusmessage) print("Successfully Signed Up") cur1.close() employee_signup.commit() employee_signup.close() return True
Admin.py

import psycopg2
from doctor import salary as doctor_salary
from patient import cost as patient_cost
from employee import salary as employee_salary
from DB_config import config
import constant


def see_info(logged_in,category,username):
    if logged_in:
        username = username.strip().lower()
        with psycopg2.connect(**config()) as info_check:
            cur1 = info_check.cursor()
            cur1.execute(f"""
                SELECT * FROM {category} WHERE username = '{username}';
            """)
            info = cur1.fetchall()
            cur1.close()
        info_check.close()
        return info


def update_db(category, username, fieldname, updated_value, logged_in):
    if logged_in:
        date = "DATE" if fieldname == "date_of_birth" else ""
        with psycopg2.connect(**config()) as updating:
            cur1 = updating.cursor()
            cur1.execute(f"""
                UPDATE {category} SET {fieldname} = '{updated_value}' WHERE username = {date}'{username}';
            """)
            print(cur1.statusmessage)
            cur1.close()
            updating.commit()
        updating.close()
        return "Database Updated"


def recent_notifications(username, logged_in, limit = 1):
    if logged_in:
        with psycopg2.connect(**config()) as latest:
            cur1 = latest.cursor()
            cur1.execute("""
                SELECT notifications FROM admin WHERE username = %s;
            """, [username])
            notifications_string = cur1.fetchall()[0][0]
            list_of_notifications = notifications_string.split(", ")
            cur1.close()
        latest.close()
        return list_of_notifications[-limit:] if limit < len(list_of_notifications) else list_of_notifications[-len(list_of_notifications):]


def add_notification(notification, category, receiver_username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as add_notifications:
            cur1 = add_notifications.cursor()
            cur1.execute(f"""
                SELECT notifications FROM {category} WHERE username = '{receiver_username}';
            """)
            notifications_string = cur1.fetchall()[0][0]
            list_of_notifications = notifications_string.split(", ")
            list_of_notifications.append(notification)
            new_notifications_string = ", ".join(list_of_notifications)
            cur1.close()
            cur2 = add_notifications.cursor()
            cur2.execute(f"""
                UPDATE {category} SET notifications = '{new_notifications_string}' WHERE username = '{receiver_username}';
            """)
            print(cur2.statusmessage)
            cur2.close()
            add_notifications.commit()
        add_notifications.close()
        return "Notification Added"


def total_earning(logged_in):
    if logged_in:
        initial_earning = 0
        with psycopg2.connect(**config()) as earning:
            cur1 = earning.cursor()
            cur1.execute("""
                SELECT username FROM employee;
            """)
            list_of_employee = cur1.fetchall()
            cur1.close()
            earned_from_employee = 0
            for row in list_of_employee:
                earned_from_employee += int(employee_salary(row[0],True)[1])
            initial_earning += earned_from_employee
            cur2 = earning.cursor()
            cur2.execute("""
                SELECT username FROM patient;
            """)
            list_of_patient = cur2.fetchall()
            cur2.close()
            earned_from_patient = 0
            for row in list_of_patient:
                earned_from_patient += int(patient_cost(row[0],True)[1])
            initial_earning += earned_from_patient
            initial_earning -= int(constant.grab_constant(True,"FIXED_COST_OF_HOSPITAL"))            

            given_to_employees = 0
            cur3 = earning.cursor()
            cur3.execute("""
                SELECT salary FROM employee WHERE work_of_doctors LIKE '%admin%';
            """)
            salary_list = cur3.fetchall()
            for salary in salary_list:
                given_to_employees += int(salary[0])
            cur3.close()
            initial_earning -= given_to_employees

            employee_pre_salary = int(doctor_salary("hpt", True)[1])
            initial_earning -= employee_pre_salary

        earning.close()
    return (earned_from_employee, earned_from_patient, int(constant.grab_constant(True,"FIXED_COST_OF_HOSPITAL")), employee_pre_salary, given_to_employees, initial_earning)


def add_employee(employee_username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as adding_employee:
            cur0 = adding_employee.cursor()
            cur0.execute("""
                SELECT work_of_doctors FROM employee WHERE username = %s;
            """, [employee_username])

            work_of_doctors = cur0.fetchall()[0][0]
            work_of_doctors += ", " + "admin"
            cur0.close()

            cur1 = adding_employee.cursor()
            cur1.execute("""
                UPDATE employee SET work_of_doctors = %s WHERE username = %s;
            """, [work_of_doctors, employee_username]) 
            print(cur1.statusmessage)        
            cur1.close()
            adding_employee.commit()
        adding_employee.close()
        return "Employee Added"


def see_my_employee(logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as my_employee:
            cur1 = my_employee.cursor()
            cur1.execute("""
                SELECT username, fullname, email, date_of_birth, work, salary FROM employee WHERE work_of_doctors LIKE '%admin%'
            """)
            list_of_employees = cur1.fetchall()
            # print part
            # for row in list_of_employees:
            #     print("Username:", row[0], "\tFullname:", row[1], "\tEmail:", row[2], "\tWork:", row[3], "\tSalary:", row[4])
            cur1.close()
        my_employee.close()
        return list_of_employees


def remove_employee(employee_username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as removing_employee:
            cur0 = removing_employee.cursor()
            cur0.execute("""
                SELECT work_of_doctors FROM employee WHERE username = %s;
            """, [employee_username])

            work_of_doctors_string = cur0.fetchall()[0][0]
            work_of_doctors_list = work_of_doctors_string.split(", ")

            work_of_doctors_list.remove("admin")
            new_work_of_doctors_string = ", ".join(work_of_doctors_list)
            cur0.close()

            cur1 = removing_employee.cursor()
            cur1.execute("""
                UPDATE employee SET work_of_doctors = %s WHERE username = %s;
            """, [new_work_of_doctors_string, employee_username]) 
            print(cur1.statusmessage)        
            cur1.close()
            removing_employee.commit()
        removing_employee.close()
        return "Employee Removed"


def show_all_doctor(logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as doctor:
            cur1 = doctor.cursor()
            cur1.execute("""
                SELECT username, fullname, email, date_of_birth, specialty, price FROM doctor;
            """)
            rows = cur1.fetchall()
            new_rows = []
            for row in rows:
                row = list(row)
                row.append(doctor_salary(row[0],True)[2])
                new_rows.append(row)
            # print(part)
            # for row in rows:
            #     print("Username:", row[0], "\tFullname:", row[1], "\tEmail:", row[2], "\tspecialty:", row[3], "\tPrice:", row[4], "\tTotal Earned:", row[5])
            cur1.close()
        doctor.close()
        return new_rows


def show_all_patient(logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as patient:
            cur1 = patient.cursor()
            cur1.execute("""
                SELECT username, fullname, email, date_of_birth, problem, requested_doctor_username, approved_doctor_username FROM patient;
            """)
            rows = cur1.fetchall()
            new_rows = []
            for row in rows:
                row = list(row)
                row.append(patient_cost(row[0], True)[2])
                new_rows.append(row)
            # print part
            # for row in rows:
            #     print("Username:", row[0], "\tFullname:", row[1], "\tEmail:", row[2], "\tProblem:", row[3], "\tRequested:", row[4], "\tApproved:", row[5], "\tTotal Cost:", row[6])
            cur1.close()
        patient.close()
        return new_rows


def show_all_employee(logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as employee:
            cur1 = employee.cursor()
            cur1.execute("""
                SELECT username, fullname, email, date_of_birth, work, work_of_doctors, salary FROM employee;
            """)
            rows = cur1.fetchall()
            new_rows = []
            for row in rows:
                row = list(row)
                row.append(employee_salary(row[0],True)[2])
                new_rows.append(row)
            # print part
            # for row in rows:
            #     print("Username:", row[0], "\tFullname:", row[1], "\tEmail:", row[2], "\tWork:", row[3], "\tDoctors:", row[4], "\tSalary:", row[5], "\tTotal Earned:", row[6])
            cur1.close()
        employee.close()
        return new_rows


def all_doctor_username(logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as doctor:
            cur1 = doctor.cursor()
            cur1.execute("""
                SELECT username FROM doctor;
            """)
            rows = cur1.fetchall()
            new_rows = []
            for row in rows:
                new_rows.append(row[0])
            cur1.close()
        doctor.close()
        return new_rows


def all_patient_username(logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as patient:
            cur1 = patient.cursor()
            cur1.execute("""
                SELECT username FROM patient;
            """)
            rows = cur1.fetchall()
            new_rows = []
            for row in rows:
                new_rows.append(row[0])
            cur1.close()
        patient.close()
        return new_rows


def all_employee_username(logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as employee:
            cur1 = employee.cursor()
            cur1.execute("""
                SELECT username FROM employee;
            """)
            rows = cur1.fetchall()
            new_rows = []
            for row in rows:
                new_rows.append(row[0])
            cur1.close()
        employee.close()
        return new_rows


def remove_doctor_parmanently(doctor_username, logged_in, final_decision = False):
    if final_decision and logged_in:
        with psycopg2.connect(**config()) as remove_doctor:
            cur1 = remove_doctor.cursor()
            cur1.execute("""
                DELETE FROM doctor WHERE username = %s;
            """, [doctor_username])
            print(cur1.statusmessage)
            remove_doctor.commit()
            cur1.close()
        remove_doctor.close()
        return "Doctor Parmanently Removed"


def remove_patient_parmanently(patient_username, logged_in, final_decision = False):
    if final_decision and logged_in:
        with psycopg2.connect(**config()) as remove_patient:
            cur1 = remove_patient.cursor()
            cur1.execute("""
                DELETE FROM patient WHERE username = %s;
            """, [patient_username])
            print(cur1.statusmessage)
            remove_patient.commit()
            cur1.close()
        remove_patient.close()
        return "Patient Parmanently Removed"


def remove_employee_parmanently(employee_username, logged_in, final_decision = False):
    if final_decision and logged_in:
        with psycopg2.connect(**config()) as remove_employee:
            cur1 = remove_employee.cursor()
            cur1.execute("""
                DELETE FROM employee WHERE username = %s;
            """, [employee_username])
            print(cur1.statusmessage)
            remove_employee.commit()
            cur1.close()
        remove_employee.close()
        return "Employee Parmanently Removed"


def patient_joins_doctor(logged_in, left = False):
    join_type = "LEFT JOIN" if left else "JOIN"
    if logged_in:
        with psycopg2.connect(**config()) as viewer:
            cur_first = viewer.cursor()
            cur_first.execute("""
                DROP VIEW IF EXISTS final_view;
            """)
            cur_first.close()
            viewer.commit()

            cur0 = viewer.cursor()
            cur0.execute("""
                DROP VIEW IF EXISTS patient_view;
            """)
            cur0.close()
            viewer.commit()

            cur1 = viewer.cursor()
            cur1.execute("""
                CREATE VIEW patient_view AS SELECT username, fullname, email, date_of_birth, problem, approved_doctor_username, appointment_timestamp FROM patient WHERE approved_doctor_username != 'hpt';
            """)
            cur1.close()

            cur2 = viewer.cursor()
            cur2.execute("""
                DROP VIEW IF EXISTS doctor_view;
            """)
            cur2.close()
            viewer.commit()

            cur3 = viewer.cursor()
            cur3.execute("""
                CREATE VIEW doctor_view AS SELECT username AS doctor_username, fullname AS doctor_fullname, email AS doctor_email, specialty, price FROM doctor;
            """)
            cur3.close()

            viewer.commit()
        viewer.close()

        with psycopg2.connect(**config()) as joiner:

            cur1 = joiner.cursor()
            cur1.execute(f"""
                CREATE VIEW final_view AS (SELECT * FROM patient_view {join_type} doctor_view ON patient_view.approved_doctor_username = doctor_view.doctor_username);
            """)
            cur1.close()
            joiner.commit()
        joiner.close()

        with psycopg2.connect(**config()) as final:
            cur1 = final.cursor()
            cur1.execute("""
                SELECT username, fullname, email, problem, appointment_timestamp, doctor_username, doctor_fullname, doctor_email, specialty, price FROM final_view;
            """)
            rows = cur1.fetchall()
            cur1.close()

            # print part
            # for row in rows:
            #     print(row)

        joiner.close()
        return rows

Doctor.py

import psycopg2
from DB_config import config
import constant
import webbrowser as web


def recent_notifications(username, logged_in, limit = 1):
    if logged_in:
        with psycopg2.connect(**config()) as latest:
            cur1 = latest.cursor()
            cur1.execute("""
                SELECT notifications FROM doctor WHERE username = %s;
            """, [username])
            notifications_string = cur1.fetchall()[0][0]
            list_of_notifications = notifications_string.split(", ")
            cur1.close()
        latest.close()
        return list_of_notifications[-limit:] if limit < len(list_of_notifications) else list_of_notifications[-len(list_of_notifications):]


def notify_admin(notification, my_username, admin_username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as add_notifications:
            cur1 = add_notifications.cursor()
            cur1.execute(f"""
                SELECT notifications FROM admin WHERE username = '{admin_username}';
            """)
            notifications_string = cur1.fetchall()[0][0]
            list_of_notifications = notifications_string.split(", ")
            notification = "From: " + my_username + " " + notification
            list_of_notifications.append(notification)
            new_notifications_string = ", ".join(list_of_notifications)
            cur1.close()
            cur2 = add_notifications.cursor()
            cur2.execute(f"""
                UPDATE admin SET notifications = '{new_notifications_string}' WHERE username = '{admin_username}';
            """)
            print(cur2.statusmessage)
            cur2.close()
            add_notifications.commit()
        add_notifications.close()
        return "Notification Added"


def salary(username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as my_salary:
            cur0 = my_salary.cursor()
            cur0.execute("""
                SELECT * FROM patient WHERE approved_doctor_username = %s;
            """, [username])
            
            total_patient = len(cur0.fetchall())
            cur0.close()

            cur1 = my_salary.cursor()
            cur1.execute("""
                SELECT price FROM doctor WHERE username = %s;
            """, [username])
            
            my_price = cur1.fetchall()[0][0]
            cur1.close()
            total_earning = total_patient * int(my_price)

            cur2 = my_salary.cursor()
            cur2.execute(f"""
                SELECT salary FROM employee WHERE work_of_doctors LIKE '%{username}%';
            """) 
            salary_list = cur2.fetchall()
            total_cost = 0
            if username == "hpt":
                for salary in salary_list:
                    total_cost += (int(salary[0])*int(constant.grab_constant(True,"PRE_SALARY")))//100
            else:
                for salary in salary_list:
                    total_cost += int(salary[0])
            cur2.close()

            nit_salary = total_earning - total_cost

        my_salary.close()
        return (total_earning, total_cost, nit_salary)


def show_all_employee(logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as all_employee:
            cur1 = all_employee.cursor()
            cur1.execute("""
                SELECT username, fullname, email, date_of_birth, work, salary FROM employee;
            """)

            rows = cur1.fetchall()
            # print part
            # for row in rows:
            #     print("Username:", row[0], "\tFullname:", row[1], "\tEmail:", row[2], "\tSalary:", row[3])
            cur1.close()
        all_employee.close()
        return rows


def add_employee(my_username, employee_username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as adding_employee:
            cur0 = adding_employee.cursor()
            cur0.execute("""
                SELECT work_of_doctors FROM employee WHERE username = %s;
            """, [employee_username])

            temporary = cur0.fetchall()
            work_of_doctors = temporary[0][0]
            work_of_doctors += ", " + my_username
            cur0.close()

            cur1 = adding_employee.cursor()
            cur1.execute("""
                UPDATE employee SET work_of_doctors = %s WHERE username = %s;
            """, [work_of_doctors, employee_username]) 
            print(cur1.statusmessage)        
            cur1.close()
            adding_employee.commit()
        adding_employee.close()
        return "Employee Added"


def see_my_employee(username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as my_employee:
            cur1 = my_employee.cursor()
            cur1.execute(f"""
                SELECT username, fullname, email, date_of_birth, work, salary FROM employee WHERE work_of_doctors LIKE '%{username}%'
            """)
            list_of_employees = cur1.fetchall()
            # print part
            # for row in list_of_employees:
            #     print("Username:", row[0], "\tFullname:", row[1], "\tEmail:", row[2], "\tWork:", row[3], "\tSalary:", row[4])
            cur1.close()
        my_employee.close()
        return list_of_employees


def remove_employee(my_username, employee_username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as removing_employee:
            cur0 = removing_employee.cursor()
            cur0.execute("""
                SELECT work_of_doctors FROM employee WHERE username = %s;
            """, [employee_username])

            work_of_doctors_string = cur0.fetchall()[0][0]
            work_of_doctors_list = work_of_doctors_string.split(", ")

            work_of_doctors_list.remove(my_username)
            new_work_of_doctors_string = ", ".join(work_of_doctors_list)
            cur0.close()

            cur1 = removing_employee.cursor()
            cur1.execute("""
                UPDATE employee SET work_of_doctors = %s WHERE username = %s;
            """, [new_work_of_doctors_string, employee_username]) 
            print(cur1.statusmessage)        
            cur1.close()
            removing_employee.commit()
        removing_employee.close()
        return "Employee Removed"


def see_all_requested_patient(username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as all_requested_patient:
            cur0 = all_requested_patient.cursor()
            cur0.execute("""
                SELECT username, fullname, email, date_of_birth, problem FROM patient WHERE requested_doctor_username = %s;
            """, [username])
            
            rows = cur0.fetchall()
            # print part
            # for row in rows:
            #     print("Username:", row[0], "\tFullname:", row[1], "\tEmail:", row[2], "\tProblem:", row[3])
            cur0.close()
        all_requested_patient.close()
        return rows


def see_all_patients_of_my_specialty(username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as all_under_specialty:
            cur0 = all_under_specialty.cursor()
            cur0.execute("""
                SELECT specialty FROM doctor WHERE username = %s;
            """, [username])
            specialty = str(cur0.fetchall()[0][0]).lower()
            cur0.close()

            cur1 = all_under_specialty.cursor()
            cur1.execute("""
                SELECT username, fullname, email, date_of_birth, requested_doctor_username, approved_doctor_username FROM patient WHERE problem = %s;
            """, [specialty])
            
            rows = cur1.fetchall()
            # for row in rows:
            #     print("Username:", row[0], "\tFullname:", row[1], "\tEmail:", row[2], "\tRequested Doctor:", row[3], "\tApproved Doctor:", row[4])
            cur1.close()
        all_under_specialty.close()
        return rows


def see_my_patient(username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as my_patient:
            cur0 = my_patient.cursor()
            cur0.execute("""
                SELECT username, fullname, email, date_of_birth, problem, appointment_timestamp FROM patient WHERE approved_doctor_username = %s;
            """, [username])
            
            rows = cur0.fetchall()
            # print part
            # for row in rows:
            #     print("Username:", row[0], "\tFullname:", row[1], "\tEmail:", row[2], "\tProblem:", row[3])
            cur0.close()
        my_patient.close()
        return rows


def see_patients_report(patient_username,report_name,logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as report:
            cur1 = report.cursor()
            cur1.execute("""
                SELECT reports FROM patient WHERE username = %s;
            """, [patient_username])
            reports_string = cur1.fetchall()[0][0]
            reports_list = reports_string.split("+++")
            for reports_substring in reports_list:
                report_tuple_without_b = reports_substring[1:-1]
                report_sublist = report_tuple_without_b.split("++")
                name = report_sublist[0]
                url = report_sublist[1]
                if name.lower() == report_name.lower(): 
                    web.open(url)
                    return ("Opening",name,"In Web Browser")


def remove_patient(patient_username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as removing_patient:
            cur0 = removing_patient.cursor()
            cur0.execute("""
                UPDATE patient SET approved_doctor_username = %s, appointment_timestamp = %s WHERE username = %s;
            """, [None, None, patient_username]) 
            print(cur0.statusmessage)        
            cur0.close()
            removing_patient.commit()
        removing_patient.close()
        return "Patient Removed"


Patient.py

import psycopg2
from constant import grab_constant
from DB_config import config
import datetime


def remaining_appointment_time(username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as remaining:
            cur1 = remaining.cursor()
            cur1.execute("""
                SELECT appointment_timestamp FROM patient WHERE username = %s;
            """, [username])
            appointment_timestamp = cur1.fetchall()[0][0]
            if appointment_timestamp != None:
                remaining_time = appointment_timestamp - datetime.datetime.now()
            else:
                remaining_time = "Your appointment isn't fixed yet."
            cur1.close()
        remaining.close()
        return remaining_time

def recent_notifications(username, logged_in, limit = 1):
    if logged_in:
        with psycopg2.connect(**config()) as latest:
            cur1 = latest.cursor()
            cur1.execute("""
                SELECT notifications FROM patient WHERE username = %s;
            """, [username])
            notifications_string = cur1.fetchall()[0][0]
            list_of_notifications = notifications_string.split(", ")
            cur1.close()
        latest.close()
        return list_of_notifications[-limit:] if limit < len(list_of_notifications) else list_of_notifications[-len(list_of_notifications):]


def notify_admin(notification, my_username, admin_username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as add_notifications:
            cur1 = add_notifications.cursor()
            cur1.execute(f"""
                SELECT notifications FROM admin WHERE username = '{admin_username}';
            """)
            notifications_string = cur1.fetchall()[0][0]
            list_of_notifications = notifications_string.split(", ")
            notification = "From: " + my_username + " " + notification
            list_of_notifications.append(notification)
            new_notifications_string = ", ".join(list_of_notifications)
            cur1.close()
            cur2 = add_notifications.cursor()
            cur2.execute(f"""
                UPDATE admin SET notifications = '{new_notifications_string}' WHERE username = '{admin_username}';
            """)
            print(cur2.statusmessage)
            cur2.close()
            add_notifications.commit()
        add_notifications.close()
        return "Notification Added"


def cost(username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as total_cost:
            cur1 = total_cost.cursor()
            cur1.execute("""
                SELECT approved_doctor_username FROM patient WHERE username = %s;
            """, [username])
            approved_doctor_username = cur1.fetchall()[0][0]
            print(approved_doctor_username)
            cur1.close()

            cur2 = total_cost.cursor()
            if approved_doctor_username != "hpt":
                cur2.execute("""
                    SELECT price FROM doctor WHERE username = %s;
                """, [approved_doctor_username])
                doctors_salary = int(cur2.fetchall()[0][0])
                final_cost = (doctors_salary * (100 + int(grab_constant(True,"CUT_FROM_PATIENT"))))//100
            else:
                doctors_salary = 0
                final_cost = 0

        total_cost.close() 
        hospital_cost = final_cost - doctors_salary        
        
        return (doctors_salary, hospital_cost, final_cost)


def add_report(report_name, report_url, username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as add_reports:
            cur1 = add_reports.cursor()
            cur1.execute("""
                SELECT reports FROM patient WHERE username = %s;
            """, [username])
            reports_string = cur1.fetchall()[0][0]
            reports_info = "(" + report_name + "++" + report_url + ")"
            reports_string += "+++" + str(reports_info)
            cur1.close()
            cur2 = add_reports.cursor()
            cur2.execute("""
                UPDATE patient SET reports = %s WHERE username = %s;
            """,  [reports_string, username])
            print(cur2.statusmessage)
            cur2.close()
            add_reports.commit()
        add_reports.close()
        return "Report Added"


def see_all_doctors_for_my_problem(username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as doctors_as_problem:
            cur1 = doctors_as_problem.cursor()
            cur1.execute("""
                SELECT problem FROM patient WHERE username = %s;
            """, [username])
            problem = cur1.fetchall()[0][0]
            cur1.close()

            cur2 = doctors_as_problem.cursor()
            cur2.execute("""
                SELECT username, fullname, email, date_of_birth, price FROM doctor WHERE specialty = %s;
            """, [problem])
            rows = cur2.fetchall()
            # print part
            # for row in rows:
            #     print("Username:", row[0], "\tFullname:", row[1], "\tEmail:", row[2], "\tPrice:", row[3])
            cur2.close()
        doctors_as_problem.close()
        return rows


def request_doctor(my_username, doctor_username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as requesting_doctor:
            cur1 = requesting_doctor.cursor()
            cur1.execute("""
                UPDATE patient SET requested_doctor_username = %s WHERE username = %s;
            """, [doctor_username, my_username])
            print(cur1.statusmessage)
            cur1.close()
            requesting_doctor.commit()
        requesting_doctor.close()
        return "Successfully Requested"


def remove_request(my_username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as removing_request:
            cur1 = removing_request.cursor()
            cur1.execute("""
                UPDATE patient SET requested_doctor_username = NULL WHERE username = %s;
            """, [my_username])
            print(cur1.statusmessage)
            cur1.close()
            removing_request.commit()
        removing_request.close()
        return "Request Removed"


def see_my_doctors_stat(username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as my_doctor:
            cur1 = my_doctor.cursor()
            cur1.execute("""
                SELECT approved_doctor_username, appointment_timestamp FROM patient WHERE username = %s;
            """, [username])
            temp = cur1.fetchall()[0]
            approved_doctor_username = temp[0]
            appointment_timestamp = temp[1]
            cur1.close()

            cur2 = my_doctor.cursor()
            cur2.execute("""
                SELECT username, fullname, email, date_of_birth, specialty, price FROM doctor WHERE username = %s;
            """, [approved_doctor_username])
            
            rows = list(cur2.fetchall()[0])
            rows.append(appointment_timestamp)
            # print part
            # for row in rows:
            #     print("Doctor's Information")
            #     print("Fullname:", row[1])
            #     print("Email:", row[2])
            #     print("specialty:", row[3])
            #     print("Price:", row[4])
            #     print("Appointment Timestamp:", row[5])
            cur2.close()
        my_doctor.close()
        return rows

Employee.py

import psycopg2
from DB_config import config
from constant import grab_constant
import datetime


def recent_notifications(username, logged_in, limit = 1):
    if logged_in:
        with psycopg2.connect(**config()) as latest:
            cur1 = latest.cursor()
            cur1.execute("""
                SELECT notifications FROM employee WHERE username = %s;
            """, [username])
            notifications_string = cur1.fetchall()[0][0]
            list_of_notifications = notifications_string.split(", ")
            cur1.close()
        latest.close()
        return list_of_notifications[-limit:] if limit < len(list_of_notifications) else list_of_notifications[-len(list_of_notifications):]


def notify_admin(notification, my_username, admin_username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as add_notifications:
            cur1 = add_notifications.cursor()
            cur1.execute(f"""
                SELECT notifications FROM admin WHERE username = '{admin_username}';
            """)
            notifications_string = cur1.fetchall()[0][0]
            list_of_notifications = notifications_string.split(", ")
            notification = "From: " + my_username + " " + notification
            list_of_notifications.append(notification)
            new_notifications_string = ", ".join(list_of_notifications)
            cur1.close()
            cur2 = add_notifications.cursor()
            cur2.execute(f"""
                UPDATE admin SET notifications = '{new_notifications_string}' WHERE username = '{admin_username}';
            """)
            print(cur2.statusmessage)
            cur2.close()
            add_notifications.commit()
        add_notifications.close()
        return "Notification Added"


def salary(username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as my_salary:
            cur1 = my_salary.cursor()
            cur1.execute("""
                SELECT work_of_doctors, salary FROM employee WHERE username = %s;
            """, [username])
            bucket = cur1.fetchall()[0]
            string_of_doctors = bucket[0]
            my_price = bucket[1]
            cur1.close()
            list_of_doctors = string_of_doctors.split(", ")
            number_of_doctors = len(list_of_doctors)

            if "hpt" in list_of_doctors:
                initial_salary = (number_of_doctors * my_price) - (my_price*(100-int(grab_constant(True,"PRE_SALARY"))))//100
            else:
                initial_salary = number_of_doctors * my_price
            hospital_cost = (initial_salary * int(grab_constant(True, "CUT_FROM_EMPLOYEE"))) // 100
            final_salary = initial_salary - hospital_cost

        my_salary.close()
        return (initial_salary, hospital_cost, final_salary)

        
def isreceptionist(username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as reception:
            cur1 = reception.cursor()
            cur1.execute("""
                SELECT work FROM employee WHERE username = %s;
            """, [username])
            work = cur1.fetchall()[0][0]
            cur1.close()
        reception.close()
        if work.lower() == "receptionist":
            return True
        else:
            return False


def appoint_doctor(my_username, doctor_username, patient_username, appointment_timestamp, logged_in):
    if logged_in and isreceptionist(my_username, logged_in):
        formated_date = datetime.datetime.strptime(appointment_timestamp, "%Y-%m-%d %H:%M:%S")
        with psycopg2.connect(**config()) as adding_patient:
            cur0 = adding_patient.cursor()
            cur0.execute("""
                UPDATE patient SET approved_doctor_username = %s, appointment_timestamp = TIMESTAMP %s WHERE username = %s;
            """, [doctor_username, formated_date, patient_username]) 
            print(cur0.statusmessage)        
            cur0.close()
            adding_patient.commit()
        adding_patient.close()
        return "Succesfully Appointed"


def see_my_doctors(username, logged_in):
    if logged_in:
        with psycopg2.connect(**config()) as my_doctor:
            cur1 = my_doctor.cursor()
            cur1.execute("""
                SELECT work_of_doctors FROM employee WHERE username = %s;
            """, [username])
            string_of_doctors = cur1.fetchall()[0][0]
            cur1.close()
            list_of_doctors = string_of_doctors.split(", ")

            doctors_bucket = []
            for doctor_username in list_of_doctors:
                cur2 = my_doctor.cursor()
                if doctor_username != "admin":
                    cur2.execute("""
                        SELECT username, fullname, email, date_of_birth, specialty FROM doctor WHERE username = %s;
                    """, [doctor_username])
                    temporary = cur2.fetchall()
                    doctors_bucket.append(temporary[0])
                    cur2.close()
                else:
                    doctors_bucket.append(('adm', 'admin','[email protected]',"2004-12-28", 'all'))
            
            # print part
            # for row in doctors_bucket:
            #     print("Username:", row[0], "\tFullname:", row[1], "\tEmail:", row[2], "\tspecialty:", row[3])
                
        my_doctor.close()
        return doctors_bucket

Frontend.py

# All Imports
import kivy
from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.popup import Popup
import webbrowser as web
from kivy.uix.widget import Widget
from kivy.graphics import Color
from kivy.graphics import Line
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.carousel import Carousel
from kivy.uix.image import Image
from kivy.uix.screenmanager import SlideTransition
from kivy.uix.screenmanager import NoTransition
from kivy.config import Config
from kivy.uix.textinput import TextInput
from kivy.graphics import Rectangle
from kivy.uix.scrollview import ScrollView
from kivy.app import runTouchApp

import setup_engine
import login
import constant
import admin
import datetime
import doctor
import patient
import employee






# Common Classes and Window Configuration
class WindowManager(ScreenManager):
    pass

class Holder():
    username = "Default"
    logged_in = True
    counter = 0
    pre_counter = 0

Config.set('graphics', 'height', 600)
Config.set('graphics', 'width', 800)
Config.set('graphics', 'resizable', 0)
Config.write()






# SignUp Classes
class GetStarted(Screen):
    first_start = True if (constant.grab_constant(True, "IS_START")=="0") else False
    def start_program(self):
        if GetStarted.first_start:
            sm.transition = SlideTransition(direction = "up")
            sm.current = "ConstantFixing"
        else:
            sm.transition = SlideTransition(direction = "up")
            sm.current = "PatientSignUp"
            

    def go_to_website(self):
        web.open_new_tab("https://ahammadshawki8.github.io/")



class ConstantFixing(Screen):
    host = ObjectProperty()  
    port = ObjectProperty()   
    user = ObjectProperty()  
    password = ObjectProperty()  
    cut_from_patient = ObjectProperty()   
    cut_from_employee = ObjectProperty()  
    fixed_cost_of_hospital = ObjectProperty()  
    pre_salary = ObjectProperty()  
    doctor_max_checkup_price = ObjectProperty()  
    employee_max_salary = ObjectProperty()  
    hospital_year = ObjectProperty()  
    hospital_total_bed = ObjectProperty()  
    hospital_remaining_bed = ObjectProperty()  
    hospital_total_employee = ObjectProperty()  
    hospital_total_doctor = ObjectProperty()  
    hospital_total_patient = ObjectProperty()  
    hospital_current_patient = ObjectProperty()  
    hospital_motto = ObjectProperty()  
    hospital_location = ObjectProperty()  
    hospital_title = ObjectProperty()  
    restore_previous = ObjectProperty()

    def set_constant_function(self):
        try:
            constants_bucket = dict()
            constants_bucket["HOST"] = self.host.text
            constants_bucket["PORT"] = self.port.text
            constants_bucket["ADMIN_DATABASE"] = "postgres"
            constants_bucket["DATABASE"] ="hms"
            constants_bucket["USER"] = self.user.text
            constants_bucket["PASSWORD"] = self.password.text
            constants_bucket["CUT_FROM_PATIENT"] = self.cut_from_patient.text 
            constants_bucket["CUT_FROM_EMPLOYEE"] = self.cut_from_employee.text
            constants_bucket["FIXED_COST_OF_HOSPITAL"] = self.fixed_cost_of_hospital.text
            constants_bucket["PRE_SALARY"] = self.pre_salary.text
            constants_bucket["DOCTOR_MAX_CHECKUP_PRICE"] = self.doctor_max_checkup_price.text
            constants_bucket["EMPLOYEE_MAX_SALARY"] = self.employee_max_salary.text
            constants_bucket["HOSPITAL_YEAR"] = self.hospital_year.text
            constants_bucket["HOSPITAL_TOTAL_BED"] = self.hospital_total_bed.text
            constants_bucket["HOSPITAL_REMAINING_BED"] = self.hospital_remaining_bed.text
            constants_bucket["HOSPITAL_TOTAL_EMPLOYEE"] = self.hospital_total_employee.text
            constants_bucket["HOSPITAL_TOTAL_DOCTOR"] = self.hospital_total_doctor.text
            constants_bucket["HOSPITAL_TOTAL_PATIENT"] = self.hospital_total_patient.text
            constants_bucket["HOSPITAL_CURRENT_PATIENT"] = self.hospital_current_patient.text
            constants_bucket["HOSPITAL_MOTTO"] = self.hospital_motto.text
            constants_bucket["HOSPITAL_LOCATION"] = self.hospital_location.text
            constants_bucket["HOSPITAL_TITLE"] = self.hospital_title.text
            constants_bucket["IS_START"] = "1"
            constant.set_constant(True, constants_bucket)
            self.proceed()
            if self.restore_previous.text == "yes":
                setup_engine.start_program()
        except:
            show_ConstantFixingPop()

        self.host.text = "localhost"
        self.port.text = "5432"
        self.user.text = "postgres"
        self.password.text = "12345678"
        self.cut_from_patient.text = "50" 
        self.cut_from_employee.text = "20"
        self.fixed_cost_of_hospital.text = "5000"
        self.pre_salary.text = "10"
        self.doctor_max_checkup_price.text = "4000"
        self.employee_max_salary.text = "15000"
        self.hospital_year.text = "2004"
        self.hospital_total_bed.text = "200"
        self.hospital_remaining_bed.text = "120"
        self.hospital_total_employee.text = "16"
        self.hospital_total_doctor.text = "10"
        self.hospital_total_patient.text = "2000"
        self.hospital_current_patient.text = "40"
        self.hospital_motto.text = "serve the nation at large"
        self.hospital_location.text = "Dhaka-Bangladesh"
        self.hospital_title.text = "The AS8 Hospital"
        self.restore_previous.text = "no"

    def proceed(self):
        sm.transition = SlideTransition(direction = "up")
        sm.current = "PatientSignUp"


class ConstantFixingPop(FloatLayout):
    pass


def show_ConstantFixingPop():
    show = ConstantFixingPop()
    popup_window = Popup(title = "Constant Fixing Error", content = show, size_hint = (0.6, 0.3))
    popup_window.open()






class AdminSignUp(Screen):
    username = ObjectProperty()
    fullname = ObjectProperty()
    email = ObjectProperty()
    date_of_birth = ObjectProperty()
    password = ObjectProperty()

    def signup_to_database(self):
        try:
            category = "admin"
            username = self.username.text.strip().lower()
            fullname = self.fullname.text.strip().title()
            email = self.email.text.strip()
            date_of_birth = self.date_of_birth.text.strip()
            password = self.password.text.strip()

            login.signup(category, username, fullname, email, date_of_birth, password)
            sm.current = "AdminLogin"
        except:
            show_SignUpPop()

        self.username.text = ""
        self.fullname.text = ""
        self.email.text = ""
        self.date_of_birth.text = "YYYY-MM-DD"
        self.password.text = ""


class DoctorSignUp(Screen):
    username = ObjectProperty()
    fullname = ObjectProperty()
    email = ObjectProperty()
    date_of_birth = ObjectProperty()
    password = ObjectProperty()
    specialty = ObjectProperty()
    price = ObjectProperty()

    def signup_to_database(self):
        try:
            category = "doctor"
            username = self.username.text.strip().lower()
            fullname = self.fullname.text.strip().title()
            email = self.email.text.strip()
            date_of_birth = self.date_of_birth.text.strip()
            password = self.password.text.strip()
            specialty = self.specialty.text.strip().lower()
            price = int(self.price.text.strip())

            login.signup(category, username, fullname, email, date_of_birth, password, specialty, price)
            sm.current = "DoctorLogin"
        except:
            show_SignUpPop()

        self.username.text = ""
        self.fullname.text = ""
        self.email.text = ""
        self.date_of_birth.text = "YYYY-MM-DD"
        self.password.text = ""
        self.specialty.text = ""
        self.price.text = ""    


class PatientSignUp(Screen):
    username = ObjectProperty()
    fullname = ObjectProperty()
    email = ObjectProperty()
    date_of_birth = ObjectProperty()
    password = ObjectProperty()
    problem = ObjectProperty()

    def signup_to_database(self):
        try:
            category = "patient"
            username = self.username.text.strip().lower()
            fullname = self.fullname.text.strip().title()
            email = self.email.text.strip()
            date_of_birth = self.date_of_birth.text.strip()
            password = self.password.text.strip()
            problem = self.problem.text.strip().lower()

            login.signup(category, username, fullname, email, date_of_birth, password, problem)
            sm.current = "PatientLogin"
        except:
            show_SignUpPop()

        self.username.text = ""
        self.fullname.text = ""
        self.email.text = ""
        self.date_of_birth.text = "YYYY-MM-DD"
        self.password.text = ""
        self.problem.text = ""  


class EmployeeSignUp(Screen):
    username = ObjectProperty()
    fullname = ObjectProperty()
    email = ObjectProperty()
    date_of_birth = ObjectProperty()
    password = ObjectProperty()
    work = ObjectProperty()
    salary = ObjectProperty()

    def signup_to_database(self):
        try:
            category = "employee"
            username = self.username.text.strip().lower()
            fullname = self.fullname.text.strip().title()
            email = self.email.text.strip()
            date_of_birth = self.date_of_birth.text.strip()
            password = self.password.text.strip()
            work = self.work.text.strip().lower()
            salary = int(self.salary.text.strip())

            login.signup(category, username, fullname, email, date_of_birth, password, work, salary)
            sm.current = "EmployeeLogin"
        except:
            show_SignUpPop()

        self.username.text = ""
        self.fullname.text = ""
        self.email.text = ""
        self.date_of_birth.text = "YYYY-MM-DD"
        self.password.text = ""
        self.work.text = ""
        self.salary.text = ""  


class SignUpPop(FloatLayout):
    pass


def show_SignUpPop():
    show = SignUpPop()
    popup_window = Popup(title = "SignUp Error", content = show, size_hint = (0.6, 0.3))
    popup_window.open()






# Login Classes
class AdminLogin(Screen):
    username = ObjectProperty()
    password = ObjectProperty()
    
    def login_to_database(self):
        try:
            category = "admin"
            username = self.username.text.strip().lower()
            Holder.username = username
            password = self.password.text.strip()
            
            logged_in = login.login(category,username,password)
            if logged_in:
                sm.current = "AdminAfterLogin"
            else:
                show_LoginPop()
        except:
            show_LoginPop()
            
        self.username.text = ""
        self.password.text = ""


class DoctorLogin(Screen):    
    username = ObjectProperty()
    password = ObjectProperty()

    def login_to_database(self):
        try:
            category = "doctor"
            username = self.username.text.strip().lower()
            Holder.username = username
            password = self.password.text.strip()

            logged_in = login.login(category,username,password)
            if logged_in:
                sm.current = "DoctorAfterLogin"  
            else:
                show_LoginPop()          
        except:
            show_LoginPop()
            
        self.username.text = ""
        self.password.text = ""


class PatientLogin(Screen):
    username = ObjectProperty()
    password = ObjectProperty()

    def login_to_database(self):
        try:
            category = "patient"
            username = self.username.text.strip().lower()
            Holder.username = username
            password = self.password.text.strip()

            logged_in = login.login(category,username,password)
            print(logged_in)
            if logged_in:
                sm.current = "PatientAfterLogin"
            else:
                show_LoginPop()
        except:
            show_LoginPop()
            
        self.username.text = ""
        self.password.text = ""


class EmployeeLogin(Screen):
    username = ObjectProperty()
    password = ObjectProperty()

    def login_to_database(self):
        try:
            category = "employee"
            username = self.username.text.strip().lower()
            Holder.username = username
            password = self.password.text.strip()
            
            logged_in = login.login(category,username,password)
            if logged_in:
                sm.current = "EmployeeAfterLogin"
            else:
                show_LoginPop()
        except:
            show_LoginPop()
            
        self.username.text = ""
        self.password.text = ""

        
class LoginPop(FloatLayout):
    pass


def show_LoginPop():
    show = LoginPop()
    popup_window = Popup(title = "Login Error", content = show, size_hint = (0.6, 0.3))
    popup_window.open()






# After Login
# Common Functions
def go_to_website(instance):
    web.open_new_tab("https://ahammadshawki8.github.io/")




# AboutHospital class
class AboutHospital(Screen):
    def __init__(self,**kwargs):
        super().__init__(**kwargs)
        with self.canvas:
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text="About Hospital", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.hospital_name_label = Label(text=constant.grab_constant(True,"HOSPITAL_TITLE").upper(), font_size=20, color=(0,0,0,1))
        self.hospital_name_label.pos_hint = {"x":0.21, "top": 1.2}
        self.add_widget(self.hospital_name_label)

        self.hospital_motto_label = Label(text=constant.grab_constant(True,"HOSPITAL_MOTTO").upper(), font_size=18, color=(51/255, 153/255, 255/255,1))
        self.hospital_motto_label.pos_hint = {"x":0.255, "top": 1.16}
        self.add_widget(self.hospital_motto_label)

        self.hospital_location_label = Label(text=constant.grab_constant(True,"HOSPITAL_LOCATION"), font_size=13, color=(0,0,0,1))
        self.hospital_location_label.pos_hint = {"x":0.17, "top": 1.13}
        self.add_widget(self.hospital_location_label)

        self.hospital_info_label = Label(text="""        Our Hospital is a well-known hospital of the country. It provides quality treatment for patients 
        and it has a qualified doctor's faculty. All of the employees are also hardworking.
        This hospital also provides an efficient GUI that can be used from any device.
        Some more information about our hospital:""", font_size=13, color=(0,0,0,1))
        self.hospital_info_label.pos_hint = {"x":0.01, "top": 0.98}
        self.add_widget(self.hospital_info_label)

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        self.info_grid.size_hint = 0.6,0.25
        self.info_grid.pos_hint = {"x": 0.25, "top": 0.4}
        self.year_name = Label(text= "Founded in:", color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.year_name)
        self.year_value = Label(text= constant.grab_constant(True, "HOSPITAL_YEAR"), color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.year_value)
        self.total_bed_name = Label(text= "Total Bed Number:", color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.total_bed_name) 
        self.total_bed_value = Label(text= constant.grab_constant(True,"HOSPITAL_TOTAL_BED"), color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.total_bed_value)
        self.remainning_bed_name = Label(text= "Number of Available Beds:", color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.remainning_bed_name)
        self.remainning_bed_value = Label(text= constant.grab_constant(True,"HOSPITAL_REMAINING_BED"), color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.remainning_bed_value)
        self.doctors_number_name = Label(text= "Total Doctors:", color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.doctors_number_name)
        self.doctors_number_value = Label(text= constant.grab_constant(True,"HOSPITAL_TOTAL_DOCTOR"), color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.doctors_number_value)
        self.patient_number_name = Label(text= "Total Treated Patient:", color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.patient_number_name)
        self.patient_number_value = Label(text= constant.grab_constant(True,"HOSPITAL_TOTAL_PATIENT"), color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.patient_number_value)
        self.patient_current_name = Label(text= "Number of Current Patient:", color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.patient_current_name) 
        self.patient_current_value = Label(text= constant.grab_constant(True,"HOSPITAL_CURRENT_PATIENT"), color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.patient_current_value)
        self.employee_number_name = Label(text= "Total Employee:", color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.employee_number_name)
        self.employee_number_value = Label(text= constant.grab_constant(True,"HOSPITAL_TOTAL_EMPLOYEE"), color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.employee_number_value) 
        self.add_widget(self.info_grid)

    def go_back(self, instance):
        pass



# Subclasses of AboutHospital class
class AdminAboutHospital(AboutHospital):
    def go_back(self, instance):
        sm.transition = SlideTransition(direction = "right")
        sm.current = "AdminAfterLogin"


class DoctorAboutHospital(AboutHospital):
    def go_back(self, instance):
        sm.transition = SlideTransition(direction = "right")
        sm.current = "DoctorAfterLogin"


class PatientAboutHospital(AboutHospital):
    def go_back(self, instance):
        sm.transition = SlideTransition(direction = "right")
        sm.current = "PatientAfterLogin"


class EmployeeAboutHospital(AboutHospital):
    def go_back(self, instance):
        sm.transition = SlideTransition(direction = "right")
        sm.current = "EmployeeAfterLogin"





# Documentation class
class Documentation(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.category = self.find_my_category()
        with self.canvas:
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text=self.category.capitalize()+ " Documentaion", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.instruction_label = Label(text="Read this documentation clearly and perform your tasks:", font_size=18, color=(51/255, 153/255, 255/255,1))
        self.instruction_label.pos_hint = {"x":-0.1, "top": 1}
        self.add_widget(self.instruction_label)

        self.instruction_body = Label(text=self.all_instructions(), font_size = 14, color = (0,0,0,1))
        self.instruction_body.size_hint = 0.8 , 0.5
        self.instruction_body.pos_hint = {"x":0.1, "top": 0.57}
        self.add_widget(self.instruction_body)

    def go_back(self):
        pass

    def find_my_category(self):
        return "Doctor"
    
    def all_instructions(self):
        return "Default"



# Subclasses of Documentation class
class AdminDocumentation(Documentation):
    def go_back(self, instance):
        sm.transition = SlideTransition(direction = "right")
        sm.current = "AdminAfterLogin"

    def find_my_category(self):
        return "admin"

    def all_instructions(self):
        text = """
        00. SignUp or Login to the application to use it.
        01. Send others notification using + button.
        02. See all of your notification as well as profile.
        03. In "Functions" secion, you have a set of functions. 
        04. Use those functions providing necessary information.
        05. In "Settings" you can edit your profile.
        06. Read more about the hospital in "About Hospital" section.
        07. You are currently reading the docs in the "Documentation" section.
        08. Visit creators webpage by clicking on his name at the bottom-right corner.
        09. Promote this "Hospital Management System" application in social network.
        10. Be active in your workflow and have a great day.
        """
        return text


class DoctorDocumentation(Documentation):
    def go_back(self, instance):
        sm.transition = SlideTransition(direction = "right")
        sm.current = "DoctorAfterLogin"

    def find_my_category(self):
        return "doctor"

    def all_instructions(self):
        text = """
        00. SignUp or Login to the application to use it.
        01. Send notifications to admin using + button.
        02. See all of your notification as well as profile.
        03. In "Functions" secion, you have a set of functions. 
        04. Use those functions providing necessary information.
        05. In "Settings" you can edit your profile.
        06. Read more about the hospital in "About Hospital" section.
        07. You are currently reading the docs in the "Documentation" section.
        08. Visit creators webpage by clicking on his name at the bottom-right corner.
        09. Promote this "Hospital Management System" application in social network.
        10. Be active in your workflow and have a great day.
        """
        return text


class PatientDocumentation(Documentation):
    def go_back(self, instance):
        sm.transition = SlideTransition(direction = "right")
        sm.current = "PatientAfterLogin"

    def find_my_category(self):
        return "patient"

    def all_instructions(self):
        text = """
        00. SignUp or Login to the application to use it.
        01. Send notifications to admin using + button.
        02. See all of your notification as well as profile.
        03. In "Functions" secion, you have a set of functions. 
        04. Use those functions providing necessary information.
        05. In "Settings" you can edit your profile.
        06. Read more about the hospital in "About Hospital" section.
        07. You are currently reading the docs in the "Documentation" section.
        08. Visit creators webpage by clicking on his name at the bottom-right corner.
        09. Promote this "Hospital Management System" application in social network.
        10. Be active in your workflow and have a great day.
        """
        return text


class EmployeeDocumentation(Documentation):
    def go_back(self, instance):
        sm.transition = SlideTransition(direction = "right")
        sm.current = "EmployeeAfterLogin"

    def find_my_category(self):
        return "employee"

    def all_instructions(self):
        text = """
        00. SignUp or Login to the application to use it.
        01. Send notifications to admin using + button.
        02. See all of your notification as well as profile.
        03. In "Functions" secion, you have a set of functions. 
        04. Use those functions providing necessary information.
        05. In "Settings" you can edit your profile.
        06. Read more about the hospital in "About Hospital" section.
        07. You are currently reading the docs in the "Documentation" section.
        08. Visit creators webpage by clicking on his name at the bottom-right corner.
        09. Promote this "Hospital Management System" application in social network.
        10. Be active in your workflow and have a great day.
        """
        return text





# Profile class
class Profile(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.username = self.find_my_username()
        self.category = self.find_my_category()
        if self.category == "admin":
            self.fullname, self.email, self.date_of_birth, *others = self.get_my_profile(self.username, self.category)[0][1:]
            self.password, self.notifications = others
        elif self.category == "doctor":
            self.fullname, self.email, self.date_of_birth, *others = self.get_my_profile(self.username, self.category)[0][1:]
            self.password, self.specialty, self.price, self.notifications = others
        elif self.category == "patient":
            self.fullname, self.email, self.date_of_birth, *others = self.get_my_profile(self.username, self.category)[0][1:]
            self.password, self.problem, self.requested_doctor_username, self.approved_doctor_username, self.appointment_timestamp, self.reports, self.notifications = others
        else:
            self.fullname, self.email, self.date_of_birth, *others = self.get_my_profile(self.username, self.category)[0][1:]
            self.password, self.work, self.work_of_doctors, self.salary, self.notifications = others

        with self.canvas:
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text=self.find_my_category().capitalize()+ " Profile", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        self.info_grid.size_hint = 0.6,0.3
        self.info_grid.pos_hint = {"x": 0.2, "top": 0.5}
        self.username_name = Label(text = "Username:", color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.username_name)
        self.username_value = Label(text = self.username, color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.username_value)
        self.fullname_name = Label(text = "Fullname:", color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.fullname_name)
        self.fullname_value = Label(text = self.fullname, color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.fullname_value)
        self.email_name = Label(text = "Email Address:", color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.email_name)
        self.email_value = Label(text = self.email, color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.email_value)
        self.date_of_birth_name = Label(text = "Date of Birth", color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.date_of_birth_name)
        self.date_of_birth_value = Label(text = datetime.datetime.strftime(self.date_of_birth, format = "%d %b,%Y" ), color = (0,0,0,1), font_size=13)
        self.info_grid.add_widget(self.date_of_birth_value)
        if self.category == "doctor":
            self.specialty_name = Label(text = "Specialty:", color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.specialty_name)
            self.specialty_value = Label(text = self.specialty, color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.specialty_value)
            self.price_name = Label(text = "Per CheckUp Fee:", color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.price_name)
            self.price_value = Label(text = str(self.price), color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.price_value)
        elif self.category == "patient":
            self.problem_name = Label(text = "Problem:", color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.problem_name)
            self.problem_value = Label(text = self.problem, color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.problem_value)
            self.requested_doctor_username_name = Label(text = "Requested Doctor:", color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.requested_doctor_username_name)
            self.requested_doctor_username_value = Label(text = (self.requested_doctor_username if not self.requested_doctor_username==None else "None"), color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.requested_doctor_username_value)
            self.approved_doctor_username_name = Label(text = "Approved Doctor:", color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.approved_doctor_username_name)
            self.approved_doctor_username_value = Label(text = (self.approved_doctor_username if not self.approved_doctor_username==None else "None"), color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.approved_doctor_username_value)
            self.appointment_timestamp_name = Label(text = "Appointment Timestamp:", color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.appointment_timestamp_name)
            self.appointment_timestamp_value = Label(text=(datetime.datetime.strftime(self.appointment_timestamp, format="%d %b, %Y %H:%M:%S") if self.appointment_timestamp != None else "None"), color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.appointment_timestamp_value)
            self.reports_name = Label(text = "Reports:", color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.reports_name)
            self.report_bucket = self.reports.split("+++")
            self.report_string = [item.replace("++", ",") for item in self.report_bucket]
            self.reports_value = Label(text = str(self.report_string), color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.reports_value)
        elif self.category =="employee":
            self.work_name = Label(text = "Work:", color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.work_name)
            self.work_value = Label(text = self.work, color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.work_value)
            self.work_of_doctors_name = Label(text = "Work of Doctors:", color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.work_of_doctors_name)
            self.work_of_doctors_value = Label(text = self.work_of_doctors, color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.work_of_doctors_value)
            self.salary_name = Label(text = "Salary:", color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.salary_name)
            self.salary_value = Label(text = str(self.salary), color = (0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.salary_value)
        self.add_widget(self.info_grid)

    def get_my_profile(self, username, category):
        return admin.see_info(True, category, username)

    def find_my_category(self):
        return "doctor"
    
    def find_my_username(self):
        return "hpt"
    
    def go_back(self):
        pass



# Subclasses of Profile class
class AdminProfile(Profile):
    def find_my_category(self):
        return "admin"
    
    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "AdminProfile":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "AdminAfterLogin"


class DoctorProfile(Profile):
    def find_my_category(self):
        return "doctor"
    
    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "DoctorProfile":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "DoctorAfterLogin"


class PatientProfile(Profile):
    def find_my_category(self):
        return "patient"

    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "PatientProfile":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "PatientAfterLogin"


class EmployeeProfile(Profile):
    def find_my_category(self):
        return "employee"

    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "EmployeeProfile":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "EmployeeAfterLogin"
        




# Notifications class
class Notifications(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.username = self.find_my_username()
        self.category = self.find_my_category()
        self.notifications = self.get_my_notification(self.username, self.category)

        with self.canvas:
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text=self.find_my_category().capitalize()+ " Notifications", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.info_grid = GridLayout()
        self.info_grid.cols = 1
        self.info_grid.pos_hint = {"x": 0.2, "top": 0.5}
        self.note_length = len(self.notifications)
        if self.note_length > 6:
            self.changable = 0.3
        elif self.note_length > 3:
            self.changable = 0.2
        else:
            self.changable = 0.1
        self.info_grid.size_hint = 0.6, self.changable

        for item in self.notifications:
            self.new_notice = Label(text=str(item), color=(0,0,0,1), font_size=13)
            self.info_grid.add_widget(self.new_notice)

        self.add_widget(self.info_grid)

    def get_my_notification(self, username, category):
        return "Default"

    def find_my_category(self):
        return "doctor"
    
    def find_my_username(self):
        return "hpt"
    
    def go_back(self):
        pass



# Subclasses of Notifications class
class AdminNotifications(Notifications):
    def find_my_category(self):
        return "admin"
    
    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "AdminNotifications":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "AdminAfterLogin"
    
    def get_my_notification(self, username, category):
        return admin.recent_notifications(username, True, limit = 10)


class DoctorNotifications(Notifications):
    def find_my_category(self):
        return "doctor"
    
    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "DoctorNotifications":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "DoctorAfterLogin"
    
    def get_my_notification(self, username, category):
        return doctor.recent_notifications(username, True, limit = 10)


class PatientNotifications(Notifications):
    def find_my_category(self):
        return "patient"

    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "PatientNotifications":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "PatientAfterLogin"
    
    def get_my_notification(self, username, category):
        return patient.recent_notifications(username, True, limit = 10)


class EmployeeNotifications(Notifications):
    def find_my_category(self):
        return "employee"

    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "EmployeeNotifications":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "EmployeeAfterLogin" 

    def get_my_notification(self, username, category):
        return employee.recent_notifications(username, True, limit = 10)





# AddNotifications class
class AddNotifications(Screen):
    receiver = ObjectProperty()
    body = ObjectProperty()
    receiver_category = ObjectProperty()
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.username = self.find_my_username()
        self.category = self.find_my_category()
        with self.canvas:
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text=self.find_my_category().capitalize()+ " Add Notifications", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        self.info_grid.pos_hint = {"x": 0.2, "top": 0.7}
        self.info_grid.size_hint = 0.6, 0.3
        if self.category == "admin":
            self.receiver_username_name = Label(text= "Receiver's username:", font_size=15, color = (0,0,0,1))
            self.info_grid.add_widget(self.receiver_username_name)
            self.receiver_username_value = TextInput(multiline = False)
            self.info_grid.add_widget(self.receiver_username_value)            
            self.receiver_category_name = Label(text= "Receiver's category:", font_size=15, color = (0,0,0,1))
            self.info_grid.add_widget(self.receiver_category_name)
            self.receiver_category_value = TextInput(multiline = False)
            self.info_grid.add_widget(self.receiver_category_value)
        else:
            self.receiver_username_name = Label(text= "Admin's username:", font_size=15, color = (0,0,0,1))
            self.info_grid.add_widget(self.receiver_username_name)
            self.receiver_username_value = TextInput(multiline = False)
            self.info_grid.add_widget(self.receiver_username_value)
        self.notification_body_name = Label(text= "Notification's Body: ", font_size=15, color = (0,0,0,1))
        self.info_grid.add_widget(self.notification_body_name)
        self.notification_body_value = TextInput(multiline = False)
        self.info_grid.add_widget(self.notification_body_value)
        self.add_widget(self.info_grid)

        self.submit = Button(text = "Send")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1,1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.2}
        self.add_widget(self.submit)
        self.submit.bind(on_release = self.pre_notifications)

    def pre_notifications(self, instance):
        receiver = self.receiver_username_value.text
        body = self.notification_body_value.text
        username = self.username
        
        self.send_notifications(body, receiver, username)
        
        self.receiver_username_value.text = ""
        self.notification_body_value.text = ""

    def send_notifications(self,body,receiver,username):
        return "Default"

    def find_my_category(self):
        return "doctor"
    
    def find_my_username(self):
        return "hpt"
    
    def go_back(self):
        pass



# Subclasses of AddNotifications class
class AdminAddNotifications(AddNotifications):
    def find_my_category(self):
        return "admin"
    
    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "AdminAddNotifications":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "AdminAfterLogin"

    def pre_notifications(self, instance):
        receiver = self.receiver_username_value.text
        receiver_cat = self.receiver_category_value.text
        body = self.notification_body_value.text
        username = self.username
        
        self.send_notifications(body, receiver, username, receiver_cat)
        
        self.receiver_username_value.text = ""
        self.notification_body_value.text = ""
        self.receiver_category_value.text = ""
    
    def send_notifications(self, body, receiver, username, category):
        self.body = body
        self.receiver = receiver
        self.username = username
        self.category = category

        try:
            admin.add_notification(body,category,receiver, True)
        except: 
            show_NotificationPop()


class DoctorAddNotifications(AddNotifications):
    def find_my_category(self):
        return "doctor"
    
    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "DoctorAddNotifications":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "DoctorAfterLogin"
    
    def send_notifications(self, body, receiver, username):
        self.body = body
        self.receiver = receiver
        self.username = username

        try:
            return doctor.notify_admin(self.body, self.username, self.receiver, True)
        except:
            show_NotificationPop()


class PatientAddNotifications(AddNotifications):
    def find_my_category(self):
        return "patient"

    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "PatientAddNotifications":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "PatientAfterLogin"
    
    def send_notifications(self, body, receiver, username):
        self.body = body
        self.receiver = receiver
        self.username = username

        try:
            return patient.notify_admin(self.body, self.username, self.receiver, True)
        except:
            show_NotificationPop()


class EmployeeAddNotifications(AddNotifications):
    def find_my_category(self):
        return "employee"

    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "EmployeeAddNotifications":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "EmployeeAfterLogin" 

    def send_notifications(self, body, receiver, username):
        self.body = body
        self.receiver = receiver
        self.username = username

        try:
            return employee.notify_admin(self.body, self.username, self.receiver, True)
        except:
            show_NotificationPop()


class NotificationPop(FloatLayout):
    pass


def show_NotificationPop():
    show = NotificationPop()
    popup_window = Popup(title = "Add Notification Error", content = show, size_hint = (0.6, 0.3))
    popup_window.open()





# Settings class
class Settings(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.username = self.find_my_username()
        self.category = self.find_my_category()
        with self.canvas:
            Color(1, 1, 1,1,mode="rgba")
            Rectangle(pos = self.pos, size = (800,600))
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text=self.find_my_category().capitalize()+ " Settings", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.poster = Image(source='resources/settings_pic.png', size_hint= (0.7,0.3), pos_hint= {"x": 0.16, "top": 0.85})
        self.add_widget(self.poster)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.notice = Label(text= "Only change the profile values which you need to change. Otherswise, leave it blank.", font_size=15, color = (51/255, 153/255, 255/255,1))
        self.notice.pos_hint = {"x": 0.015, "top": 1}
        self.add_widget(self.notice)

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        self.info_grid.pos_hint = {"x": 0.2, "top": 0.45}
        self.info_grid.size_hint = 0.6, 0.2

        self.fullname_name = Label(text= "Fullname:", font_size=15, color = (0,0,0,1))
        self.info_grid.add_widget(self.fullname_name)
        self.fullname_value = TextInput(multiline = False)
        self.info_grid.add_widget(self.fullname_value)            
        self.email_name = Label(text= "Email Address:", font_size=15, color = (0,0,0,1))
        self.info_grid.add_widget(self.email_name)
        self.email_value = TextInput(multiline = False)
        self.info_grid.add_widget(self.email_value)
        self.date_of_birth_name = Label(text= "Date of Birth:", font_size=15, color = (0,0,0,1))
        self.info_grid.add_widget(self.date_of_birth_name)
        self.date_of_birth_value = TextInput(multiline = False)
        self.info_grid.add_widget(self.date_of_birth_value)
        self.add_widget(self.info_grid)

        self.submit = Button(text = "Save Settings")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1, 1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.175}
        self.add_widget(self.submit)
        self.submit.bind(on_release = self.save_settings)

    def find_my_category(self):
        return "doctor"
    
    def find_my_username(self):
        return "hpt"
    
    def go_back(self):
        pass

    def save_settings(self, instance):
        fullname = self.fullname_value.text
        email = self.email_value.text
        date_of_birth = self.date_of_birth_value.text

        fullname_pass = False
        email_pass = False
        date_of_birth_pass = False

        if fullname != "":
            fullname_pass = True
        if email != "":
            email_pass = True
        if date_of_birth != "":
            date_of_birth_pass = True

        if fullname_pass:
            admin.update_db(self.category, self.username, "fullname", fullname, True)
        if email_pass:
            admin.update_db(self.category, self.username, "email", email, True)
        if date_of_birth_pass:
            admin.update_db(self.category, self.username, "date_of_birth", date_of_birth, True)

        

# Settings sub classes
class AdminSettings(Settings):
    def find_my_category(self):
        return "admin"
    
    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "AdminSettings":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "AdminAfterLogin"
    

class DoctorSettings(Settings):
    def find_my_category(self):
        return "doctor"
    
    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "DoctorSettings":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "DoctorAfterLogin"
    

class PatientSettings(Settings):
    def find_my_category(self):
        return "patient"

    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "PatientSettings":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "PatientAfterLogin"


class EmployeeSettings(Settings):
    def find_my_category(self):
        return "employee"

    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "EmployeeSettings":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "EmployeeAfterLogin" 






# Admin Functions
class AdminFunctions(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.username = self.find_my_username()
        self.category = "admin"
        with self.canvas:
            Color(1, 1, 1,1,mode="rgba")
            Rectangle(pos = self.pos, size = (800,600))
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text="Admin Functions", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.info_grid = GridLayout()
        self.info_grid.cols = 1
        self.info_grid.pos_hint = {"x": 0.2, "top": 0.82}
        self.info_grid.size_hint = 0.6, 0.7

        self.total_earning_button = Button(text="Total Earning", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.total_earning_button.bind(on_release = lambda x:self.set_function("total_earning_function"))
        self.info_grid.add_widget(self.total_earning_button)
        self.add_employee_button = Button(text="Add Employee", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.add_employee_button.bind(on_release = lambda x:self.set_function("add_employee_function"))
        self.info_grid.add_widget(self.add_employee_button)
        self.see_my_employee_button = Button(text="See My Employee", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.see_my_employee_button.bind(on_release = lambda x:self.set_function("see_my_employee_function"))
        self.info_grid.add_widget(self.see_my_employee_button)
        self.remove_employee_button = Button(text="Remove Employee", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.remove_employee_button)
        self.remove_employee_button.bind(on_release = lambda x:self.set_function("remove_employee_function"))
        self.show_all_doctor_button = Button(text="Show All Doctor", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.show_all_doctor_button)
        self.show_all_doctor_button.bind(on_release = lambda x:self.set_function("show_all_doctor_function"))
        self.show_all_patient_button = Button(text="Show All Patient", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.show_all_patient_button)
        self.show_all_patient_button.bind(on_release = lambda x:self.set_function("show_all_patient_function"))
        self.show_all_employee_button = Button(text="Show All Employee", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.show_all_employee_button)
        self.show_all_employee_button.bind(on_release = lambda x:self.set_function("show_all_employee_function"))
        self.remove_doctor_parmanently_button = Button(text="Remove Doctor Parmanently", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.remove_doctor_parmanently_button)
        self.remove_doctor_parmanently_button.bind(on_release = lambda x:self.set_function("remove_doctor_parmanently_function"))
        self.remove_patient_parmanently_button = Button(text="Remove Patient Parmanently", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.remove_patient_parmanently_button)
        self.remove_patient_parmanently_button.bind(on_release = lambda x:self.set_function("remove_patient_parmanently_function"))
        self.remove_employee_parmanently_button = Button(text="Remove Employee Parmanently", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.remove_employee_parmanently_button)
        self.remove_employee_parmanently_button.bind(on_release = lambda x:self.set_function("remove_employee_parmanently_function"))
        self.patient_joins_doctor_button = Button(text="Patient Joins Doctor", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.patient_joins_doctor_button)
        self.patient_joins_doctor_button.bind(on_release = lambda x:self.set_function("patient_joins_doctor_function"))

        self.add_widget(self.info_grid)
    
    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "AdminFunctions":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "AdminAfterLogin"

    def set_function(self, function_name):
        sm.add_widget(AdminDisplayFunction(function_name, name="AdminDisplayFunction"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "AdminDisplayFunction"
        


class AdminDisplayFunction(Screen):
    def __init__(self, function_name, **kwargs):
        super().__init__(**kwargs)

        self.username = self.find_my_username()
        self.category = "admin"
        self.function_name = function_name
        with self.canvas:
            Color(1, 1, 1,1,mode="rgba")
            Rectangle(pos = self.pos, size = (800,600))
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text="Admin Functions", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)        

        if self.function_name == "total_earning_function":
            final_function = self.total_earning_function
        elif self.function_name == "add_employee_function":
            final_function = self.add_employee_function
        elif self.function_name == "see_my_employee_function":
            final_function = self.see_my_employee_function
        elif self.function_name == "remove_employee_function":
            final_function = self.remove_employee_function
        elif self.function_name == "show_all_doctor_function":
            final_function = self.show_all_doctor_function
        elif self.function_name == "show_all_patient_function":
            final_function = self.show_all_patient_function
        elif self.function_name == "show_all_employee_function":
            final_function = self.show_all_employee_function
        elif self.function_name == "remove_doctor_parmanently_function":
            final_function = self.remove_doctor_parmanently_function
        elif self.function_name == "remove_patient_parmanently_function":
            final_function = self.remove_patient_parmanently_function
        elif self.function_name == "remove_employee_parmanently_function":
            final_function = self.remove_employee_parmanently_function
        else:
            final_function = self.patient_joins_doctor_function

        self.value, size_hint, pos_hint = final_function()
        self.value.size_hint = size_hint
        self.value.pos_hint = pos_hint
        self.add_widget(self.value)
        if (self.function_name == "show_all_patient_function") or (self.function_name == "patient_joins_doctor_function"):
            self.previous_button = Button()
            self.previous_button.font_size = 18
            self.previous_button.color = (1, 1, 1, 1)
            self.previous_button.italic = True
            self.previous_button.background_color = (1,1,1,0)
            self.previous_button.size_hint = (0, 0)
            self.previous_button.pos_hint = {"x":0.05, "top": 0.14}
            self.add_widget(self.previous_button)
            self.previous_button.bind(on_release = lambda x: self.next_button_function(function_name), on_press = lambda x: self.add_Holder_counter(-1))

            self.next_button = Button(text = "Next")
            self.next_button.font_size = 18
            self.next_button.color = (1, 1, 1, 1)
            self.next_button.italic = True
            self.next_button.background_color = (0/255, 153/255, 204/255, 1)
            self.next_button.size_hint = (0.1,0.05)
            self.next_button.pos_hint = {"x":0.85, "top": 0.14}
            self.add_widget(self.next_button)
            self.next_button.bind(on_release = lambda x: self.next_button_function(function_name))
            Holder.counter += 1


    def next_button_function(self,function_name):
        self.remove_widget(self.previous_button)
        self.remove_widget(self.next_button)

        if self.function_name == "total_earning_function":
            final_function = self.total_earning_function
        elif self.function_name == "add_employee_function":
            final_function = self.add_employee_function
        elif self.function_name == "see_my_employee_function":
            final_function = self.see_my_employee_function
        elif self.function_name == "remove_employee_function":
            final_function = self.remove_employee_function
        elif self.function_name == "show_all_doctor_function":
            final_function = self.show_all_doctor_function
        elif self.function_name == "show_all_patient_function":
            final_function = self.show_all_patient_function
        elif self.function_name == "show_all_employee_function":
            final_function = self.show_all_employee_function
        elif self.function_name == "remove_doctor_parmanently_function":
            final_function = self.remove_doctor_parmanently_function
        elif self.function_name == "remove_patient_parmanently_function":
            final_function = self.remove_patient_parmanently_function
        elif self.function_name == "remove_employee_parmanently_function":
            final_function = self.remove_employee_parmanently_function
        else:
            final_function = self.patient_joins_doctor_function

        self.remove_widget(self.info_grid)
        self.value, size_hint, pos_hint = final_function()
        self.value.size_hint = size_hint
        self.value.pos_hint = pos_hint
        self.add_widget(self.value)
        if (self.function_name == "show_all_patient_function") or (self.function_name == "patient_joins_doctor_function"):
            if Holder.counter != 0:
                self.previous_button = Button(text = "Previous")
                self.previous_button.font_size = 18
                self.previous_button.color = (1, 1, 1, 1)
                self.previous_button.italic = True
                self.previous_button.background_color = (0/255, 153/255, 204/255, 1)
                self.previous_button.size_hint = (0.1,0.05)
                self.previous_button.pos_hint = {"x":0.05, "top": 0.14}
                self.add_widget(self.previous_button)
                self.previous_button.bind(on_release = lambda x: self.next_button_function(function_name), on_press = lambda x: self.add_Holder_counter(-1))

            if Holder.counter != -1:
                self.next_button = Button(text = "Next")
                self.next_button.font_size = 18
                self.next_button.color = (1, 1, 1, 1)
                self.next_button.italic = True
                self.next_button.background_color = (0/255, 153/255, 204/255, 1)
                self.next_button.size_hint = (0.1,0.05)
                self.next_button.pos_hint = {"x":0.85, "top": 0.14}
                self.add_widget(self.next_button)
                self.next_button.bind(on_release = lambda x: self.next_button_function(function_name), on_press = lambda x : self.add_Holder_counter(1))                


    def add_Holder_counter(self,add_int):
        if Holder.counter == -1:
            Holder.counter = Holder.pre_counter 
        Holder.counter += add_int


    def find_my_username(self):
        return Holder.username
    

    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "AdminDisplayFunction":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "AdminFunctions"
        Holder.counter = 0


    def total_earning_function(self):
        total_earning_list = admin.total_earning(True)
        earned_from_employee = total_earning_list[0]
        earned_from_patient = total_earning_list[1]
        fixed_cost_of_hospital = total_earning_list[2]
        employee_pre_salary = total_earning_list[3]
        given_to_employees = total_earning_list[4]
        initial_earning = total_earning_list[5]

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        size_hint = 0.6, 0.5
        pos_hint = {"x": 0.2, "top": 0.715}

        self.label1 = Label(text = "Earned From Employee", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label1)
        self.label2 = Label(text = "+" + str(earned_from_employee), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label2)
        self.label3 = Label(text = "Earned From Patient", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label3)
        self.label4 = Label(text = "+" + str(earned_from_patient), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label4)
        self.label5 = Label(text = "Fixed Cost of Hospital", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label5)
        self.label6 = Label(text = "-" + str(fixed_cost_of_hospital), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label6)
        self.label7 = Label(text = "Employee_pre_salary", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label7)
        self.label8 = Label(text = "-" + str(employee_pre_salary), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label8)
        self.label9 = Label(text = "Given to Employees", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label9)
        self.label10 = Label(text = "-" + str(given_to_employees), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label10)
        self.label11 = Label(text = "Final Earning", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label11)
        self.label12 = Label(text = str(initial_earning), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label12)
        
        return (self.info_grid, size_hint, pos_hint)


    def add_employee_function(self):
        def current_function():
            try:
                admin.add_employee(self.employee_username.text, True)
            except:
                show_add_employee_popup()
            self.employee_username.text = ""

        def show_add_employee_popup():
            popup_layout = FloatLayout()
            first_line = Label(text = "Sorry, Something went Wrong :(", size_hint= (0.6, 0.2), pos_hint= {"x": 0.2, "top":0.9})
            popup_layout.add_widget(first_line)
            second_line = Label(text="Invalid Username", size_hint= (0.6, 0.2), pos_hint= {"x": 0.21, "top":0.5})
            popup_layout.add_widget(second_line)
            popup_window = Popup(title = "Add Employee Error", content = popup_layout, size_hint = (0.6, 0.3))
            popup_window.open()

        self.info_grid = GridLayout()
        self.info_grid.cols = 1
        size_hint = 0.6, 0.2
        pos_hint = {"x": 0.2, "top": 0.6}

        self.question = Label(text = "Enter the Employee Username You Want to Add", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question)
        self.employee_username = TextInput(multiline = False)
        self.info_grid.add_widget(self.employee_username)

        self.submit = Button(text = "Submit")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1, 1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.175}
        self.add_widget(self.submit)
        self.submit.bind(on_release = lambda x: current_function())

        return (self.info_grid, size_hint, pos_hint)


    def see_my_employee_function(self):
        self.info_grid = GridLayout()
        self.info_grid.cols = 6
        pos_hint = {"x": 0.05, "top": 0.75}

        employee_infos = admin.see_my_employee(True)
        if len(employee_infos) > 7:
            size_hint = 0.9, 0.6
        elif len(employee_infos) > 3:
            size_hint = 0.9, 0.45
        else:
            size_hint = 0.9, 0.2
        
        self.username_topic = Button(text = "Username", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.username_topic)
        self.fullname_topic = Button(text = "Fullname", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.fullname_topic)
        self.email_topic = Button(text = "Email", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1), size_hint_x=None, width=200)
        self.info_grid.add_widget(self.email_topic)
        self.date_of_birth_topic = Button(text = "Date of Birth", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.date_of_birth_topic)
        self.work_topic = Button(text = "Work", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.work_topic)
        self.salary_topic = Button(text = "Salary", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.salary_topic)

        for employee in employee_infos:
            self.username_info = Label(text = str(employee[0]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.username_info)
            self.fullname_info = Label(text = str(employee[1]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.fullname_info)
            self.email_info = Label(text = str(employee[2]), font_size = 12, color = (0,0,0,1), size_hint_x=None, width=200)
            self.info_grid.add_widget(self.email_info)
            self.date_of_birth_info = Label(text = str(employee[3]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.date_of_birth_info)
            self.work_info = Label(text = str(employee[4]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.work_info)
            self.salary_info = Label(text = str(employee[5]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.salary_info)

        return (self.info_grid, size_hint, pos_hint)


    def remove_employee_function(self):
        def current_function():
            try:
                admin.remove_employee(self.employee_username.text, True)
            except:
                show_remove_employee_popup()
            self.employee_username.text = ""

        def show_remove_employee_popup():
            popup_layout = FloatLayout()
            first_line = Label(text = "Sorry, Something went Wrong :(", size_hint= (0.6, 0.2), pos_hint= {"x": 0.2, "top":0.9})
            popup_layout.add_widget(first_line)
            second_line = Label(text="Invalid Username", size_hint= (0.6, 0.2), pos_hint= {"x": 0.21, "top":0.5})
            popup_layout.add_widget(second_line)
            popup_window = Popup(title = "Remove Employee Error", content = popup_layout, size_hint = (0.6, 0.3))
            popup_window.open()

        self.info_grid = GridLayout()
        self.info_grid.cols = 1
        size_hint = 0.6, 0.2
        pos_hint = {"x": 0.2, "top": 0.6}

        self.question = Label(text = "Enter the Employee Username You Want to Remove", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question)
        self.employee_username = TextInput(multiline = False)
        self.info_grid.add_widget(self.employee_username)

        self.submit = Button(text = "Submit")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1, 1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.175}
        self.add_widget(self.submit)
        self.submit.bind(on_release = lambda x: current_function())

        return (self.info_grid, size_hint, pos_hint)


    def show_all_doctor_function(self):
        self.info_grid = GridLayout()
        self.info_grid.cols = 7
        pos_hint = {"x": 0.05, "top": 0.85}

        user_infos = admin.show_all_doctor(True)
        if len(user_infos) > 15:
            size_hint = 0.9, 0.8
        elif len(user_infos) > 8:
            size_hint = 0.9, 0.5
        else:
            size_hint = 0.9, 0.3
        
        self.username_topic = Button(text = "Username", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.username_topic)
        self.fullname_topic = Button(text = "Fullname", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.fullname_topic)
        self.email_topic = Button(text = "Email", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1), size_hint_x=None, width=200)
        self.info_grid.add_widget(self.email_topic)
        self.date_of_birth_topic = Button(text = "Date of Birth", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.date_of_birth_topic)
        self.specialty_topic = Button(text = "Specialty", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.specialty_topic)
        self.price_topic = Button(text = "Price", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.price_topic)
        self.total_earned_topic = Button(text = "Total Earned", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.total_earned_topic)

        for user in user_infos:
            self.username_info = Label(text = str(user[0]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.username_info)
            self.fullname_info = Label(text = str(user[1]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.fullname_info)
            self.email_info = Label(text = str(user[2]), font_size = 12, color = (0,0,0,1), size_hint_x=None, width=200)
            self.info_grid.add_widget(self.email_info)
            self.date_of_birth_info = Label(text = str(user[3]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.date_of_birth_info)
            self.specialty_info = Label(text = str(user[4]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.specialty_info)
            self.price_info = Label(text = str(user[5]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.price_info)
            self.total_earned_info = Label(text = str(user[6]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.total_earned_info)

        return (self.info_grid, size_hint, pos_hint)


    def show_all_patient_function(self):
        self.info_grid = GridLayout()
        self.info_grid.cols = 8
        pos_hint = {"x": 0.05, "top": 0.85}
        counter = Holder.counter

        old_user_infos = admin.show_all_patient(True)
        user_infos = old_user_infos[counter*15 : counter*15 + 15]
        if len(old_user_infos) < (counter*15+15):
            Holder.pre_counter = Holder.counter
            Holder.counter = -1
        size_hint = 0.9,0.7
        if len(user_infos) < 5:
            size_hint = 0.9, 0.35
        
        self.username_topic = Button(text = "Username", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.username_topic)
        self.fullname_topic = Button(text = "Fullname", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.fullname_topic)
        self.email_topic = Button(text = "Email", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1), size_hint_x=None, width=200)
        self.info_grid.add_widget(self.email_topic)
        self.date_of_birth_topic = Button(text = "D O B", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.date_of_birth_topic)
        self.problem_topic = Button(text = "Problem", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.problem_topic)
        self.requested_doctor_username_topic = Button(text = "Requested", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.requested_doctor_username_topic)
        self.approved_doctor_username_topic = Button(text = "Approved", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.approved_doctor_username_topic)
        self.total_cost_topic = Button(text = "Cost", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.total_cost_topic)

        for user in user_infos:
            self.username_info = Label(text = str(user[0]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.username_info)
            self.fullname_info = Label(text = str(user[1]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.fullname_info)
            self.email_info = Label(text = str(user[2]), font_size = 12, color = (0,0,0,1), size_hint_x=None, width=200)
            self.info_grid.add_widget(self.email_info)
            self.date_of_birth_info = Label(text = str(user[3]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.date_of_birth_info)
            self.problem_info = Label(text = str(user[4]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.problem_info)
            self.requested_doctor_username_info = Label(text = str(user[5]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.requested_doctor_username_info)
            self.approved_doctor_username_info = Label(text = str(user[6]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.approved_doctor_username_info)
            self.total_cost_info = Label(text = str(user[7]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.total_cost_info)

        return (self.info_grid, size_hint, pos_hint)


    def show_all_employee_function(self):
        self.info_grid = GridLayout()
        self.info_grid.cols = 8
        pos_hint = {"x": 0.05, "top": 0.85}

        user_infos = admin.show_all_employee(True)
        if len(user_infos) > 20:
            size_hint = 0.9, 8
        elif len(user_infos) > 10:
            size_hint = 0.9, 0.6
        else:
            size_hint = 0.9, 0.35
        
        self.username_topic = Button(text = "Username", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.username_topic)
        self.fullname_topic = Button(text = "Fullname", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.fullname_topic)
        self.email_topic = Button(text = "Email", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1), size_hint_x=None, width=200)
        self.info_grid.add_widget(self.email_topic)
        self.date_of_birth_topic = Button(text = "D O B", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.date_of_birth_topic)
        self.work_topic = Button(text = "Work", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.work_topic)
        self.work_of_doctors_topic = Button(text = "W O D", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.work_of_doctors_topic)
        self.salary_topic = Button(text = "Salary", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.salary_topic)
        self.total_earned_topic = Button(text = "Earned", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.total_earned_topic)

        for user in user_infos:
            self.username_info = Label(text = str(user[0]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.username_info)
            self.fullname_info = Label(text = str(user[1]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.fullname_info)
            self.email_info = Label(text = str(user[2]), font_size = 12, color = (0,0,0,1), size_hint_x=None, width=200)
            self.info_grid.add_widget(self.email_info)
            self.date_of_birth_info = Label(text = str(user[3]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.date_of_birth_info)
            self.work_info = Label(text = str(user[4]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.work_info)
            self.work_of_doctors_info = Label(text = str(user[5]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.work_of_doctors_info)
            self.salary_info = Label(text = str(user[6]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.salary_info)
            self.total_earned_info = Label(text = str(user[7]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.total_earned_info)

        return (self.info_grid, size_hint, pos_hint)


    def remove_doctor_parmanently_function(self):
        def current_function():
            if self.final_decision_answer.text == "yes":
                final_decision = True
            else:
                final_decision = False
            
            if self.doctor_username.text not in admin.all_doctor_username(True):
                show_remove_doctor_parmanently_popup()
            else:
                admin.remove_doctor_parmanently(self.doctor_username.text, True, final_decision)
                
            self.doctor_username.text = ""
            self.final_decision_answer.text = ""

        def show_remove_doctor_parmanently_popup():
            popup_layout = FloatLayout()
            first_line = Label(text = "Sorry, Something went Wrong :(", size_hint= (0.6, 0.2), pos_hint= {"x": 0.2, "top":0.9})
            popup_layout.add_widget(first_line)
            second_line = Label(text="Invalid Username", size_hint= (0.6, 0.2), pos_hint= {"x": 0.21, "top":0.5})
            popup_layout.add_widget(second_line)
            popup_window = Popup(title = "Remove Doctor Parmanently Error", content = popup_layout, size_hint = (0.6, 0.3))
            popup_window.open()

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        size_hint = 0.6, 0.2
        pos_hint = {"x": 0.2, "top": 0.65}

        self.question = Label(text = "Doctor Username", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question)
        self.doctor_username = TextInput(multiline = False)
        self.info_grid.add_widget(self.doctor_username)
        self.final_decision_question = Label(text = "Are You Sure? (yes/no)", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.final_decision_question)
        self.final_decision_answer = TextInput(multiline = False)
        self.info_grid.add_widget(self.final_decision_answer) 

        self.submit = Button(text = "Submit")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1, 1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.175}
        self.add_widget(self.submit)
        self.submit.bind(on_release = lambda x: current_function())

        return (self.info_grid, size_hint, pos_hint)


    def remove_patient_parmanently_function(self):
        def current_function():
            if self.final_decision_answer.text == "yes":
                final_decision = True
            else:
                final_decision = False
            
            if self.patient_username.text not in admin.all_patient_username(True):
                show_remove_patient_parmanently_popup()
            else:
                admin.remove_patient_parmanently(self.patient_username.text, True, final_decision)
                
            self.patient_username.text = ""
            self.final_decision_answer.text = ""

        def show_remove_patient_parmanently_popup():
            popup_layout = FloatLayout()
            first_line = Label(text = "Sorry, Something went Wrong :(", size_hint= (0.6, 0.2), pos_hint= {"x": 0.2, "top":0.9})
            popup_layout.add_widget(first_line)
            second_line = Label(text="Invalid Username", size_hint= (0.6, 0.2), pos_hint= {"x": 0.21, "top":0.5})
            popup_layout.add_widget(second_line)
            popup_window = Popup(title = "Remove Patient Parmanently Error", content = popup_layout, size_hint = (0.6, 0.3))
            popup_window.open()

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        size_hint = 0.6, 0.2
        pos_hint = {"x": 0.2, "top": 0.65}

        self.question = Label(text = "Patient Username", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question)
        self.patient_username = TextInput(multiline = False)
        self.info_grid.add_widget(self.patient_username)
        self.final_decision_question = Label(text = "Are You Sure? (yes/no)", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.final_decision_question)
        self.final_decision_answer = TextInput(multiline = False)
        self.info_grid.add_widget(self.final_decision_answer) 

        self.submit = Button(text = "Submit")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1, 1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.175}
        self.add_widget(self.submit)
        self.submit.bind(on_release = lambda x: current_function())

        return (self.info_grid, size_hint, pos_hint)


    def remove_employee_parmanently_function(self):
        def current_function():
            if self.final_decision_answer.text == "yes":
                final_decision = True
            else:
                final_decision = False
            
            if self.employee_username.text not in admin.all_employee_username(True):
                show_remove_employee_parmanently_popup()
            else:
                admin.remove_employee_parmanently(self.employee_username.text, True, final_decision)
                
            self.employee_username.text = ""
            self.final_decision_answer.text = ""

        def show_remove_employee_parmanently_popup():
            popup_layout = FloatLayout()
            first_line = Label(text = "Sorry, Something went Wrong :(", size_hint= (0.6, 0.2), pos_hint= {"x": 0.2, "top":0.9})
            popup_layout.add_widget(first_line)
            second_line = Label(text="Invalid Username", size_hint= (0.6, 0.2), pos_hint= {"x": 0.21, "top":0.5})
            popup_layout.add_widget(second_line)
            popup_window = Popup(title = "Remove Employee Parmanently Error", content = popup_layout, size_hint = (0.6, 0.3))
            popup_window.open()

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        size_hint = 0.6, 0.2
        pos_hint = {"x": 0.2, "top": 0.65}

        self.question = Label(text = "Employee Username", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question)
        self.employee_username = TextInput(multiline = False)
        self.info_grid.add_widget(self.employee_username)
        self.final_decision_question = Label(text = "Are You Sure? (yes/no)", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.final_decision_question)
        self.final_decision_answer = TextInput(multiline = False)
        self.info_grid.add_widget(self.final_decision_answer) 

        self.submit = Button(text = "Submit")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1, 1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.175}
        self.add_widget(self.submit)
        self.submit.bind(on_release = lambda x: current_function())

        return (self.info_grid, size_hint, pos_hint)


    def patient_joins_doctor_function(self):
        self.info_grid = GridLayout()
        self.info_grid.cols = 6
        pos_hint = {"x": 0.05, "top": 0.85}
        counter = Holder.counter

        old_user_infos = admin.patient_joins_doctor(True)
        user_infos = old_user_infos[counter*15 : counter*15 + 15]
        if len(old_user_infos) < (counter*15+15):
            Holder.pre_counter = Holder.counter
            Holder.counter = -1
        size_hint = 0.9,0.7
        if len(user_infos) < 5:
            size_hint = 0.9, 0.35
        
        self.username_topic = Button(text = "Username", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.username_topic)
        self.fullname_topic = Button(text = "Fullname", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.fullname_topic)
        self.problem_topic = Button(text = "Problem", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.problem_topic)
        self.appointment_topic = Button(text = "Appoint Date", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1), size_hint_x=None, width=200)
        self.info_grid.add_widget(self.appointment_topic)
        self.dusername_topic = Button(text = "D Username", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.dusername_topic)
        self.dfullname_topic = Button(text = "D Fullname", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.dfullname_topic)

        for user in user_infos:
            self.username_info = Label(text = str(user[0]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.username_info)
            self.fullname_info = Label(text = str(user[1]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.fullname_info)
            self.problem_info = Label(text = str(user[3]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.problem_info)
            self.appoint_info = Label(text = str(user[4]), font_size = 12, color = (0,0,0,1), size_hint_x=None, width=200)
            self.info_grid.add_widget(self.appoint_info)
            self.dusername_info = Label(text = str(user[5]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.dusername_info)
            self.dfullname_info = Label(text = str(user[6]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.dfullname_info) 
        return (self.info_grid, size_hint, pos_hint)





# Doctor Functions
class DoctorFunctions(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.username = self.find_my_username()
        self.category = "doctor"
        with self.canvas:
            Color(1, 1, 1,1,mode="rgba")
            Rectangle(pos = self.pos, size = (800,600))
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text="Doctor Functions", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.info_grid = GridLayout()
        self.info_grid.cols = 1
        self.info_grid.pos_hint = {"x": 0.2, "top": 0.82}
        self.info_grid.size_hint = 0.6, 0.7

        self.salary_button = Button(text="Salary", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.salary_button)
        self.salary_button.bind(on_release = lambda x: self.set_function("salary_function"))
        self.show_all_employee_button = Button(text="Show All Employee", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.show_all_employee_button)
        self.show_all_employee_button.bind(on_release = lambda x: self.set_function("show_all_employee_function"))
        self.add_employee_button = Button(text="Add Employee", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.add_employee_button)
        self.add_employee_button.bind(on_release = lambda x: self.set_function("add_employee_function"))
        self.see_my_employee_button = Button(text="See My Employee", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.see_my_employee_button)
        self.see_my_employee_button.bind(on_release = lambda x: self.set_function("see_my_employee_function"))
        self.remove_employee_button = Button(text="Remove Employee", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.remove_employee_button)
        self.remove_employee_button.bind(on_release = lambda x: self.set_function("remove_employee_function"))
        self.see_all_requested_patient_button = Button(text="See All Requested Patient", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.see_all_requested_patient_button)
        self.see_all_requested_patient_button.bind(on_release = lambda x: self.set_function("see_all_requested_patient_function"))
        self.see_all_patients_of_my_specialty_button = Button(text="See All Patients of My Specialty", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.see_all_patients_of_my_specialty_button)
        self.see_all_patients_of_my_specialty_button.bind(on_release = lambda x: self.set_function("see_all_patients_of_my_specialty_function"))
        self.see_my_patient_button = Button(text="See My Patient", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.see_my_patient_button)
        self.see_my_patient_button.bind(on_release = lambda x: self.set_function("see_my_patient_function"))
        self.see_patients_report_button = Button(text="See Patients Report", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.see_patients_report_button)
        self.see_patients_report_button.bind(on_release = lambda x: self.set_function("see_patients_report_function"))
        self.remove_patient_button = Button(text="Remove Patient", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.remove_patient_button)    
        self.remove_patient_button.bind(on_release = lambda x: self.set_function("remove_patient_function"))    

        self.add_widget(self.info_grid)
    
    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "DoctorFunctions":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "DoctorAfterLogin"

    def set_function(self, function_name):
        sm.add_widget(DoctorDisplayFunction(function_name, name="DoctorDisplayFunction"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "DoctorDisplayFunction"



class DoctorDisplayFunction(Screen):
    def __init__(self, function_name, **kwargs):
        super().__init__(**kwargs)

        self.username = self.find_my_username()
        self.category = "doctor"
        self.function_name = function_name
        with self.canvas:
            Color(1, 1, 1,1,mode="rgba")
            Rectangle(pos = self.pos, size = (800,600))
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text="Doctor Functions", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)        

        if self.function_name == "salary_function":
            final_function = self.salary_function
        elif self.function_name == "show_all_employee_function":
            final_function = self.show_all_employee_function
        elif self.function_name == "add_employee_function":
            final_function = self.add_employee_function
        elif self.function_name == "see_my_employee_function":
            final_function = self.see_my_employee_function
        elif self.function_name == "remove_employee_function":
            final_function = self.remove_employee_function
        elif self.function_name == "see_all_requested_patient_function":
            final_function = self.see_all_requested_patient_function
        elif self.function_name == "see_all_patients_of_my_specialty_function":
            final_function = self.see_all_patients_of_my_specialty_function
        elif self.function_name == "see_my_patient_function":
            final_function = self.see_my_patient_function
        elif self.function_name == "see_patients_report_function":
            final_function = self.see_patients_report_function
        else:
            final_function = self.remove_patient_function        

        self.value, size_hint, pos_hint = final_function()
        self.value.size_hint = size_hint
        self.value.pos_hint = pos_hint
        self.add_widget(self.value)

    
    def find_my_username(self):
        return Holder.username
    

    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "DoctorDisplayFunction":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "DoctorFunctions"
        Holder.counter = 0




    def salary_function(self):
        total_earning_list = doctor.salary(Holder.username, True)
        total_earning = total_earning_list[0]
        total_cost = total_earning_list[1]
        nit_salary = total_earning_list[2]

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        size_hint = 0.6, 0.3
        pos_hint = {"x": 0.2, "top": 0.6}

        self.label1 = Label(text = "Total Earning", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label1)
        self.label2 = Label(text = "+" + str(total_earning), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label2)
        self.label3 = Label(text = "Total Cost", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label3)
        self.label4 = Label(text = "-" + str(total_cost), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label4)
        self.label5 = Label(text = "Nit Salary", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label5)
        self.label6 = Label(text = str(nit_salary), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label6)

        return (self.info_grid, size_hint, pos_hint)

    def show_all_employee_function(self):
        self.info_grid = GridLayout()
        self.info_grid.cols = 6
        pos_hint = {"x": 0.05, "top": 0.85}

        user_infos = doctor.show_all_employee(True)
        if len(user_infos) > 20:
            size_hint = 0.9, 8
        elif len(user_infos) > 10:
            size_hint = 0.9, 0.6
        else:
            size_hint = 0.9, 0.35
        
        self.username_topic = Button(text = "Username", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.username_topic)
        self.fullname_topic = Button(text = "Fullname", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.fullname_topic)
        self.email_topic = Button(text = "Email", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1), size_hint_x=None, width=200)
        self.info_grid.add_widget(self.email_topic)
        self.date_of_birth_topic = Button(text = "D O B", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.date_of_birth_topic)
        self.work_topic = Button(text = "Work", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.work_topic)
        self.salary_topic = Button(text = "Salary", font_size = 14, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.salary_topic)

        for user in user_infos:
            self.username_info = Label(text = str(user[0]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.username_info)
            self.fullname_info = Label(text = str(user[1]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.fullname_info)
            self.email_info = Label(text = str(user[2]), font_size = 12, color = (0,0,0,1), size_hint_x=None, width=200)
            self.info_grid.add_widget(self.email_info)
            self.date_of_birth_info = Label(text = str(user[3]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.date_of_birth_info)
            self.work_info = Label(text = str(user[4]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.work_info)
            self.salary_info = Label(text = str(user[5]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.salary_info)

        return (self.info_grid, size_hint, pos_hint)

        

    def add_employee_function(self):
        def current_function():
            try:
                doctor.add_employee(self.username,self.employee_username.text, True)
            except:
                show_add_employee_popup()
            self.employee_username.text = ""

        def show_add_employee_popup():
            popup_layout = FloatLayout()
            first_line = Label(text = "Sorry, Something went Wrong :(", size_hint= (0.6, 0.2), pos_hint= {"x": 0.2, "top":0.9})
            popup_layout.add_widget(first_line)
            second_line = Label(text="Invalid Username", size_hint= (0.6, 0.2), pos_hint= {"x": 0.21, "top":0.5})
            popup_layout.add_widget(second_line)
            popup_window = Popup(title = "Add Employee Error", content = popup_layout, size_hint = (0.6, 0.3))
            popup_window.open()

        self.info_grid = GridLayout()
        self.info_grid.cols = 1
        size_hint = 0.6, 0.2
        pos_hint = {"x": 0.2, "top": 0.6}

        self.question = Label(text = "Enter the Employee Username You Want to Add", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question)
        self.employee_username = TextInput(multiline = False)
        self.info_grid.add_widget(self.employee_username)

        self.submit = Button(text = "Submit")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1, 1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.175}
        self.add_widget(self.submit)
        self.submit.bind(on_release = lambda x: current_function())

        return (self.info_grid, size_hint, pos_hint)


    def see_my_employee_function(self):
        self.info_grid = GridLayout()
        self.info_grid.cols = 6
        pos_hint = {"x": 0.05, "top": 0.75}

        employee_infos = doctor.see_my_employee(self.username,True)
        if len(employee_infos) > 7:
            size_hint = 0.9, 0.6
        elif len(employee_infos) > 3:
            size_hint = 0.9, 0.45
        else:
            size_hint = 0.9, 0.2
        
        self.username_topic = Button(text = "Username", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.username_topic)
        self.fullname_topic = Button(text = "Fullname", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.fullname_topic)
        self.email_topic = Button(text = "Email", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1), size_hint_x=None, width=200)
        self.info_grid.add_widget(self.email_topic)
        self.date_of_birth_topic = Button(text = "Date of Birth", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.date_of_birth_topic)
        self.work_topic = Button(text = "Work", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.work_topic)
        self.salary_topic = Button(text = "Salary", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.salary_topic)

        for employee in employee_infos:
            self.username_info = Label(text = str(employee[0]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.username_info)
            self.fullname_info = Label(text = str(employee[1]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.fullname_info)
            self.email_info = Label(text = str(employee[2]), font_size = 12, color = (0,0,0,1), size_hint_x=None, width=200)
            self.info_grid.add_widget(self.email_info)
            self.date_of_birth_info = Label(text = str(employee[3]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.date_of_birth_info)
            self.work_info = Label(text = str(employee[4]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.work_info)
            self.salary_info = Label(text = str(employee[5]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.salary_info)

        return (self.info_grid, size_hint, pos_hint)


    def remove_employee_function(self):
        def current_function():
            try:
                doctor.remove_employee(self.username, self.employee_username.text, True)
            except:
                show_remove_employee_popup()
            self.employee_username.text = ""

        def show_remove_employee_popup():
            popup_layout = FloatLayout()
            first_line = Label(text = "Sorry, Something went Wrong :(", size_hint= (0.6, 0.2), pos_hint= {"x": 0.2, "top":0.9})
            popup_layout.add_widget(first_line)
            second_line = Label(text="Invalid Username", size_hint= (0.6, 0.2), pos_hint= {"x": 0.21, "top":0.5})
            popup_layout.add_widget(second_line)
            popup_window = Popup(title = "Remove Employee Error", content = popup_layout, size_hint = (0.6, 0.3))
            popup_window.open()

        self.info_grid = GridLayout()
        self.info_grid.cols = 1
        size_hint = 0.6, 0.2
        pos_hint = {"x": 0.2, "top": 0.6}

        self.question = Label(text = "Enter the Employee Username You Want to Remove", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question)
        self.employee_username = TextInput(multiline = False)
        self.info_grid.add_widget(self.employee_username)

        self.submit = Button(text = "Submit")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1, 1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.175}
        self.add_widget(self.submit)
        self.submit.bind(on_release = lambda x: current_function())

        return (self.info_grid, size_hint, pos_hint)

    
    def see_all_requested_patient_function(self):
        self.info_grid = GridLayout()
        self.info_grid.cols = 5
        pos_hint = {"x": 0.05, "top": 0.75}

        patient_infos = doctor.see_all_requested_patient(self.username,True)
        if len(patient_infos) > 7:
            size_hint = 0.9, 0.6
        elif len(patient_infos) > 3:
            size_hint = 0.9, 0.45
        else:
            size_hint = 0.9, 0.2
        
        self.username_topic = Button(text = "Username", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.username_topic)
        self.fullname_topic = Button(text = "Fullname", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.fullname_topic)
        self.email_topic = Button(text = "Email", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1), size_hint_x=None, width=200)
        self.info_grid.add_widget(self.email_topic)
        self.date_of_birth_topic = Button(text = "Date of Birth", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.date_of_birth_topic)
        self.problem_topic = Button(text = "Problem", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.problem_topic)

        for patient in patient_infos:
            self.username_info = Label(text = str(patient[0]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.username_info)
            self.fullname_info = Label(text = str(patient[1]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.fullname_info)
            self.email_info = Label(text = str(patient[2]), font_size = 12, color = (0,0,0,1), size_hint_x=None, width=200)
            self.info_grid.add_widget(self.email_info)
            self.date_of_birth_info = Label(text = str(patient[3]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.date_of_birth_info)
            self.problem_info = Label(text = str(patient[4]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.problem_info)

        return (self.info_grid, size_hint, pos_hint)


    def see_all_patients_of_my_specialty_function(self):
        self.info_grid = GridLayout()
        self.info_grid.cols = 6
        pos_hint = {"x": 0.05, "top": 0.75}

        patient_infos = doctor.see_all_patients_of_my_specialty(self.username,True)
        if len(patient_infos) > 7:
            size_hint = 0.9, 0.6
        elif len(patient_infos) > 3:
            size_hint = 0.9, 0.45
        else:
            size_hint = 0.9, 0.2
        
        self.username_topic = Button(text = "Username", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.username_topic)
        self.fullname_topic = Button(text = "Fullname", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.fullname_topic)
        self.email_topic = Button(text = "Email", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1), size_hint_x=None, width=200)
        self.info_grid.add_widget(self.email_topic)
        self.date_of_birth_topic = Button(text = "Date of Birth", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.date_of_birth_topic)
        self.requested_topic = Button(text = "Requested", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.requested_topic)
        self.approved_topic = Button(text = "Approved", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.approved_topic)

        for patient in patient_infos:
            self.username_info = Label(text = str(patient[0]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.username_info)
            self.fullname_info = Label(text = str(patient[1]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.fullname_info)
            self.email_info = Label(text = str(patient[2]), font_size = 12, color = (0,0,0,1), size_hint_x=None, width=200)
            self.info_grid.add_widget(self.email_info)
            self.date_of_birth_info = Label(text = str(patient[3]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.date_of_birth_info)
            self.requested_info = Label(text = str(patient[4]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.requested_info)
            self.approved_info = Label(text = str(patient[4]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.approved_info)

        return (self.info_grid, size_hint, pos_hint)


    def see_my_patient_function(self):
        self.info_grid = GridLayout()
        self.info_grid.cols = 6
        pos_hint = {"x": 0.05, "top": 0.75}

        patient_infos = doctor.see_my_patient(self.username,True)
        if len(patient_infos) > 7:
            size_hint = 0.9, 0.6
        elif len(patient_infos) > 3:
            size_hint = 0.9, 0.45
        else:
            size_hint = 0.9, 0.2
        
        self.username_topic = Button(text = "Username", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.username_topic)
        self.fullname_topic = Button(text = "Fullname", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.fullname_topic)
        self.email_topic = Button(text = "Email", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1), size_hint_x=None, width=200)
        self.info_grid.add_widget(self.email_topic)
        self.date_of_birth_topic = Button(text = "Date of Birth", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.date_of_birth_topic)
        self.problem_topic = Button(text = "Problem", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.problem_topic)
        self.appointment_timestamp_topic = Button(text = "Appoint TS", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1), size_hint_x=None, width=150)
        self.info_grid.add_widget(self.appointment_timestamp_topic)

        for patient in patient_infos:
            self.username_info = Label(text = str(patient[0]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.username_info)
            self.fullname_info = Label(text = str(patient[1]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.fullname_info)
            self.email_info = Label(text = str(patient[2]), font_size = 12, color = (0,0,0,1), size_hint_x=None, width=200)
            self.info_grid.add_widget(self.email_info)
            self.date_of_birth_info = Label(text = str(patient[3]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.date_of_birth_info)
            self.problem_info = Label(text = str(patient[4]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.problem_info)
            self.appointment_timestamp_info = Label(text = str(patient[5]), font_size = 12, color = (0,0,0,1), size_hint_x=None, width=150)
            self.info_grid.add_widget(self.appointment_timestamp_info)

        return (self.info_grid, size_hint, pos_hint)


    def see_patients_report_function(self):
        def current_function():
            try:
                doctor.see_patients_report(self.patient_username.text, self.report_name.text, True)
            except:
                show_see_patients_report_popup()
            self.patient_username.text = ""
            self.report_name.text = ""

        def show_see_patients_report_popup():
            popup_layout = FloatLayout()
            first_line = Label(text = "Sorry, Something went Wrong :(", size_hint= (0.6, 0.2), pos_hint= {"x": 0.2, "top":0.9})
            popup_layout.add_widget(first_line)
            second_line = Label(text="Invalid Username or Report Name", size_hint= (0.6, 0.2), pos_hint= {"x": 0.21, "top":0.5})
            popup_layout.add_widget(second_line)
            popup_window = Popup(title = "Show Patient Report Error", content = popup_layout, size_hint = (0.6, 0.3))
            popup_window.open()

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        size_hint = 0.6, 0.2
        pos_hint = {"x": 0.2, "top": 0.62}

        self.question = Label(text = "Patient Username", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question)
        self.patient_username = TextInput(multiline = False)
        self.info_grid.add_widget(self.patient_username)

        self.question2 = Label(text = "Report Name", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question2)
        self.report_name = TextInput(multiline = False)
        self.info_grid.add_widget(self.report_name)

        self.submit = Button(text = "Submit")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1, 1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.175}
        self.add_widget(self.submit)
        self.submit.bind(on_release = lambda x: current_function())

        return (self.info_grid, size_hint, pos_hint)

    
    def remove_patient_function(self):
        def current_function():
            try:
                doctor.remove_patient(self.patient_username.text, True)
            except:
                show_remove_patient_popup()
            self.patient_username.text = ""

        def show_remove_patient_popup():
            popup_layout = FloatLayout()
            first_line = Label(text = "Sorry, Something went Wrong :(", size_hint= (0.6, 0.2), pos_hint= {"x": 0.2, "top":0.9})
            popup_layout.add_widget(first_line)
            second_line = Label(text="Invalid Username", size_hint= (0.6, 0.2), pos_hint= {"x": 0.21, "top":0.5})
            popup_layout.add_widget(second_line)
            popup_window = Popup(title = "Remove Patient Error", content = popup_layout, size_hint = (0.6, 0.3))
            popup_window.open()

        self.info_grid = GridLayout()
        self.info_grid.cols = 1
        size_hint = 0.6, 0.2
        pos_hint = {"x": 0.2, "top": 0.6}

        self.question = Label(text = "Enter the Patient Username You Want to Remove", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question)
        self.patient_username = TextInput(multiline = False)
        self.info_grid.add_widget(self.patient_username)

        self.submit = Button(text = "Submit")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1, 1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.175}
        self.add_widget(self.submit)
        self.submit.bind(on_release = lambda x: current_function())

        return (self.info_grid, size_hint, pos_hint)





# Patient Functions
class PatientFunctions(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.username = self.find_my_username()
        self.category = "patient"
        with self.canvas:
            Color(1, 1, 1,1,mode="rgba")
            Rectangle(pos = self.pos, size = (800,600))
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text="Patient Functions", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.info_grid = GridLayout()
        self.info_grid.cols = 1
        self.info_grid.pos_hint = {"x": 0.2, "top": 0.82}
        self.info_grid.size_hint = 0.6, 0.7

        self.cost_button = Button(text="Total Cost", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.cost_button)
        self.cost_button.bind(on_release = lambda x: self.set_function("cost_function"))
        self.remaining_appointment_time_button = Button(text="Remaining Appointment Time", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.remaining_appointment_time_button)
        self.remaining_appointment_time_button.bind(on_release = lambda x: self.set_function("remaining_appointment_time_function"))
        self.add_report_button = Button(text="Add Report", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.add_report_button)
        self.add_report_button.bind(on_release = lambda x: self.set_function("add_report_function"))
        self.see_all_doctors_for_my_problem_button = Button(text="See All Doctors for My Problem", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.see_all_doctors_for_my_problem_button)
        self.see_all_doctors_for_my_problem_button.bind(on_release = lambda x: self.set_function("see_all_doctors_for_my_problem_function"))
        self.request_doctor_button = Button(text="Request Doctor", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.request_doctor_button)  
        self.request_doctor_button.bind(on_release = lambda x: self.set_function("request_doctor_function"))  
        self.remove_request_button = Button(text="Remove Request", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.remove_request_button)
        self.remove_request_button.bind(on_release = lambda x: self.set_function("remove_request_function"))
        self.see_my_doctors_stat_button = Button(text="See My Doctors Stat", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.see_my_doctors_stat_button)    
        self.see_my_doctors_stat_button.bind(on_release = lambda x: self.set_function("see_my_doctors_stat_function"))    

        self.add_widget(self.info_grid)
    
    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "PatientFunctions":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "PatientAfterLogin"

    def set_function(self, function_name):
        sm.add_widget(PatientDisplayFunction(function_name, name="PatientDisplayFunction"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "PatientDisplayFunction"



class PatientDisplayFunction(Screen):
    def __init__(self, function_name, **kwargs):
        super().__init__(**kwargs)

        self.username = self.find_my_username()
        self.category = "patient"
        self.function_name = function_name
        with self.canvas:
            Color(1, 1, 1,1,mode="rgba")
            Rectangle(pos = self.pos, size = (800,600))
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text="Patient Functions", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)        

        if self.function_name == "cost_function":
            final_function = self.cost_function
        elif self.function_name == "remaining_appointment_time_function":
            final_function = self.remaining_appointment_time_function
        elif self.function_name == "add_report_function":
            final_function = self.add_report_function
        elif self.function_name == "see_all_doctors_for_my_problem_function":
            final_function = self.see_all_doctors_for_my_problem_function
        elif self.function_name == "request_doctor_function":
            final_function = self.request_doctor_function
        elif self.function_name == "remove_request_function":
            final_function = self.remove_request_function
        else:
            final_function = self.see_my_doctors_stat_function        

        self.value, size_hint, pos_hint = final_function()
        self.value.size_hint = size_hint
        self.value.pos_hint = pos_hint
        self.add_widget(self.value)

    
    def find_my_username(self):
        return Holder.username
    

    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "PatientDisplayFunction":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "PatientFunctions"
        Holder.counter = 0

    def cost_function(self):
        total_earning_list = patient.cost(Holder.username, True)
        doctor_charge = total_earning_list[0]
        hospital_charge = total_earning_list[1]
        total_charge = total_earning_list[2]

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        size_hint = 0.6, 0.3
        pos_hint = {"x": 0.2, "top": 0.6}

        self.label1 = Label(text = "Doctor's Charge:", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label1)
        self.label2 = Label(text = "+" + str(doctor_charge), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label2)
        self.label3 = Label(text = "Hospital's Charge:", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label3)
        self.label4 = Label(text = "+" + str(hospital_charge), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label4)
        self.label5 = Label(text = "Total Charge:", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label5)
        self.label6 = Label(text = str(total_charge), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label6)

        return (self.info_grid, size_hint, pos_hint)

    def remaining_appointment_time_function(self):
        timestamp = str(patient.remaining_appointment_time(Holder.username, True))

        day, time = timestamp.split(", ")
        hour, minute, sec = time.split(":")

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        size_hint = 0.6, 0.3
        pos_hint = {"x": 0.2, "top": 0.62}

        self.label1 = Label(text = "Day:", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label1)
        self.label2 = Label(text = str(day), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label2)
        self.label3 = Label(text = "Hour:", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label3)
        self.label4 = Label(text = str(hour) + " hours", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label4)
        self.label5 = Label(text = "Minute:", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label5)
        self.label6 = Label(text = str(minute)+ " minutes", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label6)

        return (self.info_grid, size_hint, pos_hint)

    def add_report_function(self):
        def current_function():
            if self.report_name.text == "" or self.report_url.text == "":
                show_add_report_popup()
            try:
                patient.add_report(self.report_name.text, self.report_url.text, self.username, True)
            except:
                show_add_report_popup()
            self.report_name.text = ""
            self.report_url.text = ""

        def show_add_report_popup():
            popup_layout = FloatLayout()
            first_line = Label(text = "Sorry, Something went Wrong :(", size_hint= (0.6, 0.2), pos_hint= {"x": 0.2, "top":0.9})
            popup_layout.add_widget(first_line)
            second_line = Label(text="Invalid Username or Report Name", size_hint= (0.6, 0.2), pos_hint= {"x": 0.21, "top":0.5})
            popup_layout.add_widget(second_line)
            popup_window = Popup(title = "Add Report Error", content = popup_layout, size_hint = (0.6, 0.3))
            popup_window.open()

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        size_hint = 0.6, 0.2
        pos_hint = {"x": 0.2, "top": 0.62}

        self.question1 = Label(text = "Report Name", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question1)
        self.report_name = TextInput(multiline = False)
        self.info_grid.add_widget(self.report_name)

        self.question2 = Label(text = "Report Url", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question2)
        self.report_url = TextInput(multiline = False)
        self.info_grid.add_widget(self.report_url)

        self.submit = Button(text = "Submit")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1, 1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.175}
        self.add_widget(self.submit)
        self.submit.bind(on_release = lambda x: current_function())

        return (self.info_grid, size_hint, pos_hint)

    def see_all_doctors_for_my_problem_function(self):
        self.info_grid = GridLayout()
        self.info_grid.cols = 5
        pos_hint = {"x": 0.05, "top": 0.75}

        doctor_infos = patient.see_all_doctors_for_my_problem(self.username,True)
        if len(doctor_infos) > 7:
            size_hint = 0.9, 0.6
        elif len(doctor_infos) > 3:
            size_hint = 0.9, 0.45
        else:
            size_hint = 0.9, 0.2
        
        self.username_topic = Button(text = "Username", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.username_topic)
        self.fullname_topic = Button(text = "Fullname", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.fullname_topic)
        self.email_topic = Button(text = "Email", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1), size_hint_x=None, width=200)
        self.info_grid.add_widget(self.email_topic)
        self.date_of_birth_topic = Button(text = "Date of Birth", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.date_of_birth_topic)
        self.salary_topic = Button(text = "Salary", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.salary_topic)


        for doctor in doctor_infos:
            self.username_info = Label(text = str(doctor[0]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.username_info)
            self.fullname_info = Label(text = str(doctor[1]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.fullname_info)
            self.email_info = Label(text = str(doctor[2]), font_size = 12, color = (0,0,0,1), size_hint_x=None, width=200)
            self.info_grid.add_widget(self.email_info)
            self.date_of_birth_info = Label(text = str(doctor[3]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.date_of_birth_info)
            self.salary_info = Label(text = str(doctor[4]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.salary_info)

        return (self.info_grid, size_hint, pos_hint)

    def request_doctor_function(self):
        def current_function():
            try:
                patient.request_doctor(self.username,self.doctor_username.text, True)
            except:
                show_request_doctor_popup()
            self.doctor_username.text = ""

        def show_request_doctor_popup():
            popup_layout = FloatLayout()
            first_line = Label(text = "Sorry, Something went Wrong :(", size_hint= (0.6, 0.2), pos_hint= {"x": 0.2, "top":0.9})
            popup_layout.add_widget(first_line)
            second_line = Label(text="Invalid Username", size_hint= (0.6, 0.2), pos_hint= {"x": 0.21, "top":0.5})
            popup_layout.add_widget(second_line)
            popup_window = Popup(title = "Request Doctor Error", content = popup_layout, size_hint = (0.6, 0.3))
            popup_window.open()

        self.info_grid = GridLayout()
        self.info_grid.cols = 1
        size_hint = 0.6, 0.2
        pos_hint = {"x": 0.2, "top": 0.6}

        self.question = Label(text = "Enter the Doctor Username You Want to Request", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question)
        self.doctor_username = TextInput(multiline = False)
        self.info_grid.add_widget(self.doctor_username)

        self.submit = Button(text = "Submit")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1, 1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.175}
        self.add_widget(self.submit)
        self.submit.bind(on_release = lambda x: current_function())

        return (self.info_grid, size_hint, pos_hint)


    def remove_request_function(self):
        patient.remove_request(self.username, True)

        self.info_grid = Label(text = "Successfully removed request :)", font_size = 25, color = (0/255, 153/255, 204/255, 1))
        size_hint = 0,0
        pos_hint = {"x": 0.52, "top": 0.5}

        return(self.info_grid, size_hint, pos_hint)


    def see_my_doctors_stat_function(self):
        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        pos_hint = {"x": 0.31, "top": 0.65}

        doctor_info = patient.see_my_doctors_stat(self.username,True)
        size_hint = 0.5, 0.4
        
        self.username_topic = Button(text = "Username", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.username_topic)
        self.username_info = Label(text = str(doctor_info[0]), font_size = 12, color = (0,0,0,1))
        self.info_grid.add_widget(self.username_info)
        self.fullname_topic = Button(text = "Fullname", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.fullname_topic)
        self.fullname_info = Label(text = str(doctor_info[1]), font_size = 12, color = (0,0,0,1))
        self.info_grid.add_widget(self.fullname_info)
        self.email_topic = Button(text = "Email", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.email_topic)
        self.email_info = Label(text = str(doctor_info[2]), font_size = 12, color = (0,0,0,1))
        self.info_grid.add_widget(self.email_info)
        self.date_of_birth_topic = Button(text = "Date of Birth", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.date_of_birth_topic)
        self.date_of_birth_info = Label(text = str(doctor_info[3]), font_size = 12, color = (0,0,0,1))
        self.info_grid.add_widget(self.date_of_birth_info)
        self.salary_topic = Button(text = "Salary", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.salary_topic)
        self.salary_info = Label(text = str(doctor_info[4]), font_size = 12, color = (0,0,0,1))
        self.info_grid.add_widget(self.salary_info)
        self.appointment_timestamp_topic = Button(text = "Appointment Timestamp", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.appointment_timestamp_topic)
        self.appointment_timestamp_info = Label(text = str(doctor_info[5]), font_size = 12, color = (0,0,0,1))
        self.info_grid.add_widget(self.appointment_timestamp_info)            

        return (self.info_grid, size_hint, pos_hint)
        




# Employee Functions
class EmployeeFunctions(Screen):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.username = self.find_my_username()
        self.category = "employee"
        self.is_receptionist = employee.isreceptionist(self.username, True)
        with self.canvas:
            Color(1, 1, 1,1,mode="rgba")
            Rectangle(pos = self.pos, size = (800,600))
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text="Employee Functions", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.info_grid = GridLayout()
        self.info_grid.cols = 1
        self.info_grid.pos_hint = {"x": 0.2, "top": 0.82}
        self.info_grid.size_hint = 0.6, 0.7

        self.salary_button = Button(text="Salary", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.salary_button)
        self.salary_button.bind(on_release = lambda x: self.set_function("salary_function"))
        self.see_my_doctors_button = Button(text="See My Doctors", background_color = (0.75, 0.75, 0.75, 1), color= (1,1,1,1), font_size = 14)
        self.info_grid.add_widget(self.see_my_doctors_button)   
        self.see_my_doctors_button.bind(on_release = lambda x: self.set_function("see_my_doctors_function"))
        if self.is_receptionist:
            self.appoint_doctor_button = Button(text="Appoint Doctor", background_color = (0/255, 153/255, 204/255, 1), color= (1,1,1,1), font_size = 14)
            self.info_grid.add_widget(self.appoint_doctor_button)
            self.appoint_doctor_button.bind(on_release = lambda x: self.set_function("appoint_doctor_function"))


        self.add_widget(self.info_grid)
    
    def find_my_username(self):
        return Holder.username
    
    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "EmployeeFunctions":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "EmployeeAfterLogin"

    def set_function(self, function_name):
        sm.add_widget(EmployeeDisplayFunction(function_name, name="EmployeeDisplayFunction"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "EmployeeDisplayFunction"



class EmployeeDisplayFunction(Screen):
    def __init__(self, function_name, **kwargs):
        super().__init__(**kwargs)

        self.username = self.find_my_username()
        self.category = "employee"
        self.function_name = function_name
        with self.canvas:
            Color(1, 1, 1,1,mode="rgba")
            Rectangle(pos = self.pos, size = (800,600))
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
        self.title = Label(text="Employee Functions", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"x":0.05, "top": 1.45}
        self.add_widget(self.title)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.close_button = Button(background_normal="resources/close.png", background_down="resources/close_down.png") 
        self.close_button.size_hint = (None, None)
        self.close_button.width = 60
        self.close_button.height = 60
        self.close_button.color = (0,0,0,1)
        self.close_button.pos_hint = {"x": 0.85, "top": 0.99}
        self.add_widget(self.close_button)
        self.close_button.bind(on_release = self.go_back)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline= Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)        

        if self.function_name == "salary_function":
            final_function = self.salary_function
        elif self.function_name == "see_my_doctors_function":
            final_function = self.see_my_doctors_function
        else:
            final_function = self.appoint_doctor_function        

        self.value, size_hint, pos_hint = final_function()
        self.value.size_hint = size_hint
        self.value.pos_hint = pos_hint
        self.add_widget(self.value)

    
    def find_my_username(self):
        return Holder.username
    

    def go_back(self, instance):
        for screen in sm.screens:
            if screen.name == "EmployeeDisplayFunction":
                sm.screens.remove(screen)
        sm.transition = SlideTransition(direction = "right")
        sm.current = "EmployeeFunctions"
        Holder.counter = 0


    def salary_function(self):
        total_earning_list = employee.salary(Holder.username, True)
        initial_salary = total_earning_list[0]
        hospital_cost = total_earning_list[1]
        nit_salary = total_earning_list[2]

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        size_hint = 0.6, 0.3
        pos_hint = {"x": 0.2, "top": 0.6}

        self.label1 = Label(text = "Initial Salary", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label1)
        self.label2 = Label(text = "+" + str(initial_salary), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label2)
        self.label3 = Label(text = "Hospital Cost", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label3)
        self.label4 = Label(text = "-" + str(hospital_cost), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label4)
        self.label5 = Label(text = "Nit Salary", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label5)
        self.label6 = Label(text = str(nit_salary), color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.label6)

        return (self.info_grid, size_hint, pos_hint)


    def see_my_doctors_function(self):
        self.info_grid = GridLayout()
        self.info_grid.cols = 5
        pos_hint = {"x": 0.05, "top": 0.75}

        doctor_infos = employee.see_my_doctors(self.username,True)
        if len(doctor_infos) > 7:
            size_hint = 0.9, 0.6
        elif len(doctor_infos) > 3:
            size_hint = 0.9, 0.45
        else:
            size_hint = 0.9, 0.2
        
        self.username_topic = Button(text = "Username", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.username_topic)
        self.fullname_topic = Button(text = "Fullname", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.fullname_topic)
        self.email_topic = Button(text = "Email", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1), size_hint_x=None, width=200)
        self.info_grid.add_widget(self.email_topic)
        self.date_of_birth_topic = Button(text = "Date of Birth", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.date_of_birth_topic)
        self.specialty_topic = Button(text = "Specialty", font_size = 15, color = (1,1,1,1), background_color = (0/255, 153/255, 204/255, 1))
        self.info_grid.add_widget(self.specialty_topic)

        for doctor in doctor_infos:
            self.username_info = Label(text = str(doctor[0]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.username_info)
            self.fullname_info = Label(text = str(doctor[1]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.fullname_info)
            self.email_info = Label(text = str(doctor[2]), font_size = 12, color = (0,0,0,1), size_hint_x=None, width=200)
            self.info_grid.add_widget(self.email_info)
            self.date_of_birth_info = Label(text = str(doctor[3]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.date_of_birth_info)
            self.specialty_info = Label(text = str(doctor[4]), font_size = 12, color = (0,0,0,1))
            self.info_grid.add_widget(self.specialty_info)

        return (self.info_grid, size_hint, pos_hint)


    def appoint_doctor_function(self):
        def current_function():
            try:
                employee.appoint_doctor(self.username, self.doctor_username.text, self.patient_username.text, self.appointment_timestamp.text, True)
            except:
                show_appoint_doctor_popup()
            self.doctor_username.text = ""
            self.patient_username.text = ""
            self.appointment_timestamp.text = "YYYY-MM-DD HH:MM:SS"

        def show_appoint_doctor_popup():
            popup_layout = FloatLayout()
            first_line = Label(text = "Sorry, Something went Wrong :(", size_hint= (0.6, 0.2), pos_hint= {"x": 0.2, "top":0.9})
            popup_layout.add_widget(first_line)
            second_line = Label(text="Invalid Username or Date Format", size_hint= (0.6, 0.2), pos_hint= {"x": 0.21, "top":0.5})
            popup_layout.add_widget(second_line)
            popup_window = Popup(title = "Appoint Doctor Error", content = popup_layout, size_hint = (0.6, 0.3))
            popup_window.open()

        self.info_grid = GridLayout()
        self.info_grid.cols = 2
        size_hint = 0.6, 0.2
        pos_hint = {"x": 0.2, "top": 0.65}

        self.question1 = Label(text = "Doctor Username:", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question1)
        self.doctor_username = TextInput(multiline = False)
        self.info_grid.add_widget(self.doctor_username)

        self.question2 = Label(text = "Patient Username:", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question2)
        self.patient_username = TextInput(multiline = False)
        self.info_grid.add_widget(self.patient_username)

        self.question3 = Label(text = "Appointment Timestamp:", color = (0,0,0,1), font_size = 16)
        self.info_grid.add_widget(self.question3)
        self.appointment_timestamp = TextInput(text = "YYYY-MM-DD HH:MM:SS", multiline = False)
        self.info_grid.add_widget(self.appointment_timestamp)


        self.submit = Button(text = "Submit")
        self.submit.font_size = 18
        self.submit.color = (1, 1, 1, 1)
        self.submit.italic = True
        self.submit.background_color = (0/255, 153/255, 204/255, 1)
        self.submit.size_hint = (0.3,0.08)
        self.submit.pos_hint = {"x":0.36, "top": 0.175}
        self.add_widget(self.submit)
        self.submit.bind(on_release = lambda x: current_function())

        return (self.info_grid, size_hint, pos_hint)







# AdminAfterLogin Class
class AdminAfterLogin(Screen, Widget):
    def __init__(self,**kwargs):
        super().__init__(**kwargs)
        with self.canvas:
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
            Color(0.4, 0.4, 0.4,1,mode="rgba")
            Line(points = ((410, 80),(410, 280)), width = 2)
            Line(points = ((180, 175),(620, 175)), width = 2)
        self.title = Label(text="Admin Panel", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"top": 1.45}
        self.add_widget(self.title)

        self.add_notifications_button = Button(background_normal="resources/add_notifications.png", background_down="resources/add_notifications_down.png") 
        self.add_notifications_button.size_hint = (None, None)
        self.add_notifications_button.width = 70
        self.add_notifications_button.height = 70
        self.add_notifications_button.color = (0,0,0,1)
        self.add_notifications_button.pos_hint = {"x": 0.72, "top": 1}
        self.add_widget(self.add_notifications_button)
        self.add_notifications_button.bind(on_release = self.go_to_add_notifications)

        self.notifications_button = Button(background_normal="resources/notifications.png", background_down="resources/notifications_down.png") 
        self.notifications_button.size_hint = (None, None)
        self.notifications_button.width = 70
        self.notifications_button.height = 70
        self.notifications_button.color = (0,0,0,1)
        self.notifications_button.pos_hint = {"x": 0.80, "top": 1}
        self.add_widget(self.notifications_button)
        self.notifications_button.bind(on_release = self.go_to_notifications)

        self.profile_button = Button(background_normal="resources/profile.png", background_down="resources/profile_down.png") 
        self.profile_button.size_hint = (None, None)
        self.profile_button.width = 70
        self.profile_button.height = 70
        self.profile_button.color = (0,0,0,1)
        self.profile_button.pos_hint = {"x": 0.88, "top": 1}
        self.add_widget(self.profile_button)
        self.profile_button.bind(on_release = self.go_to_profile)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline = Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.functions_label = Label(text="Functions", font_size=15, color=(0,0,0,1))
        self.functions_label.pos_hint = {"x":-0.19, "top": 0.82}
        self.add_widget(self.functions_label)

        self.about_hospital_label = Label(text="About Hospital", font_size=15, color=(0,0,0,1))
        self.about_hospital_label.pos_hint = {"x":-0.187, "top": 0.61}
        self.add_widget(self.about_hospital_label)

        self.settings_label = Label(text="Settings", font_size=15, color=(0,0,0,1))
        self.settings_label.pos_hint = {"x":0.213, "top": 0.825}
        self.add_widget(self.settings_label)

        self.documentation_label = Label(text="Documentation", font_size=15, color=(0,0,0,1))
        self.documentation_label.pos_hint = {"x":0.215, "top": 0.615}
        self.add_widget(self.documentation_label)

    def go_to_profile(self, instance):
        sm.add_widget(AdminProfile(name = "AdminProfile"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "AdminProfile"
    
    def go_to_notifications(self, instance):
        sm.add_widget(AdminNotifications(name = "AdminNotifications"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "AdminNotifications"

    def go_to_add_notifications(self, instance):
        sm.add_widget(AdminAddNotifications(name = "AdminAddNotifications"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "AdminAddNotifications"

    def go_to_settings(self):
        Window.clearcolor = (1,1,1,1)
        sm.add_widget(AdminSettings(name = "AdminSettings"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "AdminSettings"

    def go_to_functions(self):
        sm.add_widget(AdminFunctions(name = "AdminFunctions"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "AdminFunctions"
        

        


# DoctorAfterLogin Class
class DoctorAfterLogin(Screen, Widget):
    def __init__(self,**kwargs):
        super().__init__(**kwargs)
        with self.canvas:
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
            Color(0.4, 0.4, 0.4,1,mode="rgba")
            Line(points = ((410, 80),(410, 280)), width = 2)
            Line(points = ((180, 175),(620, 175)), width = 2)
        self.title = Label(text="Doctor Panel", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"top": 1.45}
        self.add_widget(self.title)

        self.add_notifications_button = Button(background_normal="resources/add_notifications.png", background_down="resources/add_notifications_down.png") 
        self.add_notifications_button.size_hint = (None, None)
        self.add_notifications_button.width = 70
        self.add_notifications_button.height = 70
        self.add_notifications_button.color = (0,0,0,1)
        self.add_notifications_button.pos_hint = {"x": 0.72, "top": 1}
        self.add_widget(self.add_notifications_button)
        self.add_notifications_button.bind(on_release = self.go_to_add_notifications)

        self.notifications_button = Button(background_normal="resources/notifications.png", background_down="resources/notifications_down.png") 
        self.notifications_button.size_hint = (None, None)
        self.notifications_button.width = 70
        self.notifications_button.height = 70
        self.notifications_button.color = (0,0,0,1)
        self.notifications_button.pos_hint = {"x": 0.80, "top": 1}
        self.add_widget(self.notifications_button)
        self.notifications_button.bind(on_release = self.go_to_notifications)

        self.profile_button = Button(background_normal="resources/profile.png", background_down="resources/profile_down.png") 
        self.profile_button.size_hint = (None, None)
        self.profile_button.width = 70
        self.profile_button.height = 70
        self.profile_button.color = (0,0,0,1)
        self.profile_button.pos_hint = {"x": 0.88, "top": 1}
        self.add_widget(self.profile_button)
        self.profile_button.bind(on_release = self.go_to_profile)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline = Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.functions_label = Label(text="Functions", font_size=15, color=(0,0,0,1))
        self.functions_label.pos_hint = {"x":-0.19, "top": 0.82}
        self.add_widget(self.functions_label)

        self.about_hospital_label = Label(text="About Hospital", font_size=15, color=(0,0,0,1))
        self.about_hospital_label.pos_hint = {"x":-0.187, "top": 0.61}
        self.add_widget(self.about_hospital_label)

        self.settings_label = Label(text="Settings", font_size=15, color=(0,0,0,1))
        self.settings_label.pos_hint = {"x":0.213, "top": 0.825}
        self.add_widget(self.settings_label)

        self.documentation_label = Label(text="Documentation", font_size=15, color=(0,0,0,1))
        self.documentation_label.pos_hint = {"x":0.215, "top": 0.615}
        self.add_widget(self.documentation_label)

    def go_to_profile(self, instance):
        sm.add_widget(DoctorProfile(name = "DoctorProfile"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "DoctorProfile"

    def go_to_notifications(self, instance):
        sm.add_widget(DoctorNotifications(name = "DoctorNotifications"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "DoctorNotifications"

    def go_to_add_notifications(self, instance):
        sm.add_widget(DoctorAddNotifications(name = "DoctorAddNotifications"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "DoctorAddNotifications"

    def go_to_settings(self):
        sm.add_widget(DoctorSettings(name = "DoctorSettings"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "DoctorSettings"

    def go_to_functions(self):
        sm.add_widget(DoctorFunctions(name = "DoctorFunctions"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "DoctorFunctions"





# PatientAfterLogin Class
class PatientAfterLogin(Screen, Widget):
    def __init__(self,**kwargs):
        super().__init__(**kwargs)
        with self.canvas:
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
            Color(0.4, 0.4, 0.4,1,mode="rgba")
            Line(points = ((410, 80),(410, 280)), width = 2)
            Line(points = ((180, 175),(620, 175)), width = 2)
        self.title = Label(text="Patient Panel", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"top": 1.45}
        self.add_widget(self.title)

        self.add_notifications_button = Button(background_normal="resources/add_notifications.png", background_down="resources/add_notifications_down.png") 
        self.add_notifications_button.size_hint = (None, None)
        self.add_notifications_button.width = 70
        self.add_notifications_button.height = 70
        self.add_notifications_button.color = (0,0,0,1)
        self.add_notifications_button.pos_hint = {"x": 0.72, "top": 1}
        self.add_widget(self.add_notifications_button)
        self.add_notifications_button.bind(on_release = self.go_to_add_notifications)

        self.notifications_button = Button(background_normal="resources/notifications.png", background_down="resources/notifications_down.png") 
        self.notifications_button.size_hint = (None, None)
        self.notifications_button.width = 70
        self.notifications_button.height = 70
        self.notifications_button.color = (0,0,0,1)
        self.notifications_button.pos_hint = {"x": 0.80, "top": 1}
        self.add_widget(self.notifications_button)
        self.notifications_button.bind(on_release = self.go_to_notifications)        

        self.profile_button = Button(background_normal="resources/profile.png", background_down="resources/profile_down.png") 
        self.profile_button.size_hint = (None, None)
        self.profile_button.width = 70
        self.profile_button.height = 70
        self.profile_button.color = (0,0,0,1)
        self.profile_button.pos_hint = {"x": 0.88, "top": 1}
        self.add_widget(self.profile_button)
        self.profile_button.bind(on_release = self.go_to_profile)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline = Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.functions_label = Label(text="Functions", font_size=15, color=(0,0,0,1))
        self.functions_label.pos_hint = {"x":-0.19, "top": 0.82}
        self.add_widget(self.functions_label)

        self.about_hospital_label = Label(text="About Hospital", font_size=15, color=(0,0,0,1))
        self.about_hospital_label.pos_hint = {"x":-0.187, "top": 0.61}
        self.add_widget(self.about_hospital_label)

        self.settings_label = Label(text="Settings", font_size=15, color=(0,0,0,1))
        self.settings_label.pos_hint = {"x":0.213, "top": 0.825}
        self.add_widget(self.settings_label)

        self.documentation_label = Label(text="Documentation", font_size=15, color=(0,0,0,1))
        self.documentation_label.pos_hint = {"x":0.215, "top": 0.615}
        self.add_widget(self.documentation_label)

    def go_to_profile(self, instance):
        sm.add_widget(PatientProfile(name = "PatientProfile"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "PatientProfile"

    def go_to_notifications(self, instance):
        sm.add_widget(PatientNotifications(name = "PatientNotifications"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "PatientNotifications"
    
    def go_to_add_notifications(self, instance):
        sm.add_widget(PatientAddNotifications(name = "PatientAddNotifications"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "PatientAddNotifications"

    def go_to_settings(self):
        sm.add_widget(PatientSettings(name = "PatientSettings"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "PatientSettings"

    def go_to_functions(self):
        sm.add_widget(PatientFunctions(name = "PatientFunctions"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "PatientFunctions"





# EmployeeAfterLogin Class
class EmployeeAfterLogin(Screen, Widget):
    def __init__(self,**kwargs):
        super().__init__(**kwargs)
        with self.canvas:
            Color(51/255, 153/255, 255/255,1,mode="rgba")
            Line(points = ((0, 580),(1000, 580)), width = 50)
            Line(points = ((0, 0),(1000, 0)), width = 35)
            Color(0.4, 0.4, 0.4,1,mode="rgba")
            Line(points = ((410, 80),(410, 280)), width = 2)
            Line(points = ((180, 175),(620, 175)), width = 2)
        self.title = Label(text="Employee Panel", font_size=40, color=(1,1,1,1))
        self.title.pos_hint= {"top": 1.45}
        self.add_widget(self.title)

        self.add_notifications_button = Button(background_normal="resources/add_notifications.png", background_down="resources/add_notifications_down.png") 
        self.add_notifications_button.size_hint = (None, None)
        self.add_notifications_button.width = 70
        self.add_notifications_button.height = 70
        self.add_notifications_button.color = (0,0,0,1)
        self.add_notifications_button.pos_hint = {"x": 0.72, "top": 1}
        self.add_widget(self.add_notifications_button)
        self.add_notifications_button.bind(on_release = self.go_to_add_notifications)        

        self.notifications_button = Button(background_normal="resources/notifications.png", background_down="resources/notifications_down.png") 
        self.notifications_button.size_hint = (None, None)
        self.notifications_button.width = 70
        self.notifications_button.height = 70
        self.notifications_button.color = (0,0,0,1)
        self.notifications_button.pos_hint = {"x": 0.80, "top": 1}
        self.add_widget(self.notifications_button)
        self.notifications_button.bind(on_release = self.go_to_notifications)

        self.profile_button = Button(background_normal="resources/profile.png", background_down="resources/profile_down.png") 
        self.profile_button.size_hint = (None, None)
        self.profile_button.width = 70
        self.profile_button.height = 70
        self.profile_button.color = (0,0,0,1)
        self.profile_button.pos_hint = {"x": 0.88, "top": 1}
        self.add_widget(self.profile_button)
        self.profile_button.bind(on_release = self.go_to_profile)

        self.logo = Button(background_normal="resources/short_logo.png", background_down="resources/short_logo.png") 
        self.logo.size_hint = (None, None)
        self.logo.width = 120
        self.logo.height = 90
        self.logo.color = (0,0,0,1)
        self.logo.pos_hint = {"x": 0.1, "top": 1.02}
        self.add_widget(self.logo)

        self.tagline = Label(text="Built with Python, PostgreSQL, Psycopg2, and Kivy", font_size=13, color=(1,1,1,1))
        self.tagline.pos_hint = {"x":-0.27, "top": 0.525}
        self.add_widget(self.tagline)

        self.creatorline = Button(text="About Creator: Ahammad Shawki 8", font_size=13, color=(1,1,1,1))
        self.creatorline.pos_hint = {"x":0.7, "top": 0.05}
        self.creatorline.size_hint = (0.28,0.05)
        self.creatorline.background_color = (1,1,1,0)
        self.add_widget(self.creatorline)
        self.creatorline.bind(on_press = go_to_website)

        self.functions_label = Label(text="Functions", font_size=15, color=(0,0,0,1))
        self.functions_label.pos_hint = {"x":-0.19, "top": 0.82}
        self.add_widget(self.functions_label)

        self.about_hospital_label = Label(text="About Hospital", font_size=15, color=(0,0,0,1))
        self.about_hospital_label.pos_hint = {"x":-0.187, "top": 0.61}
        self.add_widget(self.about_hospital_label)

        self.settings_label = Label(text="Settings", font_size=15, color=(0,0,0,1))
        self.settings_label.pos_hint = {"x":0.213, "top": 0.825}
        self.add_widget(self.settings_label)

        self.documentation_label = Label(text="Documentation", font_size=15, color=(0,0,0,1))
        self.documentation_label.pos_hint = {"x":0.215, "top": 0.615}
        self.add_widget(self.documentation_label)

    def go_to_profile(self, instance):
        sm.add_widget(EmployeeProfile(name = "EmployeeProfile"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "EmployeeProfile"

    def go_to_notifications(self, instance):
        sm.add_widget(EmployeeNotifications(name = "EmployeeNotifications"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "EmployeeNotifications"
    
    def go_to_add_notifications(self, instance):
        sm.add_widget(EmployeeAddNotifications(name = "EmployeeAddNotifications"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "EmployeeAddNotifications"

    def go_to_settings(self):
        sm.add_widget(EmployeeSettings(name = "EmployeeSettings"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "EmployeeSettings"

    def go_to_functions(self):
        sm.add_widget(EmployeeFunctions(name = "EmployeeFunctions"))
        sm.transition = SlideTransition(direction = "left")
        sm.current = "EmployeeFunctions"








# Some tasks before the running the file
kv = Builder.load_file("frontend.kv")
sm = WindowManager(transition = SlideTransition())
screens = [
    GetStarted(name="GetStarted"), ConstantFixing(name="ConstantFixing"),
    AdminSignUp(name="AdminSignUp"), DoctorSignUp(name="DoctorSignUp"), PatientSignUp(name="PatientSignUp"), EmployeeSignUp(name="EmployeeSignUp"),
    AdminLogin(name="AdminLogin"), DoctorLogin(name="DoctorLogin"), PatientLogin(name="PatientLogin"), EmployeeLogin(name="EmployeeLogin"),
    AboutHospital(name="AboutHospital"), Documentation(name="Documentation"),
    AdminAfterLogin(name="AdminAfterLogin"), AdminAboutHospital(name="AdminAboutHospital"), AdminDocumentation(name="AdminDocumentation"),
    DoctorAfterLogin(name="DoctorAfterLogin"), DoctorAboutHospital(name="DoctorAboutHospital"), DoctorDocumentation(name="DoctorDocumentation"),
    PatientAfterLogin(name="PatientAfterLogin"), PatientAboutHospital(name="PatientAboutHospital"), PatientDocumentation(name="PatientDocumentation"),
    EmployeeAfterLogin(name="EmployeeAfterLogin"), EmployeeAboutHospital(name="EmployeeAboutHospital"), EmployeeDocumentation(name="EmployeeDocumentation"),
    Profile(name="Profile"), Notifications(name="Notifications"), AddNotifications(name="AddNotifications"), Settings(name="Settings")
    ]

for screen in screens:
    sm.add_widget(screen)
sm.current = "GetStarted"



# Main Class
class HMSApp(App):
    def build(self):
        Window.clearcolor = (1,1,1,1)
        return sm



# Running the entire file
if __name__ == "__main__":
    HMSApp().run()


Working screenshot of Hospital Management System:










 
 
 


Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.