diff --git a/=42.0.4 b/=42.0.4 new file mode 100644 index 0000000..b466fda --- /dev/null +++ b/=42.0.4 @@ -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) diff --git a/app/models.py b/app/models.py index 08684df..26168ed 100644 --- a/app/models.py +++ b/app/models.py @@ -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) diff --git a/app/routers/consultations.py b/app/routers/consultations.py index 73215d9..4e67916 100644 --- a/app/routers/consultations.py +++ b/app/routers/consultations.py @@ -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) diff --git a/app/routers/user.py b/app/routers/user.py index e821e21..589024f 100644 --- a/app/routers/user.py +++ b/app/routers/user.py @@ -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) @@ -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) diff --git a/app/schemas.py b/app/schemas.py index 8f272bf..a5e4748 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -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 \ No newline at end of file