From 361ca3a1b2202bae1512208212e738c2cd23a3c9 Mon Sep 17 00:00:00 2001 From: tebogoyungmercykay Date: Wed, 17 Jan 2024 22:56:58 +0200 Subject: [PATCH 1/3] Routes for Extracting Profile Data --- app/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models.py b/app/models.py index ed96393..7716501 100644 --- a/app/models.py +++ b/app/models.py @@ -1,3 +1,4 @@ +import datetime from sqlalchemy import Column, Integer, String, Boolean, ForeignKey, DateTime, Text, Float, ARRAY from sqlalchemy.orm import relationship from sqlalchemy.sql.expression import text From c9cb62f54b0cdb3bb7884367e9302ae681b7a69a Mon Sep 17 00:00:00 2001 From: tebogoyungmercykay Date: Wed, 17 Jan 2024 22:57:03 +0200 Subject: [PATCH 2/3] Routes for Extracting Profile Data --- app/schemas.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/schemas.py b/app/schemas.py index e2b82b3..f70bc7b 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -242,6 +242,43 @@ class Config: from_attributes = True +class PatientProfile(BaseModel): + name: str + surname: str + dob: datetime + address: str + mobile_no: int + gender: str + + class Config: + from_attributes = True + + +class DoctorProfile(PatientProfile): + qualification: str + registration_no: str + year_of_registration: datetime + state_medical_council: str + specialization: str + + class Config: + from_attributes = True + + +class JSONPatientProfile(JSONResult): + data: PatientProfile + + class Config: + from_attributes = True + + +class JSONDoctorProfile(JSONResult): + data: DoctorProfile + + class Config: + from_attributes = True + + class JSONUserData(JSONResult): data: UserData From 039f6c3d3887891858df8ac96466774fb8c7deed Mon Sep 17 00:00:00 2001 From: tebogoyungmercykay Date: Wed, 17 Jan 2024 22:57:06 +0200 Subject: [PATCH 3/3] Routes for Extracting Profile Data --- app/routers/user.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/routers/user.py b/app/routers/user.py index 8c89c3d..e821e21 100644 --- a/app/routers/user.py +++ b/app/routers/user.py @@ -170,3 +170,36 @@ def savedata(id: int, update_user: schemas.UserUpdate, db: Session = Depends(get return { "status": "success", "id": -1, "data": "User Data Successfully Updated." } + +@router.post('/patient_profile/{id}', response_model=schemas.JSONPatientProfile) +def patient_profile(id: int, db: Session = Depends(get_db), current_user: int = Depends(oauth2.get_current_user)): + + patient = db.query(models.Patient).filter(models.Patient.patient_id == id).first() + + if not patient: + error_response = { + "status": "error", + "id": -1, + "data": f"Details for Patient Profile with id: {id} does not exist" + } + + return JSONResponse(content=error_response, status_code=404) + + return schemas.JSONPatientProfile(status="success", id=patient.patient_id, data=patient) + + +@router.post('/doctor_profile/{id}', response_model=schemas.JSONDoctorProfile) +def doctor_profile(id: int, db: Session = Depends(get_db), current_user: int = Depends(oauth2.get_current_user)): + + doctor = db.query(models.Doctor).filter(models.Doctor.doctor_id == id).first() + + if not doctor: + error_response = { + "status": "error", + "id": -1, + "data": f"Details for Doctor Profile with id: {id} does not exist" + } + + return JSONResponse(content=error_response, status_code=404) + + return schemas.JSONDoctorProfile(status="success", id=doctor.doctor_id, data=doctor)