class ManagerImplementation(AddressBookManager):

    utility = Utility()
    bookImplent = AddressBookImplementation()

    def create(self):
        print("enter the name of the address book : ")
        new_address_book = self.utility.input_str_data()
        if (os.path.exists("/home/bridgeit/Zeeshan_Python/AddressJson/" +
                           new_address_book + ".json")):
            print("already exists : ")
        else:
            f = open(
                "/home/bridgeit/Zeeshan_Python/AddressJson/" +
                new_address_book + ".json", "w+")
            print("successfully created")

    def read_files(self):
        path = "/home/bridgeit/Zeeshan_Python/AddressJson"
        dirs = os.listdir(path)
        for files in dirs:
            print(files)

    def operation(self):
        self.bookImplent.operation()
class searchClinic:
    utility = Utility()

    def search_doctor(self, doctor_list):
        print("enter any detail of doctor : ")
        detail = self.utility.input_str_data()
        flag = False
        for x in doctor_list:
            if (detail == doctor_list[x]["doctor_name"]) or (detail == str(
                    doctor_list[x]["doctor_id"])) or (
                        detail == doctor_list[x]["specialization"]) or (
                            detail == doctor_list[x]["avialability"]):
                print("doctor was found")
                print("doctor name\t\t:\t" +
                      str(doctor_list[x]["doctor_name"]))
                print("doctor id\t\t:\t" + str(doctor_list[x]["doctor_id"]))
                print("specialization\t:\t" +
                      str(doctor_list[x]["specialization"]))
                print("avialability\t:\t" +
                      str(doctor_list[x]["avialability"]))
                print("\n")
                flag = True
        if (flag == False):
            print("Your entered details are not found")

    def search_patient(self, patient_list):
        print("enter any detail of patient : ")
        detail = self.utility.input_str_data()
        flag = False
        for x in patient_list:
            if (detail == patient_list[x]["patient_name"]) or (detail == str(
                    patient_list[x]["patient_id"])) or (detail == str(
                        patient_list[x]["number"])) or (detail == str(
                            patient_list[x]["age"])):
                print("name\t:\t" + str(patient_list[x]["patient_name"]))
                print("id\t\t:\t" + str(patient_list[x]["patient_id"]))
                print("number\t:\t" + str(patient_list[x]["number"]))
                print("age\t\t:\t" + str(patient_list[x]["age"]))
                print("\n")
                flag = True
        if (flag == False):
            print("Your entered details are not found")

    def search(self, doctor_list, patient_list):
        while True:
            print("enter a choice : ")
            print("1 for search doctor")
            print("2 for search patient")
            print("3 go back for menu")
            choice = self.utility.input_int_data()
            if choice == 1:
                self.search_doctor(doctor_list)
            elif choice == 2:
                self.search_patient(patient_list)
            elif choice == 3:
                break

            else:
                print("invalid choice")
Example #3
0
class clinicMain:

    utility = Utility()
    print("\t\t_____________________________________________\n")
    print("\t\t\t***Welcome to our clinic***\n")

    def clinicManagement(self):
        doctor_list = {}
        patient_list = {}
        clinic1 = ClinicImplementation(doctor_list, patient_list)
        new_doctor_list = clinic1.read("doctor")
        new_patient_list = clinic1.read("patient")
        clinic = ClinicImplementation(new_doctor_list, new_patient_list)

        while True:
            print("\t\t\t\tMAIN MENU")
            print("\t\t_____________________________________________\n")
            print("\t\tenter '1' to add doctor")
            print("\t\tenter '2' to add patient")
            print("\t\tenter '3' to take appointment")
            print("\t\tenter '4' to display appointments or to search")
            print("\t\tenter '5' to close")
            print("\t\t_____________________________________________")
            choice = self.utility.input_int_data()
            if choice == 1:
                clinic.add_doctor()

            elif choice == 2:
                clinic.add_patient()

            elif choice == 3:
                clinic.take_appointment()

            elif choice == 4:
                clinic.display()

            elif choice == 5:
                print("clinic closed...thank you")
                break

            else:
                print("invalid input")
