Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master: Routes for Extracting Profile Data #113

Merged
merged 7 commits into from
Jan 17, 2024
1 change: 1 addition & 0 deletions app/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
33 changes: 33 additions & 0 deletions app/routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
37 changes: 37 additions & 0 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,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

Expand Down
Loading