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

Feature for Allowing Doctors to Rate Predictions #224

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions =42.0.4
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Requirement already satisfied: cryptography in ./venv/lib/python3.11/site-packages (42.0.2)
Requirement already satisfied: cffi>=1.12 in ./venv/lib/python3.11/site-packages (from cryptography) (1.16.0)
Requirement already satisfied: pycparser in ./venv/lib/python3.11/site-packages (from cffi>=1.12->cryptography) (2.21)
11 changes: 11 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,14 @@ class Feedback(Base):
receiver_id = Column(Integer, ForeignKey("doctors.doctor_id", ondelete="CASCADE"))
feedback = Column(Text, nullable=False)


class RatingPrediction(Base):
__tablename__ = "ratingprediction"

id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
diseaseinfo_id = Column(Integer, ForeignKey("diseaseinfos.id", ondelete="SET NULL"), nullable=True)
consultation_id = Column(Integer, ForeignKey("consultations.id", ondelete="SET NULL"), nullable=True)
doctor_id = Column(Integer, ForeignKey("doctors.doctor_id", ondelete="SET NULL"), nullable=True)
rating = Column(Integer, server_default='0')
symptoms = Column(ARRAY(String), nullable=False)
diseasename = Column(String(200), nullable=False)
84 changes: 84 additions & 0 deletions app/routers/consultations.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,87 @@ def get_review(id: int, db: Session = Depends(get_db), current_user: int = Depen

return schemas.JSONRatingResponse(status="success", id=current_user.id, data=result)


@router.post('/rate_prediction', response_model=schemas.JSONRatingPredictionOut)
def rate_prediction(rating_details: schemas.RatingPredictionCreate, db: Session = Depends(get_db), current_user: int = Depends(oauth2.get_current_user)):
if rating_details.doctor_id != current_user.id:
error_response = {
"status": "error",
"id": -1,
"data": "You are not authorized to perform this action."
}
return JSONResponse(content=error_response, status_code=400)

doctor = db.query(models.Doctor).filter(models.Doctor.doctor_id == rating_details.doctor_id).first()
if not doctor:
error_response = {
"status": "error",
"id": -1,
"data": f"Doctor with id: {rating_details.doctor_id} not found."
}
return JSONResponse(content=error_response, status_code=404)

diseaseinfo = db.query(models.DiseaseInfo).filter(models.DiseaseInfo.id == rating_details.diseaseinfo_id).first()
if not diseaseinfo:
error_response = {
"status": "error",
"id": -1,
"data": f"Disease Info with id: {rating_details.diseaseinfo_id} not found."
}
return JSONResponse(content=error_response, status_code=404)

rating = models.RatingPrediction(**rating_details.model_dump())
db.add(rating)
db.commit()

final_rating_details = schemas.RatingPredictionOut(diseaseinfo=diseaseinfo, doctor=doctor, rating=rating_details.rating, symptoms=rating_details.symptoms, diseasename=rating_details.diseasename)
return schemas.JSONRatingPredictionOut(status="success", id=rating_details.doctor_id, data=final_rating_details)


@router.post('/get_rating_prediction', response_model=schemas.JSONListRatingPredictionOut)
def get_rating_prediction(db: Session = Depends(get_db), current_user: int = Depends(oauth2.get_current_user)):

if current_user.is_superuser != True:
error_response = {
"status": "error",
"id": -1,
"data": "You are not authorized to perform this action."
}
return JSONResponse(content=error_response, status_code=400)

ratings = db.query(models.RatingPrediction).all()

if not ratings:
error_response = {
"status": "error",
"id": -1,
"data": "There are Currently no Ratings"
}
return JSONResponse(content=error_response, status_code=404)

rating_predictions = []

for details in ratings:

doctor = db.query(models.Doctor).filter(models.Doctor.doctor_id == details.doctor_id).first()
if not doctor:
error_response = {
"status": "error",
"id": -1,
"data": f"Doctor with id: {details.doctor_id} not found."
}
return JSONResponse(content=error_response, status_code=404)

diseaseinfo = db.query(models.DiseaseInfo).filter(models.DiseaseInfo.id == details.diseaseinfo_id).first()
if not diseaseinfo:
error_response = {
"status": "error",
"id": -1,
"data": f"Disease Info with id: {details.diseaseinfo_id} not found."
}
return JSONResponse(content=error_response, status_code=404)

rating_details = schemas.RatingPredictionOut(diseaseinfo=diseaseinfo, doctor=doctor, rating=details.rating, symptoms=details.symptoms, diseasename=details.diseasename)
rating_predictions.append(rating_details)

return schemas.JSONListRatingPredictionOut(status="success", id=current_user.id, data=rating_predictions)
4 changes: 2 additions & 2 deletions app/routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def signup_patient(user: schemas.PatientCreate, db: Session = Depends(get_db)):
db.refresh(new_user)

# Accessing the ID assigned to new_user
new_patient = models.Patient(patient_id=new_user.id, **user.dict(exclude={'email', 'password'}))
new_patient = models.Patient(patient_id=new_user.id, **user.model_dump(exclude={'email', 'password'}))
db.add(new_patient)
db.commit()
db.refresh(new_patient)
Expand Down Expand Up @@ -73,7 +73,7 @@ def signup_doctor(user: schemas.DoctorCreate, db: Session = Depends(get_db)):
db.refresh(new_user)

# Accessing the ID assigned to new_user
new_doctor = models.Doctor(doctor_id=new_user.id, **user.dict(exclude={'email', 'password'}))
new_doctor = models.Doctor(doctor_id=new_user.id, **user.model_dump(exclude={'email', 'password'}))
db.add(new_doctor)
db.commit()
db.refresh(new_doctor)
Expand Down
36 changes: 36 additions & 0 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,5 +638,41 @@ class Config:
class JSONAdminDiseaseInfo(JSONResult):
data: list[AdminDiseaseInfo]

class Config:
from_attributes = True


# Disease Prediction Information

class RatingPredictionCreate(BaseModel):
doctor_id: int
diseaseinfo_id: int
consultation_id: int
rating: int
symptoms: List[str]
diseasename: str


class RatingPredictionOut(BaseModel):
diseaseinfo: DiseaseOut
doctor: DoctorOut
rating: int
symptoms: List[str]
diseasename: str

class Config:
from_attributes = True


class JSONRatingPredictionOut(JSONResult):
data: RatingPredictionOut

class Config:
from_attributes = True


class JSONListRatingPredictionOut(JSONResult):
data: List[RatingPredictionOut]

class Config:
from_attributes = True
Loading