Example #4
0
class StockMain:
    utility = Utility()
    print("\t\t_____________________________________________\n")
    print("\t\t\t***Welcome to our stock account***\n")
    def stock_account(self):
        company_list = {}
        customer_list = {}
        stock_obj1 = StockImplementation()
        # new_company_list = stock_obj1.read(Companies)
        # new_customer_list = stock_obj1.read("Customers")
        # stock_obj2 = StockImplementation(new_customer_list)

        while True:
            print("\t_____________________________________________\n")
            print("\t\t\tSTOCK ACCOUNT")
            print("\t_____________________________________________\n")
            print("\t1.	add customer")
            print("\t2.	add company")
            print("\t3.	transactions")
            print("\t4. 	display companies")
            print("\t5. 	display customers")
            print("\t6. 	display Transaction")
            print("\t7. 	to exit")
            choice = self.utility.input_int_data()
            if choice == 1:
                stock_obj1.add_customer()
            elif choice == 2:
                stock_obj1.add_company()
            elif choice == 3:
                stock_obj1.buy_sell_share()
            elif choice == 4:
                stock_obj1.display_companies()
            elif choice == 5:
                stock_obj1.display_customers()
            elif choice == 6:
                stock_obj1.display_transaction()
            elif choice == 7:
                print("Thank You")
                break
            else:
                print("invalid choice")
