Skip to content

Commit

Permalink
Initial oracle connection, menu fanciness for either paulos test or k…
Browse files Browse the repository at this point in the history
…ate aws dbs
  • Loading branch information
TomSmithCoding committed Nov 26, 2024
1 parent d92b5e8 commit 63d03ef
Show file tree
Hide file tree
Showing 7 changed files with 481 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/flask/jwtRS512.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQCuRMIh4LTJQYB7
zBdWJgjHsbpnZpQgmX+f0zmWrAN8QDxVGARRpRJeqtb7Ms1NgNk3pFZM7M52G4Ir
3XKYXRikzAyiNVCiQi2c1GM05Q1BC38gDCZrN5CTkdAXgNXrJcU4DsxDi1Fjb3tE
Z6Kn2ALQn47FuFsmBEr3D9qOeHuCz1aC0sguEMwB5LUTZW4qOBAapdYYzGX4DSKp
K5lZkCwShmV5UJJeSuB+Ef3ZSKzc1zqBw6DGVvRgYc/g8zjbQ+YifBgKx/5168Fg
DZDsc2WvI1IgHdokw1jo9s0ZgC1teTI84ywvSt19PJLkS2mCcOmasthxy27p86JW
sH9gO+EcyU8Y/lYQkgKxnLlN7Cp+b7QXZak3o+pEDT7n9VS2EKIAheLC0pKs7f/K
FJfRBQn/c+RAPYKtVdpIWQBfmcErSpNMtEo2u+/jONSR41/rhHoSNdPkAHOpg+Tv
pVRWyxO3y1f/lfpjxxMbqrHI2cNc3oPvz6KmbDrWgkIR54LtLEd6svJPEYq4PFcL
yx4cWX7rJj2WhMNUmnHX8GODwRHBabjMc7/HHHT8H+Ri7RinFuKeEpPADB0mlKiI
MG85r2J8IeK2wxSMVbaFE62cwjG7zxIt7rCc37YscOwyBaezIRHQRfbCrwVBIFU1
VNuGBOxj6rIs6lFonFjMdZoJUJVpnQIDAQABAoICAQCKNBFZWKFHMmE4zIR9V7CC
3hocQqeaquEh2RvEuCoTccXnHiLetPC6jvXrRUC4BEU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kE62uckyyXRibd7DZiV7m4y09+H+BzvYu
v96q+QWxBSjtU5GEQ/l5BHa9xSQkWeLMv/zLa0zZ6bbeCiqHRMWuugKjWA4i+Ysk
0Poywf7LnGcnwmv/T6sQw8uA9OHNYWWR5GNRCcbXpPUXMX845tAzZNIMpurRvjWK
t2hGo0k/Ln4MBfjU3KPB905xrEfrUlsb/ZoINxZKxDoLN08LFkQPByjRE8SWEsJM
h5SMrYhbFhHUemLm0a2eLa9vIHssCZ0=
-----END PRIVATE KEY-----
6 changes: 6 additions & 0 deletions src/flask/oracle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Python connector pre-requisites

- Ensure docker image for Oracle database is running and on correct port
- Install an SQL Oracle IDE of your choice
- Create a user that is not SYS if creating data, best practice
- Once finished, don't forget to stop the docker container if still working
106 changes: 106 additions & 0 deletions src/flask/oracle/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import sql
import menu

db_choices= ["TEST", "KATE"]
db = True
while db not in db_choices:
db = str.upper(input("Please enter which DB you would like to connect to (TEST/KATE): "))
if db not in db_choices:
print("DB not found, please try again")

connection = sql.create_connection(db)
cursor = connection.cursor()
tables = []

if db == "TEST":
cursor.execute("SELECT table_name FROM user_tables")
print("Available tables:")
for row in cursor:
print(row)
tables+= row

else:
cursor.execute("SELECT table_name FROM user_synonyms")
print("Available synonyms:")
for row in cursor:
print(row)
tables+= row

table_name = True
while table_name not in tables:
table_name = str.upper(input("Which would you like to interact with?: "))
if table_name not in tables:
print("Table not found, please try again")

