Exemplo n.º 1
0
 def show():
     ini_msg = "Enter username and password to login\nenter exit to go back\n"
     user_input_username = ''
     user_input_password = ''
     while True:
         user_input_username = input("Enter Your username:- ").strip()
         if (user_input_password == 'exit'
                 or user_input_username == 'exit'):
             return -1
         user_input_password = input("Enter Your password:- ").strip()
         if (user_input_password == 'exit'
                 or user_input_username == 'exit'):
             return -1
         user_record = ConfigFileReader.find_by_username_and_password(
             user_input_username,
             AuthHelper.hashed_password(user_input_password))
         if (user_record == False):
             print(
                 "Invalid username or password\npress 1 to signup\npress enter to try again"
             )
             input()
         else:
             # ConfigFileReader.print_rec(user_record)
             return UIFinder.showUI(user_record)
             break
    def patientCreate():
        print("enter details")
        while True:
            username = input("Enter_username:- ")
            if (ConfigFileReader.find_by_username(username) != False):
                print("username exist. Type a new one\n")
                continue
            else:
                break
        firstName = input("Enter_firstName:- ")
        lastName = input("Enter_lastName:- ")
        address = input("Enter_address:- ")
        while True:
            telephone = input("Enter_telephone:- +94")
            try:
                int(telephone)
                if (len(telephone) < 9):
                    print("enter a valid telephone number")
                    continue
                else:
                    break

            except Exception:
                print("enter a valid telephone number")
                continue
        while True:
            age = input("Enter_age:- ")
            try:
                int(age)
                if (True):
                    break
            except Exception:
                print("enter a valid age")
                continue
        special_notes = input("Enter_special_notes:- ")
        user_ = Patient(
            username, telephone
        )  #initial password was phone number. Patient has to change it immediatly
        data_ = PatientData(username, firstName, lastName, telephone, address,
                            age, special_notes)
        val1 = ConfigFileReader.add(user_)
        val2 = DataFileReader.add(data_)

        if (val1 == False or val2 == False):
            return False
        return True
    def doctorCreate():
        print("enter details")
        while True:
            username = input("Enter_username:- ")
            if (ConfigFileReader.find_by_username(username) != False):
                print("username exist. Type a new one\n")
                continue
            else:
                break
        firstName = input("Enter_firstName:- ")
        lastName = input("Enter_lastName:- ")
        address = input("Enter_address:- ")
        while True:
            telephone = input("Enter_telephone:- +94")
            try:
                int(telephone)
                if (len(telephone) < 9):
                    print("enter a valid telephone number")
                    continue
                else:
                    break

            except Exception:
                print("enter a valid telephone number")
                continue
        nic = input("Enter_NIC:- ")
        doc_id = input("Enter_SLRC ID:- ")
        user_ = Doctor(
            username, telephone
        )  #initial password was phone number. Patient has to change it immediatly
        data_ = DoctorData(username, firstName, lastName, telephone, address,
                           doc_id, nic)
        val1 = ConfigFileReader.add(user_)
        val2 = DataFileReader.add(data_)

        if (val1 == False or val2 == False):
            return False
        return True
 def addMembers(username):
     try:
         user_ = ConfigFileReader.find_by_username(username)
         if (user_ == False):
             return -1
         else:
             if (user_.type == 'admin'):
                 val = AddViewUsers.adminAdd(username)
             elif (user_.type == 'doctor'):
                 val = AddViewUsers.doctorAdd(username)
             elif (user_.type == 'nurse'):
                 val = AddViewUsers.nurseAdd(username)
             else:
                 print("Uou havent priviledges")
                 return -1
     except Exception as e:
         print("error in adding members")
         print(e)
         return -1
 def viewMembers(username):
     try:
         user_ = ConfigFileReader.find_by_username(username)
         if (user_ == False):
             return -1
         else:
             if (user_.type == 'admin'):
                 recs = DataFileReader.loadall(
                     ['doctor', 'nurse', 'patient'])
                 # print(recs)
                 for k in recs:
                     print("\n" + k + "\n")
                     for ele in recs[k]:
                         print("\n")
                         print(ele.__str__())
                 return 1
             elif (user_.type == 'doctor'):
                 recs = DataFileReader.loadall(['nurse', 'patient'])
                 for k in recs:
                     print("\n" + k + "\n")
                     for ele in recs[k]:
                         print("\n")
                         print(ele.__str__())
                 return 1
             elif (user_.type == 'nurse'):
                 recs = DataFileReader.loadall(['patient'])
                 for k in recs:
                     print("\n" + k + "\n")
                     for ele in recs[k]:
                         print("\n")
                         print(ele.__str__())
                 return 1
             else:
                 print("you haven't priviledges")
                 return -1
             return 1
     except Exception as e:
         print("No members to view")
         print(e)
         return -1
 def changepassword(username):
     while True:
         pas = ''
         newpas = ''
         print(
             "Type pass word and your new password. type 'exit' to go to the previous screen"
         )
         print("\n Enter the password")
         pas = input("Password:- ")
         if (pas == 'exit'):
             return True
         print("\n Enter the new password:- ")
         newpas = input("New Password:- ")
         if (newpas == 'exit'):
             return True
         pas = AuthHelper.hashed_password(pas)
         val = ConfigFileReader.changepassword(username, pas, newpas)
         if (val == False):
             continue
         else:
             print("\nYour details\n")
             return AddViewUsers.findowndetails(username)
 def get_user_by_username(username):
     rec = ConfigFileReader.find_by_username(username)
     if (rec == False):
         return False
     else:
         return rec
    def find_user_records(username):
        '''
        find all records for a specific user.
        find_user_records(seracher,owner)
        '''
        try:
            while True:
                print("You have to type the report type and the userID")
                print(
                    "Enter the type of your report ex:- lab record | sickness record | drug record\n Other inputs will discarded"
                )
                print("Type 'exit' to exit.")
                type_ = input("Enter the type:- ").strip()
                if (type_ == 'exit'):
                    return -1
                if (type_ not in [
                        'lab record', 'sickness record', 'drug record'
                ]):
                    print("\nInvalid type . Type Again\n")
                    continue
                else:
                    break
            while True:
                patient = input("Enter the patient username:- ").strip()
                find = ConfigFileReader.find_by_username(patient)
                if (patient == 'exit'):
                    return -1
                if (find == False or find.type != 'patient'):
                    print("\nUsername can't find . Type Again\n")
                    continue
                else:
                    break
            recs = DataFileReader.Record_find_by_finder_username(
                username, type_)
            records = []
            for i in recs:
                if (i.username == patient):
                    records.append(i)
            if (records == False):
                return False
            else:
                l = []
                d = []
                s = []
                for r in records:
                    if (isinstance(r, LabTestPrescription)):
                        l.append(r)
                    elif (isinstance(r, SicknessDetails)):
                        s.append(r)
                    elif (isinstance(r, DrugPrescription)):
                        d.append(r)
                if (len(l) != 0):
                    print("\nLab Descriptions\n")
                    for i in l:
                        print("patient username: "******"Description: " + i.description)
                        print("Result: " + i.result)
                        print("Issued Date: " + i.date.__str__())
                        print("\n")
                if (len(d) != 0):
                    print("\nDrug Descriptions\n")
                    for i in d:
                        print("patient username: "******"Description: " + i.description)
                        print("valid_period: " + i.valid_period)
                        print("Issued Date: " + i.date.__str__())
                        print("\n")
                if (len(s) != 0):
                    print("\nSickness Descriptions\n")
                    for i in s:
                        print("patient username: "******"Description: " + i.description)
                        print("sickness_name: " + i.sickness_name)
                        print("Issued Date: " + i.date.__str__())
                        print("\n")

        except Exception as e:
            print("No record\n")
            print(e)
            return False
    def addRecords(username):
        user_ = ConfigFileReader.find_by_username(username)
        if (user_ == False or user_.type not in ['doctor', 'admin']):
            print("You haven't access to add records.\n")
        else:
            while True:
                print(
                    "Enter the type of your report ex:- lab report | sickness report | drug report\n Other inputs will discarded"
                )
                print("Type 'exit' to exit.")
                type_ = input("Enter the type:- ").strip()
                if (type_ == 'exit'):
                    return -1
                if (type_ not in [
                        'lab report', 'sickness report', 'drug report'
                ]):
                    print("\nInvalid type . Type Again\n")
                    continue
                else:
                    break
            while True:
                patient = input("Enter the patient username:- ").strip()
                find = ConfigFileReader.find_by_username(patient)
                if (patient == 'exit'):
                    return -1
                if (find == False or find.type != 'patient'):
                    print("\nUsername can't find . Type Again\n")
                    continue
                else:
                    break
            while True:
                print(
                    "\nType the sensivity. sensivity value should be one of below values"
                )
                print("\t" + sensitive_level_1 + "," + sensitive_level_2 +
                      "," + sensitive_level_3 + "," + sensitive_level_4)
                sen = input("Enter the sensivty of the record:- ")
                if (sen == 'exit'):
                    return -1
                if (sen not in [
                        sensitive_level_1, sensitive_level_2,
                        sensitive_level_3, sensitive_level_4
                ]):
                    print("\nInvalid value. Try again\n")
                    continue
                else:
                    break
            description = input("Enter the description:- ").strip()
            if (description == 'exit'):
                return -1
            date = datetime.date.today()
            if (type_ == 'lab report'):
                result = input(
                    "Enter the result(If result not came yet press enter) :- ")
                if (result == 'exit'):
                    return -1
                if (result == ''):
                    result = 'Pending'
                obj = LabTestPrescription(patient, result, sen, description,
                                          date)

            elif (type_ == 'sickness report'):
                name = input("Enter the sickness name :- ")
                if (name == 'exit'):
                    return -1
                obj = SicknessDetails(patient, name, sen, description, date)

            elif (type_ == 'drug report'):
                valid_period = input("Enter the valid period :- ")
                if (valid_period == 'exit'):
                    return -1
                obj = DrugPrescription(patient, valid_period, sen, description,
                                       date)

            else:
                print("\nwrong type. Try again\n")
        if (obj == None or obj == False):
            print("\nwrong type. Try again\n")
            return False
        else:
            result = DataFileReader.add(obj)
            if (result == False):
                return False
            else:
                print("Succefully added")
                return True