Example #5
0
class AddressBookImplementation(AddressBook):
    my_list = {}
    utility = Utility()

    def operation(self):
        print("enter the address book name : ")
        addressbook_name = self.utility.input_str_data()
        path = "/home/bridgeit/Zeeshan_Python/AddressJson"
        dirs = os.listdir(path)
        status = False
        for files in dirs:
            if (files == addressbook_name + ".json"):
                status = True
                file_name = "/home/bridgeit/Zeeshan_Python/AddressJson/" + addressbook_name + ".json"
                if (os.stat(file_name).st_size != 0):
                    f = open(file_name, "r")
                    data = json.load(f)
                    for x in data:
                        if x in self.my_list:
                            self.my_list[x].append(data[x])
                        else:
                            self.my_list[x] = data[x]
        if (status):
            print("File exists")
            while True:
                print("\tMENU")
                print("\tselect a choice : ")
                print("1 add new person information : ")
                print("2 display information")
                print("3 sort by zip")
                print("4 sort by name")
                print("5 delete")
                print("6 edit")
                print("7 go for main menu")
                choice = self.utility.input_int_data()
                if (choice == 1):
                    self.add_person()
                    self.save(addressbook_name)

                elif (choice == 2):
                    if (os.stat(file_name).st_size == 0):
                        print("it is empty")
                    else:
                        self.display(addressbook_name)

                elif (choice == 3):
                    if (os.stat(file_name).st_size == 0):
                        print("it is empty")
                    else:
                        self.sort_by_zip(addressbook_name)

                elif (choice == 4):
                    if (os.stat(file_name).st_size == 0):
                        print("it is empty")
                    else:
                        self.sort_by_name(addressbook_name)

                elif (choice == 5):
                    if (os.stat(file_name).st_size == 0):
                        print("it is empty")
                    else:
                        print("enter a first name to delete : ")
                        self.delete(addressbook_name)

                elif (choice == 6):
                    if (os.stat(file_name).st_size == 0):
                        print("it is empty")
                    else:
                        print("enter a first name to edit : ")
                        self.edit(addressbook_name)
                elif (choice == 7):
                    self.my_list = {}
                    break
                else:
                    print('Invalid input')
        else:
            print("file doesn't found")

    def add_person(self):
        user = self.add_user()
        try:
            if user.get_first_name() in self.my_list:
                self.my_list[user.get_first_name()].append({
                    "first_name":
                    user.get_first_name(),
                    "last_name":
                    user.get_last_name(),
                    "city":
                    user.get__city(),
                    "state":
                    user.get__state(),
                    "phone":
                    user.get__phone_number(),
                    "zip":
                    user.get__zip()
                })
            else:
                self.my_list[user.get_first_name()] = {
                    "first_name": user.get_first_name(),
                    "last_name": user.get_last_name(),
                    "city": user.get__city(),
                    "state": user.get__state(),
                    "phone": user.get__phone_number(),
                    "zip": user.get__zip()
                }
        except AttributeError:
            print("enter name is already exist")

    def add_user(self):
        person = Person()
        print("enter first name : ")
        person.set_first_name(self.utility.input_str_data())
        print("enter last name : ")
        person.set_last_name(self.utility.input_str_data())
        print("enter city name : ")
        person.set__city(self.utility.input_str_data())
        print("enter state name : ")
        person.set__state(self.utility.input_str_data())
        print("enter phone number : ")
        person.set__phone_number(self.utility.input_int_data())
        print("enter zipcode : ")
        person.set__zip(self.utility.input_int_data())
        return person

    def save(self, addressbook_name):
        data = json.dumps(self.my_list)
        with open(
                "/home/bridgeit/Zeeshan_Python/AddressJson/" +
                addressbook_name + ".json", 'w') as f:
            f.write(data)

    def display(self, addressbook_name):
        f = open(
            "/home/bridgeit/Zeeshan_Python/AddressJson/" + addressbook_name +
            ".json", "r")
        data = json.load(f)
        print("***contacts***\n")
        for x in data:
            print("first name : " + str(data[x]["first_name"]))
            print("last name : " + str(data[x]["last_name"]))
            print("mobile number : " + str(data[x]["phone"]))
            print("city : " + str(data[x]["city"]))
            print("state : " + str(data[x]["state"]))
            print("zip code : " + str(data[x]["zip"]))
            print("\n")

    def sort_by_name(self, addressbook_name):
        temp = []
        f = open(
            "/home/bridgeit/Zeeshan_Python/AddressJson/" + addressbook_name +
            ".json", "r")
        data = json.load(f)
        for x in data:
            temp.append(data[x]["first_name"])
        sort_list = sorted(temp)

        print("***contacts***\n")
        print("sorted by first name")
        for y in range(0, len(sort_list)):
            for x in data:
                if (sort_list[y] == data[x]["first_name"]):
                    print("first name : " + str(data[x]["first_name"]))
                    print("lasr name : " + str(data[x]["last_name"]))
                    print("mobile number : " + str(data[x]["phone"]))
                    print("city : " + str(data[x]["city"]))
                    print("state : " + str(data[x]["state"]))
                    print("zip code : " + str(data[x]["zip"]))
                    print("\n")

    def sort_by_zip(self, addressbook_name):
        temp = []
        f = open(
            "/home/bridgeit/Zeeshan_Python/AddressJson/" + addressbook_name +
            ".json", "r")
        data = json.load(f)
        for x in data:
            var_zip = str(data[x]["zip"])[0]
            temp.append(var_zip)
        sort_list = sorted(temp)
        print("***contacts***\n")
        print("sorted by first name")
        for y in range(0, len(sort_list)):
            for x in data:
                if (sort_list[y] == str(data[x]["zip"])[0]):
                    print("first name : " + str(data[x]["first_name"]))
                    print("lasr name : " + str(data[x]["last_name"]))
                    print("mobile number : " + str(data[x]["phone"]))
                    print("city : " + str(data[x]["city"]))
                    print("state : " + str(data[x]["state"]))
                    print("zip code : " + str(data[x]["zip"]))
                    print("\n")

    def delete(self, addressbook_name):
        key = self.utility.input_str_data()
        if key in self.my_list:
            del self.my_list[key]
            print("successfully done")
            data = json.dumps(self.my_list)
            with open(
                    "/home/bridgeit/Zeeshan_Python/AddressJson/" +
                    addressbook_name + ".json", 'w') as f:
                f.write(data)
            return True
        else:
            print("entered contact is unavaialable")

    def edit(self, addressbook_name):
        status = self.delete(addressbook_name)
        if (status):
            self.add_person()
            self.save(addressbook_name)