ans=True
while ans:
print ("""
1. Add Patient(s)
2. Delete Patient(s)
3. Update Patient(s)
4. Fetch all Patients
5. Exit
""")
choice = input("What would you like to do? ")
columns = sql.get_column_names(cursor, table_name)
if choice=="1":
data = menu.insert_patients(columns)
sql.insert_patients(cursor, table_name, data)
connection.commit()
sql.print_table(cursor, table_name)
elif choice=="2":
data = menu.delete_patients(columns)
sql.delete_patients(cursor, table_name, data, columns)
connection.commit()
sql.print_table(cursor, table_name)
elif choice=="3":
data = menu.update_patients(columns)
sql.update_patients(cursor, table_name, data)
#connection.commit()
#sql.print_table(cursor, table_name)
elif choice=="4":
sql.print_table(cursor, table_name)
elif choice=="5":
cursor.close()
connection.close()
ans=False
elif choice !="":
print("\nNot Valid Choice, try again")

#Ticket BCSS-18709
#Read/Write/Update database table

# cursor.execute(sql.read_rows("MPI"))
# columns = [col[0] for col in cursor.description]
# print(columns)
# for r in cursor:
# print(r)

# print("\n")

# #Check test patient was added
# for row in cursor.execute('select person_family_name, person_given_name from mpi'):
# print(row[0] + " " + row[1], "is in the table")


# #Update a test patient
# cursor.execute(sql.update_patient_family_name('Test3', "NewPatientUpdated"))
# # cursor.execute("""
# # update mpi
# # set person_family_name = 'PatientUpdated'
# # where person_given_name = 'Test1'""")

# for row in cursor.execute('select person_family_name, person_given_name from mpi'):
# if row[0] == 'PatientUpdated':
# print("\n"+ row[0] + " " + row[1], "has been updated")

# connection.commit()

# # Fetch entire rows
# cursor.execute("select * from mpi")
# rows = cursor.fetchall()
# print("\nRows:")
# for row in rows:
# print(row)


83 changes: 83 additions & 0 deletions src/flask/oracle/menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from datetime import date

def insert_patients(columns):
#Maybe add option to read in from CSV/excel file?

#Manually
ans=True
while ans:
choice = input("Would you like to add patients manually? (Y/N): ")
if str.upper(choice)=="Y":
num_entries = int(input("Enter the number of patients to add: "))
print(columns)
data=[]
for i in range(num_entries):
print(f'\n#### Patient {i+1} ####')
data = data_entry(columns, data)

print("Adding to table: ", data)
return data
#Option to just auto-add test patient with testpatient counter
elif str.upper(choice)=="N":
return None

elif choice !="":
print("\nNot Valid Choice, try again")

def data_entry(columns, data):
temp_dict = {}
for i in columns:
x = input(f'Please enter the {i} for the patient (Leave blank to skip): ')
if(x):
temp_dict[i] = x

data.append(temp_dict)
return data

def delete_patients(columns):
print ("""
1. Delete all rows
2. Delete rows conditionally
3. Delete specific row
""")
choice = input("What would you like to do? ")
data=[]
if choice=="1":
return True
elif choice=="2":
print(columns)
column = input("What column would you like to delete rows by? \n(Please make sure it matches table column name): ")
condition = input(f'What value would you like to check and delete for in the {column} column?: ')
data = dict(column=column, condition=condition)
return data
elif choice=="3":
data = input("Which row would you like to delete? ")
elif choice !="":
print("\nNot Valid Choice, try again")
#Delete all rows
#Delete specific rows conditionally
#Delete specific row

def update_patients(columns):
ans=True
while ans:
choice = input("Would you like to update patients manually? (Y/N): ")
if str.upper(choice)=="Y":
print(columns)
field_to_update = input("What field would you like to update? \n(Please make sure it matches table name): ")
new_value = input("What value would you like to update it to?: ")
print(columns)
condition_column = input(f'What column would you like to be the condition for the updates for {field_to_update}\n(Please make sure it matches table name):?: ')
condition_value = input(f'What value in {condition_column} would you like to check for?: ')
data = dict(
field_to_update=field_to_update,
new_value=new_value,
condition_column=condition_column,
condition_value=condition_value
)
return data
#Option to just auto-update patient with NewPatientUpdated
elif str.upper(choice)=="N":
return None
elif choice !="":
print("\nNot Valid Choice, try again")
Loading

0 comments on commit 63d03ef

Please sign in to comment.