def generic_view_range(select_ports,
                       view_ports,
                       table_fields,
                       delete_check,
                       combo,
                       datefield1="",
                       datefield2="",
                       jointype="LEFT JOIN"):

    another = "Y"
    field_array = []
    data_array = []
    inequality_array = []
    while (another.lower() == "y"):
        print("Enter field: \n")
        f_no = db.select_make(select_ports)

        field_name = select_ports[f_no - 1]

        if field_name == datefield1 or field_name == datefield2:
            data_lesser = db.quote_str(
                db.date_process(input("Date(DD-MM-YYYY) > ")))

        else:
            data_lesser = db.quote_str(
                input("{field} > ".format(field=field_name)))

        if data_lesser != '""':
            data_array.append(data_lesser)
            field_array.append(field_name)
            inequality_array.append(" > ")

        if field_name == datefield1 or field_name == datefield2:
            data_greater = db.quote_str(
                db.date_process(input("Enter Date(DD-MM-YYYY) < ")))

        else:
            data_greater = db.quote_str(
                input("{field} < ".format(field=field_name)))

        if data_greater != '""':
            data_array.append(data_greater)
            field_array.append(field_name)
            inequality_array.append(" < ")

        another = input("Do you want to enter another field ? [Y/N]")

    db.view_range(delete_check,
                  field_array,
                  data_array,
                  view_ports,
                  table_fields,
                  inequality_array,
                  combo,
                  jointype=jointype)
def generic_view_singletable(select_ports, view_ports, table_fields, table):
    table_name = [table]

    another = "Y"
    field_array = []
    data_array = []
    while (another.lower() == "y"):
        print("Enter field: \n")
        f_no = db.select_make(select_ports)

        field_name = select_ports[f_no - 1]

        field_array.append(field_name)

        if field_name == "date":
            data = db.quote_str(
                db.date_process(input("Enter Date(DD-MM-YYYY): ")))

        else:
            data = db.quote_str(
                input("Enter {field}: ".format(field=select_ports[f_no - 1])))

        data_array.append(data)

        another = input("Do you want to enter another field ? [Y/N]")

    db.view_entry(table_name, field_array, data_array, view_ports,
                  table_fields)
def generic_view_value(select_ports,
                       view_ports,
                       table_fields,
                       delete_check,
                       combo,
                       datefield1="",
                       datefield2="",
                       jointype="LEFT JOIN"):

    another = "Y"
    field_array = []
    data_array = []
    while (another.lower() == "y"):
        print("Enter field: \n")
        f_no = db.select_make(select_ports)

        field_name = select_ports[f_no - 1]

        field_array.append(field_name)

        if field_name == datefield1 or field_name == datefield2:
            data = db.quote_str(
                db.date_process(input("Enter Date(DD-MM-YYYY): ")))

        else:
            data = db.quote_str(
                input("Enter {field}: ".format(field=select_ports[f_no - 1])))

        data_array.append(data)

        another = input("Do you want to enter another field ? [Y/N]")

    db.view_entry(delete_check, field_array, data_array, view_ports,
                  table_fields, combo)
def patient_admission():
    table_name = 'admission'
    patid = input("Enter Patient ID: ")
    docid = input("Enter Doctor ID: ")
    roomid = input("Enter Room ID: ")
    bedno = input("Enter Bed no: ")
    admitdate = db.quote_str(
        db.date_process(input("Enter Admission Date (DD-MM-YYYY): ")))
    admittime = db.quote_str(input("Enter Admission time: "))
    redate = db.quote_str(
        db.date_process(input("Enter Release Date (DD-MM-YYYY): ")))
    retime = db.quote_str(input("Enter Release time: "))

    data = db.list_make(patid, "1", roomid, bedno, docid, admitdate, admittime,
                        redate, retime)

    db.insert_data(table_name, insert_scope['admin:admission'], data)
def generic_range_singletable(select_ports, view_ports, table_fields, table):
    table_name = [table]

    another = "Y"
    field_array = []
    data_array = []
    inequality_array = []

    while (another.lower() == "y"):
        print("Enter field: \n")
        f_no = db.select_make(select_ports)

        field_name = select_ports[f_no - 1]

        if field_name == "date":
            data_lesser = db.quote_str(
                db.date_process(input("Date(DD-MM-YYYY) > ")))

        else:
            data_lesser = db.quote_str(
                input("{field} > ".format(field=field_name)))

        if data_lesser != '""':
            data_array.append(data_lesser)
            field_array.append(field_name)
            inequality_array.append(" > ")

        if field_name == "date":
            data_greater = db.quote_str(
                db.date_process(input("Enter Date(DD-MM-YYYY) < ")))

        else:
            data_greater = db.quote_str(
                input("{field} < ".format(field=field_name)))

        if data_greater != '""':
            data_array.append(data_greater)
            field_array.append(field_name)
            inequality_array.append(" < ")

        another = input("Do you want to enter another field ? [Y/N]")

    db.view_range(table_name, field_array, data_array, view_ports,
                  table_fields, inequality_array)