class StockImplementation(StackAbstract):
    __company_list = []
    __customer_list = {}
    utility = Utility()
    list_obj = None
    stack_obj = None
    queue_obj = None
    company = Companies()
    transaction = Transaction()
    customer = Customer()

    def __init__(self):
        self.list_obj = LinkedList()
        self.stack_obj = Stack()
        self.queue_obj = QueueLinkedList()
        self.read_companies()
        self.read_transactions()
        self.__customer_list = self.read_customers("Customers")

    #   reading companies in stack
    def read_companies(self):
        path_name = "/home/bridgeit/Zeeshan_Python/stockJson/Companies.json"
        if (os.stat(path_name).st_size != 0):
            f = open(path_name, "r")
            data = json.load(f)
            for x in range(0, len(data)):
                self.stack_obj.push(data[x])

    #   reading transactions in queue
    def read_transactions(self):
        path_name = "/home/bridgeit/Zeeshan_Python/stockJson/Transaction.json"
        if (os.stat(path_name).st_size != 0):
            f = open(path_name, "r")
            data = json.load(f)
            for x in range(0, len(data)):
                self.queue_obj.add_rear(data[x])

    #   reading transactions in list
    def read_customers(self, file_name):
        my_list = {}
        path_name = "/home/bridgeit/Zeeshan_Python/stockJson/" + file_name + ".json"
        if (os.stat(path_name).st_size != 0):
            f = open(path_name, "r")
            data = json.load(f)
            for x in data:
                if x in my_list:
                    my_list[x].append(data[x])
                else:
                    my_list[x] = data[x]
        return my_list

    def add_company(self):
        var_company_details = self.company_info()
        self.stack_obj.push({
            "company_name":
            var_company_details.get_company_name(),
            "company_symbol":
            var_company_details.get_company_symbol(),
            "share_price":
            var_company_details.get_share_price(),
            "total_shares":
            var_company_details.get_total_shares()
        })
        print("successfully added")
        self.save("Companies", self.stack_obj)

    def company_info(self):
        print("Enter a company name : ")
        self.company.set_company_name(self.utility.input_str_data())
        print("Enter a company symbol : ")
        self.company.set_company_symbol(self.utility.input_str_data())
        print("Enter a share price : ")
        self.company.set_share_price(self.utility.input_int_data())
        print("Enter a total shares : ")
        self.company.set_total_shares(self.utility.input_int_data())
        return self.company

    def add_customer(self):
        var_customer_info = self.customer_info()
        if var_customer_info.get_name() in self.__customer_list:
            self.__customer_list[var_customer_info.get_name()].append({
                "customer_name":
                var_customer_info.get_name(),
                "amount":
                var_customer_info.get_amount(),
                "no_of_shares":
                var_customer_info.get_no_of_shares()
            })
        else:
            self.__customer_list[var_customer_info.get_name()] = {
                "customer_name": var_customer_info.get_name(),
                "amount": var_customer_info.get_amount(),
                "no_of_shares": var_customer_info.get_no_of_shares()
            }
        print("successfully added")
        self.save_customers("Customers", self.__customer_list)

    def customer_info(self):
        print("Enter a customer name : ")
        self.customer.set_name(self.utility.input_str_data())
        print("Enter a amount : ")
        self.customer.set_amount(self.utility.input_int_data())
        print("Enter no of shares : ")
        self.customer.set_no_of_shares(self.utility.input_int_data())
        return self.customer

    def display_companies(self):
        new_list = self.stack_obj.get_data()
        print("\tCompanies")
        for x in range(len(new_list)):
            print("company name\t:\t" + str(new_list[x]["company_name"]))
            print("company symbol\t:\t" + str(new_list[x]["company_symbol"]))
            print("total shares\t:\t" + str(new_list[x]["total_shares"]))
            print("share price\t\t:\t" + str(new_list[x]["share_price"]))
            print("\n")

    def display_customers(self):
        for x in self.__customer_list:
            print("name\t\t:\t" +
                  str(self.__customer_list[x]["customer_name"]))
            print("amount\t\t:\t" + str(self.__customer_list[x]["amount"]))
            print("no of shares:\t" +
                  str(self.__customer_list[x]["no_of_shares"]))
            print("\n")

    def display_transaction(self):
        new_list = self.queue_obj.get_data()
        print("\ttransactions")
        for x in range(len(new_list)):
            print("customer name\t:\t" + str(new_list[x]["customer_name"]))
            print("company symbol\t:\t" + str(new_list[x]["company_symbol"]))
            print("buy or sell\t\t:\t" + str(new_list[x]["buy_sell"]))
            print("total shares\t:\t" + str(new_list[x]["total_shares"]))
            print("total price\t\t:\t" + str(new_list[x]["total_price"]))
            print("time\t\t\t:\t" + str(new_list[x]["time"]))
            print("\n")

    def save(self, file_name, obj):
        my_list = obj.get_data()
        data = json.dumps(my_list)
        print(file_name)
        print("successfully saved")
        with open(
                "/home/bridgeit/Zeeshan_Python/stockJson/" + file_name +
                ".json", 'w') as f:
            f.write(data)

    def save_customers(self, file_name, my_list):
        data = json.dumps(my_list)
        print(file_name)
        print("successfully saved")
        with open(
                "/home/bridgeit/Zeeshan_Python/stockJson/" + file_name +
                ".json", 'w') as f:
            f.write(data)

    def buy_sell_share(self):
        print("enter symbol of company : ")
        company_symbol = self.utility.input_str_data()
        particular_company = self.search_company(company_symbol)
        if particular_company == False:
            print("company not found for given input")
        else:
            print(particular_company["company_name"])
            print("enter a customer name : ")
            customer_detail = self.utility.input_str_data()
            particular_customer = self.search_customer(customer_detail)
            if particular_customer == False:
                print("customer not found for given input")
            else:
                print(particular_customer)
                print("1 for buy")
                print("2 for sell")
                choice = self.utility.input_int_data()
                if choice == 1:
                    print("enter amount to buy a shares : ")
                    var_amount = self.utility.input_int_data()
                    self.buy(var_amount, particular_company,
                             particular_customer)
                elif choice == 2:
                    print("enter amount to sell a shares : ")
                    var_amount = self.utility.input_int_data()
                    self.sell(var_amount, particular_company,
                              particular_customer)
                else:
                    print("invalid input")

    def search_company(self, details):
        new_list = self.stack_obj.get_data()
        for x in range(len(new_list)):
            if details == new_list[x]["company_symbol"]:
                return new_list[x]
        return False

    def search_customer(self, details):
        for x in self.__customer_list:
            if (self.__customer_list[x]["customer_name"] == details):
                return self.__customer_list[x]
        return False

    def buy(self, var_amount, particular_company, particular_customer):
        if var_amount <= particular_customer["amount"]:
            print("amount sufficient")
            price_per_share = particular_company["share_price"]
            shares = var_amount / price_per_share
            if (particular_company["total_shares"] >= shares):
                self.customer.set_amount(particular_customer["amount"] -
                                         var_amount)
                self.customer.set_no_of_shares(
                    particular_customer["no_of_shares"] + shares)
                self.customer.set_name(particular_customer["customer_name"])
                self.__customer_list[particular_customer["customer_name"]] = {
                    "customer_name": self.customer.get_name(),
                    "amount": self.customer.get_amount(),
                    "no_of_shares": self.customer.get_no_of_shares()
                }
                self.company.set_total_shares(
                    particular_company["total_shares"] - shares)
                self.company.set_company_name(
                    particular_company["company_name"])
                self.company.set_company_symbol(
                    particular_company["company_symbol"])
                self.company.set_share_price(particular_company["share_price"])
                self.stack_obj.remove_at(particular_company)
                self.stack_obj.push({
                    "company_name":
                    self.company.get_company_name(),
                    "company_symbol":
                    self.company.get_company_symbol(),
                    "share_price":
                    self.company.get_share_price(),
                    "total_shares":
                    self.company.get_total_shares()
                })

                self.transaction.set_customer_name(
                    particular_customer["customer_name"])
                self.transaction.set_company_symbol(
                    particular_company["company_symbol"])
                self.transaction.set_total_price(var_amount)
                self.transaction.set_total_shares(shares)
                self.transaction.set_buy_sell("Buy")
                date = datetime.now()
                self.transaction.set_time(str(date)[:20])
                self.queue_obj.add_rear({
                    "customer_name":
                    self.transaction.get_customer_name(),
                    "company_symbol":
                    self.transaction.get_company_symbol(),
                    "buy_sell":
                    self.transaction.get_buy_sell(),
                    "total_shares":
                    self.transaction.get_total_shares(),
                    "total_price":
                    self.transaction.get_total_price(),
                    "time":
                    self.transaction.get_time()
                })

                self.save("Transaction", self.queue_obj)
                self.save("Companies", self.stack_obj)
                self.save_customers("Customers", self.__customer_list)

            else:
                print("customer had insufficient shares")
        else:
            print("customer had a insufficient balance")

    def sell(self, var_amount, particular_company, particular_customer):
        price_per_share = particular_company["share_price"]
        shares = var_amount / price_per_share
        if (particular_company["total_shares"] >= shares):
            self.customer.set_amount(particular_customer["amount"] +
                                     var_amount)
            self.customer.set_no_of_shares(
                particular_customer["no_of_shares"] - shares)
            self.customer.set_name(particular_customer["customer_name"])
            self.__customer_list[particular_customer["customer_name"]] = {
                "customer_name": self.customer.get_name(),
                "amount": self.customer.get_amount(),
                "no_of_shares": self.customer.get_no_of_shares()
            }

            self.company.set_total_shares(particular_company["total_shares"] +
                                          shares)
            self.company.set_company_name(particular_company["company_name"])
            self.company.set_company_symbol(
                particular_company["company_symbol"])
            self.company.set_share_price(particular_company["share_price"])
            self.stack_obj.remove_at(particular_company)
            self.stack_obj.push({
                "company_name":
                self.company.get_company_name(),
                "company_symbol":
                self.company.get_company_symbol(),
                "share_price":
                self.company.get_share_price(),
                "total_shares":
                self.company.get_total_shares()
            })

            self.transaction.set_buy_sell("sell")
            self.transaction.set_customer_name(
                particular_customer["customer_name"])
            self.transaction.set_company_symbol(
                particular_company["company_symbol"])
            self.transaction.set_total_price(var_amount)
            self.transaction.set_total_shares(shares)
            date = datetime.now()
            self.transaction.set_time(str(date)[:20])
            self.queue_obj.add_rear({
                "customer_name":
                self.transaction.get_customer_name(),
                "company_symbol":
                self.transaction.get_company_symbol(),
                "buy_sell":
                self.transaction.get_buy_sell(),
                "total_shares":
                self.transaction.get_total_shares(),
                "total_price":
                self.transaction.get_total_price(),
                "time":
                self.transaction.get_time()
            })
            self.save("Transaction", self.queue_obj)
        else:
            print("company had insufficient shares")
