Seperate DB Connection into own file & update routers to point to connect dbconnection
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
0
backend/database/__init__.py
Normal file
0
backend/database/__init__.py
Normal file
BIN
backend/database/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
backend/database/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/database/__pycache__/dbConnection.cpython-310.pyc
Normal file
BIN
backend/database/__pycache__/dbConnection.cpython-310.pyc
Normal file
Binary file not shown.
9
backend/database/dbConnection.py
Normal file
9
backend/database/dbConnection.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import mysql.connector
|
||||||
|
|
||||||
|
def dbConnect():
|
||||||
|
return mysql.connector.connect(
|
||||||
|
host="mysqldb",
|
||||||
|
user="root",
|
||||||
|
passwd="C@rtoon1995",
|
||||||
|
database="patient_manager"
|
||||||
|
)
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,20 +1,13 @@
|
|||||||
import mysql.connector
|
import mysql.connector
|
||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
|
from ..database import dbConnection
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
def dbConnect():
|
|
||||||
return mysql.connector.connect(
|
|
||||||
host="mysqldb",
|
|
||||||
user="root",
|
|
||||||
passwd="C@rtoon1995",
|
|
||||||
database="patient_manager"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Get Doctors Office By ID
|
# Get Doctors Office By ID
|
||||||
@router.get("/docOffices/{docOffic_id}", tags="DocOffice")
|
@router.get("/docOffices/{docOffic_id}", tags="DocOffice")
|
||||||
async def read_docOfficeByID(docOffic_id: int):
|
async def read_docOfficeByID(docOffic_id: int):
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "SELECT * FROM doctor_offices WHERE iddoctor_offices=%s"
|
query = "SELECT * FROM doctor_offices WHERE iddoctor_offices=%s"
|
||||||
cursor.execute(query, (docOffic_id,))
|
cursor.execute(query, (docOffic_id,))
|
||||||
@@ -29,7 +22,7 @@ async def read_docOfficeByID(docOffic_id: int):
|
|||||||
# Get List of all Doctors Office
|
# Get List of all Doctors Office
|
||||||
@router.get("/docOffices/", tags="DocOffice")
|
@router.get("/docOffices/", tags="DocOffice")
|
||||||
async def read_All_DoctorsOffice():
|
async def read_All_DoctorsOffice():
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "SELECT * FROM doctor_offices"
|
query = "SELECT * FROM doctor_offices"
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import mysql.connector
|
import mysql.connector
|
||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
from ..database import dbConnection
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@@ -29,18 +30,11 @@ class patientUpdateRequest(BaseModel):
|
|||||||
address: str
|
address: str
|
||||||
doc_office_id: int
|
doc_office_id: int
|
||||||
|
|
||||||
def dbConnect():
|
|
||||||
return mysql.connector.connect(
|
|
||||||
host="mysqldb",
|
|
||||||
user="root",
|
|
||||||
passwd="C@rtoon1995",
|
|
||||||
database="patient_manager"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Get Patient By ID Number
|
# Get Patient By ID Number
|
||||||
@router.get("/patients/{id_no}", tags="patients")
|
@router.get("/patients/{id_no}", tags="patients")
|
||||||
async def read_patientByID(id_no: str):
|
async def read_patientByID(id_no: str):
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "SELECT * FROM patients WHERE id_no=%s"
|
query = "SELECT * FROM patients WHERE id_no=%s"
|
||||||
cursor.execute(query, (id_no,))
|
cursor.execute(query, (id_no,))
|
||||||
@@ -64,7 +58,7 @@ async def read_patientByID(id_no: str):
|
|||||||
# Get List of all patients
|
# Get List of all patients
|
||||||
@router.get("/patients/", tags="patients")
|
@router.get("/patients/", tags="patients")
|
||||||
async def read_all_patients():
|
async def read_all_patients():
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "SELECT * FROM patients"
|
query = "SELECT * FROM patients"
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
@@ -91,7 +85,7 @@ async def read_all_patients():
|
|||||||
# Get List of all patients by Doctors Office
|
# Get List of all patients by Doctors Office
|
||||||
@router.get("/patients/docOffice/{docoff_id}", tags="patients")
|
@router.get("/patients/docOffice/{docoff_id}", tags="patients")
|
||||||
async def read_all_patientsby(docoff_id: str):
|
async def read_all_patientsby(docoff_id: str):
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "SELECT * FROM patients where doc_office_id=%s"
|
query = "SELECT * FROM patients where doc_office_id=%s"
|
||||||
cursor.execute(query, (docoff_id,))
|
cursor.execute(query, (docoff_id,))
|
||||||
@@ -118,7 +112,7 @@ async def read_all_patientsby(docoff_id: str):
|
|||||||
# Insert Patient into table
|
# Insert Patient into table
|
||||||
@router.post("/patients/insert/", tags="patients", status_code=201)
|
@router.post("/patients/insert/", tags="patients", status_code=201)
|
||||||
async def insertPatient(itemRequest : patientInsertRequest):
|
async def insertPatient(itemRequest : patientInsertRequest):
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "insert into patients "
|
query = "insert into patients "
|
||||||
query += "(id_no, first_name, last_name, email, cell_no, medical_aid_name, "
|
query += "(id_no, first_name, last_name, email, cell_no, medical_aid_name, "
|
||||||
@@ -147,7 +141,7 @@ async def insertPatient(itemRequest : patientInsertRequest):
|
|||||||
# Update Patient on table
|
# Update Patient on table
|
||||||
@router.put("/patients/update/", tags="patients")
|
@router.put("/patients/update/", tags="patients")
|
||||||
async def UpdatePatient(itemRequest : patientUpdateRequest):
|
async def UpdatePatient(itemRequest : patientUpdateRequest):
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "update patients "
|
query = "update patients "
|
||||||
query += "set id_no=%s, first_name=%s, last_name=%s, email=%s, cell_no=%s, medical_aid_name=%s, "
|
query += "set id_no=%s, first_name=%s, last_name=%s, email=%s, cell_no=%s, medical_aid_name=%s, "
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import mysql.connector
|
import mysql.connector
|
||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
from ..database import dbConnection
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@@ -8,18 +9,10 @@ class fileRequest(BaseModel):
|
|||||||
DocOfficeID: int
|
DocOfficeID: int
|
||||||
patientID: int
|
patientID: int
|
||||||
|
|
||||||
def dbConnect():
|
|
||||||
return mysql.connector.connect(
|
|
||||||
host="mysqldb",
|
|
||||||
user="root",
|
|
||||||
passwd="C@rtoon1995",
|
|
||||||
database="patient_manager"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Get List of all files
|
# Get List of all files
|
||||||
@router.get("/files/patients/", tags="patients_files")
|
@router.get("/files/patients/", tags="patients_files")
|
||||||
async def read_all_files():
|
async def read_all_files():
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "SELECT * FROM patient_files"
|
query = "SELECT * FROM patient_files"
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
@@ -40,7 +33,7 @@ async def read_all_files():
|
|||||||
# Get List of all files by patient
|
# Get List of all files by patient
|
||||||
@router.get("/files/patients/{patientID}", tags="patients_files")
|
@router.get("/files/patients/{patientID}", tags="patients_files")
|
||||||
async def read_all_files_by_patient(patientID: int):
|
async def read_all_files_by_patient(patientID: int):
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "SELECT * FROM patient_files where patient_id = %s"
|
query = "SELECT * FROM patient_files where patient_id = %s"
|
||||||
cursor.execute(query, (patientID,))
|
cursor.execute(query, (patientID,))
|
||||||
@@ -61,7 +54,7 @@ async def read_all_files_by_patient(patientID: int):
|
|||||||
# Get List of all files by patient & DocOffice
|
# Get List of all files by patient & DocOffice
|
||||||
@router.get("/files/patients-docOffice/", tags="patients_files")
|
@router.get("/files/patients-docOffice/", tags="patients_files")
|
||||||
async def read_all_files_by_patient(itemRequest: fileRequest):
|
async def read_all_files_by_patient(itemRequest: fileRequest):
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "select patient_files.idpatient_files, patient_files.file_path, patient_files.file_name, patient_files.patient_id, patient_files.insert_date, patients.doc_office_id "
|
query = "select patient_files.idpatient_files, patient_files.file_path, patient_files.file_name, patient_files.patient_id, patient_files.insert_date, patients.doc_office_id "
|
||||||
query += "from patient_manager.patient_files "
|
query += "from patient_manager.patient_files "
|
||||||
|
|||||||
@@ -2,17 +2,10 @@ import mysql.connector
|
|||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
from ..database import dbConnection
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
def dbConnect():
|
|
||||||
return mysql.connector.connect(
|
|
||||||
host="mysqldb",
|
|
||||||
user="root",
|
|
||||||
passwd="C@rtoon1995",
|
|
||||||
database="patient_manager"
|
|
||||||
)
|
|
||||||
|
|
||||||
class fileRequest(BaseModel):
|
class fileRequest(BaseModel):
|
||||||
DocOfficeID: int
|
DocOfficeID: int
|
||||||
patientID: int
|
patientID: int
|
||||||
@@ -31,7 +24,7 @@ class patientNoteUpdateRequest(BaseModel):
|
|||||||
# Get List of all notes
|
# Get List of all notes
|
||||||
@router.get("/notes/patients/", tags="patients_notes")
|
@router.get("/notes/patients/", tags="patients_notes")
|
||||||
async def read_all_notes():
|
async def read_all_notes():
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "SELECT * FROM patient_notes"
|
query = "SELECT * FROM patient_notes"
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
@@ -51,7 +44,7 @@ async def read_all_notes():
|
|||||||
# Get List of all notes by patient
|
# Get List of all notes by patient
|
||||||
@router.get("/notes/patients/{patientID}", tags="patients_notes")
|
@router.get("/notes/patients/{patientID}", tags="patients_notes")
|
||||||
async def read_all_patientsby(patientID: int):
|
async def read_all_patientsby(patientID: int):
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "SELECT * FROM patient_notes where patient_id = %s"
|
query = "SELECT * FROM patient_notes where patient_id = %s"
|
||||||
cursor.execute(query, (patientID,))
|
cursor.execute(query, (patientID,))
|
||||||
@@ -71,7 +64,7 @@ async def read_all_patientsby(patientID: int):
|
|||||||
# Get List of all notes by patient
|
# Get List of all notes by patient
|
||||||
@router.get("/notes/patients-docOffice/", tags="patients_notes")
|
@router.get("/notes/patients-docOffice/", tags="patients_notes")
|
||||||
async def read_all_patientsby(itemRequest: fileRequest):
|
async def read_all_patientsby(itemRequest: fileRequest):
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "select patient_notes.idpatient_notes, patient_notes.note_name, patient_notes.note_text, patient_notes.patient_id, patient_notes.insert_date, patients.doc_office_id "
|
query = "select patient_notes.idpatient_notes, patient_notes.note_name, patient_notes.note_text, patient_notes.patient_id, patient_notes.insert_date, patients.doc_office_id "
|
||||||
query += "from patient_manager.patient_notes "
|
query += "from patient_manager.patient_notes "
|
||||||
@@ -96,7 +89,7 @@ async def read_all_patientsby(itemRequest: fileRequest):
|
|||||||
@router.post("/notes/insert/", tags="patients_notes", status_code=201)
|
@router.post("/notes/insert/", tags="patients_notes", status_code=201)
|
||||||
async def insertPatientNotes(itemRequest : patientNoteInsertRequest):
|
async def insertPatientNotes(itemRequest : patientNoteInsertRequest):
|
||||||
today = date.today()
|
today = date.today()
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "insert into patient_notes "
|
query = "insert into patient_notes "
|
||||||
query += "(note_name, note_text, patient_id, insert_date) "
|
query += "(note_name, note_text, patient_id, insert_date) "
|
||||||
@@ -119,7 +112,7 @@ async def insertPatientNotes(itemRequest : patientNoteInsertRequest):
|
|||||||
@router.put("/notes/update/", tags="patients_notes")
|
@router.put("/notes/update/", tags="patients_notes")
|
||||||
async def UpdatePatient(itemRequest : patientNoteUpdateRequest):
|
async def UpdatePatient(itemRequest : patientNoteUpdateRequest):
|
||||||
today = date.today()
|
today = date.today()
|
||||||
db = dbConnect()
|
db = dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "update patient_notes "
|
query = "update patient_notes "
|
||||||
query += "set note_name=%s, note_text=%s, patient_id=%s, insert_date=%s "
|
query += "set note_name=%s, note_text=%s, patient_id=%s, insert_date=%s "
|
||||||
|
|||||||
Reference in New Issue
Block a user