update Notes API to cater fpr app_id
This commit is contained in:
@@ -11,14 +11,14 @@ from fastapi import Depends
|
|||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
class fileRequest(BaseModel):
|
class noteRequest(BaseModel):
|
||||||
DocOfficeID: int
|
DocOfficeID: int
|
||||||
patientID: int
|
patientID: int
|
||||||
|
|
||||||
class patientNoteInsertRequest(BaseModel):
|
class patientNoteInsertRequest(BaseModel):
|
||||||
note_name: str
|
note_name: str
|
||||||
note_text: str
|
note_text: str
|
||||||
patient_id: int
|
app_id: str
|
||||||
|
|
||||||
class patientNoteUpdateRequest(BaseModel):
|
class patientNoteUpdateRequest(BaseModel):
|
||||||
idpatient_notes: int
|
idpatient_notes: int
|
||||||
@@ -27,18 +27,39 @@ class patientNoteUpdateRequest(BaseModel):
|
|||||||
patient_id: int
|
patient_id: int
|
||||||
|
|
||||||
# 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(session: SessionContainer = Depends(verify_session())):
|
# async def read_all_notes(session: SessionContainer = Depends(verify_session())):
|
||||||
|
# db = database.dbConnection.dbConnect()
|
||||||
|
# cursor = db.cursor()
|
||||||
|
# query = "SELECT * FROM patient_notes"
|
||||||
|
# cursor.execute(query)
|
||||||
|
# items = [
|
||||||
|
# {
|
||||||
|
# "idpatient_notes": item[0],
|
||||||
|
# "note_name": item[1],
|
||||||
|
# "note_text": item[2],
|
||||||
|
# "insert_date": item[3],
|
||||||
|
# }
|
||||||
|
# for item in cursor.fetchall()
|
||||||
|
# ]
|
||||||
|
# cursor.close()
|
||||||
|
# db.close()
|
||||||
|
# return items
|
||||||
|
|
||||||
|
# Get List of all notes by patient
|
||||||
|
@router.get("/notes/patients/{app_id}", tags="patients_notes")
|
||||||
|
async def read_all_patientsby(app_id: str, session: SessionContainer = Depends(verify_session())):
|
||||||
db = database.dbConnection.dbConnect()
|
db = database.dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "SELECT * FROM patient_notes"
|
query = "SELECT * FROM patient_notes where app_id = %s ORDER BY insert_date DESC"
|
||||||
cursor.execute(query)
|
cursor.execute(query, (app_id,))
|
||||||
items = [
|
items = [
|
||||||
{
|
{
|
||||||
"idpatient_notes": item[0],
|
"idpatient_notes": item[0],
|
||||||
"note_name": item[1],
|
"note_name": item[1],
|
||||||
"note_text": item[2],
|
"note_text": item[2],
|
||||||
"insert_date": item[3],
|
"insert_date": item[3],
|
||||||
|
"app_id": item[4]
|
||||||
}
|
}
|
||||||
for item in cursor.fetchall()
|
for item in cursor.fetchall()
|
||||||
]
|
]
|
||||||
@@ -47,49 +68,28 @@ async def read_all_notes(session: SessionContainer = Depends(verify_session())):
|
|||||||
return items
|
return items
|
||||||
|
|
||||||
# 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-docOffice/", tags="patients_notes")
|
||||||
async def read_all_patientsby(patientID: int, session: SessionContainer = Depends(verify_session())):
|
# async def read_all_patientsby(itemRequest: noteRequest, session: SessionContainer = Depends(verify_session())):
|
||||||
db = database.dbConnection.dbConnect()
|
# db = database.dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
# cursor = db.cursor()
|
||||||
query = "SELECT * FROM patient_notes where patient_id = %s ORDER BY insert_date DESC"
|
# 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 "
|
||||||
cursor.execute(query, (patientID,))
|
# query += "from patient_manager.patient_notes "
|
||||||
items = [
|
# query += "inner join patient_manager.patients "
|
||||||
{
|
# query += "on patient_notes.patient_id = patients.idpatients "
|
||||||
"idpatient_notes": item[0],
|
# query += "where patient_notes.patient_id = %s and patients.doc_office_id = %s"
|
||||||
"note_name": item[1],
|
# cursor.execute(query, (itemRequest.patientID, itemRequest.DocOfficeID,))
|
||||||
"note_text": item[2],
|
# items = [
|
||||||
"patient_id": item[3],
|
# {
|
||||||
"insert_date": item[4]
|
# "idpatient_notes": item[0],
|
||||||
}
|
# "note_name": item[1],
|
||||||
for item in cursor.fetchall()
|
# "note_text": item[2],
|
||||||
]
|
# "insert_date": item[3],
|
||||||
cursor.close()
|
# }
|
||||||
db.close()
|
# for item in cursor.fetchall()
|
||||||
return items
|
# ]
|
||||||
|
# cursor.close()
|
||||||
# Get List of all notes by patient
|
# db.close()
|
||||||
@router.get("/notes/patients-docOffice/", tags="patients_notes")
|
# return items
|
||||||
async def read_all_patientsby(itemRequest: fileRequest, session: SessionContainer = Depends(verify_session())):
|
|
||||||
db = database.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 "
|
|
||||||
query += "inner join patient_manager.patients "
|
|
||||||
query += "on patient_notes.patient_id = patients.idpatients "
|
|
||||||
query += "where patient_notes.patient_id = %s and patients.doc_office_id = %s"
|
|
||||||
cursor.execute(query, (itemRequest.patientID, itemRequest.DocOfficeID,))
|
|
||||||
items = [
|
|
||||||
{
|
|
||||||
"idpatient_notes": item[0],
|
|
||||||
"note_name": item[1],
|
|
||||||
"note_text": item[2],
|
|
||||||
"insert_date": item[3],
|
|
||||||
}
|
|
||||||
for item in cursor.fetchall()
|
|
||||||
]
|
|
||||||
cursor.close()
|
|
||||||
db.close()
|
|
||||||
return items
|
|
||||||
|
|
||||||
# Insert Patient note into table
|
# Insert Patient note into table
|
||||||
@router.post("/notes/insert/", tags="patients_notes", status_code=201)
|
@router.post("/notes/insert/", tags="patients_notes", status_code=201)
|
||||||
@@ -98,12 +98,13 @@ async def insertPatientNotes(itemRequest : patientNoteInsertRequest, session: Se
|
|||||||
db = database.dbConnection.dbConnect()
|
db = database.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, insert_date, app_id) "
|
||||||
query += "values (%s, %s, %s, %s)"
|
query += "values (%s, %s, %s, %s)"
|
||||||
notetData = (itemRequest.note_name,
|
notetData = (itemRequest.note_name,
|
||||||
itemRequest.note_text,
|
itemRequest.note_text,
|
||||||
itemRequest.patient_id,
|
today,
|
||||||
today)
|
itemRequest.app_id,
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
cursor.execute(query, notetData)
|
cursor.execute(query, notetData)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
@@ -115,25 +116,25 @@ async def insertPatientNotes(itemRequest : patientNoteInsertRequest, session: Se
|
|||||||
return {"message": "Successfully Created Record"}
|
return {"message": "Successfully Created Record"}
|
||||||
|
|
||||||
# Update Patient note on table
|
# Update Patient note on table
|
||||||
@router.put("/notes/update/", tags="patients_notes")
|
# @router.put("/notes/update/", tags="patients_notes")
|
||||||
async def UpdatePatient(itemRequest : patientNoteUpdateRequest, session: SessionContainer = Depends(verify_session())):
|
# async def UpdatePatient(itemRequest : patientNoteUpdateRequest, session: SessionContainer = Depends(verify_session())):
|
||||||
today = date.today()
|
# today = date.today()
|
||||||
db = database.dbConnection.dbConnect()
|
# db = database.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 "
|
||||||
query += "where idpatient_notes=%s"
|
# query += "where idpatient_notes=%s"
|
||||||
notetData = (itemRequest.note_name,
|
# notetData = (itemRequest.note_name,
|
||||||
itemRequest.note_text,
|
# itemRequest.note_text,
|
||||||
itemRequest.patient_id,
|
# itemRequest.patient_id,
|
||||||
today,
|
# today,
|
||||||
itemRequest.idpatient_notes)
|
# itemRequest.idpatient_notes)
|
||||||
try:
|
# try:
|
||||||
cursor.execute(query, notetData)
|
# cursor.execute(query, notetData)
|
||||||
except Exception as error:
|
# except Exception as error:
|
||||||
raise HTTPException(status_code=404, detail="Failed to Update Record")
|
# raise HTTPException(status_code=404, detail="Failed to Update Record")
|
||||||
#return {"query": query, "message": error}
|
# #return {"query": query, "message": error}
|
||||||
db.commit()
|
# db.commit()
|
||||||
cursor.close()
|
# cursor.close()
|
||||||
db.close()
|
# db.close()
|
||||||
return {"message": "Successfully Updated Record"}
|
# return {"message": "Successfully Updated Record"}
|
||||||
Reference in New Issue
Block a user