Example #7
0
class ClinicImplementation(ClinicManager):
    utility = Utility()
    appointment_list = {}
    __doctor_list = {}
    __patient_list = {}

    def __init__(self, doctor_list, patient_list):
        self.__doctor_list = doctor_list
        self.__patient_list = patient_list

    def add_doctor(self):
        # self.__doctor_list = self.read("doctor")
        var_doctor_details = self.doctor_details()
        if var_doctor_details.get_doctor_name() in self.__doctor_list:
            self.__doctor_list[var_doctor_details.get_doctor_name()].append({
                "doctor_name":
                var_doctor_details.get_doctor_name(),
                "doctor_id":
                var_doctor_details.get_doctor_id(),
                "specialization":
                var_doctor_details.get_specialization(),
                "avialability":
                var_doctor_details.get_avialability()
            })
        else:
            self.__doctor_list[var_doctor_details.get_doctor_name()] = {
                "doctor_name": var_doctor_details.get_doctor_name(),
                "doctor_id": var_doctor_details.get_doctor_id(),
                "specialization": var_doctor_details.get_specialization(),
                "avialability": var_doctor_details.get_avialability()
            }
        self.save("doctor", self.__doctor_list)

    def doctor_details(self):
        doctor = Doctor()
        print("please enter a doctor name : ")
        doctor.set_doctor_name(self.utility.input_str_data())
        print("please enter a doctor id : ")
        doctor.set_doctor_id(self.utility.input_int_data())
        print("please enter a doctor specialiazation : ")
        doctor.set_specialization(self.utility.input_str_data())
        print("please enter a doctor availiability : ")
        while True:
            print("1 for 'am'")
            print("2for 'pm'")
            print("3 for 'both'")
            choice = self.utility.input_int_data()
            if choice == 1:
                data = "am"
                break
            elif choice == 2:
                data = "pm"
                break
            elif choice == 3:
                data = "both"
                break
            else:
                print("invalid")
        doctor.set_avialability(data)
        return doctor

    def add_patient(self):
        # self.__patient_list = self.read("patient")
        var_patient_details = self.patient_details()
        if var_patient_details.get_patient_name() in self.__patient_list:
            self.__patient_list[var_patient_details.get_patient_name()].append(
                {
                    "patient_name": var_patient_details.get_patient_name(),
                    "patient_id": var_patient_details.get_patient_id(),
                    "number": var_patient_details.get_number(),
                    "age": get_age()
                })
        else:
            self.__patient_list[var_patient_details.get_patient_name()] = {
                "patient_name": var_patient_details.get_patient_name(),
                "patient_id": var_patient_details.get_patient_id(),
                "number": var_patient_details.get_number(),
                "age": var_patient_details.get_age()
            }
        self.save("patient", self.__patient_list)

    def patient_details(self):
        patient = Patient()
        print("please enter a patient name : ")
        patient.set__patient_name(self.utility.input_str_data())
        print("please enter a patient id : ")
        patient.set_patient_id(self.utility.input_int_data())
        print("please enter a number : ")
        patient.set_number(self.utility.input_int_data())
        print("please enter age : ")
        patient.set_age(self.utility.input_int_data())
        return patient

    def add_appointment(self, particular_doctor, particular_patient):
        var_appointment_details = self.appointment_details(
            particular_doctor, particular_patient)
        f = open("/home/bridgeit/Zeeshan_Python/clinicJson/appointment.json",
                 'r')
        data = json.load(f)
        data["appointment"].append({
            'doctor':
            var_appointment_details.get_doctor(),
            'patient':
            var_appointment_details.get_patient(),
            'date':
            var_appointment_details.get_date()
        })
        with open("/home/bridgeit/Zeeshan_Python/clinicJson/appointment.json",
                  'w') as var_x:
            json.dump(data, var_x, sort_keys=True)
        print("appointment done")

    def appointment_details(self, particular_doctor, particular_patient):
        appointment = Appointment()
        appointment.set_doctor(particular_doctor)
        appointment.set_patient(particular_patient)
        date = datetime.now()
        appointment.set_date(str(date)[:20])
        return appointment

    def take_appointment(self):
        while True:
            print("please enter a doctor name : ")
            doctor_detail = self.utility.input_str_data()
            availibility_list = self.search_doctor(doctor_detail,
                                                   self.__doctor_list)
            if availibility_list == {}:
                print("you searched doctor was unavailable : ")
            else:
                appointment_list = self.read("appointment")
                count = 0
                for x in range(0, len(appointment_list["appointment"])):
                    if (availibility_list[doctor_detail]["doctor_name"] ==
                            appointment_list["appointment"][x]["doctor"]
                        [doctor_detail]["doctor_name"]):
                        count += 1
                print(count)
                if (count >= 5):
                    print("doctor had more appointments ")
                else:
                    print("please enter any patient detail : ")
                    patient_detail = self.utility.input_str_data()
                    particular_patient = self.search_patient(
                        patient_detail, self.__patient_list)

                    if particular_patient == {}:
                        print("you searched patient was unavailable : ")
                    else:
                        self.add_appointment(availibility_list,
                                             particular_patient)
                    break

    def search_doctor(self, details, doctor_list):
        new_list = {}
        for x in doctor_list:
            if (details == doctor_list[x]["doctor_name"]
                    or details == doctor_list[x]["doctor_id"]
                    or details == doctor_list[x]["specialization"]
                    or details == doctor_list[x]["avialability"]):
                if doctor_list[x]["doctor_name"] in new_list:
                    new_list[doctor_list[x]["doctor_name"]].append[
                        doctor_list[x]]
                else:
                    new_list[doctor_list[x]["doctor_name"]] = doctor_list[x]
        return new_list

    def search_patient(self, details, patient_list):
        new_list = {}
        for x in patient_list:
            if (details == patient_list[x]["patient_name"]
                    or details == patient_list[x]["patient_id"]
                    or details == patient_list[x]["number"]
                    or details == patient_list[x]["age"]):
                new_list[patient_list[x]["patient_name"]] = patient_list[x]
        return new_list

    def save(self, file_name, my_list):
        data = json.dumps(my_list)
        print(file_name)
        print(my_list)
        with open(
                "/home/bridgeit/Zeeshan_Python/clinicJson/" + file_name +
                ".json", 'w') as f:
            f.write(data)

    def read(self, file_name):
        my_list = {}
        path_name = "/home/bridgeit/Zeeshan_Python/clinicJson/" + file_name + ".json"
        if (os.stat(path_name).st_size != 0):
            f = open(path_name, "r")
            data = json.load(f)
            for x in data:
                if x in my_list:
                    my_list[x].append(data[x])
                else:
                    my_list[x] = data[x]
        return my_list

    def display(self):
        appointment_list = self.read("appointment")
        display_clinic_obj = displayClinic()
        search_clinic_obj = searchClinic()
        while True:
            print("enter choice : ")
            print("1 for display doctor")
            print("2 for display patients")
            print("3 for display appointments")
            print("4 for display Popular Doctor")
            print("5 for display Popular Specialization")
            print("6 for search")
            print("7 for main menu")
            choice = self.utility.input_int_data()
            if choice == 1:
                display_clinic_obj.display_doctor(self.__doctor_list)
            elif choice == 2:
                display_clinic_obj.display_patient(self.__patient_list)
            elif choice == 3:
                display_clinic_obj.display_appointments(appointment_list)
            elif choice == 4:
                display_clinic_obj.popular_doctor(self.__doctor_list,
                                                  appointment_list)
            elif choice == 5:
                display_clinic_obj.popular_specialization(
                    self.__doctor_list, appointment_list)
            elif choice == 6:
                search_clinic_obj.search(self.__doctor_list,
                                         self.__patient_list)
            elif choice == 7:
                break
            else:
                print("invalid")