Add API to insert into DB
This commit is contained in:
@@ -2,6 +2,7 @@ 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
|
from ..database import dbConnection
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@@ -9,6 +10,11 @@ class fileRequest(BaseModel):
|
|||||||
DocOfficeID: int
|
DocOfficeID: int
|
||||||
patientID: int
|
patientID: int
|
||||||
|
|
||||||
|
class fileInsertRequest(BaseModel):
|
||||||
|
file_path: str
|
||||||
|
file_name: str
|
||||||
|
patient_id: int
|
||||||
|
|
||||||
# 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():
|
||||||
@@ -77,3 +83,26 @@ async def read_all_files_by_patient(itemRequest: fileRequest):
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
db.close()
|
db.close()
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
# Insert Patient note into table
|
||||||
|
@router.post("/files/insert/", tags="patients_notes", status_code=201)
|
||||||
|
async def insertPatientFiles(itemRequest : fileInsertRequest):
|
||||||
|
today = date.today()
|
||||||
|
db = dbConnection.dbConnect()
|
||||||
|
cursor = db.cursor()
|
||||||
|
query = "insert into patient_files "
|
||||||
|
query += "(file_path, file_name, patient_id, insert_date) "
|
||||||
|
query += "values (%s, %s, %s, %s)"
|
||||||
|
notetData = (itemRequest.file_path,
|
||||||
|
itemRequest.file_name,
|
||||||
|
itemRequest.patient_id,
|
||||||
|
today)
|
||||||
|
try:
|
||||||
|
cursor.execute(query, notetData)
|
||||||
|
except Exception as error:
|
||||||
|
#raise HTTPException(status_code=404, detail="Failed to Create Record")
|
||||||
|
return {"message": error}
|
||||||
|
db.commit()
|
||||||
|
cursor.close()
|
||||||
|
db.close()
|
||||||
|
return {"message": "Successfully Created file Record"}
|
||||||
|
|||||||
Reference in New Issue
Block a user