forked from yaso_meth/mih-project
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.
@@ -1,20 +1,13 @@
|
||||
import mysql.connector
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from ..database import dbConnection
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
def dbConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mysqldb",
|
||||
user="root",
|
||||
passwd="C@rtoon1995",
|
||||
database="patient_manager"
|
||||
)
|
||||
|
||||
# Get Doctors Office By ID
|
||||
@router.get("/docOffices/{docOffic_id}", tags="DocOffice")
|
||||
async def read_docOfficeByID(docOffic_id: int):
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM doctor_offices WHERE iddoctor_offices=%s"
|
||||
cursor.execute(query, (docOffic_id,))
|
||||
@@ -29,7 +22,7 @@ async def read_docOfficeByID(docOffic_id: int):
|
||||
# Get List of all Doctors Office
|
||||
@router.get("/docOffices/", tags="DocOffice")
|
||||
async def read_All_DoctorsOffice():
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM doctor_offices"
|
||||
cursor.execute(query)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import mysql.connector
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from ..database import dbConnection
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -29,18 +30,11 @@ class patientUpdateRequest(BaseModel):
|
||||
address: str
|
||||
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
|
||||
@router.get("/patients/{id_no}", tags="patients")
|
||||
async def read_patientByID(id_no: str):
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patients WHERE id_no=%s"
|
||||
cursor.execute(query, (id_no,))
|
||||
@@ -64,7 +58,7 @@ async def read_patientByID(id_no: str):
|
||||
# Get List of all patients
|
||||
@router.get("/patients/", tags="patients")
|
||||
async def read_all_patients():
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patients"
|
||||
cursor.execute(query)
|
||||
@@ -91,7 +85,7 @@ async def read_all_patients():
|
||||
# Get List of all patients by Doctors Office
|
||||
@router.get("/patients/docOffice/{docoff_id}", tags="patients")
|
||||
async def read_all_patientsby(docoff_id: str):
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patients where doc_office_id=%s"
|
||||
cursor.execute(query, (docoff_id,))
|
||||
@@ -118,7 +112,7 @@ async def read_all_patientsby(docoff_id: str):
|
||||
# Insert Patient into table
|
||||
@router.post("/patients/insert/", tags="patients", status_code=201)
|
||||
async def insertPatient(itemRequest : patientInsertRequest):
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "insert into patients "
|
||||
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
|
||||
@router.put("/patients/update/", tags="patients")
|
||||
async def UpdatePatient(itemRequest : patientUpdateRequest):
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "update patients "
|
||||
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
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from ..database import dbConnection
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -8,18 +9,10 @@ class fileRequest(BaseModel):
|
||||
DocOfficeID: int
|
||||
patientID: int
|
||||
|
||||
def dbConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mysqldb",
|
||||
user="root",
|
||||
passwd="C@rtoon1995",
|
||||
database="patient_manager"
|
||||
)
|
||||
|
||||
# Get List of all files
|
||||
@router.get("/files/patients/", tags="patients_files")
|
||||
async def read_all_files():
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patient_files"
|
||||
cursor.execute(query)
|
||||
@@ -40,7 +33,7 @@ async def read_all_files():
|
||||
# Get List of all files by patient
|
||||
@router.get("/files/patients/{patientID}", tags="patients_files")
|
||||
async def read_all_files_by_patient(patientID: int):
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patient_files where patient_id = %s"
|
||||
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
|
||||
@router.get("/files/patients-docOffice/", tags="patients_files")
|
||||
async def read_all_files_by_patient(itemRequest: fileRequest):
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
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 += "from patient_manager.patient_files "
|
||||
|
||||
@@ -2,17 +2,10 @@ import mysql.connector
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from datetime import date
|
||||
from ..database import dbConnection
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
def dbConnect():
|
||||
return mysql.connector.connect(
|
||||
host="mysqldb",
|
||||
user="root",
|
||||
passwd="C@rtoon1995",
|
||||
database="patient_manager"
|
||||
)
|
||||
|
||||
class fileRequest(BaseModel):
|
||||
DocOfficeID: int
|
||||
patientID: int
|
||||
@@ -31,7 +24,7 @@ class patientNoteUpdateRequest(BaseModel):
|
||||
# Get List of all notes
|
||||
@router.get("/notes/patients/", tags="patients_notes")
|
||||
async def read_all_notes():
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patient_notes"
|
||||
cursor.execute(query)
|
||||
@@ -51,7 +44,7 @@ async def read_all_notes():
|
||||
# Get List of all notes by patient
|
||||
@router.get("/notes/patients/{patientID}", tags="patients_notes")
|
||||
async def read_all_patientsby(patientID: int):
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM patient_notes where patient_id = %s"
|
||||
cursor.execute(query, (patientID,))
|
||||
@@ -71,7 +64,7 @@ async def read_all_patientsby(patientID: int):
|
||||
# Get List of all notes by patient
|
||||
@router.get("/notes/patients-docOffice/", tags="patients_notes")
|
||||
async def read_all_patientsby(itemRequest: fileRequest):
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
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 += "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)
|
||||
async def insertPatientNotes(itemRequest : patientNoteInsertRequest):
|
||||
today = date.today()
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "insert into patient_notes "
|
||||
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")
|
||||
async def UpdatePatient(itemRequest : patientNoteUpdateRequest):
|
||||
today = date.today()
|
||||
db = dbConnect()
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "update patient_notes "
|
||||
query += "set note_name=%s, note_text=%s, patient_id=%s, insert_date=%s "
|
||||
|
||||
Reference in New Issue
Block a user