def generic_delete_value(select_ports,
                         view_ports,
                         table_fields,
                         delete_check,
                         combo,
                         datefield1="",
                         datefield2="",
                         jointype="LEFT JOIN",
                         deletetype=""):

    table_name = [delete_check[0]]

    another = "Y"
    field_array = []
    data_array = []
    print("\nSearch for the entry: \n")
    while (another.lower() == "y"):

        print("Enter field: \n")
        f_no = db.select_make(select_ports)

        field_name = select_ports[f_no - 1]

        field_array.append(field_name)

        if field_name == "date":
            data = db.quote_str(
                db.date_process(input("Enter Date(DD-MM-YYYY): ")))

        else:
            data = db.quote_str(
                input("Enter {field}: ".format(field=select_ports[f_no - 1])))

        data_array.append(data)

        another = input("Do you want to enter another field ? [Y/N]")

    sel = db.check_entry(delete_check, field_array, data_array, view_ports,
                         table_fields, combo)

    if (sel):
        x = input("Are you sure you want to delete this entry ? : [Y/N]")
        if (x.lower() == "y"):
            if (deletetype == "admin"):
                p = db.choice_make("Soft Delete", "Hard Delete")
            else:
                p = 1

            if p == 1:
                db.update_data(table_name, sel, ['is_deleted'], ['1'])
                print("Entry Deleted")
            elif p == 2:
                db.delete_data(table_name, sel)
        else:
            print("Entry was NOT deleted")
def reports():
    table_name = 'diagnosticreport'
    presid = input("Enter Prescription ID: ")
    docid = input("Enter Doctor ID: ")
    date = db.quote_str(db.date_process(input("Enter Date (DD-MM-YYYY): ")))
    time = db.quote_str(input("Enter time: "))
    report = db.quote_str(input("Report: "))

    data = db.list_make(presid, docid, date, time, report)

    db.insert_data(table_name, insert_scope['admin:report'], data)
def roomduty_entry_staff():
    table_name = 'roomduty'

    staffid = input("Enter Staff id: ")
    roomid = input("Enter Room id: ")
    date = db.quote_str(db.date_process(input("Enter Date (DD-MM-YYYY): ")))
    time = db.quote_str(input("Enter time: "))

    #Where to start from
    data = db.list_make(staffid, roomid, date, time)

    db.insert_data(table_name, insert_scope['admin-staff:roomduty'], data)
def roomduty_entry():
    table_name = 'roomduty'

    docid = input("Enter Doctor id: ")
    roomid = input("Enter Room id: ")
    date = db.quote_str(db.date_process(input("Enter Date (DD-MM-YYYY): ")))
    print(date)
    time = db.quote_str(input("Enter time: "))

    #Where to start from
    data = db.list_make(docid, roomid, date, time)

    db.insert_data(table_name, insert_scope['admin-doc:roomduty'], data)
def prescription():
    table_name = 'prescription'
    patid = input("Enter Patient ID: ")
    docid = input("Enter Doctor ID: ")
    diagnosis = db.quote_str(input("Diagnosis: "))
    medid = input("Enter Med ID: ")
    testid = input("Enter Test ID: ")
    if len(medid) == 0:
        medid = "NULL"
    if len(testid) == 0:
        testid = "NULL"
    date = db.quote_str(db.date_process(input("Enter Date (DD-MM-YYYY): ")))
    time = db.quote_str(input("Enter time: "))

    data = db.list_make(patid, docid, diagnosis, medid, testid, date, time)

    db.insert_data(table_name, insert_scope['admin:prescription'], data)
def emergency_patient():

    patid = input("Enter Patient ID: ")
    docid = input("Enter Doctor ID: ")
    date = db.quote_str(db.date_process(input("Enter Date (DD-MM-YYYY): ")))
    time = db.quote_str(input("Enter time: "))
    print("Where did the patient come ? ")
    roomtype = db.choice_make("Emergency", "Outdoor")

    data = db.list_make(patid, docid, date, time)

    if roomtype == 1:
        db.insert_data('emergency', insert_scope['patinet:outdoor-emergency'],
                       data)
    elif roomtype == 2:
        db.insert_data('outdoor', insert_scope['patinet:outdoor-emergency'],
                       data)
def generic_update_value(select_ports,
                         view_ports,
                         table_fields,
                         delete_check,
                         combo,
                         datefield1="",
                         datefield2="",
                         jointype="LEFT JOIN",
                         update_ports=select_ports):

    table_name = [delete_check[0]]

    another = "Y"
    field_array = []
    data_array = []
    print("\nSearch for the entry: \n")
    while (another.lower() == "y"):

        print("Enter field: \n")
        f_no = db.select_make(select_ports)

        field_name = select_ports[f_no - 1]

        field_array.append(field_name)

        if field_name == "date":
            data = db.quote_str(
                db.date_process(input("Enter Date(DD-MM-YYYY): ")))

        else:
            data = db.quote_str(
                input("Enter {field}: ".format(field=select_ports[f_no - 1])))

        data_array.append(data)

        another = input("Do you want to enter another field ? [Y/N]")

    sel = db.check_entry(delete_check, field_array, data_array, view_ports,
                         table_fields, combo)

    if (sel):

        print("Select the field you want to update? ")

        select_fields = update_ports.copy()

        primary_key_check = [
            'patientmanagement', 'doctorsmanagement', 'medicine',
            'medequipment', 'staffmanagement', 'diagnostictests', 'room'
        ]

        table_name = [delete_check[0]]

        for table in primary_key_check:
            if table_name[0] == table:
                select_fields.pop(0)

        another = "Y"
        field_array = []
        data_array = []
        while (another.lower() == "y" and len(select_fields) != 0):
            print("Enter field: \n")
            f_no = db.select_make(select_fields)

            field_name = select_fields[f_no - 1]

            select_fields.pop(f_no - 1)

            field_array.append(field_name)

            if field_name == "date":
                data = db.quote_str(
                    db.date_process(input("Enter Date(DD-MM-YYYY): ")))

            else:
                data = db.quote_str(
                    input("Enter {field}: ".format(field=field_name)))

            data_array.append(data)

            another = input("Do you want to enter another field ? [Y/N]")

        db.update_data(table_name, sel, field_array, data_array)