get patient by app_id
This commit is contained in:
@@ -44,13 +44,38 @@ class patientDeleteRequest(BaseModel):
|
|||||||
id_no: str
|
id_no: str
|
||||||
doc_office_id: int
|
doc_office_id: int
|
||||||
|
|
||||||
|
# # Get Patient By ID Number
|
||||||
|
# @router.get("/patients/id/{pat_id}", tags="patients")
|
||||||
|
# async def read_patientByID(pat_id: str, session: SessionContainer = Depends(verify_session())):
|
||||||
|
# db = database.dbConnection.dbConnect()
|
||||||
|
# cursor = db.cursor()
|
||||||
|
# query = "SELECT * FROM patients WHERE idpatients=%s"
|
||||||
|
# cursor.execute(query, (pat_id,))
|
||||||
|
# item = cursor.fetchone()
|
||||||
|
# cursor.close()
|
||||||
|
# db.close()
|
||||||
|
# if item is None:
|
||||||
|
# raise HTTPException(status_code=404, detail="Item not found")
|
||||||
|
# return {"idpatients": item[0],
|
||||||
|
# "id_no": item[1],
|
||||||
|
# "first_name": item[2],
|
||||||
|
# "last_name": item[3],
|
||||||
|
# "email": item[4],
|
||||||
|
# "cell_no": item[5],
|
||||||
|
# "medical_aid_name": item[6],
|
||||||
|
# "medical_aid_no": item[7],
|
||||||
|
# "medical_aid_scheme": item[8],
|
||||||
|
# "address": item[9],
|
||||||
|
# "doc_office_id": item[10]}
|
||||||
|
|
||||||
|
|
||||||
# Get Patient By ID Number
|
# Get Patient By ID Number
|
||||||
@router.get("/patients/id/{pat_id}", tags="patients")
|
@router.get("/patients/{app_id}", tags="patients")
|
||||||
async def read_patientByID(pat_id: str, session: SessionContainer = Depends(verify_session())):
|
async def read_patientByID(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 patients WHERE idpatients=%s"
|
query = "SELECT * FROM patients WHERE app_id=%s"
|
||||||
cursor.execute(query, (pat_id,))
|
cursor.execute(query, (app_id,))
|
||||||
item = cursor.fetchone()
|
item = cursor.fetchone()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
db.close()
|
db.close()
|
||||||
@@ -66,217 +91,197 @@ async def read_patientByID(pat_id: str, session: SessionContainer = Depends(veri
|
|||||||
"medical_aid_no": item[7],
|
"medical_aid_no": item[7],
|
||||||
"medical_aid_scheme": item[8],
|
"medical_aid_scheme": item[8],
|
||||||
"address": item[9],
|
"address": item[9],
|
||||||
"doc_office_id": item[10]}
|
"medical_aid": item[10],
|
||||||
|
"medical_aid_main_member": item[11],
|
||||||
|
"medical_aid_code": item[12],
|
||||||
|
"app_id": item[13],}
|
||||||
|
|
||||||
|
# # Get Patient By ID Number
|
||||||
|
# @router.get("/patients/email/{email}", tags="patients")
|
||||||
|
# async def read_patientByID(email: str, session: SessionContainer = Depends(verify_session())):
|
||||||
|
# db = database.dbConnection.dbConnect()
|
||||||
|
# cursor = db.cursor()
|
||||||
|
# query = "SELECT * FROM patients WHERE lower(email)=%s"
|
||||||
|
# cursor.execute(query, (email.lower(),))
|
||||||
|
# item = cursor.fetchone()
|
||||||
|
# cursor.close()
|
||||||
|
# db.close()
|
||||||
|
# if item is None:
|
||||||
|
# raise HTTPException(status_code=404, detail=("Item not found for "+ email))
|
||||||
|
# return {"idpatients": item[0],
|
||||||
|
# "id_no": item[1],
|
||||||
|
# "first_name": item[2],
|
||||||
|
# "last_name": item[3],
|
||||||
|
# "email": item[4],
|
||||||
|
# "cell_no": item[5],
|
||||||
|
# "medical_aid_name": item[6],
|
||||||
|
# "medical_aid_no": item[7],
|
||||||
|
# "medical_aid_scheme": item[8],
|
||||||
|
# "address": item[9],
|
||||||
|
# "medical_aid": item[10],
|
||||||
|
# "medical_aid_main_member": item[11],
|
||||||
|
# "medical_aid_code": item[12],}
|
||||||
|
|
||||||
|
|
||||||
# Get Patient By ID Number
|
# # Get List of all patients
|
||||||
@router.get("/patients/{id_no}", tags="patients")
|
# @router.get("/patients/user/{email}", tags="patients")
|
||||||
async def read_patientByID(id_no: str, session: SessionContainer = Depends(verify_session())):
|
# async def read_all_patientsByUser(email: str, session: SessionContainer = Depends(verify_session())):
|
||||||
db = database.dbConnection.dbConnect()
|
# db = database.dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
# cursor = db.cursor()
|
||||||
query = "SELECT * FROM patients WHERE id_no=%s"
|
# #query = "SELECT * FROM patients"
|
||||||
cursor.execute(query, (id_no,))
|
# query = "Select * from patients "
|
||||||
item = cursor.fetchone()
|
# query += "inner join users "
|
||||||
cursor.close()
|
# query += "on doc_office_id = docOffice_id "
|
||||||
db.close()
|
# query += "where lower(users.email)= %s"
|
||||||
if item is None:
|
# cursor.execute(query, (email.lower(),))
|
||||||
raise HTTPException(status_code=404, detail="Item not found")
|
# items = [
|
||||||
return {"idpatients": item[0],
|
# {
|
||||||
"id_no": item[1],
|
# "idpatients": item[0],
|
||||||
"first_name": item[2],
|
# "id_no": item[1],
|
||||||
"last_name": item[3],
|
# "first_name": item[2],
|
||||||
"email": item[4],
|
# "last_name": item[3],
|
||||||
"cell_no": item[5],
|
# "email": item[4],
|
||||||
"medical_aid_name": item[6],
|
# "cell_no": item[5],
|
||||||
"medical_aid_no": item[7],
|
# "medical_aid": item[11],
|
||||||
"medical_aid_scheme": item[8],
|
# "medical_aid_name": item[6],
|
||||||
"address": item[9],
|
# "medical_aid_no": item[7],
|
||||||
"doc_office_id": item[10]}
|
# "medical_aid_main_member": item[12],
|
||||||
|
# "medical_aid_code": item[13],
|
||||||
|
# "medical_aid_scheme": item[8],
|
||||||
|
# "address": item[9],
|
||||||
|
# "doc_office_id": item[10]
|
||||||
|
# }
|
||||||
|
# for item in cursor.fetchall()
|
||||||
|
# ]
|
||||||
|
# cursor.close()
|
||||||
|
# db.close()
|
||||||
|
# return items
|
||||||
|
|
||||||
# Get Patient By ID Number
|
# # Get List of all patients
|
||||||
@router.get("/patients/{email}", tags="patients")
|
# @router.get("/patients/", tags="patients")
|
||||||
async def read_patientByID(email: str, session: SessionContainer = Depends(verify_session())):
|
# async def read_all_patients(session: SessionContainer = Depends(verify_session())):
|
||||||
db = database.dbConnection.dbConnect()
|
# db = database.dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
# cursor = db.cursor()
|
||||||
query = "SELECT * FROM patients WHERE lower(email)=%s"
|
# query = "SELECT * FROM patients"
|
||||||
cursor.execute(query, (email.lower(),))
|
# cursor.execute(query)
|
||||||
item = cursor.fetchone()
|
# items = [
|
||||||
cursor.close()
|
# {
|
||||||
db.close()
|
# "idpatients": item[0],
|
||||||
if item is None:
|
# "id_no": item[1],
|
||||||
raise HTTPException(status_code=404, detail="Item not found")
|
# "first_name": item[2],
|
||||||
return {"idpatients": item[0],
|
# "last_name": item[3],
|
||||||
"id_no": item[1],
|
# "email": item[4],
|
||||||
"first_name": item[2],
|
# "cell_no": item[5],
|
||||||
"last_name": item[3],
|
# "medical_aid_name": item[6],
|
||||||
"email": item[4],
|
# "medical_aid_no": item[7],
|
||||||
"cell_no": item[5],
|
# "medical_aid_scheme": item[8],
|
||||||
"medical_aid_name": item[6],
|
# "address": item[9],
|
||||||
"medical_aid_no": item[7],
|
# "doc_office_id": item[10]
|
||||||
"medical_aid_scheme": item[8],
|
# }
|
||||||
"address": item[9],
|
# for item in cursor.fetchall()
|
||||||
"doc_office_id": item[10]}
|
# ]
|
||||||
|
# cursor.close()
|
||||||
|
# db.close()
|
||||||
|
# return items
|
||||||
|
|
||||||
|
# # Get List of all patients by Doctors Office
|
||||||
|
# @router.get("/patients/docOffice/{docoff_id}", tags="patients")
|
||||||
|
# async def read_all_patientsby(docoff_id: str, session: SessionContainer = Depends(verify_session())):
|
||||||
|
# db = database.dbConnection.dbConnect()
|
||||||
|
# cursor = db.cursor()
|
||||||
|
# query = "SELECT * FROM patients where doc_office_id=%s"
|
||||||
|
# cursor.execute(query, (docoff_id,))
|
||||||
|
# items = [
|
||||||
|
# {
|
||||||
|
# "idpatients": item[0],
|
||||||
|
# "id_no": item[1],
|
||||||
|
# "first_name": item[2],
|
||||||
|
# "last_name": item[3],
|
||||||
|
# "email": item[4],
|
||||||
|
# "cell_no": item[5],
|
||||||
|
# "medical_aid_name": item[6],
|
||||||
|
# "medical_aid_no": item[7],
|
||||||
|
# "medical_aid_scheme": item[8],
|
||||||
|
# "address": item[9],
|
||||||
|
# "doc_office_id": item[10]
|
||||||
|
# }
|
||||||
|
# for item in cursor.fetchall()
|
||||||
|
# ]
|
||||||
|
# cursor.close()
|
||||||
|
# db.close()
|
||||||
|
# return items
|
||||||
|
|
||||||
# Get List of all patients
|
# # Insert Patient into table
|
||||||
@router.get("/patients/user/{email}", tags="patients")
|
# @router.post("/patients/insert/", tags="patients", status_code=201)
|
||||||
async def read_all_patientsByUser(email: str, session: SessionContainer = Depends(verify_session())):
|
# async def insertPatient(itemRequest : patientInsertRequest, session: SessionContainer = Depends(verify_session())):
|
||||||
db = database.dbConnection.dbConnect()
|
# db = database.dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
# cursor = db.cursor()
|
||||||
#query = "SELECT * FROM patients"
|
# query = "insert into patients "
|
||||||
query = "Select * from patients "
|
# query += "(id_no, first_name, last_name, email, cell_no, medical_aid, "
|
||||||
query += "inner join users "
|
# query += "medical_aid_main_member, medical_aid_no, medical_aid_code, medical_aid_name, "
|
||||||
query += "on doc_office_id = docOffice_id "
|
# query += "medical_aid_scheme, address, doc_office_id) "
|
||||||
query += "where lower(users.email)= %s"
|
# query += "values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
|
||||||
cursor.execute(query, (email.lower(),))
|
# patientData = (itemRequest.id_no,
|
||||||
items = [
|
# itemRequest.first_name,
|
||||||
{
|
# itemRequest.last_name,
|
||||||
"idpatients": item[0],
|
# itemRequest.email,
|
||||||
"id_no": item[1],
|
# itemRequest.cell_no,
|
||||||
"first_name": item[2],
|
# itemRequest.medical_aid,
|
||||||
"last_name": item[3],
|
# itemRequest.medical_aid_main_member,
|
||||||
"email": item[4],
|
# itemRequest.medical_aid_no,
|
||||||
"cell_no": item[5],
|
# itemRequest.medical_aid_code,
|
||||||
"medical_aid": item[11],
|
# itemRequest.medical_aid_name,
|
||||||
"medical_aid_name": item[6],
|
# itemRequest.medical_aid_scheme,
|
||||||
"medical_aid_no": item[7],
|
# itemRequest.address,
|
||||||
"medical_aid_main_member": item[12],
|
# itemRequest.doc_office_id)
|
||||||
"medical_aid_code": item[13],
|
# try:
|
||||||
"medical_aid_scheme": item[8],
|
# cursor.execute(query, patientData)
|
||||||
"address": item[9],
|
# except Exception as error:
|
||||||
"doc_office_id": item[10]
|
# raise HTTPException(status_code=404, detail="Failed to Create Record")
|
||||||
}
|
# #return {"message": "Failed to Create Record"}
|
||||||
for item in cursor.fetchall()
|
# db.commit()
|
||||||
]
|
# cursor.close()
|
||||||
cursor.close()
|
# db.close()
|
||||||
db.close()
|
# return {"message": "Successfully Created Record"}
|
||||||
return items
|
|
||||||
|
|
||||||
# Get List of all patients
|
# # Update Patient on table
|
||||||
@router.get("/patients/", tags="patients")
|
# @router.put("/patients/update/", tags="patients")
|
||||||
async def read_all_patients(session: SessionContainer = Depends(verify_session())):
|
# async def UpdatePatient(itemRequest : patientUpdateRequest, session: SessionContainer = Depends(verify_session())):
|
||||||
db = database.dbConnection.dbConnect()
|
# db = database.dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
# cursor = db.cursor()
|
||||||
query = "SELECT * FROM patients"
|
# query = "update patients "
|
||||||
cursor.execute(query)
|
# query += "set id_no=%s, first_name=%s, last_name=%s, email=%s, cell_no=%s, medical_aid=%s, "
|
||||||
items = [
|
# query += "medical_aid_main_member=%s, medical_aid_no=%s, medical_aid_code=%s, medical_aid_name=%s, "
|
||||||
{
|
# query += "medical_aid_scheme=%s, address=%s, doc_office_id=%s "
|
||||||
"idpatients": item[0],
|
# query += "where id_no=%s and doc_office_id=%s"
|
||||||
"id_no": item[1],
|
# patientData = (itemRequest.id_no,
|
||||||
"first_name": item[2],
|
# itemRequest.first_name,
|
||||||
"last_name": item[3],
|
# itemRequest.last_name,
|
||||||
"email": item[4],
|
# itemRequest.email,
|
||||||
"cell_no": item[5],
|
# itemRequest.cell_no,
|
||||||
"medical_aid_name": item[6],
|
# itemRequest.medical_aid,
|
||||||
"medical_aid_no": item[7],
|
# itemRequest.medical_aid_main_member,
|
||||||
"medical_aid_scheme": item[8],
|
# itemRequest.medical_aid_no,
|
||||||
"address": item[9],
|
# itemRequest.medical_aid_code,
|
||||||
"doc_office_id": item[10]
|
# itemRequest.medical_aid_name,
|
||||||
}
|
# itemRequest.medical_aid_scheme,
|
||||||
for item in cursor.fetchall()
|
# itemRequest.address,
|
||||||
]
|
# itemRequest.doc_office_id,
|
||||||
cursor.close()
|
# itemRequest.id_no,
|
||||||
db.close()
|
# itemRequest.doc_office_id)
|
||||||
return items
|
# try:
|
||||||
|
# cursor.execute(query, patientData)
|
||||||
|
# except Exception as error:
|
||||||
|
# raise HTTPException(status_code=404, detail="Failed to Update Record")
|
||||||
|
# #return {"query": query, "message": error}
|
||||||
|
# db.commit()
|
||||||
|
# cursor.close()
|
||||||
|
# db.close()
|
||||||
|
# return {"message": "Successfully Updated Record"}
|
||||||
|
|
||||||
# Get List of all patients by Doctors Office
|
# # delete Patient on table
|
||||||
@router.get("/patients/docOffice/{docoff_id}", tags="patients")
|
# @router.delete("/patients/delete/", tags="patients")
|
||||||
async def read_all_patientsby(docoff_id: str, session: SessionContainer = Depends(verify_session())):
|
# async def DeletePatient(itemRequest : patientDeleteRequest, session: SessionContainer = Depends(verify_session())):
|
||||||
db = database.dbConnection.dbConnect()
|
|
||||||
cursor = db.cursor()
|
|
||||||
query = "SELECT * FROM patients where doc_office_id=%s"
|
|
||||||
cursor.execute(query, (docoff_id,))
|
|
||||||
items = [
|
|
||||||
{
|
|
||||||
"idpatients": item[0],
|
|
||||||
"id_no": item[1],
|
|
||||||
"first_name": item[2],
|
|
||||||
"last_name": item[3],
|
|
||||||
"email": item[4],
|
|
||||||
"cell_no": item[5],
|
|
||||||
"medical_aid_name": item[6],
|
|
||||||
"medical_aid_no": item[7],
|
|
||||||
"medical_aid_scheme": item[8],
|
|
||||||
"address": item[9],
|
|
||||||
"doc_office_id": item[10]
|
|
||||||
}
|
|
||||||
for item in cursor.fetchall()
|
|
||||||
]
|
|
||||||
cursor.close()
|
|
||||||
db.close()
|
|
||||||
return items
|
|
||||||
|
|
||||||
# Insert Patient into table
|
|
||||||
@router.post("/patients/insert/", tags="patients", status_code=201)
|
|
||||||
async def insertPatient(itemRequest : patientInsertRequest, session: SessionContainer = Depends(verify_session())):
|
|
||||||
db = database.dbConnection.dbConnect()
|
|
||||||
cursor = db.cursor()
|
|
||||||
query = "insert into patients "
|
|
||||||
query += "(id_no, first_name, last_name, email, cell_no, medical_aid, "
|
|
||||||
query += "medical_aid_main_member, medical_aid_no, medical_aid_code, medical_aid_name, "
|
|
||||||
query += "medical_aid_scheme, address, doc_office_id) "
|
|
||||||
query += "values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
|
|
||||||
patientData = (itemRequest.id_no,
|
|
||||||
itemRequest.first_name,
|
|
||||||
itemRequest.last_name,
|
|
||||||
itemRequest.email,
|
|
||||||
itemRequest.cell_no,
|
|
||||||
itemRequest.medical_aid,
|
|
||||||
itemRequest.medical_aid_main_member,
|
|
||||||
itemRequest.medical_aid_no,
|
|
||||||
itemRequest.medical_aid_code,
|
|
||||||
itemRequest.medical_aid_name,
|
|
||||||
itemRequest.medical_aid_scheme,
|
|
||||||
itemRequest.address,
|
|
||||||
itemRequest.doc_office_id)
|
|
||||||
try:
|
|
||||||
cursor.execute(query, patientData)
|
|
||||||
except Exception as error:
|
|
||||||
raise HTTPException(status_code=404, detail="Failed to Create Record")
|
|
||||||
#return {"message": "Failed to Create Record"}
|
|
||||||
db.commit()
|
|
||||||
cursor.close()
|
|
||||||
db.close()
|
|
||||||
return {"message": "Successfully Created Record"}
|
|
||||||
|
|
||||||
# Update Patient on table
|
|
||||||
@router.put("/patients/update/", tags="patients")
|
|
||||||
async def UpdatePatient(itemRequest : patientUpdateRequest, session: SessionContainer = Depends(verify_session())):
|
|
||||||
db = database.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=%s, "
|
|
||||||
query += "medical_aid_main_member=%s, medical_aid_no=%s, medical_aid_code=%s, medical_aid_name=%s, "
|
|
||||||
query += "medical_aid_scheme=%s, address=%s, doc_office_id=%s "
|
|
||||||
query += "where id_no=%s and doc_office_id=%s"
|
|
||||||
patientData = (itemRequest.id_no,
|
|
||||||
itemRequest.first_name,
|
|
||||||
itemRequest.last_name,
|
|
||||||
itemRequest.email,
|
|
||||||
itemRequest.cell_no,
|
|
||||||
itemRequest.medical_aid,
|
|
||||||
itemRequest.medical_aid_main_member,
|
|
||||||
itemRequest.medical_aid_no,
|
|
||||||
itemRequest.medical_aid_code,
|
|
||||||
itemRequest.medical_aid_name,
|
|
||||||
itemRequest.medical_aid_scheme,
|
|
||||||
itemRequest.address,
|
|
||||||
itemRequest.doc_office_id,
|
|
||||||
itemRequest.id_no,
|
|
||||||
itemRequest.doc_office_id)
|
|
||||||
try:
|
|
||||||
cursor.execute(query, patientData)
|
|
||||||
except Exception as error:
|
|
||||||
raise HTTPException(status_code=404, detail="Failed to Update Record")
|
|
||||||
#return {"query": query, "message": error}
|
|
||||||
db.commit()
|
|
||||||
cursor.close()
|
|
||||||
db.close()
|
|
||||||
return {"message": "Successfully Updated Record"}
|
|
||||||
|
|
||||||
# delete Patient on table
|
|
||||||
@router.delete("/patients/delete/", tags="patients")
|
|
||||||
async def DeletePatient(itemRequest : patientDeleteRequest, session: SessionContainer = Depends(verify_session())):
|
|
||||||
db = database.dbConnection.dbConnect()
|
db = database.dbConnection.dbConnect()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
query = "delete from patients "
|
query = "delete from patients "
|
||||||
|
|||||||
Reference in New Issue
Block a user