From 3d4d4efa77241212ffd3da5748837cca0f5c00b0 Mon Sep 17 00:00:00 2001 From: yaso-meth Date: Wed, 31 Jul 2024 15:54:09 +0200 Subject: [PATCH] Delete file on DB --- backend/routers/patients_files.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/backend/routers/patients_files.py b/backend/routers/patients_files.py index 992f06cc..3b15f38d 100644 --- a/backend/routers/patients_files.py +++ b/backend/routers/patients_files.py @@ -11,9 +11,8 @@ from fastapi import Depends router = APIRouter() -class fileRequest(BaseModel): - DocOfficeID: int - patientID: int +class fileDeleteRequest(BaseModel): + idpatient_files: int class fileInsertRequest(BaseModel): file_path: str @@ -89,6 +88,25 @@ async def read_all_patient_files_by_app_id(app_id: str, session: SessionContaine # db.close() # return items +# Delete Patient note on table +@router.delete("/files/delete/", tags=["Patients Files"]) +async def Delete_Patient_File(itemRequest : fileDeleteRequest, session: SessionContainer = Depends(verify_session())): #session: SessionContainer = Depends(verify_session()) + # today = date.today() + db = database.dbConnection.dbConnect() + cursor = db.cursor() + query = "delete from patient_files " + query += "where idpatient_files=%s" + # notetData = (itemRequest.idpatient_notes) + try: + cursor.execute(query, (str(itemRequest.idpatient_files),)) + except Exception as error: + raise HTTPException(status_code=404, detail="Failed to Delete Record") + #return {"query": query, "message": error} + db.commit() + cursor.close() + db.close() + return {"message": "Successfully deleted Record"} + # Insert Patient note into table @router.post("/files/insert/", tags=["Patients Files"], status_code=201) async def insert_Patient_Files(itemRequest : fileInsertRequest, session: SessionContainer = Depends(verify_session())):