From 6293adc0dcd43e24ea90f7eba6456ecfb85e1072 Mon Sep 17 00:00:00 2001 From: yaso-meth Date: Tue, 25 Jun 2024 17:02:11 +0200 Subject: [PATCH] Add API to insert into DB --- backend/routers/patients_files.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/backend/routers/patients_files.py b/backend/routers/patients_files.py index 713a1a93..aba928cb 100644 --- a/backend/routers/patients_files.py +++ b/backend/routers/patients_files.py @@ -2,6 +2,7 @@ import mysql.connector from fastapi import APIRouter, HTTPException from pydantic import BaseModel from ..database import dbConnection +from datetime import date router = APIRouter() @@ -9,6 +10,11 @@ class fileRequest(BaseModel): DocOfficeID: int patientID: int +class fileInsertRequest(BaseModel): + file_path: str + file_name: str + patient_id: int + # Get List of all files @router.get("/files/patients/", tags="patients_files") async def read_all_files(): @@ -76,4 +82,27 @@ async def read_all_files_by_patient(itemRequest: fileRequest): ] cursor.close() db.close() - return items \ No newline at end of file + 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"}