Почему эта конечная точка поиска возвращает ошибку «Необрабатываемая сущность»

Я написал эту конечную точку в fastapi и sqlalchemy

но я не знаю, почему я получаю эту ошибку:

@router.get("/search_diagnosis", status_code=status.HTTP_200_OK)
async def get_diagnosis_by_name(
    user: user_dependency,
    db: db_dependency,
    patient_name: str = Query(None, description="Search by patient name"),
):
    print("*"* 100)
    if user is None:
        raise HTTPException(status_code=401, detail='Authentication Failure')

    profiles = UserProfiles.__table__

    if patient_name:
        where_clause = or_(
            profiles.c.first_name.like(f"%{patient_name}%"),
            profiles.c.last_name.like(f"%{patient_name}%")
        )
    else:
        raise HTTPException(status_code=400, detail="Please enter patient name.")

    stmt = (
        select(
            Patients.patient_id,
            Patients.registration_date,
            Diagnosis.id,
            Diagnosis.diagnosis_description,
            Diagnosis.diagnosis_date,
            Diagnosis.patient_symptoms,
            Diagnosis.doctor_id,
            Users.email,
            Users.phone,
            Users.date_of_birth,
            UserProfiles.first_name,
            UserProfiles.last_name
        )
        .join(Patients, Diagnosis.patient_id  == Patients.patient_id)
        .join(Patients, UserProfiles.user_id == Patients.user_id)
        .join(Users, UserProfiles.user_id == Users.id)
        .where(where_clause)
    )
    results = await db.execute(stmt)
    patients_data = results.fetchall()
    return [
        {
            "patient_id": row.patient_id,
            "registration_date": row.registration_date,
            "email": row.email,
            "phone": row.phone,
            "date_of_birth": row.date_of_birth,
            "first_name": row.first_name,
            "last_name": row.last_name,
        }
            for row in patients_data
    ] or []
{
  "detail": [
    {
      "type": "int_parsing",
      "loc": [
        "path",
        "patient_id"
      ],
      "msg": "Input should be a valid integer, unable to parse string as an integer",
      "input": "search_diagnosis"
    }
  ]
}

Why is it expecting it to be patient id? why the `print("*"*100)` is not outputting on the shell?
Антип
Вопрос задан25 июня 2024 г.

1 Ответ

Ваш ответ

Загрузить файл.